Search in sources :

Example 51 with IInventory

use of net.minecraft.inventory.IInventory in project Railcraft by Railcraft.

the class TileRockCrusher method update.

@Override
public void update() {
    super.update();
    if (Game.isHost(getWorld())) {
        BlockPos pos = getPos();
        double x = pos.getX();
        double y = pos.getZ();
        double z = pos.getZ();
        if (isStructureValid()) {
            // TileEntityHopper.getItemsAroundAPointOrSomethingLikeThat
            for (EntityItem item : TileEntityHopper.getCaptureItems(getWorld(), x, y + 1, z)) {
                if (item != null && useMasterEnergy(SUCKING_POWER_COST, false)) {
                    ItemStack stack = item.getEntityItem().copy();
                    InventoryManipulator.get((IInventory) invInput).addStack(stack);
                    useMasterEnergy(SUCKING_POWER_COST, true);
                    item.setDead();
                }
            }
            EntityLivingBase entity = MiscTools.getEntityAt(worldObj, EntityLivingBase.class, getPos().up());
            if (entity != null && useMasterEnergy(KILLING_POWER_COST, false))
                if (entity.attackEntityFrom(RailcraftDamageSource.CRUSHER, 10))
                    useMasterEnergy(KILLING_POWER_COST, true);
        }
        if (isMaster()) {
            if (clock % 16 == 0)
                processActions();
            if (paused)
                return;
            ItemStack input = InvTools.emptyStack();
            ICrusherCraftingManager.ICrusherRecipe recipe = null;
            for (IInvSlot slot : InventoryIterator.getVanilla((IInventory) invInput)) {
                input = slot.getStack();
                if (!InvTools.isEmpty(input)) {
                    recipe = RailcraftCraftingManager.rockCrusher.getRecipe(input);
                    if (recipe == null)
                        recipe = RockCrusherCraftingManager.NULL_RECIPE;
                    break;
                }
            }
            if (recipe != null)
                if (processTime >= PROCESS_TIME) {
                    isWorking = false;
                    InventoryCopy tempInv = new InventoryCopy(invOutput);
                    boolean hasRoom = true;
                    List<ItemStack> outputs = recipe.getProcessedOutputs();
                    for (ItemStack output : outputs) {
                        output = InvTools.moveItemStack(output, tempInv);
                        if (!InvTools.isEmpty(output)) {
                            hasRoom = false;
                            break;
                        }
                    }
                    if (hasRoom) {
                        for (ItemStack output : outputs) {
                            InvTools.moveItemStack(output, invOutput);
                        }
                        InvTools.removeOneItem(invInput, input);
                        SoundHelper.playSound(worldObj, null, getPos(), SoundEvents.ENTITY_IRONGOLEM_DEATH, SoundCategory.BLOCKS, 1.0f, worldObj.rand.nextFloat() * 0.25F + 0.7F);
                        processTime = 0;
                    }
                } else {
                    isWorking = true;
                    if (energyStorage != null) {
                        int energy = energyStorage.extractEnergy(CRUSHING_POWER_COST_PER_TICK, true);
                        if (energy >= CRUSHING_POWER_COST_PER_TICK) {
                            processTime++;
                            energyStorage.extractEnergy(CRUSHING_POWER_COST_PER_TICK, false);
                        }
                    } else
                        processTime++;
                }
            else {
                processTime = 0;
                isWorking = false;
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos) InventoryCopy(mods.railcraft.common.util.inventory.wrappers.InventoryCopy) ItemStack(net.minecraft.item.ItemStack) ICrusherCraftingManager(mods.railcraft.api.crafting.ICrusherCraftingManager) EntityItem(net.minecraft.entity.item.EntityItem)

Example 52 with IInventory

use of net.minecraft.inventory.IInventory in project ICBM-Classic by BuiltBrokenModding.

the class BlastEMP method doExplode.

@Override
public void doExplode() {
    if (!world().isRemote) {
        if (this.effectBlocks) {
            for (int x = (int) -this.getRadius(); x < (int) this.getRadius(); x++) {
                for (int y = (int) -this.getRadius(); y < (int) this.getRadius(); y++) {
                    for (int z = (int) -this.getRadius(); z < (int) this.getRadius(); z++) {
                        double dist = MathHelper.sqrt_double((x * x + y * y + z * z));
                        Pos searchPosition = new Pos(x, y, z).add(position);
                        if (dist > this.getRadius()) {
                            continue;
                        }
                        if (Math.round(position.x() + y) == position.yi()) {
                            world().spawnParticle("largesmoke", searchPosition.x(), searchPosition.y(), searchPosition.z(), 0, 0, 0);
                        }
                        Block block = searchPosition.getBlock(world());
                        TileEntity tileEntity = searchPosition.getTileEntity(world());
                        //TODO more EMP effect to UniversalEnergySystem to better support cross mod support
                        if (block != null) {
                            //}
                            if (block instanceof IEMPBlock) {
                                ((IEMPBlock) block).onEMP(world(), searchPosition.xi(), searchPosition.yi(), searchPosition.zi(), this);
                            }
                        }
                        if (tileEntity != null) {
                            //if (tileEntity instanceof IFortronStorage)
                            //{
                            //    ((IFortronStorage) tileEntity).provideFortron((int) world().rand.nextFloat() * ((IFortronStorage) tileEntity).getFortronCapacity(), true);
                            //}
                            UniversalEnergySystem.clearEnergy(tileEntity, true);
                        }
                    }
                }
            }
        }
        if (this.effectEntities) {
            // Drop all missiles
            List<Entity> entitiesNearby = RadarRegistry.getAllLivingObjectsWithin(world(), new Cube(position.sub(getRadius()), position.add(getRadius())), null);
            for (Entity entity : entitiesNearby) {
                if (entity instanceof IMissile && !entity.isEntityEqual(this.controller)) {
                    if (((IMissile) entity).getTicksInAir() > -1) {
                        ((IMissile) entity).dropMissileAsItem();
                    }
                }
            }
            int maxFx = 10;
            AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(position.x() - this.getRadius(), position.y() - this.getRadius(), position.z() - this.getRadius(), position.x() + this.getRadius(), position.y() + this.getRadius(), position.z() + this.getRadius());
            List<Entity> entities = world().getEntitiesWithinAABB(Entity.class, bounds);
            for (Entity entity : entities) {
                if (entity instanceof EntityLivingBase) {
                    if (this.world().isRemote && maxFx > 0) {
                        ICBMClassic.proxy.spawnShock(this.world(), this.position, new Pos(entity), 20);
                        maxFx--;
                    }
                    if (entity instanceof EntityCreeper) {
                        if (!this.world().isRemote) {
                            try {
                                ((EntityCreeper) entity).getDataWatcher().updateObject(17, (byte) 1);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    if (entity instanceof EntityPlayer) {
                        IInventory inventory = ((EntityPlayer) entity).inventory;
                        for (int i = 0; i < inventory.getSizeInventory(); i++) {
                            ItemStack itemStack = inventory.getStackInSlot(i);
                            if (itemStack != null) {
                                if (itemStack.getItem() instanceof IEMPItem) {
                                    ((IEMPItem) itemStack.getItem()).onEMP(itemStack, entity, this);
                                }
                                UniversalEnergySystem.clearEnergy(itemStack, true);
                            }
                        }
                    }
                } else if (entity instanceof EntityExplosive) {
                    entity.setDead();
                }
            }
        }
        VEProviderShockWave.spawnEffect(world(), position.x(), position.y(), position.z(), 0, 0, 0, 0, 0, 255, 1, 3);
        VEProviderShockWave.spawnEffect(world(), position.x(), position.y(), position.z(), 0, 0, 0, 0, 0, 255, 3, 3);
        VEProviderShockWave.spawnEffect(world(), position.x(), position.y(), position.z(), 0, 0, 0, 0, 0, 255, 5, 3);
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "emp", 4.0F, (1.0F + (world().rand.nextFloat() - world().rand.nextFloat()) * 0.2F) * 0.7F);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IInventory(net.minecraft.inventory.IInventory) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IEMPItem(resonant.api.explosion.IEMPItem) IEMPBlock(resonant.api.explosion.IEMPBlock) TileEntity(net.minecraft.tileentity.TileEntity) IMissile(resonant.api.explosion.IMissile) EntityCreeper(net.minecraft.entity.monster.EntityCreeper) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Cube(com.builtbroken.mc.imp.transform.region.Cube) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IEMPBlock(resonant.api.explosion.IEMPBlock) Block(net.minecraft.block.Block) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityExplosive(icbm.classic.content.entity.EntityExplosive) ItemStack(net.minecraft.item.ItemStack)

Example 53 with IInventory

use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.

the class TileEntityOtherworldAura method refreshNearbyInventories.

private void refreshNearbyInventories() {
    nearbyInventories = new ArrayList<AMVector3>();
    int radius = 6;
    for (int i = -radius; i <= radius; ++i) {
        for (int j = -radius; j <= radius; ++j) {
            for (int k = -radius; k <= radius; ++k) {
                if (i == 0 && j == 0 && k == 0)
                    continue;
                TileEntity te = worldObj.getTileEntity(xCoord + i, yCoord + j, zCoord + k);
                if (te == null)
                    continue;
                if (!(te instanceof IInventory))
                    continue;
                nearbyInventories.add(new AMVector3(te));
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3)

Example 54 with IInventory

use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.

the class TileEntityArcaneDeconstructor method transferOrEjectItem.

private void transferOrEjectItem(ItemStack stack) {
    if (worldObj.isRemote)
        return;
    boolean eject = false;
    for (int i = -1; i <= 1; ++i) {
        for (int j = -1; j <= 1; ++j) {
            for (int k = -1; k <= 1; ++k) {
                if (i == 0 && j == 0 && k == 0)
                    continue;
                TileEntity te = worldObj.getTileEntity(xCoord + i, yCoord + j, zCoord + k);
                if (te != null && te instanceof IInventory) {
                    for (int side = 0; side < 6; ++side) {
                        if (InventoryUtilities.mergeIntoInventory((IInventory) te, stack, stack.stackSize, side))
                            return;
                    }
                }
            }
        }
    }
    //eject the remainder
    EntityItem item = new EntityItem(worldObj);
    item.setPosition(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5);
    item.setEntityItemStack(stack);
    worldObj.spawnEntityInWorld(item);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) EntityItem(net.minecraft.entity.item.EntityItem)

Example 55 with IInventory

use of net.minecraft.inventory.IInventory in project ArsMagica2 by Mithion.

the class ItemRune method spawnBroom.

public void spawnBroom(ItemStack stack, World world, EntityPlayer player) {
    if (!world.isRemote) {
        MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, true);
        if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
            TileEntity te = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
            if (te instanceof IInventory) {
                EntityBroom broom = new EntityBroom(world);
                broom.setPosition(player.posX, player.posY, player.posZ);
                broom.setChestLocation(new AMVector3(mop.blockX, mop.blockY, mop.blockZ));
                world.spawnEntityInWorld(broom);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3)

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