coker functionality

This commit is contained in:
Boblet 2023-04-26 16:18:33 +02:00
parent a0cb8aedd8
commit 6e8e8cb9c5
5 changed files with 138 additions and 14 deletions

View File

@ -405,7 +405,7 @@ public class Fluids {
PHOSGENE.addTraits(new FT_Toxin().addEntry(new ToxinDirectDamage(ModDamageSource.cloud, 4F, 20, HazardClass.GAS_CHLORINE, false)));
MUSTARDGAS.addTraits(new FT_Toxin().addEntry(new ToxinDirectDamage(ModDamageSource.cloud, 4F, 10, HazardClass.GAS_CORROSIVE, false))
.addEntry(new ToxinEffects(HazardClass.GAS_CORROSIVE, true).add(new PotionEffect(Potion.wither.id, 100, 1), new PotionEffect(Potion.confusion.id, 100, 0))));
ESTRADIOL.addTraits(new FT_Toxin().addEntry(new ToxinEffects(HazardClass.PARTICLE_FINE, false).add(new PotionEffect(HbmPotion.mutation.id, 60 * 60 * 20, 0))));
ESTRADIOL.addTraits(new FT_Toxin().addEntry(new ToxinEffects(HazardClass.PARTICLE_FINE, false).add(new PotionEffect(HbmPotion.death.id, 60 * 60 * 20, 0))));
double eff_steam_boil = 1.0D;
double eff_steam_heatex = 0.25D;

View File

@ -75,6 +75,10 @@ public class CokerRecipes extends SerializableRecipe {
private static void registerRecipe(FluidType type, int quantity, ItemStack output, FluidStack byproduct) {
recipes.put(type, new Triplet(quantity, output, byproduct));
}
public static Triplet<Integer, ItemStack, FluidStack> getOutput(FluidType type) {
return recipes.get(type);
}
public static HashMap<ItemStack, ItemStack[]> getRecipes() {
@ -87,7 +91,10 @@ public class CokerRecipes extends SerializableRecipe {
ItemStack out = entry.getValue().getY().copy();
FluidStack byproduct = entry.getValue().getZ();
recipes.put(ItemFluidIcon.make(type, amount), new ItemStack[] {out, ItemFluidIcon.make(byproduct)});
if(out != null && byproduct != null) recipes.put(ItemFluidIcon.make(type, amount), new ItemStack[] {out, ItemFluidIcon.make(byproduct)});
if(out != null && byproduct == null) recipes.put(ItemFluidIcon.make(type, amount), new ItemStack[] {out});
if(out == null && byproduct != null) recipes.put(ItemFluidIcon.make(type, amount), new ItemStack[] {ItemFluidIcon.make(byproduct)});
}
return recipes;
@ -112,8 +119,8 @@ public class CokerRecipes extends SerializableRecipe {
public void readRecipe(JsonElement recipe) {
JsonObject obj = (JsonObject) recipe;
FluidStack in = this.readFluidStack(obj.get("input").getAsJsonArray());
ItemStack out = this.readItemStack(obj.get("output").getAsJsonArray());
FluidStack byproduct = this.readFluidStack(obj.get("byproduct").getAsJsonArray());
ItemStack out = obj.has("output") ? this.readItemStack(obj.get("output").getAsJsonArray()) : null;
FluidStack byproduct = obj.has("byproduct") ? this.readFluidStack(obj.get("byproduct").getAsJsonArray()) : null;
recipes.put(in.type, new Triplet(in.fill, out, byproduct));
}
@ -123,9 +130,13 @@ public class CokerRecipes extends SerializableRecipe {
FluidStack in = new FluidStack(rec.getKey(), rec.getValue().getX());
writer.name("input");
this.writeFluidStack(in, writer);
writer.name("output");
this.writeItemStack(rec.getValue().getY(), writer);
writer.name("byproduct");
this.writeFluidStack(rec.getValue().getZ(), writer);
if(rec.getValue().getY() != null) {
writer.name("output");
this.writeItemStack(rec.getValue().getY(), writer);
}
if(rec.getValue().getZ() != null) {
writer.name("byproduct");
this.writeFluidStack(rec.getValue().getZ(), writer);
}
}
}

View File

@ -134,10 +134,10 @@ public class CrystallizerRecipes extends SerializableRecipe {
registerRecipe(CU.dust(), new CrystallizerRecipe(DictFrame.fromOne(ModItems.chemical_dye, EnumChemDye.GREEN, 4), 20), woodOil);
registerRecipe(CO.dust(), new CrystallizerRecipe(DictFrame.fromOne(ModItems.chemical_dye, EnumChemDye.BLUE, 4), 20), woodOil);
registerRecipe(new ComparableStack(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.CRUDE)), new CrystallizerRecipe(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.WAX), 20), new FluidStack(Fluids.CHLORINE, 250));
registerRecipe(new ComparableStack(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.CRACK)), new CrystallizerRecipe(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.WAX), 20), new FluidStack(Fluids.CHLORINE, 100));
registerRecipe(new ComparableStack(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.WAX)), new CrystallizerRecipe(new ItemStack(ModItems.pellet_charged), 200), new FluidStack(Fluids.IONGEL, 500));
registerRecipe(new ComparableStack(ModItems.pill_red), new CrystallizerRecipe(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.PARAFFIN), 200), new FluidStack(Fluids.ESTRADIOL, 250));
registerRecipe(new ComparableStack(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.CRUDE)), new CrystallizerRecipe(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.WAX), 20), new FluidStack(Fluids.CHLORINE, 250));
registerRecipe(new ComparableStack(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.CRACK)), new CrystallizerRecipe(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.WAX), 20), new FluidStack(Fluids.CHLORINE, 100));
registerRecipe(new ComparableStack(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.WAX)), new CrystallizerRecipe(new ItemStack(ModItems.pellet_charged), 200), new FluidStack(Fluids.IONGEL, 500));
registerRecipe(new ComparableStack(DictFrame.fromOne(ModItems.oil_tar, EnumTarType.PARAFFIN)), new CrystallizerRecipe(new ItemStack(ModItems.pill_red), 200), new FluidStack(Fluids.ESTRADIOL, 250));
registerRecipe(KEY_SAND, new CrystallizerRecipe(Blocks.clay, 20), new FluidStack(Fluids.COLLOID, 1_000));

View File

@ -51,7 +51,7 @@ public class ItemPill extends ItemFood {
}
if(this == ModItems.pill_red) {
player.addPotionEffect(new PotionEffect(HbmPotion.mutation.id, 60 * 60 * 20, 0));
player.addPotionEffect(new PotionEffect(HbmPotion.death.id, 60 * 60 * 20, 0));
}
if(this == ModItems.radx) {

View File

@ -1,29 +1,43 @@
package com.hbm.tileentity.machine.oil;
import com.hbm.inventory.FluidStack;
import com.hbm.inventory.container.ContainerMachineCoker;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.inventory.gui.GUIMachineCoker;
import com.hbm.inventory.recipes.CokerRecipes;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.Tuple.Triplet;
import api.hbm.fluid.IFluidStandardTransceiver;
import api.hbm.tile.IHeatSource;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class TileEntityMachineCoker extends TileEntityMachineBase implements IFluidStandardTransceiver, IGUIProvider {
public int progress;
public static int processTime = 20_000;
public int heat;
public static int maxHeat = 100_000;
public static double diffusion = 0.25D;
public FluidTank[] tanks;
public TileEntityMachineCoker() {
super(2);
tanks = new FluidTank[2];
tanks[0] = new FluidTank(Fluids.HEAVYOIL, 16_000);
tanks[1] = new FluidTank(Fluids.GAS, 8_000);
tanks[1] = new FluidTank(Fluids.OIL_COKER, 8_000);
}
@Override
@ -34,6 +48,105 @@ public class TileEntityMachineCoker extends TileEntityMachineBase implements IFl
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
this.tryPullHeat();
this.tanks[0].setType(0, slots);
if(canProcess()) {
int burn = heat / 100;
if(burn > 0) {
this.progress += burn;
this.heat -= burn;
if(progress >= processTime) {
this.markChanged();
progress -= this.processTime;
Triplet<Integer, ItemStack, FluidStack> recipe = CokerRecipes.getOutput(tanks[0].getTankType());
int fillReq = recipe.getX();
ItemStack output = recipe.getY();
FluidStack byproduct = recipe.getZ();
if(output != null) {
if(slots[1] == null) {
slots[1] = output.copy();
} else {
slots[1].stackSize += output.stackSize;
}
}
if(byproduct != null) {
tanks[1].setFill(tanks[1].getFill() + byproduct.fill);
}
tanks[0].setFill(tanks[0].getFill() - fillReq);
}
}
}
NBTTagCompound data = new NBTTagCompound();
tanks[0].writeToNBT(data, "t0");
tanks[1].writeToNBT(data, "t1");
this.networkPack(data, 25);
}
}
public boolean canProcess() {
Triplet<Integer, ItemStack, FluidStack> recipe = CokerRecipes.getOutput(tanks[0].getTankType());
if(recipe == null) return false;
int fillReq = recipe.getX();
ItemStack output = recipe.getY();
FluidStack byproduct = recipe.getZ();
if(byproduct != null) tanks[1].setTankType(byproduct.type);
if(tanks[0].getFill() < recipe.getX()) return false;
if(byproduct != null && byproduct.fill + tanks[1].getFill() > tanks[1].getMaxFill()) return false;
if(output != null && slots[1] != null) {
if(output.getItem() != slots[1].getItem()) return false;
if(output.getItemDamage() != slots[1].getItemDamage()) return false;
if(output.stackSize + slots[1].stackSize > output.getMaxStackSize()) return false;
}
return true;
}
@Override
public void networkUnpack(NBTTagCompound nbt) {
tanks[0].readFromNBT(nbt, "t0");
tanks[1].readFromNBT(nbt, "t1");
}
protected void tryPullHeat() {
if(this.heat >= this.maxHeat) return;
TileEntity con = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
if(con instanceof IHeatSource) {
IHeatSource source = (IHeatSource) con;
int diff = source.getHeatStored() - this.heat;
if(diff == 0) {
return;
}
if(diff > 0) {
diff = (int) Math.ceil(diff * diffusion);
source.useUpHeat(diff);
this.heat += diff;
if(this.heat > this.maxHeat)
this.heat = this.maxHeat;
return;
}
}
this.heat = Math.max(this.heat - Math.max(this.heat / 1000, 1), 0);
}
@Override