Search in sources :

Example 1 with TileEntityFactoryInventory

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) TileEntityAutoJukebox(powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoJukebox) TileEntityFactoryInventory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactoryInventory) TileEntityDeepStorageUnit(powercrystals.minefactoryreloaded.tile.machine.TileEntityDeepStorageUnit) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with TileEntityFactoryInventory

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILiquidTank(net.minecraftforge.liquids.ILiquidTank) TileEntityFactoryInventory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactoryInventory)

Example 3 with TileEntityFactoryInventory

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());
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFactory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactory) TileEntityFactoryInventory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactoryInventory)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)3 TileEntityFactoryInventory (powercrystals.minefactoryreloaded.tile.base.TileEntityFactoryInventory)3 EntityItem (net.minecraft.entity.item.EntityItem)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 ILiquidTank (net.minecraftforge.liquids.ILiquidTank)1 TileEntityFactory (powercrystals.minefactoryreloaded.tile.base.TileEntityFactory)1 TileEntityAutoJukebox (powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoJukebox)1 TileEntityDeepStorageUnit (powercrystals.minefactoryreloaded.tile.machine.TileEntityDeepStorageUnit)1