From 11fc87d0ad0ad32ae57a39648bb6ddf726826851 Mon Sep 17 00:00:00 2001 From: Toshayo Date: Sat, 10 Jun 2023 15:43:05 +0200 Subject: [PATCH 1/5] Changed decimal colors to hexadecimal --- src/main/java/com/hbm/potion/HbmPotion.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/hbm/potion/HbmPotion.java b/src/main/java/com/hbm/potion/HbmPotion.java index 7d5855009..a7688f2da 100644 --- a/src/main/java/com/hbm/potion/HbmPotion.java +++ b/src/main/java/com/hbm/potion/HbmPotion.java @@ -47,10 +47,10 @@ public class HbmPotion extends Potion { } public static void init() { - taint = registerPotion(PotionConfig.taintID, true, 8388736, "potion.hbm_taint", 0, 0); - radiation = registerPotion(PotionConfig.radiationID, true, 8700200, "potion.hbm_radiation", 1, 0); - bang = registerPotion(PotionConfig.bangID, true, 1118481, "potion.hbm_bang", 3, 0); - mutation = registerPotion(PotionConfig.mutationID, false, 8388736, "potion.hbm_mutation", 2, 0); + taint = registerPotion(PotionConfig.taintID, true, 0x800080, "potion.hbm_taint", 0, 0); + radiation = registerPotion(PotionConfig.radiationID, true, 0x84C128, "potion.hbm_radiation", 1, 0); + bang = registerPotion(PotionConfig.bangID, true, 0x111111, "potion.hbm_bang", 3, 0); + mutation = registerPotion(PotionConfig.mutationID, false, 0x800080, "potion.hbm_mutation", 2, 0); radx = registerPotion(PotionConfig.radxID, false, 0xBB4B00, "potion.hbm_radx", 5, 0); lead = registerPotion(PotionConfig.leadID, true, 0x767682, "potion.hbm_lead", 6, 0); radaway = registerPotion(PotionConfig.radawayID, false, 0xBB4B00, "potion.hbm_radaway", 7, 0); @@ -58,7 +58,7 @@ public class HbmPotion extends Potion { phosphorus = registerPotion(PotionConfig.phosphorusID, true, 0xFFFF00, "potion.hbm_phosphorus", 1, 1); stability = registerPotion(PotionConfig.stabilityID, false, 0xD0D0D0, "potion.hbm_stability", 2, 1); potionsickness = registerPotion(PotionConfig.potionsicknessID, false, 0xff8080, "potion.hbm_potionsickness", 3, 1); - death = registerPotion(PotionConfig.deathID, false, 1118481, "potion.hbm_death", 4, 1); + death = registerPotion(PotionConfig.deathID, false, 0x111111, "potion.hbm_death", 4, 1); } public static HbmPotion registerPotion(int id, boolean isBad, int color, String name, int x, int y) { From d3e6e226007966c01614f5d40a8e6c2abd645e3e Mon Sep 17 00:00:00 2001 From: Toshayo Date: Mon, 12 Jun 2023 11:18:15 +0200 Subject: [PATCH 2/5] Bring back CurseForge config example file --- curseforge.properties.example | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 curseforge.properties.example diff --git a/curseforge.properties.example b/curseforge.properties.example new file mode 100644 index 000000000..002b2b4f5 --- /dev/null +++ b/curseforge.properties.example @@ -0,0 +1,5 @@ +# CurseForge API token (obtainable from https://legacy.curseforge.com/account/api-tokens) +api_key= + +# CurseForge project ID +project_id= From e94548ed0c1b30aa53ca3539149c0c9d289f81c3 Mon Sep 17 00:00:00 2001 From: Toshayo Date: Mon, 12 Jun 2023 11:58:11 +0200 Subject: [PATCH 3/5] Better CurseForge task configuration: display name, game versions and a fix for changelog backup not being replaced --- build.gradle | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 9a1ea516d..8cd9a478d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,8 @@ +import org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory + import java.nio.file.Files import java.nio.file.Paths +import java.nio.file.StandardCopyOption buildscript { repositories { @@ -53,7 +56,7 @@ eclipse.classpath.file.whenMerged { cp -> } // Create file reference factory - def fileref = new org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory() + def fileref = new FileReferenceFactory() // Find all codechicken development jars cp.entries.findAll { entry -> entry.path.contains("codechicken") && entry.path.endsWith("-dev.jar") }.forEach { entry -> @@ -132,12 +135,20 @@ if(Files.exists(Paths.get("curseforge.properties"))) { projectId = cfprops.project_id releaseType = "release" + displayName = "Hbm's Nuclear Tech Mod " + version_name.replace("_", "") + " for Minecraft 1.7.10" + + gameVersions.addAll([ + "Forge", + "Java 8", + "Client", "Server" + ]) + if (Files.exists(Paths.get("changelog"))) { changelog = String.join("\r\n", Files.readAllLines(Paths.get("changelog"))) // Perform a backup of the changelog and create a new file for next changes doLast { - Files.move(Paths.get("changelog"), Paths.get("changelog.bak")) + Files.move(Paths.get("changelog"), Paths.get("changelog.bak"), StandardCopyOption.REPLACE_EXISTING) Files.createFile(Paths.get("changelog")) } } From 2a01d7f2fb53a47eea2b681d12876e8c3afee600 Mon Sep 17 00:00:00 2001 From: Boblet Date: Mon, 12 Jun 2023 13:58:19 +0200 Subject: [PATCH 4/5] configurable fluid traits --- .../handler/pollution/PollutionHandler.java | 1 + .../com/hbm/inventory/fluid/FluidType.java | 2 +- .../java/com/hbm/inventory/fluid/Fluids.java | 79 +++++++++++++++++++ .../inventory/fluid/trait/FT_Combustible.java | 17 ++++ .../inventory/fluid/trait/FT_Coolable.java | 35 +++++++- .../inventory/fluid/trait/FT_Corrosive.java | 16 ++++ .../inventory/fluid/trait/FT_Flammable.java | 15 ++++ .../inventory/fluid/trait/FT_Heatable.java | 47 +++++++++++ .../hbm/inventory/fluid/trait/FT_Poison.java | 16 ++++ .../hbm/inventory/fluid/trait/FT_Toxin.java | 76 ++++++++++++++++++ .../fluid/trait/FT_VentRadiation.java | 15 ++++ .../hbm/inventory/fluid/trait/FluidTrait.java | 32 ++++++++ 12 files changed, 348 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hbm/handler/pollution/PollutionHandler.java b/src/main/java/com/hbm/handler/pollution/PollutionHandler.java index 16d91da8d..570f91415 100644 --- a/src/main/java/com/hbm/handler/pollution/PollutionHandler.java +++ b/src/main/java/com/hbm/handler/pollution/PollutionHandler.java @@ -123,6 +123,7 @@ public class PollutionHandler { try { File pollutionFile = new File(dirPath, fileName); + if(!pollutionFile.getParentFile().exists()) pollutionFile.getParentFile().mkdirs(); if(!pollutionFile.exists()) pollutionFile.createNewFile(); NBTTagCompound data = perWorld.get(world).writeToNBT(); CompressedStreamTools.writeCompressed(data, new FileOutputStream(pollutionFile)); diff --git a/src/main/java/com/hbm/inventory/fluid/FluidType.java b/src/main/java/com/hbm/inventory/fluid/FluidType.java index d4dd7c272..390fcfede 100644 --- a/src/main/java/com/hbm/inventory/fluid/FluidType.java +++ b/src/main/java/com/hbm/inventory/fluid/FluidType.java @@ -48,7 +48,7 @@ public class FluidType { public double compression = DEFAULT_COMPRESSION; public HashMap containers = new HashMap(); - private HashMap, FluidTrait> traits = new HashMap(); + public HashMap, FluidTrait> traits = new HashMap(); //public List enumTraits = new ArrayList(); private ResourceLocation texture; diff --git a/src/main/java/com/hbm/inventory/fluid/Fluids.java b/src/main/java/com/hbm/inventory/fluid/Fluids.java index 6a779d673..f9de9f7b3 100644 --- a/src/main/java/com/hbm/inventory/fluid/Fluids.java +++ b/src/main/java/com/hbm/inventory/fluid/Fluids.java @@ -1,12 +1,22 @@ package com.hbm.inventory.fluid; +import java.io.File; +import java.io.FileReader; +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.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; import com.hbm.inventory.fluid.trait.*; import com.hbm.inventory.fluid.trait.FluidTraitSimple.*; import com.hbm.lib.ModDamageSource; +import com.hbm.main.MainRegistry; import com.hbm.potion.HbmPotion; import com.hbm.inventory.fluid.trait.FT_Combustible.FuelGrade; import com.hbm.inventory.fluid.trait.FT_Coolable.CoolingType; @@ -20,6 +30,8 @@ import net.minecraft.potion.PotionEffect; public class Fluids { + public static final Gson gson = new Gson(); + public static FluidType NONE; public static FluidType WATER; public static FluidType STEAM; @@ -562,6 +574,73 @@ public class Fluids { registerCalculatedFuel(SYNGAS, (coalHeat * (1000 /* bucket */ / 100 /* mB per coal */) * flammabilityLow * demandLow * complexityChemplant) * 1.5, 1.25, FuelGrade.GAS); //same as coal oil, +50% bonus registerCalculatedFuel(OXYHYDROGEN, 5_000, 3, FuelGrade.GAS); // whatever + + File folder = MainRegistry.configHbmDir; + + File config = new File(folder.getAbsolutePath() + File.separatorChar + "hbmFluids.json"); + File template = new File(folder.getAbsolutePath() + File.separatorChar + "_hbmFluids.json"); + + if(!config.exists()) { + writeDefault(template); + } else { + readConfig(config); + } + } + + private static void writeDefault(File file) { + + try { + JsonWriter writer = new JsonWriter(new FileWriter(file)); + writer.setIndent(" "); + writer.beginObject(); + + for(FluidType type : metaOrder) { + writer.name(type.getUnlocalizedName()).beginObject(); + + for(Entry, FluidTrait> entry : type.traits.entrySet()) { + writer.name(FluidTrait.traitNameMap.inverse().get(entry.getKey())).beginObject(); + entry.getValue().serializeJSON(writer); + writer.endObject(); + } + + writer.endObject(); + } + + writer.endObject(); + writer.close(); + } catch(IOException e) { + e.printStackTrace(); + } + } + + private static void readConfig(File config) { + + try { + JsonObject json = gson.fromJson(new FileReader(config), JsonObject.class); + + for(FluidType type : metaOrder) { + + JsonElement element = json.get(type.getUnlocalizedName()); + if(element != null) { + type.traits.clear(); + JsonObject obj = element.getAsJsonObject(); + + for(Entry entry : obj.entrySet()) { + Class traitClass = FluidTrait.traitNameMap.get(entry.getKey()); + try { + FluidTrait trait = traitClass.newInstance(); + trait.deserializeJSON(entry.getValue().getAsJsonObject()); + type.addTraits(trait); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + } + } + + } catch(Exception ex) { + ex.printStackTrace(); + } } private static void registerCalculatedFuel(FluidType type, double base, double combustMult, FuelGrade grade) { diff --git a/src/main/java/com/hbm/inventory/fluid/trait/FT_Combustible.java b/src/main/java/com/hbm/inventory/fluid/trait/FT_Combustible.java index a88ac2c35..a297d40ca 100644 --- a/src/main/java/com/hbm/inventory/fluid/trait/FT_Combustible.java +++ b/src/main/java/com/hbm/inventory/fluid/trait/FT_Combustible.java @@ -1,7 +1,10 @@ package com.hbm.inventory.fluid.trait; +import java.io.IOException; import java.util.List; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; import com.hbm.util.BobMathUtil; import net.minecraft.util.EnumChatFormatting; @@ -11,6 +14,8 @@ public class FT_Combustible extends FluidTrait { protected FuelGrade fuelGrade; protected long combustionEnergy; + public FT_Combustible() { } + public FT_Combustible(FuelGrade grade, long energy) { this.fuelGrade = grade; this.combustionEnergy = energy; @@ -53,4 +58,16 @@ public class FT_Combustible extends FluidTrait { return this.grade; } } + + @Override + public void serializeJSON(JsonWriter writer) throws IOException { + writer.name("energy").value(combustionEnergy); + writer.name("grade").value(fuelGrade.name()); + } + + @Override + public void deserializeJSON(JsonObject obj) { + this.combustionEnergy = obj.get("energy").getAsLong(); + this.fuelGrade = FuelGrade.valueOf(obj.get("grade").getAsString()); + } } diff --git a/src/main/java/com/hbm/inventory/fluid/trait/FT_Coolable.java b/src/main/java/com/hbm/inventory/fluid/trait/FT_Coolable.java index 25bd1488d..f25e77c35 100644 --- a/src/main/java/com/hbm/inventory/fluid/trait/FT_Coolable.java +++ b/src/main/java/com/hbm/inventory/fluid/trait/FT_Coolable.java @@ -1,9 +1,14 @@ package com.hbm.inventory.fluid.trait; +import java.io.IOException; import java.util.HashMap; import java.util.List; +import java.util.Map.Entry; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; import com.hbm.inventory.fluid.FluidType; +import com.hbm.inventory.fluid.Fluids; import net.minecraft.util.EnumChatFormatting; @@ -11,10 +16,12 @@ public class FT_Coolable extends FluidTrait { protected HashMap efficiency = new HashMap(); - public final FluidType coolsTo; + public FluidType coolsTo; public int amountReq; public int amountProduced; - public final int heatEnergy; + public int heatEnergy; + + public FT_Coolable() { } public FT_Coolable(FluidType type, int req, int prod, int heat) { this.coolsTo = type; @@ -56,4 +63,28 @@ public class FT_Coolable extends FluidTrait { this.name = name; } } + + @Override + public void serializeJSON(JsonWriter writer) throws IOException { + writer.name("coolsTo").value(this.coolsTo.getUnlocalizedName()); + writer.name("amountReq").value(this.amountReq); + writer.name("amountProd").value(this.amountProduced); + writer.name("heatEnergy").value(this.heatEnergy); + + for(Entry entry : this.efficiency.entrySet()) { + writer.name(entry.getKey().name()).value(entry.getValue()); + } + } + + @Override + public void deserializeJSON(JsonObject obj) { + this.coolsTo = Fluids.fromName(obj.get("coolsTo").getAsString()); + this.amountReq = obj.get("amountReq").getAsInt(); + this.amountProduced = obj.get("amountProd").getAsInt(); + this.heatEnergy = obj.get("heatEnergy").getAsInt(); + + for(CoolingType type : CoolingType.values()) { + if(obj.has(type.name())) efficiency.put(type, obj.get(type.name()).getAsDouble()); + } + } } diff --git a/src/main/java/com/hbm/inventory/fluid/trait/FT_Corrosive.java b/src/main/java/com/hbm/inventory/fluid/trait/FT_Corrosive.java index 4e0354033..2a459e25c 100644 --- a/src/main/java/com/hbm/inventory/fluid/trait/FT_Corrosive.java +++ b/src/main/java/com/hbm/inventory/fluid/trait/FT_Corrosive.java @@ -1,7 +1,11 @@ package com.hbm.inventory.fluid.trait; +import java.io.IOException; import java.util.List; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; + import net.minecraft.util.EnumChatFormatting; public class FT_Corrosive extends FluidTrait { @@ -9,6 +13,8 @@ public class FT_Corrosive extends FluidTrait { /* 0-100 */ private int rating; + public FT_Corrosive() { } + public FT_Corrosive(int rating) { this.rating = rating; } @@ -29,4 +35,14 @@ public class FT_Corrosive extends FluidTrait { else info.add(EnumChatFormatting.YELLOW + "[Corrosive]"); } + + @Override + public void serializeJSON(JsonWriter writer) throws IOException { + writer.name("rating").value(rating); + } + + @Override + public void deserializeJSON(JsonObject obj) { + this.rating = obj.get("rating").getAsInt(); + } } diff --git a/src/main/java/com/hbm/inventory/fluid/trait/FT_Flammable.java b/src/main/java/com/hbm/inventory/fluid/trait/FT_Flammable.java index c2b582ae5..82e309ef9 100644 --- a/src/main/java/com/hbm/inventory/fluid/trait/FT_Flammable.java +++ b/src/main/java/com/hbm/inventory/fluid/trait/FT_Flammable.java @@ -1,7 +1,10 @@ package com.hbm.inventory.fluid.trait; +import java.io.IOException; import java.util.List; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; import com.hbm.util.BobMathUtil; import net.minecraft.util.EnumChatFormatting; @@ -11,6 +14,8 @@ public class FT_Flammable extends FluidTrait { /** How much heat energy (usually translates into HE 1:1) 1000mB hold */ private long energy; + public FT_Flammable() { } + public FT_Flammable(long energy) { this.energy = energy; } @@ -28,4 +33,14 @@ public class FT_Flammable extends FluidTrait { if(energy > 0) info.add(EnumChatFormatting.YELLOW + "Provides " + EnumChatFormatting.RED + "" + BobMathUtil.getShortNumber(energy) + "TU " + EnumChatFormatting.YELLOW + "per bucket"); } + + @Override + public void serializeJSON(JsonWriter writer) throws IOException { + writer.name("energy").value(energy); + } + + @Override + public void deserializeJSON(JsonObject obj) { + this.energy = obj.get("energy").getAsLong(); + } } diff --git a/src/main/java/com/hbm/inventory/fluid/trait/FT_Heatable.java b/src/main/java/com/hbm/inventory/fluid/trait/FT_Heatable.java index e01169076..310083cf3 100644 --- a/src/main/java/com/hbm/inventory/fluid/trait/FT_Heatable.java +++ b/src/main/java/com/hbm/inventory/fluid/trait/FT_Heatable.java @@ -1,12 +1,18 @@ package com.hbm.inventory.fluid.trait; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; import com.hbm.inventory.fluid.FluidType; +import com.hbm.inventory.fluid.Fluids; import net.minecraft.util.EnumChatFormatting; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map.Entry; public class FT_Heatable extends FluidTrait { @@ -71,4 +77,45 @@ public class FT_Heatable extends FluidTrait { this.name = name; } } + + @Override + public void serializeJSON(JsonWriter writer) throws IOException { + + writer.name("steps").beginArray(); + + for(HeatingStep step : steps) { + writer.beginObject(); + writer.name("typeProduced").value(step.typeProduced.getUnlocalizedName()); + writer.name("amountReq").value(step.amountReq); + writer.name("amountProd").value(step.amountProduced); + writer.name("heatReq").value(step.heatReq); + writer.endObject(); + } + + writer.endArray(); + + for(Entry entry : this.efficiency.entrySet()) { + writer.name(entry.getKey().name()).value(entry.getValue()); + } + } + + @Override + public void deserializeJSON(JsonObject obj) { + + JsonArray steps = obj.get("steps").getAsJsonArray(); + + for(int i = 0; i < steps.size(); i++) { + JsonObject step = steps.get(i).getAsJsonObject(); + this.steps.add(new HeatingStep( + step.get("amountReq").getAsInt(), + step.get("heatReq").getAsInt(), + Fluids.fromName(step.get("typeProduced").getAsString()), + step.get("amountProd").getAsInt() + )); + } + + for(HeatingType type : HeatingType.values()) { + if(obj.has(type.name())) efficiency.put(type, obj.get(type.name()).getAsDouble()); + } + } } diff --git a/src/main/java/com/hbm/inventory/fluid/trait/FT_Poison.java b/src/main/java/com/hbm/inventory/fluid/trait/FT_Poison.java index 2c176bc3e..335c182cb 100644 --- a/src/main/java/com/hbm/inventory/fluid/trait/FT_Poison.java +++ b/src/main/java/com/hbm/inventory/fluid/trait/FT_Poison.java @@ -1,7 +1,11 @@ package com.hbm.inventory.fluid.trait; +import java.io.IOException; import java.util.List; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; + import net.minecraft.util.EnumChatFormatting; @Deprecated //use FT_Toxin instead @@ -10,6 +14,8 @@ public class FT_Poison extends FluidTrait { protected boolean withering = false; protected int level = 0; + public FT_Poison() { } + public FT_Poison(boolean withering, int level) { this.withering = withering; this.level = level; @@ -27,4 +33,14 @@ public class FT_Poison extends FluidTrait { public void addInfoHidden(List info) { info.add(EnumChatFormatting.GREEN + "[Toxic Fumes]"); } + + @Override public void serializeJSON(JsonWriter writer) throws IOException { + writer.name("level").value(this.level); + writer.name("withering").value(this.withering); + } + + @Override public void deserializeJSON(JsonObject obj) { + this.level = obj.get("level").getAsInt(); + this.withering = obj.get("withering").getAsBoolean(); + } } diff --git a/src/main/java/com/hbm/inventory/fluid/trait/FT_Toxin.java b/src/main/java/com/hbm/inventory/fluid/trait/FT_Toxin.java index fc759219b..354da3175 100644 --- a/src/main/java/com/hbm/inventory/fluid/trait/FT_Toxin.java +++ b/src/main/java/com/hbm/inventory/fluid/trait/FT_Toxin.java @@ -1,8 +1,12 @@ package com.hbm.inventory.fluid.trait; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; import com.hbm.util.ArmorRegistry; import com.hbm.util.ArmorUtil; import com.hbm.util.I18nUtil; @@ -132,4 +136,76 @@ public class FT_Toxin extends FluidTrait { } } } + + @Override public void serializeJSON(JsonWriter writer) throws IOException { + + writer.name("entries").beginArray(); + + for(ToxinEntry entry : entries) { + writer.beginObject(); + + if(entry instanceof ToxinDirectDamage) { + ToxinDirectDamage e = (ToxinDirectDamage) entry; + writer.name("type").value("directdamage"); + writer.name("amount").value(e.amount); + writer.name("source").value(e.damage.damageType); + writer.name("delay").value(e.delay); + writer.name("hazmat").value(e.fullBody); + writer.name("masktype").value(e.clazz.name()); + } + if(entry instanceof ToxinEffects) { + ToxinEffects e = (ToxinEffects) entry; + writer.name("type").value("effects"); + writer.name("effects").beginArray(); + writer.setIndent(""); + for(PotionEffect effect : e.effects) { + writer.beginArray(); + writer.value(effect.getPotionID()).value(effect.getDuration()).value(effect.getAmplifier()).value(effect.getIsAmbient()); + writer.endArray(); + } + writer.endArray(); + writer.setIndent(" "); + writer.name("hazmat").value(e.fullBody); + writer.name("masktype").value(e.clazz.name()); + } + + writer.endObject(); + } + + writer.endArray(); + } + + @Override public void deserializeJSON(JsonObject obj) { + JsonArray array = obj.get("entries").getAsJsonArray(); + + for(int i = 0; i < array.size(); i++) { + JsonObject entry = array.get(i).getAsJsonObject(); + String name = entry.get("type").getAsString(); + + if(name.equals("directdamage")) { + ToxinDirectDamage e = new ToxinDirectDamage( + new DamageSource(entry.get("source").getAsString()), + entry.get("amount").getAsFloat(), + entry.get("delay").getAsInt(), + HazardClass.valueOf(entry.get("masktype").getAsString()), + entry.get("hazmat").getAsBoolean() + ); + this.entries.add(e); + } + + if(name.equals("effects")) { + ToxinEffects e = new ToxinEffects( + HazardClass.valueOf(entry.get("masktype").getAsString()), + entry.get("hazmat").getAsBoolean() + ); + JsonArray effects = entry.get("effects").getAsJsonArray(); + for(int j = 0; j < effects.size(); j++) { + JsonArray effect = effects.get(j).getAsJsonArray(); + PotionEffect potion = new PotionEffect(effect.get(0).getAsInt(), effect.get(1).getAsInt(), effect.get(2).getAsInt(), effect.get(3).getAsBoolean()); + e.effects.add(potion); + } + this.entries.add(e); + } + } + } } diff --git a/src/main/java/com/hbm/inventory/fluid/trait/FT_VentRadiation.java b/src/main/java/com/hbm/inventory/fluid/trait/FT_VentRadiation.java index de8dd7764..516ef0e81 100644 --- a/src/main/java/com/hbm/inventory/fluid/trait/FT_VentRadiation.java +++ b/src/main/java/com/hbm/inventory/fluid/trait/FT_VentRadiation.java @@ -1,7 +1,10 @@ package com.hbm.inventory.fluid.trait; +import java.io.IOException; import java.util.List; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; import com.hbm.handler.radiation.ChunkRadiationManager; import com.hbm.inventory.fluid.tank.FluidTank; @@ -12,6 +15,8 @@ public class FT_VentRadiation extends FluidTrait { float radPerMB = 0; + public FT_VentRadiation() { } + public FT_VentRadiation(float rad) { this.radPerMB = rad; } @@ -29,4 +34,14 @@ public class FT_VentRadiation extends FluidTrait { public void addInfo(List info) { info.add(EnumChatFormatting.YELLOW + "[Radioactive]"); } + + @Override + public void serializeJSON(JsonWriter writer) throws IOException { + writer.name("radiation").value(radPerMB); + } + + @Override + public void deserializeJSON(JsonObject obj) { + this.radPerMB = obj.get("radiation").getAsFloat(); + } } diff --git a/src/main/java/com/hbm/inventory/fluid/trait/FluidTrait.java b/src/main/java/com/hbm/inventory/fluid/trait/FluidTrait.java index 128e945b0..2d5bac5ab 100644 --- a/src/main/java/com/hbm/inventory/fluid/trait/FluidTrait.java +++ b/src/main/java/com/hbm/inventory/fluid/trait/FluidTrait.java @@ -1,12 +1,41 @@ package com.hbm.inventory.fluid.trait; +import java.io.IOException; import java.util.List; +import com.google.common.collect.HashBiMap; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; import com.hbm.inventory.fluid.tank.FluidTank; +import com.hbm.inventory.fluid.trait.FluidTraitSimple.*; import net.minecraft.world.World; public abstract class FluidTrait { + + public static HashBiMap> traitNameMap = HashBiMap.create(); + + static { + traitNameMap.put("combustible", FT_Combustible.class); // x + traitNameMap.put("coolable", FT_Coolable.class); // x + traitNameMap.put("corrosive", FT_Corrosive.class); // x + traitNameMap.put("flammable", FT_Flammable.class); // x + traitNameMap.put("heatable", FT_Heatable.class); // x + traitNameMap.put("poison", FT_Poison.class); // x + traitNameMap.put("toxin", FT_Toxin.class); // x + traitNameMap.put("ventradiation", FT_VentRadiation.class); // x + + traitNameMap.put("gaseous", FT_Gaseous.class); + traitNameMap.put("gaseous_art", FT_Gaseous_ART.class); + traitNameMap.put("liquid", FT_Liquid.class); + traitNameMap.put("viscous", FT_Viscous.class); + traitNameMap.put("plasma", FT_Plasma.class); + traitNameMap.put("amat", FT_Amat.class); + traitNameMap.put("leadcontainer", FT_LeadContainer.class); + traitNameMap.put("delicious", FT_Delicious.class); + traitNameMap.put("noid", FT_NoID.class); + traitNameMap.put("nocontainer", FT_NoContainer.class); + } /** Important information that should always be displayed */ public void addInfo(List info) { } @@ -14,4 +43,7 @@ public abstract class FluidTrait { public void addInfoHidden(List info) { } public void onFluidRelease(World world, int x, int y, int z, FluidTank tank, int overflowAmount) { } + + public void serializeJSON(JsonWriter writer) throws IOException { } + public void deserializeJSON(JsonObject obj) { } } From 58b08ac039be659e09fc723859fbaa06a5c9599b Mon Sep 17 00:00:00 2001 From: Boblet Date: Mon, 12 Jun 2023 14:32:23 +0200 Subject: [PATCH 5/5] explosion chunk loader config --- src/main/java/com/hbm/config/BombConfig.java | 3 + .../com/hbm/entity/logic/EntityBalefire.java | 83 +++++---- .../hbm/entity/logic/EntityEnvirEffect.java | 49 ------ .../entity/logic/EntityEnvirEffectRad.java | 15 -- .../logic/EntityExplosionChunkloading.java | 51 ++++++ .../entity/logic/EntityNukeExplosionMK3.java | 89 +++++----- .../entity/logic/EntityNukeExplosionMK5.java | 10 +- .../com/hbm/entity/logic/EntityTomBlast.java | 9 +- .../missile/EntityMissileBaseAdvanced.java | 160 ++++++++---------- .../com/hbm/explosion/nt/IExplosionLogic.java | 1 + src/main/java/com/hbm/explosion/nt/Mark5.java | 1 + 11 files changed, 227 insertions(+), 244 deletions(-) delete mode 100644 src/main/java/com/hbm/entity/logic/EntityEnvirEffect.java delete mode 100644 src/main/java/com/hbm/entity/logic/EntityEnvirEffectRad.java create mode 100644 src/main/java/com/hbm/entity/logic/EntityExplosionChunkloading.java diff --git a/src/main/java/com/hbm/config/BombConfig.java b/src/main/java/com/hbm/config/BombConfig.java index df2eda4b6..8c32d0a8d 100644 --- a/src/main/java/com/hbm/config/BombConfig.java +++ b/src/main/java/com/hbm/config/BombConfig.java @@ -27,6 +27,7 @@ public class BombConfig { public static int limitExplosionLifespan = 0; public static int rain = 0; public static int cont = 0; + public static boolean chunkloading = true; public static void loadFromConfig(Configuration config) { @@ -100,5 +101,7 @@ public class BombConfig { Property rainCont = config.get(CATEGORY_NUKE, "6.06_falloutRainRadiation", 0); rainCont.comment = "Radiation in 100th RADs created by fallout rain"; cont = rainCont.getInt(); + + chunkloading = CommonConfig.createConfigBool(config, CATEGORY_NUKE, "6.XX_enableChunkLoading", "Allows all types of procedural explosions to keep the central chunk loaded.", true); } } diff --git a/src/main/java/com/hbm/entity/logic/EntityBalefire.java b/src/main/java/com/hbm/entity/logic/EntityBalefire.java index 00d0f38e9..73c8e51b2 100644 --- a/src/main/java/com/hbm/entity/logic/EntityBalefire.java +++ b/src/main/java/com/hbm/entity/logic/EntityBalefire.java @@ -7,11 +7,10 @@ import com.hbm.explosion.ExplosionBalefire; import com.hbm.explosion.ExplosionNukeGeneric; import com.hbm.main.MainRegistry; -import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -public class EntityBalefire extends Entity { +public class EntityBalefire extends EntityExplosionChunkloading { public int age = 0; public int destructionRange = 0; @@ -53,48 +52,46 @@ public class EntityBalefire extends Entity { super(p_i1582_1_); } - @Override - public void onUpdate() { - super.onUpdate(); - - if(!this.did) - { - if(GeneralConfig.enableExtendedLogging && !worldObj.isRemote) - MainRegistry.logger.log(Level.INFO, "[NUKE] Initialized BF explosion at " + posX + " / " + posY + " / " + posZ + " with strength " + destructionRange + "!"); - - exp = new ExplosionBalefire((int)this.posX, (int)this.posY, (int)this.posZ, this.worldObj, this.destructionRange); - - this.did = true; - } - - speed += 1; //increase speed to keep up with expansion - - boolean flag = false; - for(int i = 0; i < this.speed; i++) - { - flag = exp.update(); - - if(flag) { - this.setDead(); - } - } - - if(!mute && rand.nextInt(5) == 0) - this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "random.explode", 10000.0F, 0.8F + this.rand.nextFloat() * 0.2F); - - if(!flag) { - - if(!mute) - this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "ambient.weather.thunder", 10000.0F, 0.8F + this.rand.nextFloat() * 0.2F); - - ExplosionNukeGeneric.dealDamage(this.worldObj, this.posX, this.posY, this.posZ, this.destructionRange * 2); - } - - age++; - } - @Override - protected void entityInit() { } + public void onUpdate() { + super.onUpdate(); + + if(!worldObj.isRemote) loadChunk((int) Math.floor(posX / 16D), (int) Math.floor(posZ / 16D)); + + if(!this.did) { + if(GeneralConfig.enableExtendedLogging && !worldObj.isRemote) + MainRegistry.logger.log(Level.INFO, "[NUKE] Initialized BF explosion at " + posX + " / " + posY + " / " + posZ + " with strength " + destructionRange + "!"); + + exp = new ExplosionBalefire((int) this.posX, (int) this.posY, (int) this.posZ, this.worldObj, this.destructionRange); + + this.did = true; + } + + speed += 1; // increase speed to keep up with expansion + + boolean flag = false; + for(int i = 0; i < this.speed; i++) { + flag = exp.update(); + + if(flag) { + clearChunkLoader(); + this.setDead(); + } + } + + if(!mute && rand.nextInt(5) == 0) + this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "random.explode", 10000.0F, 0.8F + this.rand.nextFloat() * 0.2F); + + if(!flag) { + + if(!mute) + this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "ambient.weather.thunder", 10000.0F, 0.8F + this.rand.nextFloat() * 0.2F); + + ExplosionNukeGeneric.dealDamage(this.worldObj, this.posX, this.posY, this.posZ, this.destructionRange * 2); + } + + age++; + } public EntityBalefire mute() { this.mute = true; diff --git a/src/main/java/com/hbm/entity/logic/EntityEnvirEffect.java b/src/main/java/com/hbm/entity/logic/EntityEnvirEffect.java deleted file mode 100644 index 75c912a32..000000000 --- a/src/main/java/com/hbm/entity/logic/EntityEnvirEffect.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.hbm.entity.logic; - -import net.minecraft.entity.Entity; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; - -public abstract class EntityEnvirEffect extends Entity { - - public int maxAge = 100; - public int blockRadius = 7; - public int entityRadius = 7; - public int chance = 10; - public boolean hasBlockEffect = true; - public boolean hasEntityEffect = true; - - public EntityEnvirEffect(World p_i1582_1_) { - super(p_i1582_1_); - } - - @Override - protected void entityInit() { - - } - - @Override - protected void readEntityFromNBT(NBTTagCompound nbt) { - this.ticksExisted = nbt.getInteger("lifetime"); - this.maxAge = nbt.getInteger("lifecap"); - } - - @Override - protected void writeEntityToNBT(NBTTagCompound nbt) { - nbt.setInteger("lifetime", this.ticksExisted); - nbt.setInteger("lifecap", this.maxAge); - } - - public void onUpdate() { - - if(hasBlockEffect && rand.nextInt(chance) == 0) - applyBlockEffect(); - - if(hasEntityEffect && rand.nextInt(chance) == 0) - applyEntityEffect(); - } - - private void applyBlockEffect() { }; - private void applyEntityEffect() { }; - -} diff --git a/src/main/java/com/hbm/entity/logic/EntityEnvirEffectRad.java b/src/main/java/com/hbm/entity/logic/EntityEnvirEffectRad.java deleted file mode 100644 index f67bcaf6a..000000000 --- a/src/main/java/com/hbm/entity/logic/EntityEnvirEffectRad.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hbm.entity.logic; - -import net.minecraft.world.World; - -public class EntityEnvirEffectRad extends EntityEnvirEffect { - - public EntityEnvirEffectRad(World p_i1582_1_) { - super(p_i1582_1_); - } - - public void randomizeAge(int min, int max) { - this.maxAge = min + rand.nextInt(max - min); - } - -} diff --git a/src/main/java/com/hbm/entity/logic/EntityExplosionChunkloading.java b/src/main/java/com/hbm/entity/logic/EntityExplosionChunkloading.java new file mode 100644 index 000000000..ca2ad6f6f --- /dev/null +++ b/src/main/java/com/hbm/entity/logic/EntityExplosionChunkloading.java @@ -0,0 +1,51 @@ +package com.hbm.entity.logic; + +import com.hbm.main.MainRegistry; + +import net.minecraft.entity.Entity; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeChunkManager; +import net.minecraftforge.common.ForgeChunkManager.Ticket; +import net.minecraftforge.common.ForgeChunkManager.Type; + +public abstract class EntityExplosionChunkloading extends Entity implements IChunkLoader { + + private Ticket loaderTicket; + private ChunkCoordIntPair loadedChunk; + + public EntityExplosionChunkloading(World world) { + super(world); + } + + @Override + protected void entityInit() { + init(ForgeChunkManager.requestTicket(MainRegistry.instance, worldObj, Type.ENTITY)); + } + + @Override + public void init(Ticket ticket) { + if(!worldObj.isRemote && ticket != null) { + if(loaderTicket == null) { + loaderTicket = ticket; + loaderTicket.bindEntity(this); + loaderTicket.getModData(); + } + ForgeChunkManager.forceChunk(loaderTicket, new ChunkCoordIntPair(chunkCoordX, chunkCoordZ)); + } + } + + public void loadChunk(int x, int z) { + + if(this.loadedChunk == null) { + this.loadedChunk = new ChunkCoordIntPair(x, z); + ForgeChunkManager.forceChunk(loaderTicket, loadedChunk); + } + } + + public void clearChunkLoader() { + if(!worldObj.isRemote && loaderTicket != null && loadedChunk != null) { + ForgeChunkManager.unforceChunk(loaderTicket, loadedChunk); + } + } +} diff --git a/src/main/java/com/hbm/entity/logic/EntityNukeExplosionMK3.java b/src/main/java/com/hbm/entity/logic/EntityNukeExplosionMK3.java index 93335b142..665d9550d 100644 --- a/src/main/java/com/hbm/entity/logic/EntityNukeExplosionMK3.java +++ b/src/main/java/com/hbm/entity/logic/EntityNukeExplosionMK3.java @@ -20,14 +20,13 @@ import com.hbm.packet.AuxParticlePacketNT; import com.hbm.packet.PacketDispatcher; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; -import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.Vec3; import net.minecraft.world.World; @Spaghetti("why???") -public class EntityNukeExplosionMK3 extends Entity { +public class EntityNukeExplosionMK3 extends EntityExplosionChunkloading { public int age = 0; public int destructionRange = 0; @@ -59,31 +58,32 @@ public class EntityNukeExplosionMK3 extends Entity { long time = nbt.getLong("milliTime"); - if(BombConfig.limitExplosionLifespan > 0 && System.currentTimeMillis() - time > BombConfig.limitExplosionLifespan * 1000) + if(BombConfig.limitExplosionLifespan > 0 && System.currentTimeMillis() - time > BombConfig.limitExplosionLifespan * 1000) { + this.clearChunkLoader(); this.setDead(); + } - if(this.waste) - { - exp = new ExplosionNukeAdvanced((int)this.posX, (int)this.posY, (int)this.posZ, this.worldObj, this.destructionRange, this.coefficient, 0); + if(this.waste) { + exp = new ExplosionNukeAdvanced((int) this.posX, (int) this.posY, (int) this.posZ, this.worldObj, this.destructionRange, this.coefficient, 0); exp.readFromNbt(nbt, "exp_"); - wst = new ExplosionNukeAdvanced((int)this.posX, (int)this.posY, (int)this.posZ, this.worldObj, (int)(this.destructionRange * 1.8), this.coefficient, 2); + wst = new ExplosionNukeAdvanced((int) this.posX, (int) this.posY, (int) this.posZ, this.worldObj, (int) (this.destructionRange * 1.8), this.coefficient, 2); wst.readFromNbt(nbt, "wst_"); - vap = new ExplosionNukeAdvanced((int)this.posX, (int)this.posY, (int)this.posZ, this.worldObj, (int)(this.destructionRange * 2.5), this.coefficient, 1); + vap = new ExplosionNukeAdvanced((int) this.posX, (int) this.posY, (int) this.posZ, this.worldObj, (int) (this.destructionRange * 2.5), this.coefficient, 1); vap.readFromNbt(nbt, "vap_"); - } else { + } else { - if(extType == 0) { - expl = new ExplosionFleija((int)this.posX, (int)this.posY, (int)this.posZ, this.worldObj, this.destructionRange, this.coefficient, this.coefficient2); + if(extType == 0) { + expl = new ExplosionFleija((int) this.posX, (int) this.posY, (int) this.posZ, this.worldObj, this.destructionRange, this.coefficient, this.coefficient2); expl.readFromNbt(nbt, "expl_"); - } - if(extType == 1) { - sol = new ExplosionSolinium((int)this.posX, (int)this.posY, (int)this.posZ, this.worldObj, this.destructionRange, this.coefficient, this.coefficient2); - sol.readFromNbt(nbt, "sol_"); - } - } - - this.did = true; - + } + if(extType == 1) { + sol = new ExplosionSolinium((int) this.posX, (int) this.posY, (int) this.posZ, this.worldObj, this.destructionRange, this.coefficient, this.coefficient2); + sol.readFromNbt(nbt, "sol_"); + } + } + + this.did = true; + } @Override @@ -120,6 +120,8 @@ public class EntityNukeExplosionMK3 extends Entity { @Override public void onUpdate() { super.onUpdate(); + + if(!worldObj.isRemote) loadChunk((int) Math.floor(posX / 16D), (int) Math.floor(posZ / 16D)); if(!this.did) { @@ -149,25 +151,31 @@ public class EntityNukeExplosionMK3 extends Entity { boolean flag = false; boolean flag3 = false; - for(int i = 0; i < this.speed; i++) - { - if(waste) { - flag = exp.update(); - wst.update(); - flag3 = vap.update(); - - if(flag3) { - this.setDead(); - } - } else { - if(extType == 0) - if(expl.update()) - this.setDead(); - if(extType == 1) - if(sol.update()) - this.setDead(); - } - } + for(int i = 0; i < this.speed; i++) { + if(waste) { + flag = exp.update(); + wst.update(); + flag3 = vap.update(); + + if(flag3) { + this.clearChunkLoader(); + this.setDead(); + } + } else { + if(extType == 0) { + if(expl.update()) { + this.clearChunkLoader(); + this.setDead(); + } + } + if(extType == 1) { + if(sol.update()) { + this.clearChunkLoader(); + this.setDead(); + } + } + } + } if(!flag) { @@ -196,9 +204,6 @@ public class EntityNukeExplosionMK3 extends Entity { age++; } - - @Override - protected void entityInit() { } public static HashMap at = new HashMap(); diff --git a/src/main/java/com/hbm/entity/logic/EntityNukeExplosionMK5.java b/src/main/java/com/hbm/entity/logic/EntityNukeExplosionMK5.java index e924e43da..15cb2679b 100644 --- a/src/main/java/com/hbm/entity/logic/EntityNukeExplosionMK5.java +++ b/src/main/java/com/hbm/entity/logic/EntityNukeExplosionMK5.java @@ -14,7 +14,6 @@ import com.hbm.util.ContaminationUtil; import com.hbm.util.ContaminationUtil.ContaminationType; import com.hbm.util.ContaminationUtil.HazardType; -import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; @@ -22,7 +21,7 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Vec3; import net.minecraft.world.World; -public class EntityNukeExplosionMK5 extends Entity { +public class EntityNukeExplosionMK5 extends EntityExplosionChunkloading { //Strength of the blast public int strength; @@ -52,9 +51,12 @@ public class EntityNukeExplosionMK5 extends Entity { public void onUpdate() { if(strength == 0) { + this.clearChunkLoader(); this.setDead(); return; } + + if(!worldObj.isRemote) loadChunk((int) Math.floor(posX / 16D), (int) Math.floor(posZ / 16D)); for(Object player : this.worldObj.playerEntities) { ((EntityPlayer)player).triggerAchievement(MainRegistry.achManhattan); @@ -92,9 +94,11 @@ public class EntityNukeExplosionMK5 extends Entity { fallout.setScale((int)(this.length * 2.5 + falloutAdd) * BombConfig.falloutRange / 100); this.worldObj.spawnEntityInWorld(fallout); - + + this.clearChunkLoader(); this.setDead(); } else { + this.clearChunkLoader(); this.setDead(); } } diff --git a/src/main/java/com/hbm/entity/logic/EntityTomBlast.java b/src/main/java/com/hbm/entity/logic/EntityTomBlast.java index 4eb855576..093638a6d 100644 --- a/src/main/java/com/hbm/entity/logic/EntityTomBlast.java +++ b/src/main/java/com/hbm/entity/logic/EntityTomBlast.java @@ -8,11 +8,10 @@ import com.hbm.explosion.ExplosionTom; import com.hbm.main.MainRegistry; import com.hbm.saveddata.TomSaveData; -import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -public class EntityTomBlast extends Entity { +public class EntityTomBlast extends EntityExplosionChunkloading { public int age = 0; public int destructionRange = 0; @@ -54,6 +53,8 @@ public class EntityTomBlast extends Entity { public void onUpdate() { super.onUpdate(); + if(!worldObj.isRemote) loadChunk((int) Math.floor(posX / 16D), (int) Math.floor(posZ / 16D)); + if(!this.did) { if(GeneralConfig.enableExtendedLogging && !worldObj.isRemote) @@ -89,8 +90,4 @@ public class EntityTomBlast extends Entity { age++; } - - @Override - protected void entityInit() { - } } diff --git a/src/main/java/com/hbm/entity/missile/EntityMissileBaseAdvanced.java b/src/main/java/com/hbm/entity/missile/EntityMissileBaseAdvanced.java index 5c0d93b67..69d128a51 100644 --- a/src/main/java/com/hbm/entity/missile/EntityMissileBaseAdvanced.java +++ b/src/main/java/com/hbm/entity/missile/EntityMissileBaseAdvanced.java @@ -48,46 +48,36 @@ public abstract class EntityMissileBaseAdvanced extends Entity implements IChunk targetZ = (int) posZ; } - public boolean canBeCollidedWith() - { - return true; - } - - public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) - { - if (this.isEntityInvulnerable()) - { - return false; - } - else - { - if (!this.isDead && !this.worldObj.isRemote) - { - health -= p_70097_2_; - - if (this.health <= 0) - { - this.setDead(); - this.killMissile(); - } - } + public boolean canBeCollidedWith() { + return true; + } - return true; - } - } - - private void killMissile() { - ExplosionLarge.explode(worldObj, posX, posY, posZ, 5, true, false, true); - ExplosionLarge.spawnShrapnelShower(worldObj, posX, posY, posZ, motionX, motionY, motionZ, 15, 0.075); - ExplosionLarge.spawnMissileDebris(worldObj, posX, posY, posZ, motionX, motionY, motionZ, 0.25, getDebris(), getDebrisRareDrop()); - } + public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { + if(this.isEntityInvulnerable()) { + return false; + } else { + if(!this.isDead && !this.worldObj.isRemote) { + health -= p_70097_2_; + + if(this.health <= 0) { + this.setDead(); + this.killMissile(); + } + } + + return true; + } + } + + private void killMissile() { + ExplosionLarge.explode(worldObj, posX, posY, posZ, 5, true, false, true); + ExplosionLarge.spawnShrapnelShower(worldObj, posX, posY, posZ, motionX, motionY, motionZ, 15, 0.075); + ExplosionLarge.spawnMissileDebris(worldObj, posX, posY, posZ, motionX, motionY, motionZ, 0.25, getDebris(), getDebrisRareDrop()); + } public EntityMissileBaseAdvanced(World world, float x, float y, float z, int a, int b) { super(world); this.ignoreFrustumCheck = true; - /*this.posX = x; - this.posY = y; - this.posZ = z;*/ this.setLocationAndAngles(x, y, z, 0, 0); startX = (int) x; startZ = (int) z; @@ -95,19 +85,19 @@ public abstract class EntityMissileBaseAdvanced extends Entity implements IChunk targetZ = b; this.motionY = 2; - Vec3 vector = Vec3.createVectorHelper(targetX - startX, 0, targetZ - startZ); - accelXZ = decelY = 1/vector.lengthVector(); + Vec3 vector = Vec3.createVectorHelper(targetX - startX, 0, targetZ - startZ); + accelXZ = decelY = 1 / vector.lengthVector(); decelY *= 2; - + velocity = 1; - this.setSize(1.5F, 1.5F); + this.setSize(1.5F, 1.5F); } @Override protected void entityInit() { init(ForgeChunkManager.requestTicket(MainRegistry.instance, worldObj, Type.ENTITY)); - this.dataWatcher.addObject(8, Integer.valueOf(this.health)); + this.dataWatcher.addObject(8, Integer.valueOf(this.health)); } @Override @@ -212,7 +202,6 @@ public abstract class EntityMissileBaseAdvanced extends Entity implements IChunk } if(!this.worldObj.isRemote) - //this.worldObj.spawnEntityInWorld(new EntitySmokeFX(this.worldObj, this.posX, this.posY, this.posZ, 0.0, 0.0, 0.0)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacket(posX, posY, posZ, 2), new TargetPoint(worldObj.provider.dimensionId, posX, posY, posZ, 300)); @@ -220,30 +209,28 @@ public abstract class EntityMissileBaseAdvanced extends Entity implements IChunk this.worldObj.getBlock((int)this.posX, (int)this.posY, (int)this.posZ) != Blocks.water && this.worldObj.getBlock((int)this.posX, (int)this.posY, (int)this.posZ) != Blocks.flowing_water) { - if(!this.worldObj.isRemote) - { - onImpact(); - } - this.setDead(); - return; - } - - loadNeighboringChunks((int)(posX / 16), (int)(posZ / 16)); - - if(motionY < -1 && this.isCluster && !worldObj.isRemote) { - cluster(); - this.setDead(); - return; - } + if(!this.worldObj.isRemote) { + onImpact(); + } + this.killAndClear(); + return; + } + + loadNeighboringChunks((int) (posX / 16), (int) (posZ / 16)); + + if(motionY < -1 && this.isCluster && !worldObj.isRemote) { + cluster(); + this.setDead(); + return; + } } - } + } - @Override + @Override @SideOnly(Side.CLIENT) - public boolean isInRangeToRenderDist(double distance) - { - return distance < 500000; - } + public boolean isInRangeToRenderDist(double distance) { + return true; + } public abstract void onImpact(); @@ -272,30 +259,31 @@ public abstract class EntityMissileBaseAdvanced extends Entity implements IChunk List loadedChunks = new ArrayList(); - public void loadNeighboringChunks(int newChunkX, int newChunkZ) - { - if(!worldObj.isRemote && loaderTicket != null) - { - for(ChunkCoordIntPair chunk : loadedChunks) - { - ForgeChunkManager.unforceChunk(loaderTicket, chunk); - } + public void loadNeighboringChunks(int newChunkX, int newChunkZ) { + if(!worldObj.isRemote && loaderTicket != null) { + + clearChunkLoader(); - loadedChunks.clear(); - loadedChunks.add(new ChunkCoordIntPair(newChunkX, newChunkZ)); - loadedChunks.add(new ChunkCoordIntPair(newChunkX + 1, newChunkZ + 1)); - loadedChunks.add(new ChunkCoordIntPair(newChunkX - 1, newChunkZ - 1)); - loadedChunks.add(new ChunkCoordIntPair(newChunkX + 1, newChunkZ - 1)); - loadedChunks.add(new ChunkCoordIntPair(newChunkX - 1, newChunkZ + 1)); - loadedChunks.add(new ChunkCoordIntPair(newChunkX + 1, newChunkZ)); - loadedChunks.add(new ChunkCoordIntPair(newChunkX, newChunkZ + 1)); - loadedChunks.add(new ChunkCoordIntPair(newChunkX - 1, newChunkZ)); - loadedChunks.add(new ChunkCoordIntPair(newChunkX, newChunkZ - 1)); + loadedChunks.clear(); + loadedChunks.add(new ChunkCoordIntPair(newChunkX, newChunkZ)); + loadedChunks.add(new ChunkCoordIntPair(newChunkX + (int) Math.ceil((this.posX + this.motionX) / 16D), newChunkZ + (int) Math.ceil((this.posZ + this.motionZ) / 16D))); - for(ChunkCoordIntPair chunk : loadedChunks) - { - ForgeChunkManager.forceChunk(loaderTicket, chunk); - } - } - } + for(ChunkCoordIntPair chunk : loadedChunks) { + ForgeChunkManager.forceChunk(loaderTicket, chunk); + } + } + } + + public void killAndClear() { + this.setDead(); + this.clearChunkLoader(); + } + + public void clearChunkLoader() { + if(!worldObj.isRemote && loaderTicket != null) { + for(ChunkCoordIntPair chunk : loadedChunks) { + ForgeChunkManager.unforceChunk(loaderTicket, chunk); + } + } + } } diff --git a/src/main/java/com/hbm/explosion/nt/IExplosionLogic.java b/src/main/java/com/hbm/explosion/nt/IExplosionLogic.java index b2b2e86b8..0886cb3eb 100644 --- a/src/main/java/com/hbm/explosion/nt/IExplosionLogic.java +++ b/src/main/java/com/hbm/explosion/nt/IExplosionLogic.java @@ -1,5 +1,6 @@ package com.hbm.explosion.nt; +@Deprecated public interface IExplosionLogic { public void updateLogic(); diff --git a/src/main/java/com/hbm/explosion/nt/Mark5.java b/src/main/java/com/hbm/explosion/nt/Mark5.java index 6827b6758..16d2d5ee4 100644 --- a/src/main/java/com/hbm/explosion/nt/Mark5.java +++ b/src/main/java/com/hbm/explosion/nt/Mark5.java @@ -10,6 +10,7 @@ import net.minecraft.init.Blocks; import net.minecraft.util.Vec3; import net.minecraft.world.World; +@Deprecated public class Mark5 implements IExplosionLogic { //holds rays after being calculated up to where the blocks get removed