diff --git a/src/main/java/com/hbm/particle/ParticleFoam.java b/src/main/java/com/hbm/particle/ParticleFoam.java index 81579833b..87d3bf164 100644 --- a/src/main/java/com/hbm/particle/ParticleFoam.java +++ b/src/main/java/com/hbm/particle/ParticleFoam.java @@ -31,13 +31,11 @@ public class ParticleFoam extends EntityFX { private static class TrailPoint { double x, y, z; - float alpha; public TrailPoint(double x, double y, double z, float alpha) { this.x = x; this.y = y; this.z = z; - this.alpha = alpha; } } diff --git a/src/main/java/com/hbm/util/DamageResistanceHandler.java b/src/main/java/com/hbm/util/DamageResistanceHandler.java index 320dcf897..c8f6deb5c 100644 --- a/src/main/java/com/hbm/util/DamageResistanceHandler.java +++ b/src/main/java/com/hbm/util/DamageResistanceHandler.java @@ -1,11 +1,17 @@ package com.hbm.util; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; +import com.google.gson.Gson; +import com.google.gson.stream.JsonWriter; import com.hbm.items.ModItems; +import com.hbm.main.MainRegistry; import com.hbm.util.Tuple.Quartet; import api.hbm.entity.IResistanceProvider; @@ -39,6 +45,8 @@ public class DamageResistanceHandler { public static final String CATEGORY_PROJECTILE = "PROJ"; public static final String CATEGORY_ENERGY = "EN"; + public static final Gson gson = new Gson(); + public static HashMap itemStats = new HashMap(); public static HashMap, ResistanceStats> setStats = new HashMap(); public static HashMap, ResistanceStats> entityStats = new HashMap(); @@ -46,13 +54,44 @@ public class DamageResistanceHandler { public static HashMap>> itemInfoSet = new HashMap(); public static void init() { + File folder = MainRegistry.configHbmDir; + + File config = new File(folder.getAbsolutePath() + File.separatorChar + "hbmArmor.json"); + File template = new File(folder.getAbsolutePath() + File.separatorChar + "_hbmArmor.json"); itemStats.clear(); setStats.clear(); entityStats.clear(); itemInfoSet.clear(); - entityStats.put(EntityCreeper.class, new ResistanceStats().addCategory(CATEGORY_EXPLOSION, 2F, 0.5F)); + if(!config.exists()) { + initDefaults(); + writeDefault(template); + } else { + /// + } + } + + private static void writeDefault(File file) { + + try { + JsonWriter writer = new JsonWriter(new FileWriter(file)); + writer.setIndent(" "); + writer.beginObject(); + writer.name("comment").value("Template file, remove the underscore ('_') from the name to enable the config."); + + serialize(writer); + + writer.endObject(); + writer.close(); + } catch(IOException e) { + e.printStackTrace(); + } + } + + public static void initDefaults() { + + entityStats.put(EntityCreeper.class, new ResistanceStats().addCategory(CATEGORY_EXPLOSION, 2F, 0.25F)); itemStats.put(ModItems.jackt, new ResistanceStats() .addCategory(CATEGORY_PROJECTILE, 5F, 0.5F)); @@ -250,6 +289,47 @@ public class DamageResistanceHandler { } } + public static void serialize(JsonWriter writer) throws IOException { + /// ITEMS /// + writer.name("itemStats").beginArray(); + for(Entry entry : itemStats.entrySet()) { + writer.beginArray().setIndent(""); + writer.value(Item.itemRegistry.getNameForObject(entry.getKey())).setIndent(" "); + writer.beginObject(); + entry.getValue().serialize(writer); + writer.setIndent(""); + writer.endObject().endArray().setIndent(" "); + } + writer.endArray(); + + /// SETS /// + writer.name("setStats").beginArray(); + for(Entry, ResistanceStats> entry : setStats.entrySet()) { + writer.beginArray().setIndent(""); + writer.value(Item.itemRegistry.getNameForObject(entry.getKey().getW())) + .value(Item.itemRegistry.getNameForObject(entry.getKey().getX())) + .value(Item.itemRegistry.getNameForObject(entry.getKey().getY())) + .value(Item.itemRegistry.getNameForObject(entry.getKey().getZ())).setIndent(" "); + writer.beginObject(); + entry.getValue().serialize(writer); + writer.setIndent(""); + writer.endObject().endArray().setIndent(" "); + } + writer.endArray(); + + /// ENTITIES /// + writer.name("entityStats").beginArray(); + for(Entry, ResistanceStats> entry : entityStats.entrySet()) { + writer.beginArray().setIndent(""); + writer.value(entry.getKey().getName()).setIndent(" "); + writer.beginObject(); + entry.getValue().serialize(writer); + writer.setIndent(""); + writer.endObject().endArray().setIndent(" "); + } + writer.endArray(); + } + public static enum DamageClass { PHYSICAL, FIRE, @@ -393,6 +473,32 @@ public class DamageResistanceHandler { public ResistanceStats addExact(String type, float threshold, float resistance) { exactResistances.put(type, new Resistance(threshold, resistance)); return this; } public ResistanceStats addCategory(String type, float threshold, float resistance) { categoryResistances.put(type, new Resistance(threshold, resistance)); return this; } public ResistanceStats setOther(float threshold, float resistance) { otherResistance = new Resistance(threshold, resistance); return this; } + + public void serialize(JsonWriter writer) throws IOException { + + if(!exactResistances.isEmpty()) { + writer.name("exact").beginArray(); + for(Entry entry : exactResistances.entrySet()) { + writer.beginArray().setIndent(""); + writer.value(entry.getKey()).value(entry.getValue().threshold).value(entry.getValue().resistance).endArray().setIndent(" "); + } + writer.endArray(); + } + + if(!categoryResistances.isEmpty()) { + writer.name("category").beginArray(); + for(Entry entry : categoryResistances.entrySet()) { + writer.beginArray().setIndent(""); + writer.value(entry.getKey()).value(entry.getValue().threshold).value(entry.getValue().resistance).endArray().setIndent(" "); + } + writer.endArray(); + } + + if(otherResistance != null) { + writer.name("other").beginArray().setIndent(""); + writer.value(otherResistance.threshold).value(otherResistance.resistance).endArray().setIndent(" "); + } + } } public static class Resistance {