use of minechem.item.molecule.MoleculeEnum in project Minechem by iopleke.
the class ScheduledTickHandler method checkForPoison.
@SubscribeEvent
public void checkForPoison(PlayerUseItemEvent.Finish event) {
if (event.item != null && event.item.getTagCompound() != null && Settings.FoodSpiking) {
NBTTagCompound stackTag = event.item.getTagCompound();
boolean isPoisoned = stackTag.getBoolean("minechem.isPoisoned");
int[] effectTypes = stackTag.getIntArray("minechem.effectTypes");
if (isPoisoned) {
for (int effectType : effectTypes) {
MoleculeEnum molecule = MoleculeEnum.getById(effectType);
PharmacologyEffectRegistry.applyEffect(molecule, event.entityPlayer);
}
}
}
}
use of minechem.item.molecule.MoleculeEnum in project Minechem by iopleke.
the class FluidItemRenderingHandler method renderItem.
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
Fluid fluid = ((BlockFluidBase) ((ItemBlock) item.getItem()).field_150939_a).getFluid();
if (fluid instanceof FluidElement) {
RenderingUtil.setColorForElement(((FluidElement) fluid).element);
} else if (fluid instanceof FluidMolecule) {
MoleculeEnum molecule = ((FluidMolecule) fluid).molecule;
GL11.glColor3f(molecule.red, molecule.green, molecule.blue);
}
IIcon icon = ((ItemBlock) item.getItem()).field_150939_a.getBlockTextureFromSide(0);
switch(type) {
case INVENTORY:
RenderingUtil.drawTexturedRectUV(0, 0, 0, 16, 16, icon);
break;
case EQUIPPED_FIRST_PERSON:
case EQUIPPED:
ItemRenderer.renderItemIn2D(Tessellator.instance, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(), icon.getIconWidth(), icon.getIconHeight(), 0.0625F);
break;
case ENTITY:
EntityItem entityItem = (EntityItem) data[1];
if (entityItem.worldObj == null) {
float angle = (Minecraft.getSystemTime() % 8000L) / 8000.0F * 360.0F;
GL11.glPushMatrix();
GL11.glRotatef(angle, 0.0F, 1.0F, 0.0F);
GL11.glTranslatef(-0.2F, -0.5F, 0.0F);
renderItemAsEntity(item, icon);
GL11.glPopMatrix();
} else {
renderItemAsEntity(item, icon);
}
break;
default:
break;
}
}
use of minechem.item.molecule.MoleculeEnum 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;
}
use of minechem.item.molecule.MoleculeEnum in project Minechem by iopleke.
the class ElementItem method onItemUseFirst.
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
TileEntity te = world.getTileEntity(x, y, z);
boolean result = !world.isRemote;
if (te != null && te instanceof IFluidHandler && !player.isSneaking() && !(te instanceof IInventory)) {
if (stack.getItemDamage() != 0) {
int filled = 0;
for (int i = 0; i < 6; i++) {
FluidElement fluid = FluidHelper.elements.get(getElement(stack));
if (fluid == null) {
return super.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
filled = ((IFluidHandler) te).fill(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), false);
if (filled > 0) {
if (result) {
((IFluidHandler) te).fill(ForgeDirection.getOrientation(i), new FluidStack(FluidHelper.elements.get(getElement(stack)), 125), true);
}
if (!player.capabilities.isCreativeMode) {
MinechemUtil.incPlayerInventory(stack, -1, player, new ItemStack(MinechemItemsRegistration.element, 1, 0));
}
return result || stack.stackSize <= 0;
}
}
} else {
FluidStack drained = null;
Fluid fluid = MinechemUtil.getFluid((IFluidHandler) te);
ElementEnum element = MinechemUtil.getElement(fluid);
if (element != null) {
for (int i = 0; i < 6; i++) {
drained = ((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), false);
if (drained != null && drained.amount > 0) {
if (result) {
((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), true);
}
if (!player.capabilities.isCreativeMode) {
MinechemUtil.incPlayerInventory(stack, -1, player, new ItemStack(MinechemItemsRegistration.element, 1, element.atomicNumber()));
}
return result;
}
}
} else {
MoleculeEnum molecule = MinechemUtil.getMolecule(fluid);
if (fluid == FluidRegistry.WATER) {
molecule = MoleculeEnum.water;
}
if (molecule != null) {
for (int i = 0; i < 6; i++) {
drained = ((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), false);
if (drained != null && drained.amount > 0) {
if (result) {
((IFluidHandler) te).drain(ForgeDirection.getOrientation(i), new FluidStack(fluid, 125), true);
}
if (!player.capabilities.isCreativeMode) {
MinechemUtil.incPlayerInventory(stack, -1, player, new ItemStack(MinechemItemsRegistration.molecule, 1, molecule.id()));
}
return result;
}
}
}
}
}
return result;
}
return super.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
use of minechem.item.molecule.MoleculeEnum in project Minechem by iopleke.
the class MinechemRecipes method addSynthesisRecipesFromMolecules.
private void addSynthesisRecipesFromMolecules() {
for (MoleculeEnum molecule : MoleculeEnum.molecules.values()) {
if (molecule != null) {
ItemStack moleculeItemStack = new ItemStack(MinechemItemsRegistration.molecule, 1, molecule.id());
SynthesisRecipe.add(new SynthesisRecipe(moleculeItemStack, false, COST_ITEM, molecule.components()));
}
}
}
Aggregations