Search in sources :

Example 1 with RadiationFluidTileEntity

use of minechem.radiation.RadiationFluidTileEntity in project Minechem by iopleke.

the class MoleculeItem method emptyTube.

private ItemStack emptyTube(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z) {
    if (!world.isAirBlock(x, y, z) && !world.getBlock(x, y, z).getMaterial().isSolid()) {
        Block sourceBlock = world.getBlock(x, y, z);
        int metadata = world.getBlockMetadata(x, y, z);
        sourceBlock.harvestBlock(world, player, x, y, z, metadata);
        sourceBlock.breakBlock(world, x, y, z, sourceBlock, metadata);
        world.setBlockToAir(x, y, z);
    }
    if (world.isAirBlock(x, y, z)) {
        RadiationInfo radioactivity = ElementItem.getRadiationInfo(itemStack, world);
        long worldtime = world.getTotalWorldTime();
        long leftTime = radioactivity.radioactivity.getLife() - (worldtime - radioactivity.decayStarted);
        MoleculeEnum molecule = getMolecule(itemStack);
        Fluid fluid = FluidHelper.molecules.get(molecule);
        if (fluid == null) {
            return itemStack;
        }
        if (!player.capabilities.isCreativeMode) {
            if (itemStack.stackSize >= 8) {
                itemStack.stackSize -= 8;
            } else {
                int needs = 8 - itemStack.stackSize;
                Set<ItemStack> otherItemsStacks = MinechemUtil.findItemStacks(player.inventory, itemStack.getItem(), itemStack.getItemDamage());
                otherItemsStacks.remove(itemStack);
                int free = 0;
                Iterator<ItemStack> it2 = otherItemsStacks.iterator();
                while (it2.hasNext()) {
                    ItemStack stack = it2.next();
                    free += stack.stackSize;
                }
                if (free < needs) {
                    return itemStack;
                }
                itemStack.stackSize = 0;
                Iterator<ItemStack> it = otherItemsStacks.iterator();
                while (it.hasNext()) {
                    ItemStack stack = it.next();
                    RadiationInfo anotherRadiation = ElementItem.getRadiationInfo(stack, world);
                    long anotherLeft = anotherRadiation.radioactivity.getLife() - (worldtime - anotherRadiation.decayStarted);
                    if (anotherLeft < leftTime) {
                        radioactivity = anotherRadiation;
                        leftTime = anotherLeft;
                    }
                    if (stack.stackSize >= needs) {
                        stack.stackSize -= needs;
                        needs = 0;
                    } else {
                        needs -= stack.stackSize;
                        stack.stackSize = 0;
                    }
                    if (stack.stackSize <= 0) {
                        MinechemUtil.removeStackInInventory(player.inventory, stack);
                    }
                    if (needs == 0) {
                        break;
                    }
                }
            }
            ItemStack empties = MinechemUtil.addItemToInventory(player.inventory, new ItemStack(MinechemItemsRegistration.element, 8, 0));
            MinechemUtil.throwItemStack(world, empties, x, y, z);
        }
        Block block = Blocks.flowing_water;
        if (getMolecule(itemStack) != MoleculeEnum.water) {
            block = FluidHelper.moleculeBlocks.get(fluid);
        }
        world.setBlock(x, y, z, block, 0, 3);
        TileEntity tile = world.getTileEntity(x, y, z);
        if (radioactivity.isRadioactive() && tile instanceof RadiationFluidTileEntity) {
            ((RadiationFluidTileEntity) tile).info = radioactivity;
        }
    }
    return itemStack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) RadiationInfo(minechem.radiation.RadiationInfo) Fluid(net.minecraftforge.fluids.Fluid) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 2 with RadiationFluidTileEntity

use of minechem.radiation.RadiationFluidTileEntity in project Minechem by iopleke.

the class FluidChemicalDispenser method dispense.

@Override
public ItemStack dispense(IBlockSource blockSource, ItemStack itemStack) {
    EnumFacing enumfacing = BlockDispenser.func_149937_b(blockSource.getBlockMetadata());
    World world = blockSource.getWorld();
    int x = blockSource.getXInt() + enumfacing.getFrontOffsetX();
    int y = blockSource.getYInt() + enumfacing.getFrontOffsetY();
    int z = blockSource.getZInt() + enumfacing.getFrontOffsetZ();
    TileEntity inventoryTile = blockSource.getBlockTileEntity();
    if (itemStack.getItem() instanceof ElementItem && itemStack.getItemDamage() != 0) {
        Block frontBlock = world.getBlock(x, y, z);
        MinechemChemicalType chemical = MinechemUtil.getChemical(frontBlock);
        if (chemical != null && MinechemUtil.canDrain(world, frontBlock, x, y, z)) {
            ItemStack stack = MinechemUtil.createItemStack(chemical, 8);
            if (stack != null) {
                if (itemStack.stackSize >= 8) {
                    itemStack.stackSize -= 8;
                } else {
                    if (inventoryTile instanceof IInventory) {
                        int needs = 8 - itemStack.stackSize;
                        IInventory inventory = (IInventory) inventoryTile;
                        Set<ItemStack> otherTubes = MinechemUtil.findItemStacks(inventory, MinechemItemsRegistration.element, 0);
                        int free = 0;
                        otherTubes.remove(itemStack);
                        for (ItemStack emptyStack : otherTubes) {
                            free += emptyStack.stackSize;
                        }
                        if (free < needs) {
                            return itemStack;
                        }
                        itemStack.stackSize = 0;
                        for (ItemStack emptyStack : otherTubes) {
                            if (emptyStack.stackSize >= needs) {
                                emptyStack.stackSize -= needs;
                                needs = 0;
                            } else {
                                needs -= emptyStack.stackSize;
                                emptyStack.stackSize = 0;
                            }
                            if (emptyStack.stackSize <= 0) {
                                MinechemUtil.removeStackInInventory(inventory, emptyStack);
                            }
                            if (needs == 0) {
                                break;
                            }
                        }
                    }
                }
                TileEntity tile = world.getTileEntity(x, y, z);
                if (tile instanceof RadiationFluidTileEntity && ((RadiationFluidTileEntity) tile).info != null) {
                    RadiationInfo.setRadiationInfo(((RadiationFluidTileEntity) tile).info, stack);
                }
                world.setBlockToAir(x, y, z);
                if (inventoryTile instanceof IInventory) {
                    stack = MinechemUtil.addItemToInventory((IInventory) inventoryTile, stack);
                }
                MinechemUtil.throwItemStack(world, stack, x, y, z);
            }
        }
    } else {
        IInventory inventory;
        Block block;
        if (inventoryTile instanceof IInventory) {
            inventory = (IInventory) inventoryTile;
        } else {
            return itemStack;
        }
        if (itemStack.getItem() instanceof ElementItem) {
            ElementEnum element = ElementItem.getElement(itemStack);
            block = FluidHelper.elementsBlocks.get(FluidHelper.elements.get(element));
        } else if (itemStack.getItem() instanceof MoleculeItem) {
            MoleculeEnum molecule = MoleculeEnum.getById(itemStack.getItemDamage());
            block = FluidHelper.moleculeBlocks.get(FluidHelper.molecules.get(molecule));
        } else {
            return itemStack;
        }
        if (!world.isAirBlock(x, y, z) && !world.getBlock(x, y, z).getMaterial().isSolid()) {
            world.func_147480_a(x, y, z, true);
            world.setBlockToAir(x, y, z);
        }
        if (world.isAirBlock(x, y, z)) {
            RadiationInfo radioactivity = ElementItem.getRadiationInfo(itemStack, world);
            long worldtime = world.getTotalWorldTime();
            long leftTime = radioactivity.radioactivity.getLife() - (worldtime - radioactivity.decayStarted);
            if (itemStack.stackSize >= 8) {
                itemStack.stackSize -= 8;
            } else {
                int needs = 8 - itemStack.stackSize;
                itemStack.stackSize = 0;
                Set<ItemStack> otherItemsStacks = MinechemUtil.findItemStacks(inventory, itemStack.getItem(), itemStack.getItemDamage());
                otherItemsStacks.remove(itemStack);
                int free = 0;
                for (ItemStack stack : otherItemsStacks) {
                    free += stack.stackSize;
                }
                if (free < needs) {
                    return itemStack;
                }
                for (ItemStack stack : otherItemsStacks) {
                    RadiationInfo anotherRadiation = ElementItem.getRadiationInfo(stack, world);
                    long anotherLeft = anotherRadiation.radioactivity.getLife() - (worldtime - anotherRadiation.decayStarted);
                    if (anotherLeft < leftTime) {
                        radioactivity = anotherRadiation;
                        leftTime = anotherLeft;
                    }
                    if (stack.stackSize >= needs) {
                        stack.stackSize -= needs;
                        needs = 0;
                    } else {
                        needs -= stack.stackSize;
                        stack.stackSize = 0;
                    }
                    if (stack.stackSize <= 0) {
                        MinechemUtil.removeStackInInventory(inventory, stack);
                    }
                    if (needs == 0) {
                        break;
                    }
                }
            }
            ItemStack empties = MinechemUtil.addItemToInventory(inventory, new ItemStack(MinechemItemsRegistration.element, 8, 0));
            MinechemUtil.throwItemStack(world, empties, x, y, z);
            world.setBlock(x, y, z, block, 0, 3);
            TileEntity tile = world.getTileEntity(x, y, z);
            if (radioactivity.isRadioactive() && tile instanceof RadiationFluidTileEntity) {
                ((RadiationFluidTileEntity) tile).info = radioactivity;
            }
        }
        return itemStack;
    // Block block = null;
    // RadiationEnum radioactivity = null;
    // if (itemStack.getItem() instanceof ElementItem)
    // {
    // ElementEnum element = ElementItem.getElement(itemStack);
    // block = FluidHelper.elementsBlocks.get(FluidHelper.elements.get(element));
    // radioactivity = element.radioactivity();
    // } else if (itemStack.getItem() instanceof MoleculeItem)
    // {
    // MoleculeEnum molecule = MoleculeEnum.getById(itemStack.getItemDamage());
    // block = FluidHelper.moleculeBlocks.get(FluidHelper.molecules.get(molecule));
    // radioactivity = molecule.radioactivity();
    // }
    // 
    // if (!world.isAirBlock(x, y, z) && !world.getBlock(x, y, z).getMaterial().isSolid())
    // {
    // world.func_147480_a(x, y, z, true);
    // world.setBlockToAir(x, y, z);
    // }
    // 
    // if (world.isAirBlock(x, y, z) && block != null)
    // {
    // world.setBlock(x, y, z, block, 0, 3);
    // --itemStack.stackSize;
    // TileEntity tile = world.getTileEntity(x, y, z);
    // if (radioactivity != RadiationEnum.stable && tile instanceof RadiationFluidTileEntity)
    // {
    // ((RadiationFluidTileEntity) tile).info = ElementItem.getRadiationInfo(itemStack, world);
    // }
    // ItemStack elementStack = new ItemStack(MinechemItemsRegistration.element, 1, ElementEnum.heaviestMass);
    // TileEntity inventoryTile = blockSource.getBlockTileEntity();
    // if (inventoryTile instanceof IInventory)
    // {
    // elementStack = MinechemUtil.addItemToInventory((IInventory) inventoryTile, elementStack);
    // }
    // MinechemUtil.throwItemStack(world, elementStack, x, y, z);
    // }
    }
    return itemStack;
}
Also used : ElementItem(minechem.item.element.ElementItem) IInventory(net.minecraft.inventory.IInventory) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) EnumFacing(net.minecraft.util.EnumFacing) MoleculeItem(minechem.item.molecule.MoleculeItem) World(net.minecraft.world.World) MinechemChemicalType(minechem.item.MinechemChemicalType) TileEntity(net.minecraft.tileentity.TileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) ElementEnum(minechem.item.element.ElementEnum) RadiationInfo(minechem.radiation.RadiationInfo) Block(net.minecraft.block.Block) MoleculeEnum(minechem.item.molecule.MoleculeEnum) ItemStack(net.minecraft.item.ItemStack)

Example 3 with RadiationFluidTileEntity

use of minechem.radiation.RadiationFluidTileEntity in project Minechem by iopleke.

the class ElementItem method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
    boolean flag = itemStack.getItemDamage() == 0;
    MovingObjectPosition movingObjectPosition = this.getMovingObjectPositionFromPlayer(world, player, flag);
    if (movingObjectPosition == null) {
        return itemStack;
    }
    if (movingObjectPosition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
        int blockX = movingObjectPosition.blockX;
        int blockY = movingObjectPosition.blockY;
        int blockZ = movingObjectPosition.blockZ;
        Block block = world.getBlock(blockX, blockY, blockZ);
        if (flag) {
            MinechemChemicalType chemical = MinechemUtil.getChemical(block);
            if (chemical != null && MinechemUtil.canDrain(world, block, blockX, blockY, blockZ)) {
                ItemStack stack = MinechemUtil.createItemStack(chemical, 1);
                if (stack != null) {
                    stack.stackSize = 8;
                    TileEntity tile = world.getTileEntity(blockX, blockY, blockZ);
                    if (tile instanceof RadiationFluidTileEntity && ((RadiationFluidTileEntity) tile).info != null) {
                        RadiationInfo.setRadiationInfo(((RadiationFluidTileEntity) tile).info, stack);
                    }
                    world.setBlockToAir(blockX, blockY, blockZ);
                    world.removeTileEntity(blockX, blockY, blockZ);
                    return fillTube(itemStack, player, stack);
                }
            }
        } else {
            ForgeDirection dir = ForgeDirection.getOrientation(movingObjectPosition.sideHit);
            blockX += dir.offsetX;
            blockY += dir.offsetY;
            blockZ += dir.offsetZ;
            if (!player.canPlayerEdit(blockX, blockY, blockZ, movingObjectPosition.sideHit, itemStack)) {
                return itemStack;
            }
            return emptyTube(itemStack, player, world, blockX, blockY, blockZ);
        }
    }
    return itemStack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) MinechemChemicalType(minechem.item.MinechemChemicalType)

Example 4 with RadiationFluidTileEntity

use of minechem.radiation.RadiationFluidTileEntity in project Minechem by iopleke.

the class ElementItem method emptyTube.

private ItemStack emptyTube(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z) {
    if (!world.isAirBlock(x, y, z) && !world.getBlock(x, y, z).getMaterial().isSolid()) {
        Block sourceBlock = world.getBlock(x, y, z);
        int metadata = world.getBlockMetadata(x, y, z);
        sourceBlock.harvestBlock(world, player, x, y, z, metadata);
        sourceBlock.breakBlock(world, x, y, z, sourceBlock, metadata);
        world.setBlockToAir(x, y, z);
    }
    if (world.isAirBlock(x, y, z)) {
        RadiationInfo radioactivity = getRadiationInfo(itemStack, world);
        long worldtime = world.getTotalWorldTime();
        long leftTime = radioactivity.radioactivity.getLife() - (worldtime - radioactivity.decayStarted);
        Fluid fluid = FluidHelper.elements.get(getElement(itemStack));
        if (fluid == null) {
            return itemStack;
        }
        if (!player.capabilities.isCreativeMode) {
            if (itemStack.stackSize >= 8) {
                itemStack.stackSize -= 8;
            } else {
                int needs = 8 - itemStack.stackSize;
                Set<ItemStack> otherItemsStacks = MinechemUtil.findItemStacks(player.inventory, itemStack.getItem(), itemStack.getItemDamage());
                otherItemsStacks.remove(itemStack);
                int free = 0;
                Iterator<ItemStack> it2 = otherItemsStacks.iterator();
                while (it2.hasNext()) {
                    ItemStack stack = it2.next();
                    free += stack.stackSize;
                }
                if (free < needs) {
                    return itemStack;
                }
                itemStack.stackSize = 0;
                Iterator<ItemStack> it = otherItemsStacks.iterator();
                while (it.hasNext()) {
                    ItemStack stack = it.next();
                    RadiationInfo anotherRadiation = getRadiationInfo(stack, world);
                    long anotherLeft = anotherRadiation.radioactivity.getLife() - (worldtime - anotherRadiation.decayStarted);
                    if (anotherLeft < leftTime) {
                        radioactivity = anotherRadiation;
                        leftTime = anotherLeft;
                    }
                    if (stack.stackSize >= needs) {
                        stack.stackSize -= needs;
                        needs = 0;
                    } else {
                        needs -= stack.stackSize;
                        stack.stackSize = 0;
                    }
                    if (stack.stackSize <= 0) {
                        MinechemUtil.removeStackInInventory(player.inventory, stack);
                    }
                    if (needs == 0) {
                        break;
                    }
                }
            }
            ItemStack empties = MinechemUtil.addItemToInventory(player.inventory, new ItemStack(MinechemItemsRegistration.element, 8, 0));
            MinechemUtil.throwItemStack(world, empties, x, y, z);
        }
        Block block = FluidHelper.elementsBlocks.get(fluid);
        world.setBlock(x, y, z, block, 0, 3);
        TileEntity tile = world.getTileEntity(x, y, z);
        if (radioactivity.isRadioactive() && tile instanceof RadiationFluidTileEntity) {
            ((RadiationFluidTileEntity) tile).info = radioactivity;
        }
    }
    return itemStack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) RadiationInfo(minechem.radiation.RadiationInfo) Fluid(net.minecraftforge.fluids.Fluid) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 5 with RadiationFluidTileEntity

use of minechem.radiation.RadiationFluidTileEntity in project Minechem by iopleke.

the class MinechemBucketItem method placeLiquid.

public boolean placeLiquid(World world, ItemStack itemstack, int x, int y, int z) {
    Material material = world.getBlock(x, y, z).getMaterial();
    boolean flag = !material.isSolid();
    if (!world.isAirBlock(x, y, z) && !flag) {
        return false;
    } else {
        if (!world.isRemote && flag && !material.isLiquid()) {
            world.func_147480_a(x, y, z, true);
        }
        world.setBlock(x, y, z, this.block, 0, 3);
        TileEntity tile = world.getTileEntity(x, y, z);
        if (chemical.radioactivity() != RadiationEnum.stable && tile instanceof RadiationFluidTileEntity) {
            int dimensionID = itemstack.stackTagCompound.getInteger("dimensionID");
            long lastUpdate = itemstack.stackTagCompound.getLong("lastUpdate");
            long decayStart = itemstack.stackTagCompound.getLong("decayStart");
            RadiationInfo radioactivity = new RadiationInfo(itemstack, decayStart, lastUpdate, dimensionID, chemical.radioactivity());
            ((RadiationFluidTileEntity) tile).info = radioactivity;
        }
        return true;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) RadiationFluidTileEntity(minechem.radiation.RadiationFluidTileEntity) RadiationInfo(minechem.radiation.RadiationInfo) Material(net.minecraft.block.material.Material)

Aggregations

RadiationFluidTileEntity (minechem.radiation.RadiationFluidTileEntity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 Block (net.minecraft.block.Block)7 ItemStack (net.minecraft.item.ItemStack)6 RadiationInfo (minechem.radiation.RadiationInfo)5 EnumFacing (net.minecraft.util.EnumFacing)3 World (net.minecraft.world.World)3 MinechemChemicalType (minechem.item.MinechemChemicalType)2 MinechemBucketItem (minechem.item.bucket.MinechemBucketItem)2 IInventory (net.minecraft.inventory.IInventory)2 Fluid (net.minecraftforge.fluids.Fluid)2 MinechemFluidBlock (minechem.fluid.MinechemFluidBlock)1 ElementEnum (minechem.item.element.ElementEnum)1 ElementItem (minechem.item.element.ElementItem)1 MoleculeEnum (minechem.item.molecule.MoleculeEnum)1 MoleculeItem (minechem.item.molecule.MoleculeItem)1 RadiationEnum (minechem.radiation.RadiationEnum)1 Material (net.minecraft.block.material.Material)1 Item (net.minecraft.item.Item)1 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)1