Search in sources :

Example 71 with TileEntity

use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.

the class BlockAssemblyPlatform method dropInventory.

//overriden here because the Assembly Platform isn't implementing IInventory (intentionally).
@Override
protected void dropInventory(World world, int x, int y, int z) {
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (!(tileEntity instanceof TileEntityAssemblyPlatform))
        return;
    TileEntityAssemblyPlatform inventory = (TileEntityAssemblyPlatform) tileEntity;
    Random rand = new Random();
    ItemStack itemStack = inventory.getHeldStack();
    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) TileEntityAssemblyPlatform(pneumaticCraft.common.tileentity.TileEntityAssemblyPlatform) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 72 with TileEntity

use of net.minecraft.tileentity.TileEntity 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 73 with TileEntity

use of net.minecraft.tileentity.TileEntity 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 74 with TileEntity

use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.

the class BlockElevatorCaller method onNeighborBlockChange.

/**
     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
     * their own) Args: x, y, z, neighbor blockID
     */
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
    int oldMeta = world.getBlockMetadata(x, y, z);
    boolean wasPowered = oldMeta / 8 > 0;
    boolean isPowered = world.isBlockIndirectlyGettingPowered(x, y, z);
    if (!wasPowered && isPowered) {
        world.setBlockMetadataWithNotify(x, y, z, oldMeta + 8, 3);
        TileEntity te = world.getTileEntity(x, y, z);
        if (te instanceof TileEntityElevatorCaller) {
            setSurroundingElevators(world, x, y, z, ((TileEntityElevatorCaller) te).thisFloor);
        }
    } else if (wasPowered && !isPowered) {
        world.setBlockMetadataWithNotify(x, y, z, oldMeta - 8, 3);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityElevatorCaller(pneumaticCraft.common.tileentity.TileEntityElevatorCaller)

Example 75 with TileEntity

use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.

the class BlockElevatorCaller method collisionRayTrace.

@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
    setBlockBounds(0, 0, 0, 1, 1, 1);
    MovingObjectPosition rayTrace = super.collisionRayTrace(world, x, y, z, origin, direction);
    ForgeDirection orientation = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z) & 7).getOpposite();
    if (rayTrace != null && rayTrace.sideHit == orientation.ordinal()) {
        TileEntity te = world.getTileEntity(x, y, z);
        if (te instanceof TileEntityElevatorCaller) {
            TileEntityElevatorCaller caller = (TileEntityElevatorCaller) te;
            for (TileEntityElevatorCaller.ElevatorButton button : caller.getFloors()) {
                float startX = 0, startZ = 0, endX = 0, endZ = 0;
                switch(orientation) {
                    case NORTH:
                        startZ = 0F;
                        endZ = 0.01F;
                        endX = 1 - (float) button.posX;
                        startX = 1 - ((float) button.posX + (float) button.width);
                        break;
                    case SOUTH:
                        startZ = 0.99F;
                        endZ = 1F;
                        startX = (float) button.posX;
                        endX = (float) button.posX + (float) button.width;
                        break;
                    case WEST:
                        startX = 0F;
                        endX = 0.01F;
                        startZ = (float) button.posX;
                        endZ = (float) button.posX + (float) button.width;
                        break;
                    case EAST:
                        startX = 0.99F;
                        endX = 1F;
                        endZ = 1 - (float) button.posX;
                        startZ = 1 - ((float) button.posX + (float) button.width);
                        break;
                }
                setBlockBounds(startX, 1 - (float) (button.posY + button.height), startZ, endX, 1 - (float) button.posY, endZ);
                MovingObjectPosition buttonTrace = super.collisionRayTrace(world, x, y, z, origin, direction);
                if (buttonTrace != null) {
                    if (startX > 0.01F && startX < 0.98F)
                        startX += 0.01F;
                    if (startZ > 0.01F && startZ < 0.98F)
                        startZ += 0.01F;
                    if (endX > 0.02F && endX < 0.99F)
                        endX -= 0.01F;
                    if (endZ > 0.02F && endZ < 0.99F)
                        endZ -= 0.01F;
                    setBlockBounds(startX, 1.01F - (float) (button.posY + button.height), startZ, endX, 0.99F - (float) button.posY, endZ);
                    buttonTrace.subHit = button.floorNumber;
                    return buttonTrace;
                }
            }
        }
    }
    setBlockBounds(0, 0, 0, 1, 1, 1);
    return rayTrace;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) TileEntityElevatorCaller(pneumaticCraft.common.tileentity.TileEntityElevatorCaller)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)822 ItemStack (net.minecraft.item.ItemStack)149 BlockPos (net.minecraft.util.math.BlockPos)130 Block (net.minecraft.block.Block)83 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)76 EnumFacing (net.minecraft.util.EnumFacing)62 ArrayList (java.util.ArrayList)61 IBlockState (net.minecraft.block.state.IBlockState)61 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 IInventory (net.minecraft.inventory.IInventory)49 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)44 World (net.minecraft.world.World)43 EntityItem (net.minecraft.entity.item.EntityItem)39 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)35 FluidStack (net.minecraftforge.fluids.FluidStack)29 EntityPlayer (net.minecraft.entity.player.EntityPlayer)28 HashMap (java.util.HashMap)25 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)23 AMVector3 (am2.api.math.AMVector3)21 Entity (net.minecraft.entity.Entity)21