Java Code Examples for net.minecraft.util.NonNullList#get()
The following examples show how to use
net.minecraft.util.NonNullList#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockSnowTest.java From customstuff4 with GNU General Public License v3.0 | 7 votes |
@Test public void test_getDrops() { ContentBlockSnow content = new ContentBlockSnow(); content.id = "test_getDrops"; content.snowball = new WrappedItemStackConstant(new ItemStack(Items.APPLE, 3)); content.drop = Attribute.constant(new BlockDrop[] {new BlockDrop(new WrappedItemStackConstant(new ItemStack(Items.STICK)), IntRange.create(2, 2))}); Block block = content.createBlock(); NonNullList<ItemStack> drops = NonNullList.create(); block.getDrops(drops, null, null, block.getDefaultState().withProperty(BlockSnow.LAYERS, 5), 0); ItemStack drop1 = drops.get(0); ItemStack drop2 = drops.get(1); assertEquals(2, drops.size()); assertSame(Items.APPLE, drop1.getItem()); assertEquals(18, drop1.getCount()); assertSame(Items.STICK, drop2.getItem()); assertEquals(2, drop2.getCount()); }
Example 2
Source File: MachineManager.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
public static MachineFuel findMatchingFuel(ResourceLocation list, NonNullList<ItemStack> input) { if (list.toString().equals("minecraft:vanilla")) { if (input.size() == 1 && !input.get(0).isEmpty()) { ItemStack stack = input.get(0); int burnTime = TileEntityFurnace.getItemBurnTime(stack); if (burnTime > 0) return new VanillaFurnaceFuel(stack, burnTime); } return MachineFuel.EMPTY; } return findMatchingFuel(getInstance(list).fuels, input); }
Example 3
Source File: MachineRecipeDeserializerTest.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@Test public void test_deserializer() { MachineRecipeImpl recipe = gson.fromJson("{" + "\"recipeList\": \"cs4examplemod:machine\"," + "\"input\": [\"minecraft:apple\", \"minecraft:gold_ingot\"]," + "\"output\": \"minecraft:golden_apple\"," + "\"inputFluid\": [\"water@500\"]," + "\"cookTime\": 400" + "}", MachineRecipeImpl.class); recipe.init(InitPhase.PRE_INIT, null); List<RecipeInput> inputItems = recipe.getRecipeInput(); List<FluidStack> inputFluids = recipe.getFluidRecipeInput(); NonNullList<MachineRecipeOutput> outputs = recipe.getOutputs(); MachineRecipeOutput output = outputs.get(0); assertEquals(400, recipe.getCookTime()); assertEquals(2, inputItems.size()); assertEquals(1, inputFluids.size()); assertEquals(1, outputs.size()); assertEquals(1, output.getWeight()); assertEquals(1, output.getOutputItems().size()); assertEquals(0, output.getOutputFluids().size()); }
Example 4
Source File: MachineRecipeDeserializerTest.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@Test public void test_multipleOutputs_noWeight() { MachineRecipeImpl recipe = gson.fromJson("{" + "\"recipeList\": \"cs4examplemod:machine\"," + "\"output\": [" + "\"minecraft:golden_apple\"," + "\"minecraft:iron_ingot\"" + "]" + "}", MachineRecipeImpl.class); recipe.init(InitPhase.PRE_INIT, null); NonNullList<MachineRecipeOutput> outputs = recipe.getOutputs(); assertEquals(2, outputs.size()); MachineRecipeOutput output0 = outputs.get(0); MachineRecipeOutput output1 = outputs.get(1); assertEquals(1, output0.getOutputItems().size()); assertEquals(1, output1.getOutputItems().size()); assertEquals(0, output0.getOutputFluids().size()); assertEquals(0, output1.getOutputFluids().size()); assertEquals(1, output0.getWeight()); assertEquals(1, output1.getWeight()); }
Example 5
Source File: RecipeShapedFluid.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
@Override public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) { NonNullList<ItemStack> remains = ForgeHooks.defaultRecipeGetRemainingItems(inv); for (int i = 0; i < height * width; i++) { ItemStack stack = inv.getStackInSlot(i); NonNullList<Ingredient> matchedIngredients = this.input; if (matchedIngredients.get(i) instanceof IngredientFluidStack) { if (!stack.isEmpty()) { ItemStack copy = stack.copy(); copy.setCount(1); remains.set(i, copy); } IFluidHandlerItem handler = FluidUtil.getFluidHandler(remains.get(i)); if (handler != null) { FluidStack fluid = ((IngredientFluidStack) matchedIngredients.get(i)).getFluid(); handler.drain(fluid.amount, true); remains.set(i, handler.getContainer()); } } } return remains; }
Example 6
Source File: CraftingHelper.java From malmo with MIT License | 6 votes |
/** * Inspect a player's inventory to see whether they have enough items to form the supplied list of ItemStacks.<br> * The ingredients list MUST be amalgamated such that no two ItemStacks contain the same type of item. * * @param player * @param ingredients an amalgamated list of ingredients * @return true if the player's inventory contains sufficient quantities of all the required items. */ public static boolean playerHasIngredients(EntityPlayerSP player, List<ItemStack> ingredients) { NonNullList<ItemStack> main = player.inventory.mainInventory; NonNullList<ItemStack> arm = player.inventory.armorInventory; for (ItemStack isIngredient : ingredients) { int target = isIngredient.getCount(); for (int i = 0; i < main.size() + arm.size() && target > 0; i++) { ItemStack isPlayer = (i >= main.size()) ? arm.get(i - main.size()) : main.get(i); if (isPlayer != null && isIngredient != null && itemStackIngredientsMatch(isPlayer, isIngredient)) target -= isPlayer.getCount(); } if (target > 0) return false; // Don't have enough of this. } return true; }
Example 7
Source File: CraftingHelper.java From malmo with MIT License | 6 votes |
/** * Inspect a player's inventory to see whether they have enough items to form the supplied list of ItemStacks.<br> * The ingredients list MUST be amalgamated such that no two ItemStacks contain the same type of item. * * @param player * @param ingredients an amalgamated list of ingredients * @return true if the player's inventory contains sufficient quantities of all the required items. */ public static boolean playerHasIngredients(EntityPlayerMP player, List<ItemStack> ingredients) { NonNullList<ItemStack> main = player.inventory.mainInventory; NonNullList<ItemStack> arm = player.inventory.armorInventory; for (ItemStack isIngredient : ingredients) { int target = isIngredient.getCount(); for (int i = 0; i < main.size() + arm.size() && target > 0; i++) { ItemStack isPlayer = (i >= main.size()) ? arm.get(i - main.size()) : main.get(i); if (isPlayer != null && isIngredient != null && itemStackIngredientsMatch(isPlayer, isIngredient)) target -= isPlayer.getCount(); } if (target > 0) return false; // Don't have enough of this. } return true; }
Example 8
Source File: NBTUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
/** * Writes the ItemStacks in <b>items</b> to a new NBTTagList and returns that list. * @param items */ @Nonnull public static NBTTagList createTagListForItems(NonNullList<ItemStack> items) { NBTTagList nbtTagList = new NBTTagList(); final int invSlots = items.size(); // Write all the ItemStacks into a TAG_List for (int slotNum = 0; slotNum < invSlots; slotNum++) { ItemStack stack = items.get(slotNum); if (stack.isEmpty() == false) { NBTTagCompound tag = storeItemStackInTag(stack, new NBTTagCompound()); if (invSlots <= 127) { tag.setByte("Slot", (byte) slotNum); } else { tag.setShort("Slot", (short) slotNum); } nbtTagList.appendTag(tag); } } return nbtTagList; }
Example 9
Source File: ItemUtils.java From TofuCraftReload with MIT License | 5 votes |
public static void growOrSetInventoryItem(NonNullList<ItemStack> inventory, ItemStack toSet, int index) { ItemStack stack = inventory.get(index); if (stack.isEmpty()) { inventory.set(index, toSet); } else { stack.grow(toSet.getCount()); } }
Example 10
Source File: SlotItemHandlerCraftResult.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public ItemStack onTake(EntityPlayer player, ItemStack stack) { this.onCrafting(stack); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(player); NonNullList<ItemStack> remainingItems = CraftingManager.getRemainingItems(this.craftMatrix, player.getEntityWorld()); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null); for (int i = 0; i < remainingItems.size(); i++) { ItemStack stackInSlot = this.craftMatrix.getStackInSlot(i); ItemStack remainingItemsInSlot = remainingItems.get(i); if (stackInSlot.isEmpty() == false) { this.craftMatrix.decrStackSize(i, 1); stackInSlot = this.craftMatrix.getStackInSlot(i); } if (remainingItemsInSlot.isEmpty() == false) { if (stackInSlot.isEmpty()) { this.craftMatrix.setInventorySlotContents(i, remainingItemsInSlot); } else if (ItemStack.areItemsEqual(stackInSlot, remainingItemsInSlot) && ItemStack.areItemStackTagsEqual(stackInSlot, remainingItemsInSlot)) { remainingItemsInSlot.grow(stackInSlot.getCount()); this.craftMatrix.setInventorySlotContents(i, remainingItemsInSlot); } else if (this.player.inventory.addItemStackToInventory(remainingItemsInSlot) == false) { this.player.dropItem(remainingItemsInSlot, false); } } } return stack; }
Example 11
Source File: InventoryUtils.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
/** * Checks if there is a matching ItemStack in the provided array of stacks */ public static boolean matchingStackFoundOnList(NonNullList<ItemStack> list, @Nonnull ItemStack stackTemplate, boolean ignoreMeta, boolean ignoreNbt) { Item item = stackTemplate.getItem(); int meta = stackTemplate.getMetadata(); final int size = list.size(); for (int i = 0; i < size; i++) { ItemStack stackTmp = list.get(i); if (stackTmp.isEmpty() || stackTmp.getItem() != item) { continue; } if (ignoreMeta == false && (meta != OreDictionary.WILDCARD_VALUE && stackTmp.getMetadata() != meta)) { continue; } if (ignoreNbt == false && ItemStack.areItemStackTagsEqual(stackTemplate, stackTmp) == false) { continue; } return true; } return false; }
Example 12
Source File: SlotCraftingTFC.java From TFC2 with GNU General Public License v3.0 | 5 votes |
@Override public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack) { this.onCrafting(stack); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(thePlayer); NonNullList<ItemStack> nonnulllist = CraftingManagerTFC.getInstance().getRemainingItems(this.craftMatrix, thePlayer.world); net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null); for (int i = 0; i < nonnulllist.size(); ++i) { ItemStack itemstack = this.craftMatrix.getStackInSlot(i); ItemStack itemstack1 = (ItemStack)nonnulllist.get(i); if (!itemstack.isEmpty()) { this.craftMatrix.decrStackSize(i, 1); itemstack = this.craftMatrix.getStackInSlot(i); } if (!itemstack1.isEmpty()) { if (itemstack.isEmpty()) { this.craftMatrix.setInventorySlotContents(i, itemstack1); } else if (ItemStack.areItemsEqual(itemstack, itemstack1) && ItemStack.areItemStackTagsEqual(itemstack, itemstack1)) { itemstack1.grow(itemstack.getCount()); this.craftMatrix.setInventorySlotContents(i, itemstack1); } else if (!this.player.inventory.addItemStackToInventory(itemstack1)) { this.player.dropItem(itemstack1, false); } } } return stack; }
Example 13
Source File: CraftingHelper.java From malmo with MIT License | 5 votes |
/** * Manually attempt to remove ingredients from the player's inventory.<br> * * @param player * @param ingredients */ public static void removeIngredientsFromPlayer(EntityPlayerMP player, List<ItemStack> ingredients) { NonNullList<ItemStack> main = player.inventory.mainInventory; NonNullList<ItemStack> arm = player.inventory.armorInventory; for (ItemStack isIngredient : ingredients) { int target = isIngredient.getCount(); for (int i = 0; i < main.size() + arm.size() && target > 0; i++) { ItemStack isPlayer = (i >= main.size()) ? arm.get(i - main.size()) : main.get(i); if (itemStackIngredientsMatch(isPlayer, isIngredient)) { if (target >= isPlayer.getCount()) { // Consume this stack: target -= isPlayer.getCount(); if (i >= main.size()) arm.get(i - main.size()).setCount(0); else main.get(i).setCount(0); } else { isPlayer.setCount(isPlayer.getCount() - target); target = 0; } } } ItemStack resultForReward = isIngredient.copy(); RewardForDiscardingItemImplementation.LoseItemEvent event = new RewardForDiscardingItemImplementation.LoseItemEvent(resultForReward); MinecraftForge.EVENT_BUS.post(event); } }
Example 14
Source File: RecipeShapelessFluid.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
@Override public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) { NonNullList<ItemStack> remains = super.getRemainingItems(inv); for (int i = 0; i < remains.size(); i++) { ItemStack stack = inv.getStackInSlot(i); ItemStack remain = remains.get(i); if (!stack.isEmpty() && remain.isEmpty() && stack.getItem() instanceof UniversalBucket) { ItemStack empty = ((UniversalBucket) stack.getItem()).getEmpty(); if (!empty.isEmpty()) remains.set(i, empty.copy()); } } return remains; }
Example 15
Source File: MachineRecipeDeserializerTest.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
@Test public void test_multipleOutputs_withWeight() { MachineRecipeImpl recipe = gson.fromJson("{" + "\"recipeList\": \"cs4examplemod:machine\"," + "\"output\": [" + "{ " + "\"items\": [\"minecraft:golden_apple\", \"minecraft:gold_nugget\"]," + "\"weight\": 25" + "}," + "\"minecraft:iron_ingot\"" + "]" + "}", MachineRecipeImpl.class); recipe.init(InitPhase.PRE_INIT, null); NonNullList<MachineRecipeOutput> outputs = recipe.getOutputs(); assertEquals(2, outputs.size()); MachineRecipeOutput output0 = outputs.get(0); MachineRecipeOutput output1 = outputs.get(1); assertEquals(2, output0.getOutputItems().size()); assertEquals(1, output1.getOutputItems().size()); assertEquals(0, output0.getOutputFluids().size()); assertEquals(0, output1.getOutputFluids().size()); assertEquals(25, output0.getWeight()); assertEquals(1, output1.getWeight()); }
Example 16
Source File: ShapedRecipe.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
private boolean isSameInputs(NonNullList<Ingredient> targetInput) { Object[] sourceInput = getRecipeInput(); for (int i = 0; i < targetInput.size(); i++) { Ingredient target = targetInput.get(i); Object source = sourceInput[i]; if (!ItemHelper.isSameRecipeInput(target, source)) return false; } return true; }
Example 17
Source File: GTHelperStack.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
public static ItemStack getStackFromOreDict(String entry) { ItemStack stack = null; if (OreDictionary.doesOreNameExist(entry)) { NonNullList<ItemStack> list = OreDictionary.getOres(entry, false); if (!list.isEmpty()) { stack = list.get(0); } } return stack; }
Example 18
Source File: ArmorHooks.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public static void damageArmor(float damage, EntityLivingBase entity, NonNullList<ItemStack> inventory, DamageSource damageSource) { double armorDamage = Math.max(1.0F, damage / 4.0F); for (int i = 0; i < inventory.size(); i++) { ItemStack itemStack = inventory.get(i); if (itemStack.getItem() instanceof IArmorItem) { ((IArmorItem) itemStack.getItem()).damageArmor(entity, itemStack, damageSource, (int) armorDamage, i); if (inventory.get(i).getCount() == 0) { inventory.set(i, ItemStack.EMPTY); } } } }
Example 19
Source File: ShapelessOreRecipeTFC.java From TFC2 with GNU General Public License v3.0 | 4 votes |
/** * Used to check if a recipe matches current crafting inventory */ @Override public boolean matches(NonNullList<ItemStack> var1, World world) { ArrayList<Object> required = new ArrayList<Object>(input); for (int x = 0; x < var1.size(); x++) { ItemStack slot = var1.get(x); if (slot != ItemStack.EMPTY) { boolean inRecipe = false; Iterator<Object> req = required.iterator(); while (req.hasNext()) { boolean match = false; Object next = req.next(); if (next instanceof ItemStack) { match = OreDictionary.itemMatches((ItemStack)next, slot, false); } else if (next instanceof List) { Iterator<ItemStack> itr = ((List<ItemStack>)next).iterator(); while (itr.hasNext() && !match) { match = OreDictionary.itemMatches(itr.next(), slot, false); } } if (match) { if(!tempMatch(slot)) { break; } inRecipe = true; required.remove(next); break; } } if (!inRecipe) { return false; } } } return required.isEmpty(); }
Example 20
Source File: ShulkerPreviewModule.java From seppuku with GNU General Public License v3.0 | 4 votes |
@Listener public void onRenderTooltip(EventRenderTooltip event) { if (event.getItemStack() == null) return; final Minecraft mc = Minecraft.getMinecraft(); if (event.getItemStack().getItem() instanceof ItemShulkerBox) { ItemStack shulker = event.getItemStack(); NBTTagCompound tagCompound = shulker.getTagCompound(); if (tagCompound != null && tagCompound.hasKey("BlockEntityTag", 10)) { NBTTagCompound blockEntityTag = tagCompound.getCompoundTag("BlockEntityTag"); if (blockEntityTag.hasKey("Items", 9)) { event.setCanceled(true); // cancel rendering the old tooltip NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(27, ItemStack.EMPTY); ItemStackHelper.loadAllItems(blockEntityTag, nonnulllist); // load the itemstacks from the tag to the list // store mouse/event coords int x = event.getX(); int y = event.getY(); // translate to mouse x, y GlStateManager.translate(x + 10, y - 5, 0); GlStateManager.disableLighting(); GlStateManager.disableDepth(); // background RenderUtil.drawRect(-3, -mc.fontRenderer.FONT_HEIGHT - 4, 9 * 16 + 3, 3 * 16 + 3, 0x99101010); RenderUtil.drawRect(-2, -mc.fontRenderer.FONT_HEIGHT - 3, 9 * 16 + 2, 3 * 16 + 2, 0xFF202020); RenderUtil.drawRect(0, 0, 9 * 16, 3 * 16, 0xFF101010); // text mc.fontRenderer.drawStringWithShadow(shulker.getDisplayName(), 0, -mc.fontRenderer.FONT_HEIGHT - 1, 0xFFFFFFFF); GlStateManager.enableDepth(); mc.getRenderItem().zLevel = 150.0F; RenderHelper.enableGUIStandardItemLighting(); // loop through items in shulker inventory for (int i = 0; i < nonnulllist.size(); i++) { ItemStack itemStack = nonnulllist.get(i); int offsetX = (i % 9) * 16; int offsetY = (i / 9) * 16; mc.getRenderItem().renderItemAndEffectIntoGUI(itemStack, offsetX, offsetY); mc.getRenderItem().renderItemOverlayIntoGUI(mc.fontRenderer, itemStack, offsetX, offsetY, null); } RenderHelper.disableStandardItemLighting(); mc.getRenderItem().zLevel = 0.0F; GlStateManager.enableLighting(); // reverse the translate GlStateManager.translate(-(x + 10), -(y - 5), 0); } } if(this.middleClick.getValue()) { if (Mouse.isButtonDown(2)) { if (!this.clicked) { final BlockShulkerBox shulkerBox = (BlockShulkerBox) Block.getBlockFromItem(shulker.getItem()); if (shulkerBox != null) { final NBTTagCompound tag = shulker.getTagCompound(); if (tag != null && tag.hasKey("BlockEntityTag", 10)) { final NBTTagCompound entityTag = tag.getCompoundTag("BlockEntityTag"); final TileEntityShulkerBox te = new TileEntityShulkerBox(); te.setWorld(mc.world); te.readFromNBT(entityTag); mc.displayGuiScreen(new GuiShulkerBox(mc.player.inventory, te)); } } } this.clicked = true; } else { this.clicked = false; } } } }