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;
}
}
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);
}
}
}
}
}
}
}
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;
}
}
}
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);
}
}
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;
}
Aggregations