From 4c0b503b8b368dd49d9b7091995da5eeff1235ed Mon Sep 17 00:00:00 2001 From: dibbydoda <93301589+dibbydoda@users.noreply.github.com> Date: Sat, 17 May 2025 19:39:34 +1000 Subject: [PATCH] Add thunder substrate for rainmaker (#95) --- .../forestry/api/fuels/RainSubstrate.java | 26 ++++++---- .../java/forestry/core/config/Constants.java | 1 + .../forestry/core/items/ItemRegistryCore.java | 3 +- .../factory/inventory/InventoryRainmaker.java | 10 ++-- .../factory/tiles/TileMillRainmaker.java | 47 +++++++++++++----- .../java/forestry/plugins/PluginFactory.java | 27 +++++++++- .../resources/assets/forestry/lang/en_US.lang | 1 + .../items/phosphoricIodineCapsule.png | Bin 0 -> 789 bytes 8 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 src/main/resources/assets/forestry/textures/items/phosphoricIodineCapsule.png diff --git a/src/main/java/forestry/api/fuels/RainSubstrate.java b/src/main/java/forestry/api/fuels/RainSubstrate.java index 729b3edea..6a91a2671 100644 --- a/src/main/java/forestry/api/fuels/RainSubstrate.java +++ b/src/main/java/forestry/api/fuels/RainSubstrate.java @@ -9,33 +9,37 @@ import net.minecraft.item.ItemStack; public class RainSubstrate { + public enum WeatherState { + CLEAR, + RAIN, + STORM + } + /** * Rain substrate capable of activating the rainmaker. */ public ItemStack item; /** - * Duration of the rain shower triggered by this substrate in Minecraft ticks. + * Duration of the weather event triggered by this substrate in Minecraft ticks. */ public int duration; /** * Speed of activation sequence triggered. */ public float speed; + /** + * The type of weather triggered. + */ + public WeatherState weather; - public boolean reverse; - - public RainSubstrate(ItemStack item, int duration, float speed) { - this(item, duration, speed, false); + public RainSubstrate(ItemStack item, float speed, WeatherState weather) { + this(item, 0, speed, weather); } - public RainSubstrate(ItemStack item, float speed) { - this(item, 0, speed, true); - } - - public RainSubstrate(ItemStack item, int duration, float speed, boolean reverse) { + public RainSubstrate(ItemStack item, int duration, float speed, WeatherState weather) { this.item = item; this.duration = duration; this.speed = speed; - this.reverse = reverse; + this.weather = weather; } } diff --git a/src/main/java/forestry/core/config/Constants.java b/src/main/java/forestry/core/config/Constants.java index 165a2cf3f..677b98acb 100644 --- a/src/main/java/forestry/core/config/Constants.java +++ b/src/main/java/forestry/core/config/Constants.java @@ -109,6 +109,7 @@ public class Constants implements IForestryConstants { public static final int MACHINE_MAX_ENERGY = 5000; public static final int RAINMAKER_RAIN_DURATION_IODINE = 10000; + public static final int RAINMAKER_RAIN_DURATION_PHOSPHORICIODINE = 10000; public static final int STILL_DESTILLATION_DURATION = 100; public static final int STILL_DESTILLATION_INPUT = 10; diff --git a/src/main/java/forestry/core/items/ItemRegistryCore.java b/src/main/java/forestry/core/items/ItemRegistryCore.java index 95e563441..b37f272f2 100644 --- a/src/main/java/forestry/core/items/ItemRegistryCore.java +++ b/src/main/java/forestry/core/items/ItemRegistryCore.java @@ -78,6 +78,7 @@ public class ItemRegistryCore extends ItemRegistry { /* Rainmaker */ public final ItemForestry iodineCharge; public final ItemForestry phosphor; + public final ItemForestry phosphorCharge; /* Misc */ public final ItemCraftingMaterial craftingMaterial; @@ -181,8 +182,8 @@ public class ItemRegistryCore extends ItemRegistry { // / RAINMAKER SUBSTRATES iodineCharge = registerItem(new ItemForestry(), "iodineCapsule"); - phosphor = registerItem(new ItemForestry(), "phosphor"); + phosphorCharge = registerItem(new ItemForestry(), "phosphoricIodineCapsule"); // / BEE RESOURCES beeswax = registerItem(new ItemForestry(), "beeswax"); diff --git a/src/main/java/forestry/factory/inventory/InventoryRainmaker.java b/src/main/java/forestry/factory/inventory/InventoryRainmaker.java index 21290d418..416d0f895 100644 --- a/src/main/java/forestry/factory/inventory/InventoryRainmaker.java +++ b/src/main/java/forestry/factory/inventory/InventoryRainmaker.java @@ -26,16 +26,14 @@ public class InventoryRainmaker extends InventoryAdapterTile @Override public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { if (slotIndex == SLOT_SUBSTRATE) { + if (getStackInSlot(SLOT_SUBSTRATE) != null) { + return false; + } if (FuelManager.rainSubstrate.containsKey(itemStack) && tile.charge == 0 && tile.progress == 0) { RainSubstrate substrate = FuelManager.rainSubstrate.get(itemStack); - if (tile.getWorld().isRaining() && substrate.reverse) { - return true; - } else if (!tile.getWorld().isRaining() && !substrate.reverse) { - return true; - } + return tile.isValidSubstrate(substrate); } } - return false; } diff --git a/src/main/java/forestry/factory/tiles/TileMillRainmaker.java b/src/main/java/forestry/factory/tiles/TileMillRainmaker.java index 906b4928c..a153fab62 100644 --- a/src/main/java/forestry/factory/tiles/TileMillRainmaker.java +++ b/src/main/java/forestry/factory/tiles/TileMillRainmaker.java @@ -10,6 +10,7 @@ package forestry.factory.tiles; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.storage.WorldInfo; import forestry.api.fuels.FuelManager; import forestry.api.fuels.RainSubstrate; @@ -20,7 +21,7 @@ import forestry.factory.inventory.InventoryRainmaker; public class TileMillRainmaker extends TileMill { private int duration; - private boolean reverse; + private RainSubstrate.WeatherState weather; public TileMillRainmaker() { super(null); @@ -39,9 +40,9 @@ public class TileMillRainmaker extends TileMill { } // We don't have a gui, but we can be activated - if (FuelManager.rainSubstrate.containsKey(player.inventory.getCurrentItem()) && charge == 0) { + if (FuelManager.rainSubstrate.containsKey(player.inventory.getCurrentItem()) && charge == 0 && progress == 0) { RainSubstrate substrate = FuelManager.rainSubstrate.get(player.inventory.getCurrentItem()); - if (substrate.item.isItemEqual(player.inventory.getCurrentItem())) { + if (isValidSubstrate(substrate)) { addCharge(substrate); player.inventory.getCurrentItem().stackSize--; } @@ -49,6 +50,17 @@ public class TileMillRainmaker extends TileMill { sendNetworkUpdate(); } + public boolean isValidSubstrate(RainSubstrate substrate) { + boolean thundering = getWorld().isThundering(); + boolean raining = getWorld().isRaining(); + + return switch (substrate.weather) { + case CLEAR -> (thundering || raining); + case RAIN -> (thundering || !raining); + case STORM -> (!thundering); + }; + } + @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); @@ -57,7 +69,7 @@ public class TileMillRainmaker extends TileMill { progress = nbttagcompound.getFloat("Progress"); stage = nbttagcompound.getInteger("Stage"); duration = nbttagcompound.getInteger("Duration"); - reverse = nbttagcompound.getBoolean("Reverse"); + weather = RainSubstrate.WeatherState.valueOf(nbttagcompound.getString("Weather")); } @Override @@ -68,14 +80,14 @@ public class TileMillRainmaker extends TileMill { nbttagcompound.setFloat("Progress", progress); nbttagcompound.setInteger("Stage", stage); nbttagcompound.setInteger("Duration", duration); - nbttagcompound.setBoolean("Reverse", reverse); + nbttagcompound.setString("Weather", weather.name()); } public void addCharge(RainSubstrate substrate) { charge = 1; speed = substrate.speed; duration = substrate.duration; - reverse = substrate.reverse; + weather = substrate.weather; sendNetworkUpdate(); } @@ -103,15 +115,26 @@ public class TileMillRainmaker extends TileMill { } if (!worldObj.isRemote) { - if (reverse) { - worldObj.getWorldInfo().setRaining(false); - } else { - worldObj.getWorldInfo().setRaining(true); - worldObj.getWorldInfo().setRainTime(duration); + WorldInfo world = worldObj.getWorldInfo(); + switch (weather) { + case CLEAR: + world.setRaining(false); + world.setThundering(false); + break; + case STORM: + world.setRaining(true); + world.setRainTime(duration); + world.setThundering(true); + world.setThunderTime(duration); + break; + case RAIN: + world.setRaining(true); + world.setRainTime(duration); + world.setThundering(false); + break; } charge = 0; duration = 0; - reverse = false; sendNetworkUpdate(); } } diff --git a/src/main/java/forestry/plugins/PluginFactory.java b/src/main/java/forestry/plugins/PluginFactory.java index bc34c0442..e2e1842f4 100644 --- a/src/main/java/forestry/plugins/PluginFactory.java +++ b/src/main/java/forestry/plugins/PluginFactory.java @@ -222,9 +222,23 @@ public class PluginFactory extends ForestryPlugin { // Set rain substrates ItemStack iodineCharge = coreItems.iodineCharge.getItemStack(); ItemStack dissipationCharge = coreItems.craftingMaterial.getDissipationCharge(); + ItemStack phosphorCharge = coreItems.phosphorCharge.getItemStack(); + FuelManager.rainSubstrate.put( + iodineCharge, + new RainSubstrate( + iodineCharge, + Constants.RAINMAKER_RAIN_DURATION_IODINE, + 0.01f, + RainSubstrate.WeatherState.RAIN)); FuelManager.rainSubstrate - .put(iodineCharge, new RainSubstrate(iodineCharge, Constants.RAINMAKER_RAIN_DURATION_IODINE, 0.01f)); - FuelManager.rainSubstrate.put(dissipationCharge, new RainSubstrate(dissipationCharge, 0.075f)); + .put(dissipationCharge, new RainSubstrate(dissipationCharge, 0.075f, RainSubstrate.WeatherState.CLEAR)); + FuelManager.rainSubstrate.put( + phosphorCharge, + new RainSubstrate( + phosphorCharge, + Constants.RAINMAKER_RAIN_DURATION_PHOSPHORICIODINE, + 0.008f, + RainSubstrate.WeatherState.STORM)); for (BlockFactoryTesrType type : BlockFactoryTesrType.VALUES) { MachineDefinition machineDefinition = new MachineDefinition(type); @@ -594,6 +608,15 @@ public class PluginFactory extends ForestryPlugin { PluginFluids.items.canEmpty, 'Z', beeItems.honeydew); + RecipeManagers.carpenterManager.addRecipe( + 5, + PluginCore.items.iodineCharge.getItemStack(), + PluginCore.items.phosphorCharge.getItemStack(), + "# #", + " # ", + "# #", + '#', + PluginCore.items.phosphor.getItemStack()); } // Ender pearl diff --git a/src/main/resources/assets/forestry/lang/en_US.lang b/src/main/resources/assets/forestry/lang/en_US.lang index bf359fbd3..ca6f27cb4 100644 --- a/src/main/resources/assets/forestry/lang/en_US.lang +++ b/src/main/resources/assets/forestry/lang/en_US.lang @@ -755,6 +755,7 @@ item.for.naturalistHelmet.name=Spectacles item.for.oakStick.name=Impregnated Stick item.for.peat.name=Peat item.for.phosphor.name=Phosphor +item.for.phosphoricIodineCapsule.name=Phosphoric Iodine Capsule item.for.pipette.name=Pipette item.for.pollenFertile.name=Fertile Pollen diff --git a/src/main/resources/assets/forestry/textures/items/phosphoricIodineCapsule.png b/src/main/resources/assets/forestry/textures/items/phosphoricIodineCapsule.png new file mode 100644 index 0000000000000000000000000000000000000000..47ee3501030bcf33a86c8ef97f090b0031b3afcd GIT binary patch literal 789 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBuf-vKbiP>*~8rm~MB1$5BeXNr6bM+Ea@{>~aDsl^esu>t; z>?;Zqle1Gx6p~WYGxKcK-|yb9u8^5xs~&FZYv5bpoSKp8QB{;0T;&&%T$P<{nWAoQ z$IE3?VFffHH?<^Dp&~aYuh^=>Rtapd6_5=Q)>pE#DN0GR3UYCSssQqAl`=|73as?? z%gf94%8m8%i_-NCEiEne4UF`SjC6r2bc-wVN)jt{^NN+B2DqdaCl_TFlw{`TDS!-2 zOv*1Uu~jN9%}lXMOH4CON=Y%*O-eLQ(KR$oNz_eDF*ejqF*Z&yH#M{{N;6DSf?8ja znTD`GuNWE(zyQ$)$>>wgQzXDnC zkO2h~Jakj@fI(Ug3_G1EGq{0KBJSzp7-HeScCw=XVF!se`4fH*{LKzt@SWJu+Q1gv z$a<0M7rQ~QvBZ-v0&5Q{7(S5Z;1gnES+QqH%FdLtLgzwwj&6#(J@eC!>iys4zSdrt zBx=nN;C1#5&w;`@Ui*bKmZm-aDAADUUQqC(sYm6Q#3!5M-~V2kfA#2brKoHse`V#& zelHU)hOWRyzAduTBeVn-K6qDlxzGCwSDS1j2kZ0n^(^z;*k?VztiGGgx9Q+Tsmw>0 z-j{j`i#N<&9Sam!{Z?##Wu!1IH9iSq5Y2Tzt?tK+Ye`)+vb#$wB<(F`4rcYK@i#`=eN Z9pkS9;bEI5?O6ayo1U(IF6*2UngAX&Bsl;8 literal 0 HcmV?d00001