use of minechem.item.bucket.MinechemBucketItem in project Minechem by iopleke.
the class RadiationHandler method decayElement.
private int decayElement(ItemStack element, RadiationInfo radiationInfo, long currentTime, World world, IInventory inventory, double x, double y, double z) {
if (element.stackSize == 0) {
radiationInfo.decayStarted += currentTime - radiationInfo.lastDecayUpdate;
radiationInfo.lastDecayUpdate = currentTime;
RadiationInfo.setRadiationInfo(radiationInfo, element);
return 0;
}
radiationInfo.lastDecayUpdate = currentTime;
long lifeTime = currentTime - radiationInfo.decayStarted - radiationInfo.radioactivity.getLife();
if (lifeTime > 0) {
int damage = radiationInfo.radioactivity.getDamage() * element.stackSize;
Item item = element.getItem();
if (item == MinechemItemsRegistration.element) {
radiationInfo = ElementItem.decay(element, world);
} else if (item == MinechemItemsRegistration.molecule) {
radiationInfo = RadiationMoleculeHandler.getInstance().handleRadiationMolecule(world, element, inventory, x, y, z);
} else if (item instanceof MinechemBucketItem) {
MinechemChemicalType type = ((MinechemBucketItem) item).chemical;
if (type instanceof ElementEnum) {
element.func_150996_a(MinechemBucketHandler.getInstance().buckets.get(FluidHelper.elementsBlocks.get(FluidHelper.elements.get(ElementEnum.getByID(((ElementEnum) type).atomicNumber())))));
radiationInfo = ElementItem.initiateRadioactivity(element, world);
} else {
radiationInfo = RadiationMoleculeHandler.getInstance().handleRadiationMoleculeBucket(world, element, inventory, x, y, z);
}
}
RadiationInfo.setRadiationInfo(radiationInfo, element);
return damage;
}
RadiationInfo.setRadiationInfo(radiationInfo, element);
return 0;
}
use of minechem.item.bucket.MinechemBucketItem in project Minechem by iopleke.
the class RadiationInfo method getRadioactivity.
public static RadiationEnum getRadioactivity(ItemStack itemstack) {
int id = itemstack.getItemDamage();
Item item = itemstack.getItem();
if (item == MinechemItemsRegistration.element) {
ElementEnum element = ElementEnum.getByID(id);
return id != 0 && element != null ? element.radioactivity() : RadiationEnum.stable;
} else if (item == MinechemItemsRegistration.molecule) {
if (id >= MoleculeEnum.molecules.size() || MoleculeEnum.molecules.get(id) == null) {
return RadiationEnum.stable;
}
return MoleculeEnum.molecules.get(id).radioactivity();
} else if (item instanceof MinechemBucketItem) {
return ((MinechemBucketItem) item).chemical.radioactivity();
}
return RadiationEnum.stable;
}
use of minechem.item.bucket.MinechemBucketItem in project Minechem by iopleke.
the class MinechemBucketDispenser 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();
Block front = world.getBlock(x, y, z);
if (!front.getMaterial().isSolid()) {
world.func_147480_a(x, y, z, true);
world.setBlockToAir(x, y, z);
MinechemBucketItem item = (MinechemBucketItem) itemstack.getItem();
Block block = item.block;
world.setBlock(x, y, z, block, 0, 3);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile != null && item.chemical.radioactivity() != RadiationEnum.stable) {
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, item.chemical.radioactivity());
((RadiationFluidTileEntity) tile).info = radioactivity;
}
itemstack.func_150996_a(Items.bucket);
return itemstack;
}
return itemstack;
}
use of minechem.item.bucket.MinechemBucketItem in project Minechem by iopleke.
the class RadiationHandler method updateRadiationOnItems.
private void updateRadiationOnItems(World world, IInventory inventory, List<ItemStack> itemstacks, EntityPlayer player, Container container, double posX, double posY, double posZ) {
for (int i = 0; i < itemstacks.size(); i++) {
ItemStack itemstack = itemstacks.get(i);
if (itemstack != null) {
RadiationEnum radiation = null;
Item item = itemstack.getItem();
if (item == MinechemItemsRegistration.element) {
radiation = RadiationInfo.getRadioactivity(itemstack);
} else if (item == MinechemItemsRegistration.molecule) {
radiation = MoleculeItem.getMolecule(itemstack).radioactivity();
} else if (item instanceof MinechemBucketItem) {
radiation = ((MinechemBucketItem) item).chemical.radioactivity();
}
if (radiation != null && radiation != RadiationEnum.stable) {
Long time = world.getTotalWorldTime() - ElementItem.getRadiationInfo(itemstack, world).decayStarted;
ItemStack before = itemstack.copy();
int damage = updateRadiation(world, itemstack, inventory, posX, posY, posZ);
ItemStack after = itemstack.copy();
if (damage > 0) {
IInventory decayInventory = (container == null) ? inventory : container.getSlot(i).inventory;
MinecraftForge.EVENT_BUS.post(new RadiationDecayEvent(decayInventory, damage, time, before, after, player));
if (container != null && player != null) {
applyRadiationDamage(player, container, damage);
}
}
}
}
}
}
use of minechem.item.bucket.MinechemBucketItem in project Minechem by iopleke.
the class RadiationHandler method updateContainerNoDecay.
private void updateContainerNoDecay(EntityPlayer player, Container openContainer, IInventory inventory) {
INoDecay container = (INoDecay) openContainer;
List<ItemStack> itemstacks = container.getStorageInventory();
if (itemstacks != null) {
for (ItemStack itemstack : itemstacks) {
if (itemstack != null && (itemstack.getItem() == MinechemItemsRegistration.molecule || itemstack.getItem() == MinechemItemsRegistration.element || itemstack.getItem() instanceof MinechemBucketItem) && RadiationInfo.getRadioactivity(itemstack) != RadiationEnum.stable) {
RadiationInfo radiationInfo = ElementItem.getRadiationInfo(itemstack, player.worldObj);
radiationInfo.decayStarted += player.worldObj.getTotalWorldTime() - radiationInfo.lastDecayUpdate;
radiationInfo.lastDecayUpdate = player.worldObj.getTotalWorldTime();
RadiationInfo.setRadiationInfo(radiationInfo, itemstack);
}
}
}
List<ItemStack> playerStacks = container.getPlayerInventory();
if (playerStacks != null) {
updateRadiationOnItems(player.worldObj, player, openContainer, inventory, playerStacks);
}
}
Aggregations