Java Code Examples for net.minecraft.inventory.IInventory

The following are top voted examples for showing how to use net.minecraft.inventory.IInventory. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: CustomWorldGen   File: LootTable.java   View source code 6 votes vote down vote up
public void fillInventory(IInventory inventory, Random rand, LootContext context)
{
    List<ItemStack> list = this.generateLootForPools(rand, context);
    List<Integer> list1 = this.getEmptySlotsRandomized(inventory, rand);
    this.shuffleItems(list, list1.size(), rand);

    for (ItemStack itemstack : list)
    {
        if (list1.isEmpty())
        {
            LOGGER.warn("Tried to over-fill a container");
            return;
        }

        if (itemstack == null)
        {
            inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), (ItemStack)null);
        }
        else
        {
            inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), itemstack);
        }
    }
}
 
Example 2
Project: rezolve   File: TileEntityBase.java   View source code 6 votes vote down vote up
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {

    if (this.customName != null) {
        compound.setString("CustomName", this.getCustomName());
    }
    
	if (this instanceof IInventory) {
		RezolveNBT.writeInventory(compound, (IInventory)this);
	}
	
	if (this.storedEnergy >= 0)
		compound.setInteger("RF", this.storedEnergy);
	
	return super.writeToNBT(compound);
}
 
Example 3
Project: BaseClient   File: TileEntityHopper.java   View source code 6 votes vote down vote up
/**
 * Pulls from the specified slot in the inventory and places in any available slot in the hopper. Returns true if
 * the entire stack was moved
 */
private static boolean pullItemFromSlot(IHopper hopper, IInventory inventoryIn, int index, EnumFacing direction)
{
    ItemStack itemstack = inventoryIn.getStackInSlot(index);

    if (itemstack != null && canExtractItemFromSlot(inventoryIn, itemstack, index, direction))
    {
        ItemStack itemstack1 = itemstack.copy();
        ItemStack itemstack2 = putStackInInventoryAllSlots(hopper, inventoryIn.decrStackSize(index, 1), (EnumFacing)null);

        if (itemstack2 == null || itemstack2.stackSize == 0)
        {
            inventoryIn.markDirty();
            return true;
        }

        inventoryIn.setInventorySlotContents(index, itemstack1);
    }

    return false;
}
 
Example 4
Project: Backmemed   File: BlockRailDetector.java   View source code 6 votes vote down vote up
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
    if (((Boolean)blockState.getValue(POWERED)).booleanValue())
    {
        List<EntityMinecartCommandBlock> list = this.<EntityMinecartCommandBlock>findMinecarts(worldIn, pos, EntityMinecartCommandBlock.class, new Predicate[0]);

        if (!list.isEmpty())
        {
            return ((EntityMinecartCommandBlock)list.get(0)).getCommandBlockLogic().getSuccessCount();
        }

        List<EntityMinecart> list1 = this.<EntityMinecart>findMinecarts(worldIn, pos, EntityMinecart.class, new Predicate[] {EntitySelectors.HAS_INVENTORY});

        if (!list1.isEmpty())
        {
            return Container.calcRedstoneFromInventory((IInventory)list1.get(0));
        }
    }

    return 0;
}
 
Example 5
Project: ToolBelt   File: BeltFinder.java   View source code 6 votes vote down vote up
@Nullable
public BeltGetter findStack(EntityPlayer player)
{
    IInventory playerInv = player.inventory;
    for (int i = 0; i < playerInv.getSizeInventory(); i++)
    {
        ItemStack inSlot = playerInv.getStackInSlot(i);
        if (inSlot.getCount() > 0)
        {
            if (inSlot.getItem() instanceof ItemToolBelt)
            {
                return new InventoryBeltGetter(player, i);
            }
        }
    }

    return null;
}
 
Example 6
Project: ToolBelt   File: ContainerBelt.java   View source code 6 votes vote down vote up
private void bindPlayerInventory(IInventory playerInventory, int blockedSlot)
{
    for (int l = 0; l < 3; ++l)
    {
        for (int j1 = 0; j1 < 9; ++j1)
        {
            int index = j1 + l * 9 + 9;
            this.addSlotToContainer(
                    blockedSlot == index
                            ? new SlotLocked(playerInventory, index, 8 + j1 * 18, l * 18 + 51)
                            : new Slot(playerInventory, index, 8 + j1 * 18, l * 18 + 51)
            );
        }
    }

    for (int i1 = 0; i1 < 9; ++i1)
    {
        this.addSlotToContainer(
                blockedSlot == i1
                        ? new SlotLocked(playerInventory, i1, 8 + i1 * 18, 109)
                        : new Slot(playerInventory, i1, 8 + i1 * 18, 109)
        );
    }
}
 
Example 7
Project: Technical   File: TileEntityGrabber.java   View source code 6 votes vote down vote up
protected int getSlotToPushTo(IInventory inventory) {
	int slot = 0;
	for(; slot < inventory.getSizeInventory(); ++slot) {
		if(debug) {
			FMLLog.log(Level.INFO, "E " + (inventory.getStackInSlot(slot) != null));
			if(inventory.getStackInSlot(slot) != null) {
				FMLLog.log(Level.INFO, "E " + slot + " " + inventory.getStackInSlot(slot).toString());
				FMLLog.log(Level.INFO, "E-true " + (inventory.getStackInSlot(slot) == null));
				FMLLog.log(Level.INFO, "E-true " + (inventory.getStackInSlot(slot).getItem() == blockItemStack.getItem()));
				FMLLog.log(Level.INFO, "E-true " + (inventory.getStackInSlot(slot).getItemDamage() == blockItemStack.getItemDamage()));
				FMLLog.log(Level.INFO, "E-true " + inventory.getStackInSlot(slot).stackSize + " < " + inventory.getStackInSlot(slot).getItem().getItemStackLimit(inventory.getStackInSlot(slot)));
			}
		}
		if(inventory.getStackInSlot(slot) == null || inventory.getStackInSlot(slot).getItem() == blockItemStack.getItem() && inventory.getStackInSlot(slot).getItemDamage() == blockItemStack.getItemDamage()
				&& inventory.getStackInSlot(slot).stackSize < inventory.getStackInSlot(slot).getItem().getItemStackLimit(inventory.getStackInSlot(slot)))
			break;
	}

	if(slot > inventory.getSizeInventory() - 1)
		slot = inventory.getSizeInventory() - 1;

	if(debug)
		FMLLog.log(Level.INFO, "E" + slot);

	return slot;
}
 
Example 8
Project: Thermionics   File: ContainerMotor.java   View source code 6 votes vote down vote up
public ContainerMotor(IInventory player, IInventory container, TileEntity te) {
	super(player, container);
	
	this.setTitleColor(0xFFFFFFFF);
	this.setColor(0xCC707070);
	
	WGridPanel panel = new WGridPanel();
	super.setRootPanel(panel);
	
	if (Thermionics.isAprilFools()) {
		panel.add(new WPlasma(), 0, 0, 9, 4);
	}
	
	panel.add(new WPBar(container, 3, 2, 4), 1, 1);
	
	panel.add(new WBar(
			new ResourceLocation("thermionics","textures/gui/progress.heat.bg.png"),
			new ResourceLocation("thermionics","textures/gui/progress.heat.bar.png"),
			container, 0, 1, WBar.Direction.RIGHT
			), 1, 2, 7, 1);
	
	panel.add(this.createPlayerInventoryPanel(), 0, 4);
}
 
Example 9
Project: BaseClient   File: TileEntityHopper.java   View source code 6 votes vote down vote up
/**
 * Pulls from the specified slot in the inventory and places in any available slot in the hopper. Returns true if
 * the entire stack was moved
 */
private static boolean pullItemFromSlot(IHopper hopper, IInventory inventoryIn, int index, EnumFacing direction)
{
    ItemStack itemstack = inventoryIn.getStackInSlot(index);

    if (itemstack != null && canExtractItemFromSlot(inventoryIn, itemstack, index, direction))
    {
        ItemStack itemstack1 = itemstack.copy();
        ItemStack itemstack2 = putStackInInventoryAllSlots(hopper, inventoryIn.decrStackSize(index, 1), (EnumFacing)null);

        if (itemstack2 == null || itemstack2.stackSize == 0)
        {
            inventoryIn.markDirty();
            return true;
        }

        inventoryIn.setInventorySlotContents(index, itemstack1);
    }

    return false;
}
 
Example 10
Project: Technical   File: TileEntityGrabber.java   View source code 6 votes vote down vote up
protected boolean pushItemIInventory(IInventory inventory, int slot) {
	if(inventory.getStackInSlot(slot) == null) {
		if(debug)
			FMLLog.log(Level.INFO, "F");
		inventory.setInventorySlotContents(slot, blockItemStack.copy());
		blockItemStack = null;
		markDirty = true;
	} else if(inventory.getStackInSlot(slot).getItem() == blockItemStack.getItem() && inventory.getStackInSlot(slot).stackSize < inventory.getInventoryStackLimit() && inventory.getStackInSlot(slot).stackSize < inventory.getStackInSlot(slot).getMaxStackSize()) {
		if(debug)
			FMLLog.log(Level.INFO, "G");
		blockItemStack.stackSize = blockItemStack.stackSize + inventory.getStackInSlot(slot).stackSize;
		inventory.setInventorySlotContents(slot, blockItemStack.copy());
		blockItemStack = null;
		markDirty = true;
	} else {
		if(debug)
			FMLLog.log(Level.INFO, "Ga");
	}
	return markDirty;
}
 
Example 11
Project: StructPro   File: Tiles.java   View source code 6 votes vote down vote up
/**
 * Load inventory data from NBT tag
 * @param inventory Target inventory
 * @param tag tag to load
 * @param seed Loading seed
 */
private static void load(IInventory inventory, NBTTagCompound tag, long seed) {
    if (tag == null || !Configurator.NATIVE_LOOT) {
        return;
    }
    Random random = new Random(seed);
    NBTTagList items = tag.getTagList("Items", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < items.tagCount() && i < inventory.getSizeInventory(); ++i) {
        NBTTagCompound stackTag = items.getCompoundTagAt(i);
        String itemName = stackTag.getString("id").replaceAll(".*:", "");
        itemName = itemName.isEmpty() ? String.valueOf(stackTag.getShort("id")) : itemName;
        Pattern iPattern = Pattern.compile(Pattern.quote(itemName), Pattern.CASE_INSENSITIVE);
        UItem item = Utils.select(UItems.items.select(iPattern), random.nextLong());
        byte count = items.getCompoundTagAt(i).getByte("Count");
        int damage = items.getCompoundTagAt(i).getShort("Damage");
        int slot = stackTag.hasKey("Slot", Constants.NBT.TAG_BYTE) ? stackTag.getByte("Slot") : i;
        slot = (slot < 0 || slot >= inventory.getSizeInventory()) ? i : slot;
        if (item != null && count > 0 && UItems.getPossibleMeta(item).contains(damage)) {
            inventory.setInventorySlotContents(slot, new UItemStack(item, count, damage).getItemStack());
        }
    }
}
 
Example 12
Project: bit-client   File: ModuleChestStealer.java   View source code 6 votes vote down vote up
private int getItemRandom(GuiChest chest) {
    try {
        if (Wrapper.player_inventory() == null) return -1;
        List<Integer> items = new ArrayList<>();
        for (int i = 0; i < ((IInventory) ReflectionUtil.getFieldValue("field_147015_w", chest)).func_70302_i_(); i++) {
            ItemStack stack = ((IInventory) ReflectionUtil.getFieldValue("field_147015_w", chest)).func_70301_a(i);
            if (stack != null && ((itemFilter.getValue() && !ItemUtil.isUseless(stack, itemFilterMode.getCurrent())) || !itemFilter.getValue()))
                items.add(i);
        }
        if (items.isEmpty()) return -1;
        Collections.shuffle(items);
        return items.get(0);
    } catch (Exception e) {
        return -1;
    }
}
 
Example 13
Project: DecompiledMinecraft   File: EntityPlayerMP.java   View source code 6 votes vote down vote up
public void displayVillagerTradeGui(IMerchant villager)
{
    this.getNextWindowId();
    this.openContainer = new ContainerMerchant(this.inventory, villager, this.worldObj);
    this.openContainer.windowId = this.currentWindowId;
    this.openContainer.onCraftGuiOpened(this);
    IInventory iinventory = ((ContainerMerchant)this.openContainer).getMerchantInventory();
    IChatComponent ichatcomponent = villager.getDisplayName();
    this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "minecraft:villager", ichatcomponent, iinventory.getSizeInventory()));
    MerchantRecipeList merchantrecipelist = villager.getRecipes(this);

    if (merchantrecipelist != null)
    {
        PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
        packetbuffer.writeInt(this.currentWindowId);
        merchantrecipelist.writeToBuf(packetbuffer);
        this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|TrList", packetbuffer));
    }
}
 
Example 14
Project: StructPro   File: Tiles.java   View source code 6 votes vote down vote up
/**
 * Load inventory data from NBT tag
 * @param inventory Target inventory
 * @param tag tag to load
 * @param seed Loading seed
 */
private static void load(IInventory inventory, NBTTagCompound tag, long seed) {
    if (tag == null || !Configurator.NATIVE_LOOT) {
        return;
    }
    Random random = new Random(seed);
    NBTTagList items = tag.getTagList("Items", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < items.tagCount() && i < inventory.getSizeInventory(); ++i) {
        NBTTagCompound stackTag = items.getCompoundTagAt(i);
        String itemName = stackTag.getString("id").replaceAll(".*:", "");
        itemName = itemName.isEmpty() ? String.valueOf(stackTag.getShort("id")) : itemName;
        Pattern iPattern = Pattern.compile(Pattern.quote(itemName), Pattern.CASE_INSENSITIVE);
        UItem item = Utils.select(UItems.items.select(iPattern), random.nextLong());
        byte count = items.getCompoundTagAt(i).getByte("Count");
        int damage = items.getCompoundTagAt(i).getShort("Damage");
        int slot = stackTag.hasKey("Slot", Constants.NBT.TAG_BYTE) ? stackTag.getByte("Slot") : i;
        slot = (slot < 0 || slot >= inventory.getSizeInventory()) ? i : slot;
        if (item != null && count > 0 && UItems.getPossibleMeta(item).contains(damage)) {
            inventory.setInventorySlotContents(slot, new UItemStack(item, count, damage).getItemStack());
        }
    }
}
 
Example 15
Project: Loot-Slash-Conquer   File: CustomLootTable.java   View source code 5 votes vote down vote up
@Override
public void fillInventory(IInventory inventory, Random rand, LootContext context)
{
	TileEntityChest chest = (TileEntityChest) inventory;
    CustomLootContext.Builder context$builder = new CustomLootContext.Builder((WorldServer) chest.getWorld());
    context$builder.withChestPos(chest.getPos());
    CustomLootContext customContext = context$builder.build();
	
    List<ItemStack> list = this.generateLootForPools(rand, customContext);
    List<Integer> list1 = this.getEmptySlotsRandomized(inventory, rand);
    this.shuffleItems(list, list1.size(), rand);

    for (ItemStack itemstack : list)
    {
        if (list1.isEmpty())
        {
        	LootSlashConquer.LOGGER.warn("Tried to over-fill a container");
            return;
        }
        
        if (itemstack.isEmpty())
        {
            inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), ItemStack.EMPTY);
        }
        else
        {
            inventory.setInventorySlotContents(((Integer)list1.remove(list1.size() - 1)).intValue(), itemstack);
        }
    }
}
 
Example 16
Project: BetterBeginningsReborn   File: ContainerSimpleWorkbench.java   View source code 5 votes vote down vote up
/**
 * Callback for when the crafting matrix is changed.
 */
@Override
public void onCraftMatrixChanged(IInventory inventory)
{
	craftResult.setInventorySlotContents(0,
										 CraftingManager.findMatchingRecipe(craftMatrix, worldObj).getCraftingResult(craftMatrix));
}
 
Example 17
Project: Technical   File: TileEntityGrabberFiltering.java   View source code 5 votes vote down vote up
protected boolean pushItemIInventory(IInventory inventory, int slot) {
	if(blockItemStack.stackSize > 1) {
		ItemStack oldStack = blockItemStack.copy();
		ItemStack newStack = blockItemStack.splitStack(1);
		
		if(inventory.getStackInSlot(slot) == null) {
			if(debug)
				FMLLog.log(Level.INFO, "fF");
			inventory.setInventorySlotContents(slot, newStack.copy());
			newStack = null;
			markDirty = true;
		} else if(inventory.getStackInSlot(slot).getItem() == newStack.getItem() && inventory.getStackInSlot(slot).stackSize < inventory.getInventoryStackLimit() && inventory.getStackInSlot(slot).stackSize < inventory.getStackInSlot(slot).getMaxStackSize()) {
			if(debug)
				FMLLog.log(Level.INFO, "fG");
			newStack.stackSize += inventory.getStackInSlot(slot).stackSize;
			inventory.setInventorySlotContents(slot, newStack.copy());
			newStack = null;
			markDirty = true;
		} else {
			if(debug)
				FMLLog.log(Level.INFO, "fGa");
		}
		
		if(newStack == null || newStack.stackSize == 0) {
			if(debug)
				FMLLog.log(Level.INFO, "fDa");
			markDirty = true;
		} else {
			blockItemStack = oldStack;
		}
	}
	return markDirty;
}
 
Example 18
Project: BaseClient   File: TileEntityHopper.java   View source code 5 votes vote down vote up
/**
 * Returns false if the specified IInventory contains any items
 */
private static boolean isInventoryEmpty(IInventory inventoryIn, EnumFacing side)
{
    if (inventoryIn instanceof ISidedInventory)
    {
        ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
        int[] aint = isidedinventory.getSlotsForFace(side);

        for (int i = 0; i < aint.length; ++i)
        {
            if (isidedinventory.getStackInSlot(aint[i]) != null)
            {
                return false;
            }
        }
    }
    else
    {
        int j = inventoryIn.getSizeInventory();

        for (int k = 0; k < j; ++k)
        {
            if (inventoryIn.getStackInSlot(k) != null)
            {
                return false;
            }
        }
    }

    return true;
}
 
Example 19
Project: rezolve   File: TileBlockBase.java   View source code 5 votes vote down vote up
@Override
  public void breakBlock(World world, BlockPos pos, IBlockState state) {

  	// Drop any items we have if necessary
TileEntity te = world.getTileEntity(pos);
if (te != null && te instanceof IInventory) {
	InventoryHelper.dropInventoryItems(world, pos, (IInventory)te);
}
   
      super.breakBlock(world, pos, state);
      world.removeTileEntity(pos);
  }
 
Example 20
Project: BaseClient   File: GuiBeacon.java   View source code 5 votes vote down vote up
public GuiBeacon(InventoryPlayer playerInventory, IInventory tileBeaconIn)
{
    super(new ContainerBeacon(playerInventory, tileBeaconIn));
    this.tileBeacon = tileBeaconIn;
    this.xSize = 230;
    this.ySize = 219;
}
 
Example 21
Project: rezolve   File: RezolveNBT.java   View source code 5 votes vote down vote up
public static void readInventory(NBTTagCompound nbt, IInventory inventory) {
	if (nbt == null)
		return;
	
	if (!nbt.hasKey("Items"))
		return;
	
    NBTTagList list = nbt.getTagList("Items", 10);
    for (int i = 0; i < list.tagCount(); ++i) {
        NBTTagCompound stackTag = list.getCompoundTagAt(i);
        int slot = stackTag.getByte("Slot") & 255;
        
        inventory.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(stackTag));
    }
}
 
Example 22
Project: Mods   File: ContainerRecover.java   View source code 5 votes vote down vote up
public ContainerRecover(IInventory playerInventory, ItemStackHandler dispenserInventoryIn)
{
    this.lostItemsHandler = dispenserInventoryIn;

    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 9; ++j)
        {
            this.addSlotToContainer(new SlotItemHandler(dispenserInventoryIn, j + i * 9, 8 + j * 18, 18 + i * 18){
            	public boolean isItemValid(@Nullable ItemStack stack)
                {
                    return false;
                }
            });
        }
    }

    for (int k = 0; k < 3; ++k)
    {
        for (int i1 = 0; i1 < 9; ++i1)
        {
            this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 27, 8 + i1 * 18, 85 + k * 18));
        }
    }

    for (int l = 0; l < 9; ++l)
    {
        this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 143));
    }
}
 
Example 23
Project: EndermanEvolution   File: EntityFrienderman.java   View source code 5 votes vote down vote up
public int testInventoryInsertion(IInventory inventory, ItemStack item) {
	if (item.isEmpty() || item.getCount() == 0) {
		return 0;
	}
	if (inventory == null) {
		return 0;
	}
	int slotCount = inventory.getSizeInventory();
	int itemSizeCounter = item.getCount();
	for (int i = 0; i < slotCount && itemSizeCounter > 0; i++) {

		if (!inventory.isItemValidForSlot(i, item)) {
			continue;
		}
		ItemStack inventorySlot = inventory.getStackInSlot(i);
		if (inventorySlot.isEmpty()) {
			itemSizeCounter -= Math.min(Math.min(itemSizeCounter, inventory.getInventoryStackLimit()), item.getMaxStackSize());
		}
		else if (areMergeCandidates(item, inventorySlot)) {

			int space = inventorySlot.getMaxStackSize() - inventorySlot.getCount();
			itemSizeCounter -= Math.min(itemSizeCounter, space);
		}
	}
	if (itemSizeCounter != item.getCount()) {
		itemSizeCounter = Math.max(itemSizeCounter, 0);
		return item.getCount() - itemSizeCounter;
	}
	return 0;
}
 
Example 24
Project: UniversalRemote   File: EntityPlayerMPProxy.java   View source code 5 votes vote down vote up
@Override
public void displayGUIChest(IInventory chestInventory) {
	if (m_realPlayer == null) {
		super.displayGUIChest(chestInventory);
	} else {
		syncToRealPlayer();
		m_realPlayer.displayGUIChest(chestInventory);
		syncPublicFieldsFromReal();
	}
}
 
Example 25
Project: BetterBeginningsReborn   File: SlotAdvancedCrafting.java   View source code 5 votes vote down vote up
public SlotAdvancedCrafting(EntityPlayer player, ContainerDoubleWorkbench container_, InventoryCrafting matrix,
    IInventory resultInv, IInventory addedMats, int id, int x, int y)
   {
super(resultInv, id, x, y);
container = container_;
thePlayer = player;
craftMatrix = matrix;
additionalMaterials = addedMats;
   }
 
Example 26
Project: Minecoprocessors   File: GuiMinecoprocessor.java   View source code 5 votes vote down vote up
public GuiMinecoprocessor(IInventory playerInv, TileEntityMinecoprocessor te) {
  super(new ContainerMinecoprocessor(playerInv, te));
  this.playerInventory = playerInv;
  this.minecoprocessor = te;
  INSTANCE = this;
  Minecoprocessors.NETWORK.sendToServer(new MessageEnableGuiUpdates(minecoprocessor.getPos(), true));
}
 
Example 27
Project: BaseClient   File: TileEntityHopper.java   View source code 5 votes vote down vote up
/**
 * Returns false if the inventory has any room to place items in
 */
private boolean isInventoryFull(IInventory inventoryIn, EnumFacing side)
{
    if (inventoryIn instanceof ISidedInventory)
    {
        ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
        int[] aint = isidedinventory.getSlotsForFace(side);

        for (int k = 0; k < aint.length; ++k)
        {
            ItemStack itemstack1 = isidedinventory.getStackInSlot(aint[k]);

            if (itemstack1 == null || itemstack1.stackSize != itemstack1.getMaxStackSize())
            {
                return false;
            }
        }
    }
    else
    {
        int i = inventoryIn.getSizeInventory();

        for (int j = 0; j < i; ++j)
        {
            ItemStack itemstack = inventoryIn.getStackInSlot(j);

            if (itemstack == null || itemstack.stackSize != itemstack.getMaxStackSize())
            {
                return false;
            }
        }
    }

    return true;
}
 
Example 28
Project: Defier   File: CompressorContainer.java   View source code 5 votes vote down vote up
public CompressorContainer(IInventory playerInventory, CompressorTileEntity te) {
	this.te = te;

	IItemHandler itemHandler = this.te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
	addSlotToContainer(new SlotItemHandler(itemHandler, 0, 80, 34));

	addPlayerSlots(playerInventory);
}
 
Example 29
Project: DecompiledMinecraft   File: TileEntityHopper.java   View source code 5 votes vote down vote up
/**
 * Attempts to place the passed stack in the inventory, using as many slots as required. Returns leftover items
 */
public static ItemStack putStackInInventoryAllSlots(IInventory inventoryIn, ItemStack stack, EnumFacing side)
{
    if (inventoryIn instanceof ISidedInventory && side != null)
    {
        ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
        int[] aint = isidedinventory.getSlotsForFace(side);

        for (int k = 0; k < aint.length && stack != null && stack.stackSize > 0; ++k)
        {
            stack = insertStack(inventoryIn, stack, aint[k], side);
        }
    }
    else
    {
        int i = inventoryIn.getSizeInventory();

        for (int j = 0; j < i && stack != null && stack.stackSize > 0; ++j)
        {
            stack = insertStack(inventoryIn, stack, j, side);
        }
    }

    if (stack != null && stack.stackSize == 0)
    {
        stack = null;
    }

    return stack;
}
 
Example 30
Project: CustomWorldGen   File: NetHandlerPlayClient.java   View source code 5 votes vote down vote up
/**
 * Displays a GUI by ID. In order starting from id 0: Chest, Workbench, Furnace, Dispenser, Enchanting table,
 * Brewing stand, Villager merchant, Beacon, Anvil, Hopper, Dropper, Horse
 */
public void handleOpenWindow(SPacketOpenWindow packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
    EntityPlayerSP entityplayersp = this.gameController.thePlayer;

    if ("minecraft:container".equals(packetIn.getGuiId()))
    {
        entityplayersp.displayGUIChest(new InventoryBasic(packetIn.getWindowTitle(), packetIn.getSlotCount()));
        entityplayersp.openContainer.windowId = packetIn.getWindowId();
    }
    else if ("minecraft:villager".equals(packetIn.getGuiId()))
    {
        entityplayersp.displayVillagerTradeGui(new NpcMerchant(entityplayersp, packetIn.getWindowTitle()));
        entityplayersp.openContainer.windowId = packetIn.getWindowId();
    }
    else if ("EntityHorse".equals(packetIn.getGuiId()))
    {
        Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId());

        if (entity instanceof EntityHorse)
        {
            entityplayersp.openGuiHorseInventory((EntityHorse)entity, new AnimalChest(packetIn.getWindowTitle(), packetIn.getSlotCount()));
            entityplayersp.openContainer.windowId = packetIn.getWindowId();
        }
    }
    else if (!packetIn.hasSlots())
    {
        entityplayersp.displayGui(new LocalBlockIntercommunication(packetIn.getGuiId(), packetIn.getWindowTitle()));
        entityplayersp.openContainer.windowId = packetIn.getWindowId();
    }
    else
    {
        IInventory iinventory = new ContainerLocalMenu(packetIn.getGuiId(), packetIn.getWindowTitle(), packetIn.getSlotCount());
        entityplayersp.displayGUIChest(iinventory);
        entityplayersp.openContainer.windowId = packetIn.getWindowId();
    }
}
 
Example 31
Project: VillagerInventory   File: ContainerVillagerInventory.java   View source code 5 votes vote down vote up
public ContainerVillagerInventory(IInventory playerInventory, final InventoryBasic villagerInventoryIn, final EntityVillager villager, EntityPlayer player)
{
	this.villagerInventory = villagerInventoryIn;
	this.villager = villager;

	this.villagerInventory.setCustomName(this.villager.getDisplayName().getUnformattedText());


	villagerInventoryIn.openInventory(player);

	// villager inventory slots
	int offsetX = 17;
	int offsetY = 20;
	for (int col = 0; col < 8; col++)
	{
		this.addSlotToContainer(new Slot(villagerInventoryIn, col, offsetX + col * 18, offsetY));
	}

	// player inventory
	offsetX = 8;
	offsetY = 51;
	for (int row = 0; row < 3; row++)
	{
		for (int col = 0; col < 9; col++)
		{
			this.addSlotToContainer(new Slot(playerInventory, col + row * 9 + 9, offsetX + col * 18, offsetY + row * 18));
		}
	}

	// player hotbar inventory
	offsetY = 109;
	for (int col = 0; col < 9; col++)
	{
		this.addSlotToContainer(new Slot(playerInventory, col, offsetX + col * 18, offsetY));
	}

}
 
Example 32
Project: BaseClient   File: TileEntityHopper.java   View source code 5 votes vote down vote up
private boolean transferItemsOut()
{
    IInventory iinventory = this.getInventoryForHopperTransfer();

    if (iinventory == null)
    {
        return false;
    }
    else
    {
        EnumFacing enumfacing = BlockHopper.getFacing(this.getBlockMetadata()).getOpposite();

        if (this.isInventoryFull(iinventory, enumfacing))
        {
            return false;
        }
        else
        {
            for (int i = 0; i < this.getSizeInventory(); ++i)
            {
                if (this.getStackInSlot(i) != null)
                {
                    ItemStack itemstack = this.getStackInSlot(i).copy();
                    ItemStack itemstack1 = putStackInInventoryAllSlots(iinventory, this.decrStackSize(i, 1), enumfacing);

                    if (itemstack1 == null || itemstack1.stackSize == 0)
                    {
                        iinventory.markDirty();
                        return true;
                    }

                    this.setInventorySlotContents(i, itemstack);
                }
            }

            return false;
        }
    }
}
 
Example 33
Project: EndermanEvolution   File: FriendermanUtils.java   View source code 5 votes vote down vote up
public static boolean canInsertStack(IInventory inventory, ItemStack stack) {
	for (int i = 0; i < inventory.getSizeInventory(); i++) {
		if (canInsertStack(inventory, stack, i, null)) {
			return true;
		}
	}
	return false;
}
 
Example 34
Project: Randores2   File: CraftiniumTableContainer.java   View source code 5 votes vote down vote up
@Override
public void onCraftMatrixChanged(IInventory in) {
    CraftiniumRecipe matching = CraftiniumRecipeRegistry.findMatching(this.matrix, this.world, this.table, this.player);
    if (matching != null) {
        this.craftResult.setInventorySlotContents(0, matching.result(this.matrix, this.world, this.table, this.player));
    } else {
        this.craftResult.setInventorySlotContents(0, ItemStack.EMPTY);
    }
}
 
Example 35
Project: DecompiledMinecraft   File: EntityPlayerMP.java   View source code 5 votes vote down vote up
/**
 * Displays the GUI for interacting with a chest inventory. Args: chestInventory
 */
public void displayGUIChest(IInventory chestInventory)
{
    if (this.openContainer != this.inventoryContainer)
    {
        this.closeScreen();
    }

    if (chestInventory instanceof ILockableContainer)
    {
        ILockableContainer ilockablecontainer = (ILockableContainer)chestInventory;

        if (ilockablecontainer.isLocked() && !this.canOpen(ilockablecontainer.getLockCode()) && !this.isSpectator())
        {
            this.playerNetServerHandler.sendPacket(new S02PacketChat(new ChatComponentTranslation("container.isLocked", new Object[] {chestInventory.getDisplayName()}), (byte)2));
            this.playerNetServerHandler.sendPacket(new S29PacketSoundEffect("random.door_close", this.posX, this.posY, this.posZ, 1.0F, 1.0F));
            return;
        }
    }

    this.getNextWindowId();

    if (chestInventory instanceof IInteractionObject)
    {
        this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, ((IInteractionObject)chestInventory).getGuiID(), chestInventory.getDisplayName(), chestInventory.getSizeInventory()));
        this.openContainer = ((IInteractionObject)chestInventory).createContainer(this.inventory, this);
    }
    else
    {
        this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "minecraft:container", chestInventory.getDisplayName(), chestInventory.getSizeInventory()));
        this.openContainer = new ContainerChest(this.inventory, chestInventory, this);
    }

    this.openContainer.windowId = this.currentWindowId;
    this.openContainer.onCraftGuiOpened(this);
}
 
Example 36
Project: Simple-Chunks   File: ContainerChunkLoader.java   View source code 5 votes vote down vote up
public ContainerChunkLoader(IInventory playerInventory, TileEntityChunkLoader te)
{
	this.te = te;

	addTileEntitySlots();
	addPlayerSlots(playerInventory);
}
 
Example 37
Project: interactionwheel   File: DumpSimilarInventoryAction.java   View source code 5 votes vote down vote up
private boolean isSimilar(IInventory handler, ItemStack stack) {
    Set<Integer> ores = getOres(stack);
    for (int i = 0 ; i < handler.getSizeInventory() ; i++) {
        ItemStack s = handler.getStackInSlot(i);
        if (matchStack(stack, ores, s)) {
            return true;
        }
    }
    return false;
}
 
Example 38
Project: interactionwheel   File: DefaultWheelActionProvider.java   View source code 5 votes vote down vote up
@Override
    public void updateWheelActions(@Nonnull Set<String> actions, @Nonnull EntityPlayer player, World world, @Nullable BlockPos pos) {
        ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
        if (ItemStackTools.isValid(heldItem)) {
            actions.add(StandardWheelActions.ID_SEARCH);
        }
        if (pos != null) {
            actions.add(StandardWheelActions.ID_ROTATE);
            Block block = world.getBlockState(pos).getBlock();
            TileEntity te = world.getTileEntity(pos);
            if (te instanceof IInventory || (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))) {
                actions.add(StandardWheelActions.ID_DUMP);
                actions.add(StandardWheelActions.ID_EXTRACT);
                actions.add(StandardWheelActions.ID_DUMPORES);
                actions.add(StandardWheelActions.ID_DUMPBLOCKS);
                actions.add(StandardWheelActions.ID_DUMPSIMILARINV);
                if (ItemStackTools.isValid(heldItem)) {
                    actions.add(StandardWheelActions.ID_DUMP1);
                    actions.add(StandardWheelActions.ID_DUMPSIMILAR);
                }
            }
            actions.add(StandardWheelActions.ID_PICKTOOL);

            if (block instanceof IWheelBlockSupport) {
                ((IWheelBlockSupport) block).updateWheelActions(actions);
            }
        }
//        actions.add("std.dummy0");
//        actions.add("std.dummy1");
//        actions.add("std.dummy2");
//        actions.add("std.dummy3");
//        actions.add("std.dummy4");
//        actions.add("std.dummy5");
//        actions.add("std.dummy7");
//        actions.add("std.dummy8");
//        actions.add("std.dummy9");
//        actions.add("std.dummy10");
    }
 
Example 39
Project: Thermionics   File: TileEntityMashTun.java   View source code 5 votes vote down vote up
@Override
public IInventory getContainerInventory() {
	ValidatedInventoryView result = new ValidatedInventoryView(items);
	if (world.isRemote) {
		return result;
	} else {
		return result
				.withField(0, heat::getHeatStored)
				.withField(1, heat::getMaxHeatStored);
	}
}
 
Example 40
Project: StructPro   File: Tiles.java   View source code 5 votes vote down vote up
/**
 * Load tile entity data from NBT tag
 * @param tile Target tile
 * @param tag Tag to load
 * @param seed Loading seed
 */
public static void load(TileEntity tile, NBTTagCompound tag, long seed) {
    if (tile == null) {
        return;
    }
    if (tile instanceof TileEntityChest) {
        load((TileEntityChest)tile, tag, seed);
        return;
    }
    if (tile instanceof TileEntityMobSpawner) {
        load((TileEntityMobSpawner)tile, tag, seed);
    }
    if (tile instanceof TileEntitySign) {
        load((TileEntitySign)tile, tag, seed);
        return;
    }
    if (tile instanceof TileEntityCommandBlock) {
        load((TileEntityCommandBlock)tile, tag, seed);
        return;
    }
    if (tile instanceof IInventory) {
        load((IInventory)tile, tag, seed);
        return;
    }
    if (tile instanceof TileEntityComparator) {
        load((TileEntityComparator)tile, tag, seed);
        return;
    }
    if (tile instanceof TileEntityFlowerPot) {
        load((TileEntityFlowerPot)tile, tag, seed);
        return;
    }
    if (tile instanceof TileEntityNote) {
        load((TileEntityNote)tile, tag, seed);
    }
}