Java Code Examples for net.minecraft.inventory.ItemStackHelper#loadAllItems()

The following examples show how to use net.minecraft.inventory.ItemStackHelper#loadAllItems() . 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: TileEntitySaltFurnace.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound) {
    super.readFromNBT(par1NBTTagCompound);
    this.furnaceItemStacks = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
    ItemStackHelper.loadAllItems(par1NBTTagCompound, this.furnaceItemStacks);

    this.furnaceBurnTime = par1NBTTagCompound.getShort("BurnTime");
    this.cookTime = par1NBTTagCompound.getShort("CookTime");
    this.currentItemBurnTime = par1NBTTagCompound.getShort("ItemBurnTime");
    ;
    this.nigariTank.readFromNBT(par1NBTTagCompound.getCompoundTag("NigariTank"));

    if (par1NBTTagCompound.hasKey("CustomName")) {
        this.customName = par1NBTTagCompound.getString("CustomName");
    }
}
 
Example 2
Source File: TileEntityTFStorage.java    From TofuCraftReload with MIT License 5 votes vote down vote up
public void readPacketNBT(NBTTagCompound cmp) {
    this.inventory =
            NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
    ItemStackHelper.loadAllItems(cmp, this.inventory);

    this.workload = cmp.getInteger("workload");
    this.current_workload = cmp.getInteger("current");

    this.tank.readFromNBT(cmp.getCompoundTag("Tank"));
}
 
Example 3
Source File: TileEntityMapleCauldron.java    From Sakura_mod with MIT License 5 votes vote down vote up
public void readPacketNBT(NBTTagCompound cmp) {
    this.inventory =
            NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
    ItemStackHelper.loadAllItems(cmp, this.inventory);
    this.mapleTime = cmp.getInteger("MapleTime");
    this.cookTime = cmp.getInteger("CookTime");
    this.tank.readFromNBT(cmp.getCompoundTag("Tank"));
}
 
Example 4
Source File: TileEntityDistillation.java    From Sakura_mod with MIT License 5 votes vote down vote up
public void readPacketNBT(NBTTagCompound cmp) {
	this.inventory = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
	ItemStackHelper.loadAllItems(cmp, this.inventory);

	processTimer = cmp.getInteger(TAG_PROCESS);

	this.tank.readFromNBT(cmp.getCompoundTag("Tank"));
	this.resultTank.readFromNBT(cmp.getCompoundTag("ResultTank"));
}
 
Example 5
Source File: TileEntityStoneMortar.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);
    this.inventorySlotItemStack =
            NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
    ItemStackHelper.loadAllItems(compound, this.inventorySlotItemStack);

    this.maxprocessTimer = compound.getInteger("maxProcessTimer");
    this.processTimer = compound.getInteger("processTimer");
}
 
Example 6
Source File: TileEntityBarrel.java    From Sakura_mod with MIT License 5 votes vote down vote up
public void readPacketNBT(NBTTagCompound cmp) {
	this.inventory = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
	ItemStackHelper.loadAllItems(cmp, this.inventory);

	processTimer = cmp.getInteger(TAG_PROCESS);

	this.tank.readFromNBT(cmp.getCompoundTag("Tank"));
	this.resultTank.readFromNBT(cmp.getCompoundTag("ResultTank"));
}
 
Example 7
Source File: TileEntityCampfirePot.java    From Sakura_mod with MIT License 5 votes vote down vote up
public void readPacketNBT(NBTTagCompound cmp) {
    this.inventory =
            NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
    ItemStackHelper.loadAllItems(cmp, this.inventory);
    this.burnTime = cmp.getInteger("BurnTime");
    this.cookTime = cmp.getInteger("CookTime");
    this.tank.readFromNBT(cmp.getCompoundTag("Tank"));
}
 
Example 8
Source File: Peek.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Post event) {
	if (!(event.getGui() instanceof ContainerScreen<?>)) return;
	ContainerScreen<?> screen = (ContainerScreen<?>) event.getGui();
	
	if (screen.getSlotUnderMouse() == null) return;
	if (!(screen.getSlotUnderMouse().getStack().getItem() instanceof BlockItem)) return;
	if (!(((BlockItem) screen.getSlotUnderMouse().getStack().getItem()).getBlock() instanceof ContainerBlock)) return;
	
	NonNullList<ItemStack> items = NonNullList.withSize(27, new ItemStack(Items.AIR));
	CompoundNBT nbt = screen.getSlotUnderMouse().getStack().getTag();
	
	if (nbt != null && nbt.contains("BlockEntityTag")) {
		CompoundNBT itemnbt = nbt.getCompound("BlockEntityTag");
		if (itemnbt.contains("Items")) ItemStackHelper.loadAllItems(itemnbt, items);
	}
	
	GlStateManager.translatef(0.0F, 0.0F, 500.0F);
	Block block = ((BlockItem) screen.getSlotUnderMouse().getStack().getItem()).getBlock();
	
	int count = block instanceof HopperBlock || block instanceof DispenserBlock ? 18 : 0;
	for (ItemStack i: items) {
		if (count > 26) break;
		int x = event.getMouseX() + 8 + (17 * (count % 9));
		int y = event.getMouseY() - 68 + (17 * (count / 9));
		
		if (i.getItem() != Items.AIR) {
			Screen.fill(x, y, x+17, y+17, 0x90000000);
			Screen.fill(x, y, x+17, y+1, 0xff000000); Screen.fill(x, y+1, x+1, y+17, 0xff000000);
			Screen.fill(x+16, y+1, x+17, y+17, 0xff000000); Screen.fill(x+1, y+16, x+17, y+17, 0xff000000);
		}
		
	    mc.getItemRenderer().renderItemAndEffectIntoGUI(i, x, y);
	    mc.getItemRenderer().renderItemOverlayIntoGUI(mc.fontRenderer, i, x, y, i.getCount() > 1 ? i.getCount() + "" : "");
		count++;
	}
}
 
Example 9
Source File: CmdPeek.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(String command, String[] args) throws Exception {
	ItemStack item = mc.player.inventory.getCurrentItem();
	
	if (!(item.getItem() instanceof BlockItem)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	if (!(((BlockItem) item.getItem()).getBlock() instanceof ContainerBlock)) {
		BleachLogger.errorMessage("Must be holding a containter to peek.");
		return;
	}
	
	NonNullList<ItemStack> items = NonNullList.withSize(27, new ItemStack(Items.AIR));
	CompoundNBT nbt = item.getTag();
	
	if (nbt != null && nbt.contains("BlockEntityTag")) {
		CompoundNBT itemnbt = nbt.getCompound("BlockEntityTag");
		if (itemnbt.contains("Items")) ItemStackHelper.loadAllItems(itemnbt, items);
	}
	
	Inventory inv = new Inventory(items.toArray(new ItemStack[27]));
	
	BleachQueue.queue.add(() -> {
		mc.displayGuiScreen(new ShulkerBoxScreen(
				new ShulkerBoxContainer(420, mc.player.inventory, inv),
				mc.player.inventory,
				item.getDisplayName()));
	});
}
 
Example 10
Source File: TileEntityMinecoprocessor.java    From Minecoprocessors with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound c) {
  super.readFromNBT(c);
  processor.readFromNBT(c.getCompoundTag(NBT_PROCESSOR));

  codeItemStacks = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
  ItemStackHelper.loadAllItems(c, codeItemStacks);

  loadTime = c.getShort(NBT_LOAD_TIME);

  if (c.hasKey(NBT_CUSTOM_NAME, 8)) {
    this.customName = c.getString(NBT_CUSTOM_NAME);
  }
}
 
Example 11
Source File: Utils.java    From ForgeHax with MIT License 5 votes vote down vote up
public static List<ItemStack> getShulkerContents(ItemStack stack) { // TODO: move somewhere else
  NonNullList<ItemStack> contents = NonNullList.withSize(27, ItemStack.EMPTY);
  NBTTagCompound compound = stack.getTagCompound();
  if (compound != null && compound.hasKey("BlockEntityTag", 10)) {
    NBTTagCompound tags = compound.getCompoundTag("BlockEntityTag");
    if (tags.hasKey("Items", 9)) {
      // load in the items
      ItemStackHelper.loadAllItems(tags, contents);
    }
  }
  return contents;
}
 
Example 12
Source File: TileEntitySenderBaseInvenotried.java    From TofuCraftReload with MIT License 4 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    this.inventory = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
    ItemStackHelper.loadAllItems(compound, this.inventory);
    super.readFromNBT(compound);
}
 
Example 13
Source File: TileEntityProcessorBaseInventoried.java    From TofuCraftReload with MIT License 4 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound compound) {
    this.inventory = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
    ItemStackHelper.loadAllItems(compound, this.inventory);
    super.readFromNBT(compound);
}
 
Example 14
Source File: ShulkerPreviewModule.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
@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;
            }
        }
    }
}