Skip to content

Commit

Permalink
added preview config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Globox1997 committed Aug 16, 2023
1 parent 824636c commit b8a14a2
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 69 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Added:
-
- Added thirst preview config option
### Fixed:
- Fixed pump place crash
-
### Changed:
- Updated to mc 1.20.1
-
2 changes: 2 additions & 0 deletions src/main/java/net/dehydration/config/DehydrationConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
37 changes: 23 additions & 14 deletions src/main/java/net/dehydration/item/LeatherFlask.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,24 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> 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<TooltipData> 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) {
Expand All @@ -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;
Expand All @@ -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
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/net/dehydration/mixin/HoneyBottleItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ public void finishUsingMixin(ItemStack stack, World world, LivingEntity user, Ca
// check here and for milk and potion
@Override
public Optional<TooltipData> 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);
}
}
61 changes: 33 additions & 28 deletions src/main/java/net/dehydration/mixin/ItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,59 @@ public class ItemMixin {
private void finishUsingMixin(ItemStack stack, World world, LivingEntity user, CallbackInfoReturnable<ItemStack> 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<Optional<TooltipData>> 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)));
}

}
22 changes: 13 additions & 9 deletions src/main/java/net/dehydration/mixin/MilkBucketItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ public void finishUsingMixin(ItemStack stack, World world, LivingEntity user, Ca

@Override
public Optional<TooltipData> 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);
}

}
10 changes: 5 additions & 5 deletions src/main/java/net/dehydration/mixin/PotionItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private boolean isBadPotion(Potion potion) {

@Override
public Optional<TooltipData> 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++) {
Expand All @@ -98,12 +98,12 @@ public Optional<TooltipData> 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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/dehydration/thirst/ThirstHudRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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();
} else if (playerEntity.getOffHandStack().isEmpty() && !playerEntity.getOffHandStack().getTooltipData().isEmpty()
&& 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);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/dehydration/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down

0 comments on commit b8a14a2

Please sign in to comment.