Search in sources :

Example 11 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class ContainerBetterStorage method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotId) {
    ItemStack stack = null;
    Slot slot = (Slot) inventorySlots.get(slotId);
    // If slot isn't empty and item can be stacked.
    if ((slot != null) && slot.getHasStack()) {
        ItemStack slotStack = slot.getStack();
        stack = slotStack.copy();
        if (!mergeItemStack(slotStack, transferStart(slotId), transferEnd(slotId), transferDirection(slotId)))
            return null;
        if (slotStack.stackSize != 0)
            slot.onSlotChanged();
        else
            slot.putStack(null);
    }
    return stack;
}
Also used : Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 12 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class ContainerCraftingStation method slotClick.

@Override
public ItemStack slotClick(int slotId, int button, int special, EntityPlayer player) {
    if (!inv.outputIsReal && (inv.currentCrafting != null) && (slotId >= 9) && (slotId < 18) && (inv.output[slotId - 9] != null) && inv.canTake(player) && (special != 3)) {
        ItemStack craftingStack = inv.output[slotId - 9];
        int amount = craftingStack.stackSize;
        // Shift-click: Craft up to one stack of items at once.
        if (special == 1) {
            ItemStack stack;
            int count = 0;
            do {
                count += amount;
                inv.craft(player);
                stack = super.slotClick(slotId, button, special, player);
            } while (!inv.outputIsReal && (inv.currentCrafting != null) && (inv.output[slotId - 9] != null) && inv.canTake(player) && ((stack == null) || (StackUtils.matches(stack, inv.output[slotId - 9]))) && inv.hasItemRequirements() && (count + amount <= craftingStack.getMaxStackSize()));
            return stack;
        // Regular clicking: Craft once. 
        } else if (special < 2) {
            ItemStack holding = player.inventory.getItemStack();
            if ((holding == null) || (StackUtils.matches(holding, craftingStack) && (holding.stackSize <= holding.getMaxStackSize() - amount)))
                inv.craft(player);
        // No fancy inventory mechanics in the crafting slots.
        } else
            return craftingStack;
    }
    return super.slotClick(slotId, button, special, player);
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Example 13 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class EntityFrienderman method onLivingUpdate.

@Override
public void onLivingUpdate() {
    if (worldObj.isRemote) {
        super.onLivingUpdate();
        return;
    }
    int x = (int) Math.floor(posX);
    int y = (int) (posY + 0.6);
    int z = (int) Math.floor(posZ);
    GameRules rules = worldObj.getGameRules();
    String ruleBefore = rules.getGameRuleStringValue("mobGriefing");
    boolean ruleChanged = false;
    boolean hasEnderChest = (func_146080_bZ() == Blocks.ender_chest);
    boolean hasBackpack = (getEquipmentInSlot(EquipmentSlot.CHEST) != null);
    // Temporarily change the blocks which endermen can carry.
    // TODO: Make a pull request to Forge which allows us to do this by overriding a method instead.
    IdentityHashMap<Block, Boolean> carriable = ReflectionUtils.get(EntityEnderman.class, null, "carriable", "");
    ReflectionUtils.set(EntityEnderman.class, null, "carriable", "", friendermanCarriable);
    // prevent dropping of enderchests regardless of the gamerule.
    if (hasEnderChest) {
        if (ruleBefore.equalsIgnoreCase("true")) {
            rules.setOrCreateGameRule("mobGriefing", "false");
            ruleChanged = true;
        }
    } else if (hasBackpack && worldObj.isAirBlock(x, y, z)) {
        if (ruleBefore.equalsIgnoreCase("false")) {
            rules.setOrCreateGameRule("mobGriefing", "true");
            ruleChanged = true;
        }
    }
    super.onLivingUpdate();
    // Reset carriable blocks and gamerule.
    ReflectionUtils.set(EntityEnderman.class, null, "carriable", "", carriable);
    if (ruleChanged)
        rules.setOrCreateGameRule("mobGriefing", ruleBefore);
    // If ender chest was picked up, remove ender backpack and place it on the ground.
    if (!hasEnderChest && (func_146080_bZ() == Blocks.ender_chest)) {
        setCurrentItemOrArmor(3, null);
        worldObj.setBlock(x, y, z, BetterStorageTiles.enderBackpack, RandomUtils.getInt(2, 6), 3);
        WorldUtils.get(worldObj, x, y, z, TileEntityBackpack.class).stack = new ItemStack(BetterStorageItems.itemEnderBackpack);
        double px = x + 0.5;
        double py = y + 0.5;
        double pz = z + 0.5;
        BetterStorage.networkChannel.sendToAllAround(new PacketBackpackTeleport(px, py, pz, x, y, z), worldObj, px, py, pz, 256);
        worldObj.playSoundEffect(px, py, pz, "mob.endermen.portal", 1.0F, 1.0F);
    }
}
Also used : PacketBackpackTeleport(net.mcft.copy.betterstorage.network.packet.PacketBackpackTeleport) GameRules(net.minecraft.world.GameRules) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 14 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class InventoryBetterStorage method decrStackSize.

@Override
public ItemStack decrStackSize(int slot, int amount) {
    ItemStack stack = getStackInSlot(slot);
    if (stack == null)
        return null;
    amount = Math.min(amount, stack.stackSize);
    if (amount < stack.stackSize) {
        stack.stackSize -= amount;
        stack = StackUtils.copyStack(stack, amount);
        markDirty();
    } else
        setInventorySlotContents(slot, null);
    return stack;
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Example 15 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class InventoryBetterStorage method getStackInSlotOnClosing.

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
    ItemStack stack = getStackInSlot(slot);
    if (stack == null)
        return null;
    setInventorySlotContents(slot, null);
    return stack;
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2512 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)250 ArrayList (java.util.ArrayList)244 EntityItem (net.minecraft.entity.item.EntityItem)170 Slot (net.minecraft.inventory.Slot)164 TileEntity (net.minecraft.tileentity.TileEntity)155 EntityPlayer (net.minecraft.entity.player.EntityPlayer)153 Block (net.minecraft.block.Block)148 Item (net.minecraft.item.Item)118 BlockPos (net.minecraft.util.math.BlockPos)83 NBTTagList (net.minecraft.nbt.NBTTagList)74 IInventory (net.minecraft.inventory.IInventory)73 IBlockState (net.minecraft.block.state.IBlockState)70 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)67 FluidStack (net.minecraftforge.fluids.FluidStack)63 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)63 World (net.minecraft.world.World)56 List (java.util.List)55 ResourceLocation (net.minecraft.util.ResourceLocation)50 Entity (net.minecraft.entity.Entity)47