Search in sources :

Example 1 with TileEntityHopper

use of net.minecraft.tileentity.TileEntityHopper in project MinecraftForge by MinecraftForge.

the class VanillaInventoryCodeHooks method insertStack.

/**
     * Copied from TileEntityHopper#insertStack and added capability support
     */
private static ItemStack insertStack(TileEntity source, Object destination, IItemHandler destInventory, ItemStack stack, int slot) {
    ItemStack itemstack = destInventory.getStackInSlot(slot);
    if (destInventory.insertItem(slot, stack, true).isEmpty()) {
        boolean insertedItem = false;
        boolean inventoryWasEmpty = isEmpty(destInventory);
        if (itemstack.isEmpty()) {
            destInventory.insertItem(slot, stack, false);
            stack = ItemStack.EMPTY;
            insertedItem = true;
        } else if (ItemHandlerHelper.canItemStacksStack(itemstack, stack)) {
            int originalSize = stack.getCount();
            stack = destInventory.insertItem(slot, stack, false);
            insertedItem = originalSize < stack.getCount();
        }
        if (insertedItem) {
            if (inventoryWasEmpty && destination instanceof TileEntityHopper) {
                TileEntityHopper destinationHopper = (TileEntityHopper) destination;
                if (!destinationHopper.mayTransfer()) {
                    int k = 0;
                    if (source instanceof TileEntityHopper) {
                        if (destinationHopper.getLastUpdateTime() >= ((TileEntityHopper) source).getLastUpdateTime()) {
                            k = 1;
                        }
                    }
                    destinationHopper.setTransferCooldown(8 - k);
                }
            }
        }
    }
    return stack;
}
Also used : TileEntityHopper(net.minecraft.tileentity.TileEntityHopper) ItemStack(net.minecraft.item.ItemStack)

Example 2 with TileEntityHopper

use of net.minecraft.tileentity.TileEntityHopper in project SpongeCommon by SpongePowered.

the class CooldownDataProcessor method removeFrom.

@Override
public DataTransactionResult removeFrom(ValueContainer<?> container) {
    if (container instanceof TileEntityHopper) {
        TileEntityHopper hopper = (TileEntityHopper) container;
        Optional<Integer> old = getVal(hopper);
        if (!old.isPresent()) {
            return DataTransactionResult.successNoData();
        }
        hopper.transferCooldown = -1;
        return DataTransactionResult.successRemove(constructImmutableValue(old.get()));
    }
    return DataTransactionResult.failNoData();
}
Also used : TileEntityHopper(net.minecraft.tileentity.TileEntityHopper)

Example 3 with TileEntityHopper

use of net.minecraft.tileentity.TileEntityHopper in project Charset by CharsetMC.

the class CarryTransformerEntityMinecart method getExtractedPair.

protected Pair<IBlockState, TileEntity> getExtractedPair(@Nonnull Entity object, boolean simulate) {
    if (object instanceof EntityMinecartTNT) {
        return Pair.of(Blocks.TNT.getDefaultState(), null);
    } else if (object instanceof EntityMinecartCommandBlock) {
        TileEntityCommandBlock tile = new TileEntityCommandBlock();
        NBTTagCompound compound = ((EntityMinecartCommandBlock) object).getCommandBlockLogic().writeToNBT(new NBTTagCompound());
        tile.readFromNBT(compound);
        return Pair.of(Blocks.COMMAND_BLOCK.getDefaultState(), tile);
    } else if (object instanceof EntityMinecartChest) {
        TileEntityChest tile = new TileEntityChest();
        copyEntityToTile(tile, object, "Items");
        return Pair.of(Blocks.CHEST.getDefaultState(), tile);
    } else if (object instanceof EntityMinecartHopper) {
        TileEntityHopper tile = new TileEntityHopper();
        copyEntityToTile(tile, object, "Items");
        return Pair.of(Blocks.HOPPER.getDefaultState(), tile);
    } else /* else if (object instanceof EntityMinecartFurnace) {
			TileEntityFurnace tile = new TileEntityFurnace();
			copyEntityToTile(tile, object, "Fuel");
			return Pair.of(Blocks.FURNACE.getDefaultState(), tile);
		}*/
    {
        return null;
    }
}
Also used : TileEntityHopper(net.minecraft.tileentity.TileEntityHopper) TileEntityChest(net.minecraft.tileentity.TileEntityChest) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TileEntityCommandBlock(net.minecraft.tileentity.TileEntityCommandBlock)

Aggregations

TileEntityHopper (net.minecraft.tileentity.TileEntityHopper)3 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntityChest (net.minecraft.tileentity.TileEntityChest)1 TileEntityCommandBlock (net.minecraft.tileentity.TileEntityCommandBlock)1