Search in sources :

Example 6 with TileEntityElevatorBase

use of pneumaticCraft.common.tileentity.TileEntityElevatorBase in project PneumaticCraft by MineMaarten.

the class BlockElevatorBase method onNeighborBlockChange.

@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
    super.onNeighborBlockChange(world, x, y, z, block);
    TileEntity te = world.getTileEntity(x, y, z);
    if (te instanceof TileEntityElevatorBase) {
        TileEntityElevatorBase thisTe = (TileEntityElevatorBase) te;
        if (thisTe.isCoreElevator()) {
            TileEntityElevatorBase teAbove = getCoreTileEntity(world, x, y, z);
            if (teAbove != null && teAbove != thisTe) {
                for (int i = 0; i < thisTe.getSizeInventory(); i++) {
                    ItemStack item = thisTe.getStackInSlot(i);
                    if (item != null) {
                        ItemStack leftover = TileEntityHopper.func_145889_a(teAbove, item, 0);
                        thisTe.setInventorySlotContents(i, null);
                        if (leftover != null) {
                            EntityItem entity = new EntityItem(world, teAbove.xCoord + 0.5, teAbove.yCoord + 1.5, teAbove.zCoord + 0.5, leftover);
                            world.spawnEntityInWorld(entity);
                        }
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityElevatorBase(pneumaticCraft.common.tileentity.TileEntityElevatorBase) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 7 with TileEntityElevatorBase

use of pneumaticCraft.common.tileentity.TileEntityElevatorBase in project PneumaticCraft by MineMaarten.

the class BlockElevatorBase method onBlockAdded.

@Override
public void onBlockAdded(World world, int x, int y, int z) {
    super.onBlockAdded(world, x, y, z);
    TileEntityElevatorBase elevatorBase = getCoreTileEntity(world, x, y, z);
    if (elevatorBase != null) {
        elevatorBase.updateMaxElevatorHeight();
    }
}
Also used : TileEntityElevatorBase(pneumaticCraft.common.tileentity.TileEntityElevatorBase)

Example 8 with TileEntityElevatorBase

use of pneumaticCraft.common.tileentity.TileEntityElevatorBase in project PneumaticCraft by MineMaarten.

the class BlockElevatorBase method dropInventory.

@Override
protected void dropInventory(World world, int x, int y, int z) {
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (!(tileEntity instanceof TileEntityElevatorBase))
        return;
    TileEntityElevatorBase inventory = (TileEntityElevatorBase) tileEntity;
    Random rand = new Random();
    for (int i = getInventoryDropStartSlot(inventory); i < getInventoryDropEndSlot(inventory); i++) {
        ItemStack itemStack = inventory.getRealStackInSlot(i);
        if (itemStack != null && itemStack.stackSize > 0) {
            float dX = rand.nextFloat() * 0.8F + 0.1F;
            float dY = rand.nextFloat() * 0.8F + 0.1F;
            float dZ = rand.nextFloat() * 0.8F + 0.1F;
            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;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Random(java.util.Random) TileEntityElevatorBase(pneumaticCraft.common.tileentity.TileEntityElevatorBase) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 9 with TileEntityElevatorBase

use of pneumaticCraft.common.tileentity.TileEntityElevatorBase in project PneumaticCraft by MineMaarten.

the class BlockElevatorBase method breakBlock.

@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
    if (world.getBlock(x, y - 1, z) == Blockss.elevatorBase) {
        TileEntity te = world.getTileEntity(x, y - 1, z);
        ((TileEntityElevatorBase) te).moveInventoryToThis();
    }
    TileEntityElevatorBase elevatorBase = getCoreTileEntity(world, x, y, z);
    if (elevatorBase != null) {
        elevatorBase.updateMaxElevatorHeight();
    }
    super.breakBlock(world, x, y, z, block, meta);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityElevatorBase(pneumaticCraft.common.tileentity.TileEntityElevatorBase)

Example 10 with TileEntityElevatorBase

use of pneumaticCraft.common.tileentity.TileEntityElevatorBase in project PneumaticCraft by MineMaarten.

the class BlockElevatorCaller method getElevatorBase.

private TileEntityElevatorBase getElevatorBase(World world, int x, int y, int z) {
    Block block = world.getBlock(x, y, z);
    TileEntityElevatorBase elevator = null;
    if (block == Blockss.elevatorFrame) {
        elevator = BlockElevatorFrame.getElevatorTE(world, x, y, z);
    }
    if (block == Blockss.elevatorBase) {
        TileEntity te = world.getTileEntity(x, y, z);
        if (te instanceof TileEntityElevatorBase && ((TileEntityElevatorBase) te).isCoreElevator()) {
            elevator = (TileEntityElevatorBase) te;
        }
    }
    return elevator;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityElevatorBase(pneumaticCraft.common.tileentity.TileEntityElevatorBase) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock)

Aggregations

TileEntityElevatorBase (pneumaticCraft.common.tileentity.TileEntityElevatorBase)11 TileEntity (net.minecraft.tileentity.TileEntity)4 EntityItem (net.minecraft.entity.item.EntityItem)2 ItemStack (net.minecraft.item.ItemStack)2 Random (java.util.Random)1 Block (net.minecraft.block.Block)1 ItemBlock (net.minecraft.item.ItemBlock)1