From 9a5b9ec72a978eff0874cdec46a59cb1ea4b52ac Mon Sep 17 00:00:00 2001 From: Onyx_i7 Date: Sun, 12 Jul 2026 14:58:03 -0400 Subject: [PATCH 1/3] Refactor ItemCanteen dose handling logic --- .../simpledifficulty/item/ItemCanteen.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/charles445/simpledifficulty/item/ItemCanteen.java b/src/main/java/com/charles445/simpledifficulty/item/ItemCanteen.java index ad9de66..517a8ae 100644 --- a/src/main/java/com/charles445/simpledifficulty/item/ItemCanteen.java +++ b/src/main/java/com/charles445/simpledifficulty/item/ItemCanteen.java @@ -100,7 +100,11 @@ public ActionResult onItemRightClick(World world, EntityPlayer player boolean success = false; if (trace == ThirstEnum.PURIFIED) { - if (ServerConfig.instance.getBoolean(ServerOptions.INFINITE_PURIFIED_WATER) || player.world.setBlockToAir(traceBlockPos.pos)) { + // Only consume the block if INFINITE_PURIFIED_WATER is false + if (ServerConfig.instance.getBoolean(ServerOptions.INFINITE_PURIFIED_WATER)) { + tryAddDose(stack, ThirstEnum.PURIFIED); + success = true; + } else if (player.world.setBlockToAir(traceBlockPos.pos)) { tryAddDose(stack, ThirstEnum.PURIFIED); success = true; } @@ -109,8 +113,7 @@ public ActionResult onItemRightClick(World world, EntityPlayer player success = true; } else if (trace == ThirstEnum.NORMAL) { if (ServerConfig.instance.getBoolean(ServerOptions.THIRST_DRINK_BLOCKS) && !isCanteenFull(stack)) { - formatCanteen(stack, ThirstEnum.NORMAL); - setDosesInternal(stack, Math.min(getDoses(stack) + 1, getMaxDoses(stack))); + tryAddDose(stack, ThirstEnum.NORMAL); success = true; } } else if (trace == ThirstEnum.RAIN) { @@ -315,30 +318,29 @@ public void setDoses(ItemStack stack, ThirstEnum thirstEnum, int amount) { @Override public boolean tryAddDose(ItemStack stack, ThirstEnum thirstEnum) { - int oldDamage = getDoses(stack); - if (oldDamage < 0) { - oldDamage = 0; + int oldDoses = getDoses(stack); + if (oldDoses < 0) { + oldDoses = 0; } boolean format = formatCanteen(stack, thirstEnum); - if (thirstEnum == ThirstEnum.NORMAL) { - setDosesInternal(stack, getMaxDoses(stack)); - } else { - setDosesInternal(stack, getDoses(stack) + 1); - } + // Always add just one dose, regardless of water type + setDosesInternal(stack, getDoses(stack) + 1); - return format || getDoses(stack) != oldDamage; + return format || getDoses(stack) != oldDoses; } protected boolean formatCanteen(ItemStack stack, ThirstEnum thirstEnum) { if (thirstEnum != getThirstEnum(stack)) { - setCanteenEmpty(stack); + // When changing water type, keep existing doses but change the type + // This prevents losing all water when switching types + int currentDoses = getDoses(stack); setTypeTag(stack, thirstEnum); + setDosesInternal(stack, currentDoses); return true; } - getDoses(stack); return false; } From f5a64905cb80bd5e98b68275e06023168bca034d Mon Sep 17 00:00:00 2001 From: Onyx_i7 Date: Sun, 12 Jul 2026 14:58:46 -0400 Subject: [PATCH 2/3] Change canteen crafting result to PURIFIED Updated the getCraftingResult method to set the canteen doses to PURIFIED instead of NORMAL after crafting. --- .../register/crafting/CanteenCharcoalRecipe.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/charles445/simpledifficulty/register/crafting/CanteenCharcoalRecipe.java b/src/main/java/com/charles445/simpledifficulty/register/crafting/CanteenCharcoalRecipe.java index 4b7ea2b..c687e01 100644 --- a/src/main/java/com/charles445/simpledifficulty/register/crafting/CanteenCharcoalRecipe.java +++ b/src/main/java/com/charles445/simpledifficulty/register/crafting/CanteenCharcoalRecipe.java @@ -30,7 +30,6 @@ public CanteenCharcoalRecipe(ResourceLocation group, NonNullList inp @Nonnull public ItemStack getCraftingResult(@Nonnull InventoryCrafting invcraft) { - //return output.copy(); ItemStack output = super.getCraftingResult(invcraft); if(!output.isEmpty()) @@ -41,14 +40,14 @@ public ItemStack getCraftingResult(@Nonnull InventoryCrafting invcraft) if(!ingredient.isEmpty() && (ingredient.getItem() == SDItems.canteen || ingredient.getItem() == SDItems.ironCanteen)) { IItemCanteen canteen = (ItemCanteen)ingredient.getItem(); - canteen.setDoses(output, ThirstEnum.NORMAL, canteen.getDoses(ingredient)); + // Charcoal filter purifies water, so set to PURIFIED + canteen.setDoses(output, ThirstEnum.PURIFIED, canteen.getDoses(ingredient)); break; } } } return output; - } public static class Factory implements IRecipeFactory @@ -70,4 +69,4 @@ public IRecipe parse(JsonContext context, JsonObject json) result); } } -} \ No newline at end of file +} From 6cd601eddd481c10a4db807ae2d04848662e8977 Mon Sep 17 00:00:00 2001 From: Onyx_i7 Date: Sun, 12 Jul 2026 15:12:56 -0400 Subject: [PATCH 3/3] Optimize ThirstUtilInternal for block position lookups --- .../util/internal/ThirstUtilInternal.java | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/charles445/simpledifficulty/util/internal/ThirstUtilInternal.java b/src/main/java/com/charles445/simpledifficulty/util/internal/ThirstUtilInternal.java index cb73a06..f18c67d 100644 --- a/src/main/java/com/charles445/simpledifficulty/util/internal/ThirstUtilInternal.java +++ b/src/main/java/com/charles445/simpledifficulty/util/internal/ThirstUtilInternal.java @@ -13,8 +13,10 @@ import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionEffect; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.biome.Biome; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; @@ -128,29 +130,58 @@ public ThirstEnumBlockPos traceWater(EntityPlayer player) return null; //Hit a block - Block traceBlock = player.getEntityWorld().getBlockState(trace.getBlockPos()).getBlock(); + BlockPos blockPos = trace.getBlockPos(); + Block traceBlock = player.getEntityWorld().getBlockState(blockPos).getBlock(); + if(traceBlock == Blocks.WATER) { - return new ThirstEnumBlockPos(ThirstEnum.NORMAL, trace.getBlockPos()); + // Check if the water is in an ocean biome - if so, it's salt water + Biome biome = player.getEntityWorld().getBiome(blockPos); + if (isOceanBiome(biome)) { + return new ThirstEnumBlockPos(ThirstEnum.SALT, blockPos); + } + return new ThirstEnumBlockPos(ThirstEnum.NORMAL, blockPos); } else if(traceBlock == SDFluids.blockPurifiedWater) { - return new ThirstEnumBlockPos(ThirstEnum.PURIFIED, trace.getBlockPos()); + return new ThirstEnumBlockPos(ThirstEnum.PURIFIED, blockPos); } else if(traceBlock == SDFluids.blockSaltWater) { - return new ThirstEnumBlockPos(ThirstEnum.SALT, trace.getBlockPos()); + return new ThirstEnumBlockPos(ThirstEnum.SALT, blockPos); } // Optimized lookup using HashSet instead of array iteration String blockRegistryName = traceBlock.getRegistryName().toString(); if(RIVER_BLOCKS_SET.contains(blockRegistryName)) { - return new ThirstEnumBlockPos(ThirstEnum.NORMAL, trace.getBlockPos()); + return new ThirstEnumBlockPos(ThirstEnum.NORMAL, blockPos); } return null; } + // Helper method to check if a biome is an ocean biome + private boolean isOceanBiome(Biome biome) { + if (biome == null) { + return false; + } + + // Check biome category/name for ocean types + String biomeName = biome.getRegistryName() != null ? biome.getRegistryName().toString() : ""; + + // Vanilla ocean biomes + return biomeName.contains("ocean") || + biomeName.equals("minecraft:frozen_ocean") || + biomeName.equals("minecraft:deep_ocean") || + biomeName.equals("minecraft:frozen_ocean") || + biomeName.equals("minecraft:cold_ocean") || + biomeName.equals("minecraft:deep_cold_ocean") || + biomeName.equals("minecraft:lukewarm_ocean") || + biomeName.equals("minecraft:deep_lukewarm_ocean") || + biomeName.equals("minecraft:warm_ocean") || + biomeName.equals("minecraft:deep_warm_ocean"); + } + // Removed riverBlocks array - now using RIVER_BLOCKS_SET for O(1) lookups