use of minechem.item.MinechemChemicalType 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;
}
use of minechem.item.MinechemChemicalType in project Minechem by iopleke.
the class ChemicalFluidReactionHandler method checkToReact.
public static boolean checkToReact(Block source, Block destination, World world, int destinationX, int destinationY, int destinationZ, int sourceX, int sourceY, int sourceZ) {
MinechemChemicalType chemicalA = MinechemUtil.getChemical(source);
MinechemChemicalType chemicalB = MinechemUtil.getChemical(destination);
if (chemicalA != null && chemicalB != null) {
ChemicalFluidReactionRule rule = new ChemicalFluidReactionRule(chemicalA, chemicalB);
if (reactionRules.containsKey(rule)) {
boolean flag = !(MinechemUtil.canDrain(world, source, sourceX, sourceY, sourceZ) && MinechemUtil.canDrain(world, destination, destinationX, destinationY, destinationZ));
world.setBlockToAir(sourceX, sourceY, sourceZ);
world.setBlockToAir(destinationX, destinationY, destinationZ);
chemicalReaction(world, null, destinationX, destinationY, destinationZ, rule, flag);
return true;
}
}
return false;
}
use of minechem.item.MinechemChemicalType in project Minechem by iopleke.
the class MinechemBucketRecipe method matches.
@Override
public boolean matches(InventoryCrafting inv, World world) {
int chemicals = 0;
boolean hasBucket = false;
type = null;
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack == null) {
continue;
}
if (stack.getItem() == Items.bucket) {
if (hasBucket) {
return false;
}
hasBucket = true;
continue;
}
MinechemChemicalType anotherType;
if (stack.getItem() == MinechemItemsRegistration.element) {
anotherType = ElementItem.getElement(stack);
if (!FluidHelper.elements.containsKey(anotherType))
return false;
} else if (stack.getItem() == MinechemItemsRegistration.molecule) {
anotherType = MoleculeItem.getMolecule(stack);
if (!FluidHelper.molecules.containsKey(anotherType))
return false;
} else {
return false;
}
if (type == null) {
type = anotherType;
}
if (anotherType == type) {
chemicals++;
} else {
return false;
}
}
return hasBucket && chemicals == 8 && MinechemBucketHandler.getInstance().getBucket(type) != null;
}
use of minechem.item.MinechemChemicalType in project Minechem by iopleke.
the class ChemicalFluidReactionHandler method chemicalReaction.
private static void chemicalReaction(World world, Entity entity, int x, int y, int z, ChemicalFluidReactionRule rule, boolean popFlowingFluid) {
ChemicalFluidReactionOutput output = reactionRules.get(rule);
if (output == null) {
return;
}
if (!Float.isNaN(output.explosionLevel)) {
world.createExplosion(null, x, y, z, output.explosionLevel, true);
}
int halfSpace = FLUIDS_GENERATE_SPACE / 2;
List[] availableSpaces = new List[FLUIDS_GENERATE_SPACE];
for (int i = 0; i < availableSpaces.length; i++) {
availableSpaces[i] = findAvailableSpacesAtCrossSection(world, x, y - halfSpace + i, z, 1);
}
Iterator<MinechemChemicalType> it = output.outputs.iterator();
while (it.hasNext()) {
MinechemChemicalType chemical = it.next();
boolean hasFlowingStatus = chemical.roomState().getQuanta() > 2;
CoordTuple coords = null;
if (!(!hasFlowingStatus && popFlowingFluid)) {
boolean isGas = chemical.roomState().isGas();
if (isGas) {
for (int i = availableSpaces.length - 1; i > -1; i--) {
if (!availableSpaces[i].isEmpty()) {
coords = (CoordTuple) availableSpaces[i].remove(availableSpaces[i].size() - 1);
break;
}
}
} else {
for (int i = 0; i < availableSpaces.length; i++) {
if (!availableSpaces[i].isEmpty()) {
coords = (CoordTuple) availableSpaces[i].remove(availableSpaces[i].size() - 1);
break;
}
}
}
}
if (coords == null) {
if (!popFlowingFluid) {
ItemStack itemStack = MinechemUtil.createItemStack(chemical, 8);
MinechemUtil.throwItemStack(world, itemStack, x, y, z);
}
} else if (!(popFlowingFluid && !hasFlowingStatus)) {
int px = coords.getX();
int py = coords.getY();
int pz = coords.getZ();
world.func_147480_a(px, py, pz, true);
world.setBlockToAir(px, py, pz);
Block fluidBlock = null;
if (chemical instanceof ElementEnum) {
fluidBlock = FluidHelper.elementsBlocks.get(FluidHelper.elements.get(chemical));
} else if (chemical instanceof MoleculeEnum) {
fluidBlock = FluidHelper.moleculeBlocks.get(FluidHelper.molecules.get(chemical));
}
if (fluidBlock != null) {
world.setBlock(px, py, pz, fluidBlock, popFlowingFluid ? 1 : 0, 3);
}
}
}
}
use of minechem.item.MinechemChemicalType in project Minechem by iopleke.
the class ChemicalFluidReactionHandler method checkEntityItem.
public void checkEntityItem(World world, EntityItem entityItem) {
ItemStack itemStack = entityItem.getEntityItem();
if (itemStack.stackSize <= 0) {
return;
}
Item item = itemStack.getItem();
MinechemChemicalType chemicalA = null;
if (item instanceof MinechemBucketItem) {
chemicalA = MinechemUtil.getChemical(((MinechemBucketItem) item).fluid);
}
if (chemicalA != null && (world.isMaterialInBB(entityItem.boundingBox, Material.water) || world.isMaterialInBB(entityItem.boundingBox, MinechemFluidBlock.materialFluidBlock))) {
int x = MathHelper.floor_double(entityItem.posX);
int y = MathHelper.floor_double(entityItem.posY);
int z = MathHelper.floor_double(entityItem.posZ);
Block block = world.getBlock(x, y, z);
MinechemChemicalType chemicalB = MinechemUtil.getChemical(block);
if (chemicalB != null) {
ChemicalFluidReactionRule rule = new ChemicalFluidReactionRule(chemicalA, chemicalB);
if (reactionRules.containsKey(rule)) {
chemicalReaction(world, entityItem, x, y, z, rule, !(MinechemUtil.canDrain(world, block, x, y, z)));
itemStack.stackSize--;
entityItem.setEntityItemStack(itemStack);
if (itemStack.stackSize <= 0) {
world.removeEntity(entityItem);
}
MinechemUtil.throwItemStack(world, new ItemStack(Items.bucket), x, y, z);
}
}
}
}
Aggregations