Search in sources :

Example 31 with EntityItem

use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.

the class TileEntityProgrammableController method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    oldCurX = curX;
    oldCurY = curY;
    oldCurZ = curZ;
    if (PneumaticCraftUtils.distBetween(getPosition(), targetX, targetY, targetZ) <= getSpeed()) {
        curX = targetX;
        curY = targetY;
        curZ = targetZ;
    } else {
        Vec3 vec = Vec3.createVectorHelper(targetX - curX, targetY - curY, targetZ - curZ).normalize();
        curX += vec.xCoord * getSpeed();
        curY += vec.yCoord * getSpeed();
        curZ += vec.zCoord * getSpeed();
    }
    if (!worldObj.isRemote) {
        getAIManager();
        if (worldObj.getTotalWorldTime() % 40 == 0) {
            dispenserUpgrades = getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE);
            speedUpgrades = getUpgrades(ItemMachineUpgrade.UPGRADE_SPEED_DAMAGE);
            for (int i = getDroneSlots(); i < 36; i++) {
                ItemStack stack = getFakePlayer().inventory.getStackInSlot(i);
                if (stack != null) {
                    worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, stack));
                    getFakePlayer().inventory.setInventorySlotContents(i, null);
                }
            }
            tank.setCapacity((dispenserUpgrades + 1) * 16000);
            if (tank.getFluidAmount() > tank.getCapacity()) {
                tank.getFluid().amount = tank.getCapacity();
            }
        }
        for (int i = 0; i < 4; i++) {
            getFakePlayer().theItemInWorldManager.updateBlockRemoving();
        }
        if (getPressure(ForgeDirection.UNKNOWN) >= getMinWorkingPressure()) {
            if (!aiManager.isIdling())
                addAir(-10, ForgeDirection.UNKNOWN);
            aiManager.onUpdateTasks();
        }
    } else {
        if (drone == null || drone.isDead) {
            drone = new EntityProgrammableController(worldObj, this);
            drone.posX = curX;
            drone.posY = curY;
            drone.posZ = curZ;
            worldObj.spawnEntityInWorld(drone);
        }
        drone.setPosition(curX, curY, curZ);
    // drone.getMoveHelper().setMoveTo(curX, curY, curZ, 0);
    /*   drone.prevPosX = oldCurX;
            drone.prevPosY = oldCurY;
            drone.prevPosZ = oldCurZ;*/
    //drone.getMoveHelper().setMoveTo(curX, curY, curZ, getSpeed());
    }
}
Also used : EntityProgrammableController(pneumaticCraft.common.entity.EntityProgrammableController) Vec3(net.minecraft.util.Vec3) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 32 with EntityItem

use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.

the class TileEntityProgrammer method tryProgramDrone.

private void tryProgramDrone(EntityPlayer player) {
    if (inventory[PROGRAM_SLOT] != null) {
        if (player == null || !player.capabilities.isCreativeMode) {
            List<ItemStack> requiredStacks = getRequiredPuzzleStacks();
            for (ItemStack stack : requiredStacks) {
                if (!hasEnoughPuzzleStacks(player, stack))
                    return;
            }
            for (ItemStack stack : requiredStacks) {
                int left = stack.stackSize;
                if (player != null) {
                    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                        if (PneumaticCraftUtils.areStacksEqual(stack, player.inventory.getStackInSlot(i), true, true, false, false)) {
                            left -= player.inventory.decrStackSize(i, left).stackSize;
                            if (left <= 0)
                                break;
                        }
                    }
                }
                if (left > 0) {
                    for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                        IInventory neighbor = IOHelper.getInventoryForTE(getWorldObj().getTileEntity(xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ));
                        for (int slot : IOHelper.getAccessibleSlotsForInventory(neighbor, d.getOpposite())) {
                            if (IOHelper.canExtractItemFromInventory(neighbor, stack, slot, d.getOpposite().ordinal())) {
                                ItemStack neighborStack = neighbor.getStackInSlot(slot);
                                if (PneumaticCraftUtils.areStacksEqual(neighborStack, stack, true, true, false, false)) {
                                    left -= neighbor.decrStackSize(slot, left).stackSize;
                                    if (left <= 0)
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            List<ItemStack> returnedStacks = getReturnedPuzzleStacks();
            for (ItemStack stack : returnedStacks) {
                for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                    IInventory neighbor = IOHelper.getInventoryForTE(getWorldObj().getTileEntity(xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ));
                    stack = IOHelper.insert(neighbor, stack, d.getOpposite().ordinal(), false);
                    if (stack == null)
                        break;
                }
                if (player != null && stack != null) {
                    if (!player.inventory.addItemStackToInventory(stack)) {
                        player.dropPlayerItemWithRandomChoice(stack.copy(), false);
                        stack = null;
                    }
                }
                if (stack != null) {
                    worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, stack));
                }
            }
        }
        NBTTagCompound tag = inventory[PROGRAM_SLOT].getTagCompound();
        if (tag == null) {
            tag = new NBTTagCompound();
            inventory[PROGRAM_SLOT].setTagCompound(tag);
        }
        writeProgWidgetsToNBT(tag);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 33 with EntityItem

use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.

the class TileEntityPressureChamberValve method dropInventory.

private void dropInventory(World world, double x, double y, double z) {
    IInventory inventory = this;
    Random rand = new Random();
    for (int i = 0; i < inventory.getSizeInventory(); i++) {
        ItemStack itemStack = inventory.getStackInSlot(i);
        if (itemStack != null && itemStack.stackSize > 0) {
            float dX = rand.nextFloat() * 0.8F - 0.4F;
            float dY = rand.nextFloat() * 0.8F - 0.4F;
            float dZ = rand.nextFloat() * 0.8F - 0.4F;
            EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));
            if (itemStack.hasTagCompound()) {
                entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
            }
            float factor = 0.05F;
            entityItem.motionX = rand.nextGaussian() * factor;
            entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
            entityItem.motionZ = rand.nextGaussian() * factor;
            world.spawnEntityInWorld(entityItem);
        // itemStack.stackSize = 0;
        }
    }
    this.inventory = new ItemStack[4];
}
Also used : IInventory(net.minecraft.inventory.IInventory) Random(java.util.Random) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 34 with EntityItem

use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.

the class TileEntityPressureChamberValve method giveOutput.

private void giveOutput(ItemStack[] output, double[] outputPosition) {
    for (ItemStack iStack : output) {
        if (iStack.getItem() == etchingAcid) {
            for (EntityPlayer player : (List<EntityPlayer>) worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord - 32, yCoord - 32, zCoord - 32, xCoord + 32, yCoord + 32, zCoord + 32))) {
                AchievementHandler.giveAchievement(player, new ItemStack(etchingAcid));
            }
        }
        EntityItem item = new EntityItem(worldObj, outputPosition[0], outputPosition[1], outputPosition[2], iStack.copy());
        worldObj.spawnEntityInWorld(item);
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ArrayList(java.util.ArrayList) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 35 with EntityItem

use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.

the class TileEntityLiquidHopper method exportItem.

@Override
protected boolean exportItem(int maxItems) {
    ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata());
    if (tank.getFluid() != null) {
        TileEntity neighbor = IOHelper.getNeighbor(this, dir);
        if (neighbor instanceof IFluidHandler) {
            IFluidHandler fluidHandler = (IFluidHandler) neighbor;
            if (fluidHandler.canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
                FluidStack fluid = tank.getFluid().copy();
                fluid.amount = Math.min(maxItems * 100, tank.getFluid().amount - (leaveMaterial ? 1000 : 0));
                if (fluid.amount > 0) {
                    tank.getFluid().amount -= fluidHandler.fill(dir.getOpposite(), fluid, true);
                    if (tank.getFluidAmount() <= 0)
                        tank.setFluid(null);
                    return true;
                }
            }
        }
    }
    if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
        for (EntityItem entity : getNeighborItems(this, dir)) {
            if (!entity.isDead) {
                List<ItemStack> returnedItems = new ArrayList<ItemStack>();
                if (FluidUtils.tryExtractingLiquid(this, entity.getEntityItem(), returnedItems)) {
                    if (entity.getEntityItem().stackSize <= 0)
                        entity.setDead();
                    for (ItemStack stack : returnedItems) {
                        EntityItem item = new EntityItem(worldObj, entity.posX, entity.posY, entity.posZ, stack);
                        item.motionX = entity.motionX;
                        item.motionY = entity.motionY;
                        item.motionZ = entity.motionZ;
                        worldObj.spawnEntityInWorld(item);
                    }
                    return true;
                }
            }
        }
    }
    if (getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
        if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
            FluidStack extractedFluid = drain(ForgeDirection.UNKNOWN, 1000, false);
            if (extractedFluid != null && extractedFluid.amount == 1000) {
                Block fluidBlock = extractedFluid.getFluid().getBlock();
                if (fluidBlock != null) {
                    drain(ForgeDirection.UNKNOWN, 1000, true);
                    worldObj.setBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, fluidBlock);
                }
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityItem (net.minecraft.entity.item.EntityItem)284 ItemStack (net.minecraft.item.ItemStack)178 TileEntity (net.minecraft.tileentity.TileEntity)45 EntityPlayer (net.minecraft.entity.player.EntityPlayer)36 Entity (net.minecraft.entity.Entity)26 ArrayList (java.util.ArrayList)19 BlockPos (net.minecraft.util.math.BlockPos)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)18 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)16 World (net.minecraft.world.World)16 Random (java.util.Random)15 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)14 Item (net.minecraft.item.Item)13 IInventory (net.minecraft.inventory.IInventory)12 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)12 List (java.util.List)11 Block (net.minecraft.block.Block)11 EntityLivingBase (net.minecraft.entity.EntityLivingBase)11 IBlockState (net.minecraft.block.state.IBlockState)10 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6