From b8a14a2cd390696992f442ae98cc1f4e0a03926b Mon Sep 17 00:00:00 2001 From: Globox1997 Date: Wed, 16 Aug 2023 10:58:25 +0200 Subject: [PATCH] added preview config option --- CHANGELOG.md | 6 +- .../dehydration/config/DehydrationConfig.java | 2 + .../net/dehydration/item/LeatherFlask.java | 37 ++++++----- .../mixin/HoneyBottleItemMixin.java | 20 +++--- .../java/net/dehydration/mixin/ItemMixin.java | 61 ++++++++++--------- .../mixin/MilkBucketItemMixin.java | 22 ++++--- .../dehydration/mixin/PotionItemMixin.java | 10 +-- .../dehydration/thirst/ThirstHudRender.java | 4 +- .../assets/dehydration/lang/en_us.json | 1 + 9 files changed, 94 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a93182..3e89214 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ### Added: -- +- Added thirst preview config option ### Fixed: -- Fixed pump place crash +- ### Changed: -- Updated to mc 1.20.1 \ No newline at end of file +- \ No newline at end of file diff --git a/src/main/java/net/dehydration/config/DehydrationConfig.java b/src/main/java/net/dehydration/config/DehydrationConfig.java index 62613a6..bc58f27 100644 --- a/src/main/java/net/dehydration/config/DehydrationConfig.java +++ b/src/main/java/net/dehydration/config/DehydrationConfig.java @@ -81,4 +81,6 @@ public class DehydrationConfig implements ConfigData { public int hud_x = 0; @ConfigEntry.Category("advanced_settings") public int hud_y = 0; + @ConfigEntry.Category("advanced_settings") + public boolean thirst_preview = true; } diff --git a/src/main/java/net/dehydration/item/LeatherFlask.java b/src/main/java/net/dehydration/item/LeatherFlask.java index 01e6df8..15101b4 100644 --- a/src/main/java/net/dehydration/item/LeatherFlask.java +++ b/src/main/java/net/dehydration/item/LeatherFlask.java @@ -261,20 +261,24 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List too } tooltip.add(Text.translatable("item.dehydration.leather_flask.tooltip3." + string)); } - } else + } else { tooltip.add(Text.translatable("item.dehydration.leather_flask.tooltip2", addition + 2).formatted(Formatting.GRAY)); + } super.appendTooltip(stack, world, tooltip, context); } @Override public Optional getTooltipData(ItemStack stack) { - if (stack.hasNbt() && stack.getNbt().contains("leather_flask")) { - if (stack.getNbt().getInt("leather_flask") == 0) - return Optional.empty(); - - return Optional.of(new ThirstTooltipData(stack.getNbt().getInt("purified_water"), stack.getNbt().getInt("leather_flask") * ConfigInit.CONFIG.flask_thirst_quench)); + if (ConfigInit.CONFIG.thirst_preview) { + if (stack.hasNbt() && stack.getNbt().contains("leather_flask")) { + if (stack.getNbt().getInt("leather_flask") == 0) { + return Optional.empty(); + } + return Optional.of(new ThirstTooltipData(stack.getNbt().getInt("purified_water"), stack.getNbt().getInt("leather_flask") * ConfigInit.CONFIG.flask_thirst_quench)); + } + return Optional.of(new ThirstTooltipData(0, (2 + this.addition) * ConfigInit.CONFIG.flask_thirst_quench)); } - return Optional.of(new ThirstTooltipData(0, (2 + this.addition) * ConfigInit.CONFIG.flask_thirst_quench)); + return super.getTooltipData(stack); } public static void fillFlask(ItemStack itemStack, int quench) { @@ -284,8 +288,9 @@ public static void fillFlask(ItemStack itemStack, int quench) { nbt.putInt("purified_water", 0); } else { nbt = itemStack.getNbt().copy(); - if (nbt.getInt("leather_flask") == 0) + if (nbt.getInt("leather_flask") == 0) { nbt.putInt("purified_water", 0); + } } int fillQuench = nbt.getInt("leather_flask") + quench; int addition = ((LeatherFlask) itemStack.getItem()).addition; @@ -296,23 +301,27 @@ public static void fillFlask(ItemStack itemStack, int quench) { public static boolean isFlaskEmpty(ItemStack stack) { NbtCompound tags = stack.getNbt(); if (tags != null) { - if (tags.getInt("leather_flask") != 0) + if (tags.getInt("leather_flask") != 0) { return false; - else + } else { return true; - } else + } + } else { return false; + } } public static boolean isFlaskFull(ItemStack stack) { NbtCompound tags = stack.getNbt(); if (tags != null) { - if (tags.getInt("leather_flask") >= ((LeatherFlask) stack.getItem()).addition + 2) + if (tags.getInt("leather_flask") >= ((LeatherFlask) stack.getItem()).addition + 2) { return true; - else + } else { return false; - } else + } + } else { return true; + } } // purified_water: 0 = purified, 1 impurified, 2 dirty diff --git a/src/main/java/net/dehydration/mixin/HoneyBottleItemMixin.java b/src/main/java/net/dehydration/mixin/HoneyBottleItemMixin.java index 808084f..98db9fb 100644 --- a/src/main/java/net/dehydration/mixin/HoneyBottleItemMixin.java +++ b/src/main/java/net/dehydration/mixin/HoneyBottleItemMixin.java @@ -45,15 +45,19 @@ public void finishUsingMixin(ItemStack stack, World world, LivingEntity user, Ca // check here and for milk and potion @Override public Optional getTooltipData(ItemStack stack) { - int thirstQuench = 0; - for (int i = 0; i < DehydrationMain.HYDRATION_TEMPLATES.size(); i++) { - if (DehydrationMain.HYDRATION_TEMPLATES.get(i).containsItem(stack.getItem())) { - thirstQuench = DehydrationMain.HYDRATION_TEMPLATES.get(i).getHydration(); - break; + if (ConfigInit.CONFIG.thirst_preview) { + int thirstQuench = 0; + for (int i = 0; i < DehydrationMain.HYDRATION_TEMPLATES.size(); i++) { + if (DehydrationMain.HYDRATION_TEMPLATES.get(i).containsItem(stack.getItem())) { + thirstQuench = DehydrationMain.HYDRATION_TEMPLATES.get(i).getHydration(); + break; + } + } + if (thirstQuench == 0) { + thirstQuench = ConfigInit.CONFIG.honey_quench; } + return Optional.of(new ThirstTooltipData(0, thirstQuench)); } - if (thirstQuench == 0) - thirstQuench = ConfigInit.CONFIG.honey_quench; - return Optional.of(new ThirstTooltipData(0, thirstQuench)); + return super.getTooltipData(stack); } } diff --git a/src/main/java/net/dehydration/mixin/ItemMixin.java b/src/main/java/net/dehydration/mixin/ItemMixin.java index 06c3e8e..e1dc419 100644 --- a/src/main/java/net/dehydration/mixin/ItemMixin.java +++ b/src/main/java/net/dehydration/mixin/ItemMixin.java @@ -26,54 +26,59 @@ public class ItemMixin { private void finishUsingMixin(ItemStack stack, World world, LivingEntity user, CallbackInfoReturnable info) { if (!stack.isFood() && user instanceof PlayerEntity player) { int thirstQuench = 0; - if (stack.isIn(TagInit.HYDRATING_STEW)) + if (stack.isIn(TagInit.HYDRATING_STEW)) { thirstQuench = ConfigInit.CONFIG.stew_thirst_quench; - if (stack.isIn(TagInit.HYDRATING_FOOD)) + } else if (stack.isIn(TagInit.HYDRATING_FOOD)) { thirstQuench = ConfigInit.CONFIG.food_thirst_quench; - if (stack.isIn(TagInit.HYDRATING_DRINKS)) + } else if (stack.isIn(TagInit.HYDRATING_DRINKS)) { thirstQuench = ConfigInit.CONFIG.drinks_thirst_quench; - if (stack.isIn(TagInit.STRONGER_HYDRATING_STEW)) + } else if (stack.isIn(TagInit.STRONGER_HYDRATING_STEW)) { thirstQuench = ConfigInit.CONFIG.stronger_stew_thirst_quench; - if (stack.isIn(TagInit.STRONGER_HYDRATING_FOOD)) + } else if (stack.isIn(TagInit.STRONGER_HYDRATING_FOOD)) { thirstQuench = ConfigInit.CONFIG.stronger_food_thirst_quench; - if (stack.isIn(TagInit.STRONGER_HYDRATING_DRINKS)) + } else if (stack.isIn(TagInit.STRONGER_HYDRATING_DRINKS)) { thirstQuench = ConfigInit.CONFIG.stronger_drinks_thirst_quench; - + } for (int i = 0; i < DehydrationMain.HYDRATION_TEMPLATES.size(); i++) { if (DehydrationMain.HYDRATION_TEMPLATES.get(i).containsItem(stack.getItem())) { thirstQuench = DehydrationMain.HYDRATION_TEMPLATES.get(i).getHydration(); break; } } - ((ThirstManagerAccess) player).getThirstManager().add(thirstQuench); + if (thirstQuench > 0) { + ((ThirstManagerAccess) player).getThirstManager().add(thirstQuench); + } } } @Inject(method = "getTooltipData", at = @At("HEAD"), cancellable = true) private void getTooltipDataMixin(ItemStack stack, CallbackInfoReturnable> info) { - int thirstQuench = 0; - if (stack.isIn(TagInit.HYDRATING_STEW)) - thirstQuench = ConfigInit.CONFIG.stew_thirst_quench; - if (stack.isIn(TagInit.HYDRATING_FOOD)) - thirstQuench = ConfigInit.CONFIG.food_thirst_quench; - if (stack.isIn(TagInit.HYDRATING_DRINKS)) - thirstQuench = ConfigInit.CONFIG.drinks_thirst_quench; - if (stack.isIn(TagInit.STRONGER_HYDRATING_STEW)) - thirstQuench = ConfigInit.CONFIG.stronger_stew_thirst_quench; - if (stack.isIn(TagInit.STRONGER_HYDRATING_FOOD)) - thirstQuench = ConfigInit.CONFIG.stronger_food_thirst_quench; - if (stack.isIn(TagInit.STRONGER_HYDRATING_DRINKS)) - thirstQuench = ConfigInit.CONFIG.stronger_drinks_thirst_quench; + if (ConfigInit.CONFIG.thirst_preview) { + int thirstQuench = 0; + if (stack.isIn(TagInit.HYDRATING_STEW)) { + thirstQuench = ConfigInit.CONFIG.stew_thirst_quench; + } else if (stack.isIn(TagInit.HYDRATING_FOOD)) { + thirstQuench = ConfigInit.CONFIG.food_thirst_quench; + } else if (stack.isIn(TagInit.HYDRATING_DRINKS)) { + thirstQuench = ConfigInit.CONFIG.drinks_thirst_quench; + } else if (stack.isIn(TagInit.STRONGER_HYDRATING_STEW)) { + thirstQuench = ConfigInit.CONFIG.stronger_stew_thirst_quench; + } else if (stack.isIn(TagInit.STRONGER_HYDRATING_FOOD)) { + thirstQuench = ConfigInit.CONFIG.stronger_food_thirst_quench; + } else if (stack.isIn(TagInit.STRONGER_HYDRATING_DRINKS)) { + thirstQuench = ConfigInit.CONFIG.stronger_drinks_thirst_quench; + } + for (int i = 0; i < DehydrationMain.HYDRATION_TEMPLATES.size(); i++) { + if (DehydrationMain.HYDRATION_TEMPLATES.get(i).containsItem(stack.getItem())) { + thirstQuench = DehydrationMain.HYDRATION_TEMPLATES.get(i).getHydration(); + break; + } + } - for (int i = 0; i < DehydrationMain.HYDRATION_TEMPLATES.size(); i++) { - if (DehydrationMain.HYDRATION_TEMPLATES.get(i).containsItem(stack.getItem())) { - thirstQuench = DehydrationMain.HYDRATION_TEMPLATES.get(i).getHydration(); - break; + if (thirstQuench > 0) { + info.setReturnValue(Optional.of(new ThirstTooltipData(0, thirstQuench))); } } - - if (thirstQuench > 0) - info.setReturnValue(Optional.of(new ThirstTooltipData(0, thirstQuench))); } } diff --git a/src/main/java/net/dehydration/mixin/MilkBucketItemMixin.java b/src/main/java/net/dehydration/mixin/MilkBucketItemMixin.java index 5917d45..37df8f8 100644 --- a/src/main/java/net/dehydration/mixin/MilkBucketItemMixin.java +++ b/src/main/java/net/dehydration/mixin/MilkBucketItemMixin.java @@ -51,16 +51,20 @@ public void finishUsingMixin(ItemStack stack, World world, LivingEntity user, Ca @Override public Optional getTooltipData(ItemStack stack) { - int thirstQuench = 0; - for (int i = 0; i < DehydrationMain.HYDRATION_TEMPLATES.size(); i++) { - if (DehydrationMain.HYDRATION_TEMPLATES.get(i).containsItem(stack.getItem())) { - thirstQuench = DehydrationMain.HYDRATION_TEMPLATES.get(i).getHydration(); - break; + if (ConfigInit.CONFIG.thirst_preview) { + int thirstQuench = 0; + for (int i = 0; i < DehydrationMain.HYDRATION_TEMPLATES.size(); i++) { + if (DehydrationMain.HYDRATION_TEMPLATES.get(i).containsItem(stack.getItem())) { + thirstQuench = DehydrationMain.HYDRATION_TEMPLATES.get(i).getHydration(); + break; + } } - } - if (thirstQuench == 0) - thirstQuench = ConfigInit.CONFIG.milk_thirst_quench; - return Optional.of(new ThirstTooltipData(1, thirstQuench)); + if (thirstQuench == 0) { + thirstQuench = ConfigInit.CONFIG.milk_thirst_quench; + } + return Optional.of(new ThirstTooltipData(1, thirstQuench)); + } else + return super.getTooltipData(stack); } } diff --git a/src/main/java/net/dehydration/mixin/PotionItemMixin.java b/src/main/java/net/dehydration/mixin/PotionItemMixin.java index e710f8f..5a849a4 100644 --- a/src/main/java/net/dehydration/mixin/PotionItemMixin.java +++ b/src/main/java/net/dehydration/mixin/PotionItemMixin.java @@ -89,7 +89,7 @@ private boolean isBadPotion(Potion potion) { @Override public Optional getTooltipData(ItemStack stack) { - if (!(stack.getItem() instanceof ThrowablePotionItem)) { + if (ConfigInit.CONFIG.thirst_preview && !(stack.getItem() instanceof ThrowablePotionItem)) { int thirstQuench = 0; for (int i = 0; i < DehydrationMain.HYDRATION_TEMPLATES.size(); i++) { @@ -98,12 +98,12 @@ public Optional getTooltipData(ItemStack stack) { break; } } - if (thirstQuench == 0) + if (thirstQuench == 0) { thirstQuench = ConfigInit.CONFIG.potion_thirst_quench; - - if (isBadPotion(PotionUtil.getPotion(stack))) + } + if (isBadPotion(PotionUtil.getPotion(stack))) { return Optional.of(new ThirstTooltipData(2, thirstQuench)); - + } return Optional.of(new ThirstTooltipData(0, thirstQuench)); } return Optional.empty(); diff --git a/src/main/java/net/dehydration/thirst/ThirstHudRender.java b/src/main/java/net/dehydration/thirst/ThirstHudRender.java index 88481b5..7f3cb47 100644 --- a/src/main/java/net/dehydration/thirst/ThirstHudRender.java +++ b/src/main/java/net/dehydration/thirst/ThirstHudRender.java @@ -35,7 +35,7 @@ public static void renderThirstHud(DrawContext context, MinecraftClient client, if (vehicleHeartCount == 0) { ItemStack itemStack = null; - if (thirst < 20) + if (ConfigInit.CONFIG.thirst_preview && thirst < 20) { if (!playerEntity.getMainHandStack().isEmpty() && !playerEntity.getMainHandStack().getTooltipData().isEmpty() && playerEntity.getMainHandStack().getTooltipData().get() instanceof ThirstTooltipData) { itemStack = playerEntity.getMainHandStack(); @@ -43,7 +43,7 @@ public static void renderThirstHud(DrawContext context, MinecraftClient client, && playerEntity.getOffHandStack().getTooltipData().get() instanceof ThirstTooltipData) { itemStack = playerEntity.getOffHandStack(); } - + } if (itemStack != null) { ((HudAccess) client.inGameHud).setOtherFlashAlpha(otherFlashAlpha += MathHelper.PI / (48F)); ((HudAccess) client.inGameHud).setFlashAlpha((MathHelper.cos(otherFlashAlpha + MathHelper.PI) + 1f) / 2f); diff --git a/src/main/resources/assets/dehydration/lang/en_us.json b/src/main/resources/assets/dehydration/lang/en_us.json index 74819e0..2caa500 100644 --- a/src/main/resources/assets/dehydration/lang/en_us.json +++ b/src/main/resources/assets/dehydration/lang/en_us.json @@ -42,6 +42,7 @@ "text.autoconfig.dehydration.option.pump_requires_water": "Pump Requires Water", "text.autoconfig.dehydration.option.bottle_consumes_source_block": "Bottle Consumes Source Block", "text.autoconfig.dehydration.option.special_effects": "Special Effects", + "text.autoconfig.dehydration.option.thirst_preview": "Thirst Preview", "item.dehydration.item_group": "Dehydration",