use of powercrystals.minefactoryreloaded.tile.base.TileEntityFactoryInventory in project MineFactoryReloaded by powercrystals.
the class BlockFactoryMachine method breakBlock.
@Override
public void breakBlock(World world, int x, int y, int z, int blockId, int meta) {
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof IInventory && !(te instanceof TileEntityDeepStorageUnit)) {
IInventory inventory = ((IInventory) te);
inv: for (int i = 0; i < inventory.getSizeInventory(); i++) {
if (te instanceof TileEntityFactoryInventory && !((TileEntityFactoryInventory) te).shouldDropSlotWhenBroken(i)) {
continue;
}
ItemStack itemstack = inventory.getStackInSlot(i);
if (itemstack == null) {
continue;
}
float xOffset = world.rand.nextFloat() * 0.8F + 0.1F;
float yOffset = world.rand.nextFloat() * 0.8F + 0.1F;
float zOffset = world.rand.nextFloat() * 0.8F + 0.1F;
do {
if (itemstack.stackSize <= 0) {
continue inv;
}
int amountToDrop = world.rand.nextInt(21) + 10;
if (amountToDrop > itemstack.stackSize) {
amountToDrop = itemstack.stackSize;
}
itemstack.stackSize -= amountToDrop;
EntityItem entityitem = new EntityItem(world, x + xOffset, y + yOffset, z + zOffset, new ItemStack(itemstack.itemID, amountToDrop, itemstack.getItemDamage()));
if (itemstack.getTagCompound() != null) {
entityitem.getEntityItem().setTagCompound(itemstack.getTagCompound());
}
float motionMultiplier = 0.05F;
entityitem.motionX = (float) world.rand.nextGaussian() * motionMultiplier;
entityitem.motionY = (float) world.rand.nextGaussian() * motionMultiplier + 0.2F;
entityitem.motionZ = (float) world.rand.nextGaussian() * motionMultiplier;
world.spawnEntityInWorld(entityitem);
} while (true);
}
}
if (te instanceof TileEntityFactoryInventory) {
((TileEntityFactoryInventory) te).onBlockBroken();
}
if (te instanceof TileEntityAutoJukebox) {
((TileEntityAutoJukebox) te).stopRecord();
}
super.breakBlock(world, x, y, z, blockId, meta);
}
use of powercrystals.minefactoryreloaded.tile.base.TileEntityFactoryInventory in project MineFactoryReloaded by powercrystals.
the class BlockFactoryMachine method getComparatorInputOverride.
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int side) {
int ret = 0;
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityFactoryInventory) {
TileEntityFactoryInventory inv = (TileEntityFactoryInventory) te;
ILiquidTank tank = inv.getTank();
float tankPercent = 0, invPercent = 0;
boolean hasTank = false, hasInventory = false;
if (tank != null) {
hasTank = true;
if (tank.getLiquid() != null) {
tankPercent = ((float) tank.getLiquid().amount) / tank.getCapacity();
}
}
int[] accSlots = inv.getAccessibleSlotsFromSide(side);
if (accSlots.length > 0) {
hasInventory = true;
invPercent = inv.getComparatorOutput(side);
}
float mult = hasTank & hasInventory ? (tankPercent + invPercent) / 2 : hasTank ? tankPercent : hasInventory ? invPercent : 0f;
ret = (int) Math.ceil(15 * mult);
}
return ret;
}
use of powercrystals.minefactoryreloaded.tile.base.TileEntityFactoryInventory in project MineFactoryReloaded by powercrystals.
the class BlockFactoryMachine method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entity, ItemStack stack) {
if (entity == null) {
return;
}
TileEntity te = world.getBlockTileEntity(x, y, z);
if (stack.getTagCompound() != null) {
stack.getTagCompound().setInteger("x", x);
stack.getTagCompound().setInteger("y", y);
stack.getTagCompound().setInteger("z", z);
te.readFromNBT(stack.getTagCompound());
}
if (te instanceof TileEntityFactory && ((TileEntityFactory) te).canRotate()) {
int facing = MathHelper.floor_double((entity.rotationYaw * 4F) / 360F + 0.5D) & 3;
if (facing == 0) {
((TileEntityFactory) te).rotateDirectlyTo(3);
} else if (facing == 1) {
((TileEntityFactory) te).rotateDirectlyTo(4);
} else if (facing == 2) {
((TileEntityFactory) te).rotateDirectlyTo(2);
} else if (facing == 3) {
((TileEntityFactory) te).rotateDirectlyTo(5);
}
if (te instanceof TileEntityFactoryInventory) {
if (stack.hasDisplayName()) {
((TileEntityFactoryInventory) te).setInvName(stack.getDisplayName());
}
}
}
}
Aggregations