custom fluid traits fix

Fixed some custom fluid traits buds, like the JSON output error of the polluting trait and the java.lang.InstantiationException issue of the PWRModerator and Pheromone traits. Mean while, the hot reload function of hbmFluidTypes.json and hbmFluidTraits.json has been added.
This commit is contained in:
FOlkvangrField 2024-11-14 21:13:13 +08:00
parent e95123c359
commit 146e19d463
6 changed files with 134 additions and 102 deletions

View File

@ -1,7 +1,9 @@
package com.hbm.commands; package com.hbm.commands;
import com.hbm.config.ItemPoolConfigJSON; import com.hbm.config.ItemPoolConfigJSON;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.recipes.loader.SerializableRecipe; import com.hbm.inventory.recipes.loader.SerializableRecipe;
import com.hbm.main.MainRegistry;
import com.hbm.util.ChatBuilder; import com.hbm.util.ChatBuilder;
import net.minecraft.command.CommandBase; import net.minecraft.command.CommandBase;
@ -9,6 +11,10 @@ import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumChatFormatting;
import java.io.File;
public class CommandReloadRecipes extends CommandBase { public class CommandReloadRecipes extends CommandBase {
@Override @Override
@ -26,6 +32,7 @@ public class CommandReloadRecipes extends CommandBase {
try { try {
SerializableRecipe.initialize(); SerializableRecipe.initialize();
ItemPoolConfigJSON.initialize(); ItemPoolConfigJSON.initialize();
Fluids.reloadFluids();
sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Reload complete :)")); sender.addChatMessage(new ChatComponentText(EnumChatFormatting.YELLOW + "Reload complete :)"));
} catch(Exception ex) { } catch(Exception ex) {
sender.addChatMessage(ChatBuilder.start("----------------------------------").color(EnumChatFormatting.GRAY).flush()); sender.addChatMessage(ChatBuilder.start("----------------------------------").color(EnumChatFormatting.GRAY).flush());

View File

@ -22,10 +22,11 @@ public class BoilingHandler extends NEIUniversalHandler {
} }
public static HashMap<Object, Object> cache; public static HashMap<Object, Object> cache;
public static boolean isReload=false;
public static HashMap<Object, Object> generateRecipes() { public static HashMap<Object, Object> generateRecipes() {
if(cache != null) return cache; if(cache != null && !isReload) return cache;
cache = new HashMap(); cache = new HashMap();
@ -40,7 +41,7 @@ public class BoilingHandler extends NEIUniversalHandler {
} }
} }
} }
isReload=false;
return cache; return cache;
} }
} }

View File

@ -14,6 +14,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.stream.JsonWriter; import com.google.gson.stream.JsonWriter;
import com.hbm.handler.nei.BoilingHandler;
import com.hbm.handler.pollution.PollutionHandler; import com.hbm.handler.pollution.PollutionHandler;
import com.hbm.handler.pollution.PollutionHandler.PollutionType; import com.hbm.handler.pollution.PollutionHandler.PollutionType;
import com.hbm.inventory.fluid.trait.*; import com.hbm.inventory.fluid.trait.*;
@ -842,7 +843,29 @@ public class Fluids {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public static void reloadFluids(){
File folder = MainRegistry.configHbmDir;
File customTypes = new File(folder.getAbsolutePath() + File.separatorChar + "hbmFluidTypes.json");
if(!customTypes.exists()) initDefaultFluids(customTypes);
for(FluidType type : customFluids){
idMapping.remove(type.getID());
registerOrder.remove(type);
nameMapping.remove(type.getName());
metaOrder.remove(type);
}
customFluids.clear();
readCustomFluids(customTypes);
for(FluidType custom : customFluids) metaOrder.add(custom);
File config = new File(MainRegistry.configHbmDir.getAbsolutePath() + File.separatorChar + "hbmFluidTraits.json");
File template = new File(MainRegistry.configHbmDir.getAbsolutePath() + File.separatorChar + "_hbmFluidTraits.json");
if(!config.exists()) {
writeDefaultTraits(template);
} else {
readTraits(config);
}
BoilingHandler.isReload=true;
}
private static void registerCalculatedFuel(FluidType type, double base, double combustMult, FuelGrade grade) { private static void registerCalculatedFuel(FluidType type, double base, double combustMult, FuelGrade grade) {
long flammable = (long) base; long flammable = (long) base;

View File

@ -11,7 +11,7 @@ import net.minecraft.util.EnumChatFormatting;
public class FT_PWRModerator extends FluidTrait { public class FT_PWRModerator extends FluidTrait {
private double multiplier; private double multiplier;
public FT_PWRModerator(){}
public FT_PWRModerator(double mulitplier) { public FT_PWRModerator(double mulitplier) {
this.multiplier = mulitplier; this.multiplier = mulitplier;
} }

View File

@ -11,6 +11,7 @@ import java.util.List;
public class FT_Pheromone extends FluidTrait{ public class FT_Pheromone extends FluidTrait{
public int type; public int type;
public FT_Pheromone() {}
public FT_Pheromone(int type) { public FT_Pheromone(int type) {
this.type = type; this.type = type;

View File

@ -60,12 +60,12 @@ public class FT_Polluting extends FluidTrait {
public void serializeJSON(JsonWriter writer) throws IOException { public void serializeJSON(JsonWriter writer) throws IOException {
writer.name("release").beginObject(); writer.name("release").beginObject();
for(Entry<PollutionType, Float> entry : releaseMap.entrySet()) { for(Entry<PollutionType, Float> entry : releaseMap.entrySet()) {
writer.name(entry.toString()).value(entry.getValue()); writer.name(entry.getKey().name()).value(entry.getValue());
} }
writer.endObject(); writer.endObject();
writer.name("burn").beginObject(); writer.name("burn").beginObject();
for(Entry<PollutionType, Float> entry : burnMap.entrySet()) { for(Entry<PollutionType, Float> entry : burnMap.entrySet()) {
writer.name(entry.toString()).value(entry.getValue()); writer.name(entry.getKey().name()).value(entry.getValue());
} }
writer.endObject(); writer.endObject();
} }