Search in sources :

Example 71 with IInventory

use of net.minecraft.inventory.IInventory in project NewHorizonsCoreMod by GTNewHorizons.

the class BlockBabyChest method dropItems.

private void dropItems(World pWorld, int pX, int pY, int pZ) {
    Random tRand = new Random();
    TileEntity tTileEntity = pWorld.getTileEntity(pX, pY, pZ);
    if (!(tTileEntity instanceof IInventory)) {
        return;
    }
    IInventory tInventory = (IInventory) tTileEntity;
    for (int i = 0; i < tInventory.getSizeInventory(); i++) {
        ItemStack tItem = tInventory.getStackInSlot(i);
        if (tItem != null && tItem.stackSize > 0) {
            float tx = tRand.nextFloat() * 0.8F + 0.1F;
            float ty = tRand.nextFloat() * 0.8F + 0.1F;
            float tz = tRand.nextFloat() * 0.8F + 0.1F;
            EntityItem tEntityItem = new EntityItem(pWorld, pX + tx, pY + ty, pZ + tz, new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage()));
            if (tItem.hasTagCompound())
                tEntityItem.getEntityItem().setTagCompound((NBTTagCompound) tItem.getTagCompound().copy());
            float tFactor = 0.05F;
            tEntityItem.motionX = tRand.nextGaussian() * tFactor;
            tEntityItem.motionY = tRand.nextGaussian() * tFactor + 0.2F;
            tEntityItem.motionZ = tRand.nextGaussian() * tFactor;
            pWorld.spawnEntityInWorld(tEntityItem);
            tItem.stackSize = 0;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) Random(java.util.Random) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 72 with IInventory

use of net.minecraft.inventory.IInventory in project BetterStorage by copygirl.

the class TileEnderBackpack method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        TileEntityBackpack backpack = WorldUtils.get(world, x, y, z, TileEntityBackpack.class);
        IInventory inventory = new InventoryTileEntity(backpack, player.getInventoryEnderChest());
        Container container = new ContainerBetterStorage(player, inventory, 9, 3);
        String name = "container." + Constants.modId + ".enderBackpack";
        PlayerUtils.openGui(player, name, 9, 3, backpack.getCustomTitle(), container);
    }
    return true;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ContainerBetterStorage(net.mcft.copy.betterstorage.container.ContainerBetterStorage) Container(net.minecraft.inventory.Container) TileEntityBackpack(net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack) InventoryTileEntity(net.mcft.copy.betterstorage.inventory.InventoryTileEntity)

Example 73 with IInventory

use of net.minecraft.inventory.IInventory in project BetterStorage by copygirl.

the class ChristmasEventHandler method onPlayerLogin.

@SubscribeEvent
public void onPlayerLogin(PlayerLoggedInEvent event) {
    List<ItemStack> items = getItemsForYear(getYear(), event.player);
    BetterChristmasProperties properties = EntityUtils.getProperties(event.player, BetterChristmasProperties.class);
    if (items == null)
        return;
    if (isBeforeChristmas() && (properties.year < getYear())) {
        ItemStack book = new ItemStack(BetterStorageItems.presentBook);
        StackUtils.set(book, getYear(), "year");
        StackUtils.set(book, event.player.getUniqueID().toString(), "uuid");
        StackUtils.set(book, event.player.getCommandSenderName(), "name");
        event.player.inventory.addItemStackToInventory(book);
        properties.year = getYear();
        properties.gotPresent = false;
    }
    if (isPresentTime() && !properties.gotPresent) {
        IInventory inv = event.player.inventory;
        for (int i = 0; i < inv.getSizeInventory(); i++) {
            ItemStack stack = inv.getStackInSlot(i);
            if ((stack != null) && (stack.getItem() == BetterStorageItems.presentBook) && (StackUtils.get(stack, 9001, "year") == getYear()) && event.player.getUniqueID().toString().equals(StackUtils.get(stack, null, "uuid"))) {
                ItemStack present = new ItemStack(BetterStorageTiles.present);
                present.setStackDisplayName("Christmas Present " + getYear());
                StackUtils.set(present, event.player.getCommandSenderName(), TileEntityPresent.TAG_NAMETAG);
                int color = DyeUtils.getDyeColor(new ItemStack(Items.dye, 1, 1));
                StackUtils.set(present, color, "color");
                StackUtils.set(present, (byte) 14, TileEntityPresent.TAG_COLOR_INNER);
                StackUtils.set(present, (byte) 16, TileEntityPresent.TAG_COLOR_OUTER);
                ItemStack[] contents = new ItemStack[ItemCardboardBox.getRows() * 9];
                for (int j = 0; ((j < contents.length) && !items.isEmpty()); j++) if (RandomUtils.getBoolean((double) items.size() / (contents.length - j)))
                    contents[j] = items.remove(RandomUtils.getInt(items.size()));
                StackUtils.setStackContents(present, contents);
                if (event.player.getCommandSenderName().equalsIgnoreCase("xXxCJxXx")) {
                    StackUtils.set(present, (byte) 1, TileEntityPresent.TAG_SKOJANZA_MODE);
                    StackUtils.set(present, NbtUtils.createList("Just for you!", "skojanzaMode = true"), "display", "Lore");
                }
                inv.setInventorySlotContents(i, present);
                properties.gotPresent = true;
                break;
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 74 with IInventory

use of net.minecraft.inventory.IInventory in project Minechem by iopleke.

the class BasicBlockContainer method breakBlock.

/**
     * Called when the block is broken
     *
     * @param world    the world object
     * @param x        world X coordinate of broken block
     * @param y        world Y coordinate of broken block
     * @param z        world Z coordinate of broken block
     * @param block    the block being broken
     * @param metaData block metadata value
     */
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int metaData) {
    if (block instanceof BasicBlockContainer) {
        TileEntity tileEntity = world.getTileEntity(x, y, z);
        if (tileEntity != null) {
            ArrayList<ItemStack> droppedStacks = new ArrayList<ItemStack>();
            if (dropInventory()) {
                if (tileEntity instanceof IInventory) {
                    IInventory inventory = (IInventory) tileEntity;
                    for (int i = 0; i < inventory.getSizeInventory(); i++) {
                        ItemStack stack = inventory.getStackInSlot(i);
                        if (stack != null) {
                            droppedStacks.add(stack);
                        }
                    }
                }
            }
            addStacksDroppedOnBlockBreak(tileEntity, droppedStacks);
            for (ItemStack itemstack : droppedStacks) {
                ItemHelper.throwItemStack(world, itemstack, x, y, z);
            }
            super.breakBlock(world, x, y, z, block, metaData);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 75 with IInventory

use of net.minecraft.inventory.IInventory in project BetterStorage by copygirl.

the class ItemThaumcraftBackpack method repairItems.

/* TODO: Readd flux effects.
	
	private void createFlux(EntityPlayer player, ItemStack backpack) {
		
		// Every 5 seconds.
		if (player.ticksExisted % 100 != 0) return;
		
		// Count items over normal backpack capacity.
		IInventory inventory = ItemBackpack.getBackpackItems(player);
		int count = -(getRows() * 9);
		for (int i = 0; i < inventory.getSizeInventory(); i++)
			if (inventory.getStackInSlot(i) != null) count++;
		
		// When count <= 0, return.
		// When count = 1, chance is ~2%.
		// When count = 12, chance is 25%.
		if (RandomUtils.getInt(48) > count) return;
		
		int auraId = ThaumcraftApi.getClosestAuraWithinRange(player.worldObj, player.posX, player.posY, player.posZ, 640);
		if (auraId == -1) return;
		ThaumcraftApi.queueNodeChanges(auraId, 0, 0, false, (new ObjectTags()).add(EnumTag.VOID, 3), 0, 0, 0);
		
	}
	
	private void fluxEffects(EntityPlayer player, ItemStack backpack) {
		
		// Every 10 seconds.
		if (player.ticksExisted % 200 != 0) return;
		
		BackpackFluxEffect effect = (BackpackFluxEffect)FluxEffect.pick(
				BackpackFluxEffect.effects, player.worldObj, player.posX, player.posY, player.posZ);
		if (effect == null) return;
		effect.apply(player, backpack);
		
	}
	*/
public void repairItems(ItemStack backpack, EntityPlayer player) {
    IInventory backpackInventory = ItemBackpack.getBackpackItems(player);
    int repair = EnchantmentHelper.getEnchantmentLevel(ThaumcraftApi.enchantRepair, backpack);
    int time = ((repair > 0) ? (15 - Math.min(repair, 2) * 5) : 30) * 20;
    if ((player.ticksExisted % time) > 0)
        return;
    for (int i = 0; i < backpackInventory.getSizeInventory(); i++) {
        ItemStack stack = backpackInventory.getStackInSlot(i);
        if ((stack != null) && (stack.isItemDamaged()) && (stack.getItem() instanceof IRepairable) && (EnchantmentHelper.getEnchantmentLevel(ThaumcraftApi.enchantRepair, stack) > 0))
            repairItem(stack, player);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack) IRepairable(thaumcraft.api.IRepairable)

Aggregations

IInventory (net.minecraft.inventory.IInventory)129 ItemStack (net.minecraft.item.ItemStack)80 TileEntity (net.minecraft.tileentity.TileEntity)59 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)21 ArrayList (java.util.ArrayList)18 ISidedInventory (net.minecraft.inventory.ISidedInventory)13 EntityItem (net.minecraft.entity.item.EntityItem)12 EntityPlayer (net.minecraft.entity.player.EntityPlayer)12 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 WorldCoordinatesWrapper (network.rs485.logisticspipes.world.WorldCoordinatesWrapper)9 AMVector3 (am2.api.math.AMVector3)8 List (java.util.List)8 SidedInventoryMinecraftAdapter (logisticspipes.utils.SidedInventoryMinecraftAdapter)8 SinkReply (logisticspipes.utils.SinkReply)8 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)8 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)7 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7 ConnectionPipeType (logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType)7