From f0ead63cf60fbd39e0c90c6d3b5331abaf27ab0e Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Sun, 6 Feb 2022 19:50:09 +0100 Subject: [PATCH] Consolidate code, fix item tooltips --- HotOrNot.iml | 7 +- build.gradle | 2 +- gradle.properties | 2 +- .../java/com/buuz135/hotornot/HotOrNot.java | 2 +- .../buuz135/hotornot/client/HotTooltip.java | 4 +- .../buuz135/hotornot/config/HotConfig.java | 16 +- .../com/buuz135/hotornot/config/HotLists.java | 37 ++-- .../buuz135/hotornot/server/ServerTick.java | 186 +++++++----------- 8 files changed, 119 insertions(+), 137 deletions(-) diff --git a/HotOrNot.iml b/HotOrNot.iml index 629a742..a142fa2 100644 --- a/HotOrNot.iml +++ b/HotOrNot.iml @@ -1,5 +1,5 @@ - + @@ -11,7 +11,10 @@ - diff --git a/build.gradle b/build.gradle index 899f600..eff934b 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = '1.1.8' +version = '1.1.9' group = 'com.buuz135' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'HotOrNotPlus-1.12.2' diff --git a/gradle.properties b/gradle.properties index 1847633..21a27b8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ modGroup=com.buuz135 minecraftVersion=1.12.2 -modVersion=1.1.8 +modVersion=1.1.9 modBaseName=HotOrNotPlus forgeVersion=1.12.2-14.23.5.2860 mcpVersion=stable_39 \ No newline at end of file diff --git a/src/main/java/com/buuz135/hotornot/HotOrNot.java b/src/main/java/com/buuz135/hotornot/HotOrNot.java index 3ad7fba..65a47ed 100644 --- a/src/main/java/com/buuz135/hotornot/HotOrNot.java +++ b/src/main/java/com/buuz135/hotornot/HotOrNot.java @@ -37,7 +37,7 @@ public class HotOrNot { public static final String MOD_ID = "hotornot"; public static final String MOD_NAME = "Hot or Not +"; - public static final String VERSION = "1.1.8"; + public static final String VERSION = "1.1.9"; public static final CreativeTabs HOTORNOT_TAB = new HotOrNotTab(); @Mod.EventHandler diff --git a/src/main/java/com/buuz135/hotornot/client/HotTooltip.java b/src/main/java/com/buuz135/hotornot/client/HotTooltip.java index 4552664..072e937 100644 --- a/src/main/java/com/buuz135/hotornot/client/HotTooltip.java +++ b/src/main/java/com/buuz135/hotornot/client/HotTooltip.java @@ -55,12 +55,12 @@ else if (HotLists.isGaseousItem(stack)) { event.getToolTip().add(FluidEffect.GAS.color + new TextComponentTranslation(FluidEffect.GAS.tooltip).getUnformattedText()); } - else if (Loader.isModLoaded("tfc")) + else if (Loader.isModLoaded("tfc") && HotConfig.HOT_ITEMS) { if (stack.hasCapability(CapabilityItemHeat.ITEM_HEAT_CAPABILITY, null)) { IItemHeat heat = stack.getCapability(CapabilityItemHeat.ITEM_HEAT_CAPABILITY, null); - if (heat.getTemperature() >= HotConfig.HOT_ITEM) + if (heat.getTemperature() >= HotConfig.HOT_ITEM_TEMP) { event.getToolTip().add(FluidEffect.HOT.color + new TextComponentTranslation(FluidEffect.HOT.tooltip).getUnformattedText()); } diff --git a/src/main/java/com/buuz135/hotornot/config/HotConfig.java b/src/main/java/com/buuz135/hotornot/config/HotConfig.java index 8cbd935..12e37db 100644 --- a/src/main/java/com/buuz135/hotornot/config/HotConfig.java +++ b/src/main/java/com/buuz135/hotornot/config/HotConfig.java @@ -11,8 +11,14 @@ @Config(modid = HotOrNot.MOD_ID) public class HotConfig { - @Config.Comment("If true, effects for items will be enabled") - public static boolean ITEM_EFFECTS = true; + @Config.Comment("If true, hot effects for items will be enabled") + public static boolean HOT_ITEMS = true; + + @Config.Comment("If true, cold effects for items will be enabled") + public static boolean COLD_ITEMS = true; + + @Config.Comment("If true, gaseous effects for items will be enabled") + public static boolean GASEOUS_ITEMS = true; @Config.Comment("If true, hot effects for fluids will be enabled") public static boolean HOT_FLUIDS = true; @@ -30,13 +36,13 @@ public class HotConfig public static boolean YEET = true; @Config.Comment("How hot a fluid should be to start burning the player (in Celsius)") - public static int HOT_FLUID = 480; + public static int HOT_FLUID_TEMP = 480; @Config.Comment("How cold a fluid should be to start adding effects the player (in Celsius)") - public static int COLD_FLUID = 0; + public static int COLD_FLUID_TEMP = 0; @Config.Comment("How hot an item should be to start burning the player (in Celsius)") - public static int HOT_ITEM = 480; + public static int HOT_ITEM_TEMP = 480; @Config.RequiresMcRestart() @Config.Comment("Max durability of the wooden tongs, 0 for infinite durability") diff --git a/src/main/java/com/buuz135/hotornot/config/HotLists.java b/src/main/java/com/buuz135/hotornot/config/HotLists.java index 4625024..b1b64a9 100644 --- a/src/main/java/com/buuz135/hotornot/config/HotLists.java +++ b/src/main/java/com/buuz135/hotornot/config/HotLists.java @@ -7,12 +7,12 @@ public class HotLists { public static boolean isHotFluid(FluidStack fluidStack) { - return HotConfig.HOT_FLUIDS && fluidStack.getFluid().getTemperature(fluidStack) >= HotConfig.HOT_FLUID + 273; + return HotConfig.HOT_FLUIDS && fluidStack.getFluid().getTemperature(fluidStack) >= HotConfig.HOT_FLUID_TEMP + 273; } public static boolean isColdFluid(FluidStack fluidStack) { - return HotConfig.COLD_FLUIDS && fluidStack.getFluid().getTemperature(fluidStack) <= HotConfig.COLD_FLUID + 273; + return HotConfig.COLD_FLUIDS && fluidStack.getFluid().getTemperature(fluidStack) <= HotConfig.COLD_FLUID_TEMP + 273; } public static boolean isGaseousFluid(FluidStack fluidStack) @@ -35,12 +35,15 @@ public static boolean isRemovedItem(ItemStack stack) public static boolean isHotItem(ItemStack stack) { - String regName = stack.getItem().getRegistryName().toString(); - for (String s : HotConfig.HOT_ITEM_ADDITIONS) + if (HotConfig.HOT_ITEMS) { - if (regName.equals(s)) + String regName = stack.getItem().getRegistryName().toString(); + for (String s : HotConfig.HOT_ITEM_ADDITIONS) { - return true; + if (regName.equals(s)) + { + return true; + } } } return false; @@ -48,12 +51,15 @@ public static boolean isHotItem(ItemStack stack) public static boolean isColdItem(ItemStack stack) { - String regName = stack.getItem().getRegistryName().toString(); - for (String s : HotConfig.COLD_ITEM_ADDITIONS) + if (HotConfig.COLD_ITEMS) { - if (regName.equals(s)) + String regName = stack.getItem().getRegistryName().toString(); + for (String s : HotConfig.COLD_ITEM_ADDITIONS) { - return true; + if (regName.equals(s)) + { + return true; + } } } return false; @@ -61,12 +67,15 @@ public static boolean isColdItem(ItemStack stack) public static boolean isGaseousItem(ItemStack stack) { - String regName = stack.getItem().getRegistryName().toString(); - for (String s : HotConfig.GASEOUS_ITEM_ADDITIONS) + if (HotConfig.GASEOUS_ITEMS) { - if (regName.equals(s)) + String regName = stack.getItem().getRegistryName().toString(); + for (String s : HotConfig.GASEOUS_ITEM_ADDITIONS) { - return true; + if (regName.equals(s)) + { + return true; + } } } return false; diff --git a/src/main/java/com/buuz135/hotornot/server/ServerTick.java b/src/main/java/com/buuz135/hotornot/server/ServerTick.java index 49241db..aec5cef 100644 --- a/src/main/java/com/buuz135/hotornot/server/ServerTick.java +++ b/src/main/java/com/buuz135/hotornot/server/ServerTick.java @@ -48,141 +48,54 @@ public static void onTick(TickEvent.WorldTickEvent event) { if (HotLists.isHotFluid(fluidStack) || HotLists.isColdFluid(fluidStack) || HotLists.isGaseousFluid(fluidStack)) { - ItemStack offHand = entityPlayerMP.getHeldItemOffhand(); - if (offHand.getItem().equals(ModItems.MITTS)) - { - if (HotConfig.MITTS_DURABILITY != 0) - { - offHand.damageItem(1, entityPlayerMP); - } - } - else if (offHand.getItem().equals(ModItems.WOODEN_TONGS)) - { - if (HotConfig.WOODEN_TONGS_DURABILITY != 0) - { - offHand.damageItem(1, entityPlayerMP); - } - } - else if (offHand.getItem().equals(ModItems.IRON_TONGS)) - { - if (HotConfig.IRON_TONGS_DURABILITY != 0) - { - offHand.damageItem(1, entityPlayerMP); - } - } - else if (event.world.getTotalWorldTime() % 20 == 0) + if (!damageProtectionItem(entityPlayerMP) && event.world.getTotalWorldTime() % 20 == 0) { if (HotLists.isHotFluid(fluidStack)) { - entityPlayerMP.setFire(1); - if (HotConfig.YEET) - { - entityPlayerMP.dropItem(stack, false, true); - entityPlayerMP.inventory.decrStackSize(i, 1); - } + applyHotEffect(entityPlayerMP, stack, i); } else if (HotLists.isColdFluid(fluidStack)) { - entityPlayerMP.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 21, 1)); - entityPlayerMP.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 21, 1)); + applyColdEffect(entityPlayerMP); } else if (HotLists.isGaseousFluid(fluidStack)) { - entityPlayerMP.addPotionEffect(new PotionEffect(MobEffects.LEVITATION, 21, 1)); + applyGaseousEffect(entityPlayerMP); } } } } } - // ITEMS - if (HotConfig.ITEM_EFFECTS) + // CONFIG-ADDED ITEMS + else if (HotLists.isHotItem(stack) || HotLists.isColdItem(stack) || HotLists.isGaseousItem(stack)) { - // TFC ITEMS - if (Loader.isModLoaded("tfc")) - { - if (stack.hasCapability(CapabilityItemHeat.ITEM_HEAT_CAPABILITY, null)) - { - IItemHeat heatHandlerItem = stack.getCapability(CapabilityItemHeat.ITEM_HEAT_CAPABILITY, null); - if (heatHandlerItem.getTemperature() >= HotConfig.HOT_ITEM) - { - ItemStack offHand = entityPlayerMP.getHeldItemOffhand(); - if (offHand.getItem().equals(ModItems.MITTS)) - { - if (HotConfig.MITTS_DURABILITY != 0) - { - offHand.damageItem(1, entityPlayerMP); - } - } - else if (offHand.getItem().equals(ModItems.WOODEN_TONGS)) - { - if (HotConfig.WOODEN_TONGS_DURABILITY != 0) - { - offHand.damageItem(1, entityPlayerMP); - } - } - else if (offHand.getItem().equals(ModItems.IRON_TONGS)) - { - if (HotConfig.IRON_TONGS_DURABILITY != 0) - { - offHand.damageItem(1, entityPlayerMP); - } - } - else if (event.world.getTotalWorldTime() % 10 == 0) - { - entityPlayerMP.setFire(1); - if (HotConfig.YEET) - { - entityPlayerMP.dropItem(stack, false, true); - entityPlayerMP.inventory.decrStackSize(i, 1); - } - } - } - } - } - // MANUALLY ADDED ITEMS - if (HotLists.isHotItem(stack) || HotLists.isColdItem(stack) || HotLists.isGaseousItem(stack)) + if (!damageProtectionItem(entityPlayerMP) && event.world.getTotalWorldTime() % 20 == 0) { - ItemStack offHand = entityPlayerMP.getHeldItemOffhand(); - if (offHand.getItem().equals(ModItems.MITTS)) + if (HotLists.isHotItem(stack)) { - if (HotConfig.MITTS_DURABILITY != 0) - { - offHand.damageItem(1, entityPlayerMP); - } + applyHotEffect(entityPlayerMP, stack, i); } - else if (offHand.getItem().equals(ModItems.WOODEN_TONGS)) + else if (HotLists.isColdItem(stack)) { - if (HotConfig.WOODEN_TONGS_DURABILITY != 0) - { - offHand.damageItem(1, entityPlayerMP); - } + applyColdEffect(entityPlayerMP); } - else if (offHand.getItem().equals(ModItems.IRON_TONGS)) + else if (HotLists.isGaseousItem(stack)) { - if (HotConfig.IRON_TONGS_DURABILITY != 0) - { - offHand.damageItem(1, entityPlayerMP); - } + applyGaseousEffect(entityPlayerMP); } - else if (event.world.getTotalWorldTime() % 10 == 0) + } + } + // TFC ITEMS + else if (Loader.isModLoaded("tfc") && HotConfig.HOT_ITEMS) + { + if (stack.hasCapability(CapabilityItemHeat.ITEM_HEAT_CAPABILITY, null)) + { + IItemHeat heatHandlerItem = stack.getCapability(CapabilityItemHeat.ITEM_HEAT_CAPABILITY, null); + if (heatHandlerItem.getTemperature() >= HotConfig.HOT_ITEM_TEMP) { - if (HotLists.isHotItem(stack)) + if (!damageProtectionItem(entityPlayerMP) && event.world.getTotalWorldTime() % 20 == 0) { - entityPlayerMP.setFire(1); - if (HotConfig.YEET) - { - entityPlayerMP.dropItem(stack, false, true); - entityPlayerMP.inventory.decrStackSize(i, 1); - } - } - else if (HotLists.isColdItem(stack)) - { - entityPlayerMP.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 21, 1)); - entityPlayerMP.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 21, 1)); - } - else if (HotLists.isGaseousItem(stack)) - { - entityPlayerMP.addPotionEffect(new PotionEffect(MobEffects.LEVITATION, 21, 1)); + applyHotEffect(entityPlayerMP, stack, i); } } } @@ -193,4 +106,55 @@ else if (HotLists.isGaseousItem(stack)) } } } + + public static boolean damageProtectionItem(EntityPlayerMP entityPlayerMP) + { + ItemStack offHand = entityPlayerMP.getHeldItemOffhand(); + if (offHand.getItem().equals(ModItems.MITTS)) + { + if (HotConfig.MITTS_DURABILITY != 0) + { + offHand.damageItem(1, entityPlayerMP); + } + return true; + } + else if (offHand.getItem().equals(ModItems.WOODEN_TONGS)) + { + if (HotConfig.WOODEN_TONGS_DURABILITY != 0) + { + offHand.damageItem(1, entityPlayerMP); + } + return true; + } + else if (offHand.getItem().equals(ModItems.IRON_TONGS)) + { + if (HotConfig.IRON_TONGS_DURABILITY != 0) + { + offHand.damageItem(1, entityPlayerMP); + } + return true; + } + return false; + } + + public static void applyHotEffect(EntityPlayerMP entityPlayerMP, ItemStack stack, int index) + { + entityPlayerMP.setFire(1); + if (HotConfig.YEET) + { + entityPlayerMP.dropItem(stack, false, true); + entityPlayerMP.inventory.decrStackSize(index, 1); + } + } + + public static void applyColdEffect(EntityPlayerMP entityPlayerMP) + { + entityPlayerMP.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 21, 1)); + entityPlayerMP.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 21, 1)); + } + + public static void applyGaseousEffect(EntityPlayerMP entityPlayerMP) + { + entityPlayerMP.addPotionEffect(new PotionEffect(MobEffects.LEVITATION, 21, 1)); + } } \ No newline at end of file