From 250a1e61a22a428d9c56dc759e506f82772f1b29 Mon Sep 17 00:00:00 2001 From: Koiro <1165997495@qq.com> Date: Sun, 9 Jun 2024 16:22:28 +0800 Subject: [PATCH] feat: update water max saturation upto 40 --- gradle.properties | 2 +- .../xyz/koiro/watersource/WSClientConfig.kt | 1 + .../watersource/api/WaterBallRenderer.kt | 13 +++- .../api/WaterLevelUiRenderUtils.kt | 17 +++++ .../event/ItemTooltipEventHandlers.kt | 65 +++++++++++------- .../watersource/render/hud/ModClientHUD.kt | 21 ++++-- .../xyz/koiro/watersource/ModItemGroups.kt | 8 ++- .../kotlin/xyz/koiro/watersource/WSConfig.kt | 4 ++ .../datagen/HydrationDataGenerator.kt | 16 ++--- .../koiro/watersource/datagen/ModLanguages.kt | 2 + .../watersource/datagen/ModRecipeGenerator.kt | 19 +++++ .../world/attachment/WaterLevelData.kt | 16 +++-- .../world/enchantment/ModEnchantments.kt | 15 ++++ .../enchantment/MoisturizingEnchantment.kt | 37 ++++++++++ .../watersource/textures/gui/hud/icons.png | Bin 1822 -> 1504 bytes 15 files changed, 185 insertions(+), 51 deletions(-) create mode 100644 src/client/kotlin/xyz/koiro/watersource/api/WaterLevelUiRenderUtils.kt create mode 100644 src/main/kotlin/xyz/koiro/watersource/world/enchantment/ModEnchantments.kt create mode 100644 src/main/kotlin/xyz/koiro/watersource/world/enchantment/MoisturizingEnchantment.kt diff --git a/gradle.properties b/gradle.properties index f97804a..3a2167a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ loader_version=0.15.7 fabric_kotlin_version=1.10.18+kotlin.1.9.22 # Mod Properties -mod_version=2.0.0 +mod_version=2.0.0-nightly maven_group=xyz.koiro.watersource archives_base_name=watersource diff --git a/src/client/kotlin/xyz/koiro/watersource/WSClientConfig.kt b/src/client/kotlin/xyz/koiro/watersource/WSClientConfig.kt index ed49593..ab467a5 100644 --- a/src/client/kotlin/xyz/koiro/watersource/WSClientConfig.kt +++ b/src/client/kotlin/xyz/koiro/watersource/WSClientConfig.kt @@ -9,6 +9,7 @@ object WSClientConfig { @Serializable class Format( val showHydrationRestorationDataOnItemTooltip: Boolean = true, + val showHydrationSaturationInTooltip: Boolean = true, val showHydrationDryDataOnItemTooltip: Boolean = true, val showWaterLevelBar: Boolean = true, val showWaterSaturationInBar: Boolean = true, diff --git a/src/client/kotlin/xyz/koiro/watersource/api/WaterBallRenderer.kt b/src/client/kotlin/xyz/koiro/watersource/api/WaterBallRenderer.kt index 315fbc8..40c9c9b 100644 --- a/src/client/kotlin/xyz/koiro/watersource/api/WaterBallRenderer.kt +++ b/src/client/kotlin/xyz/koiro/watersource/api/WaterBallRenderer.kt @@ -18,13 +18,20 @@ data class WaterBallRenderer( } enum class Part(val u: Int) { - Empty(0), Full(9), LeftHalf(18), RightHalf(27), SaturationUp(36), SaturationDown(45), DryUp(54), DryDown(63) + Empty(0), Full(9), LeftHalf(18), RightHalf(27), SaturationDown(36), SaturationRight(45), SaturationUp(54), SaturationLeft( + 63 + ) } fun draw(context: DrawContext) { + val x = when (part) { + Part.SaturationLeft -> this.x - 1 + Part.SaturationRight -> this.x + 1 + else -> x + } val y = when (part) { - Part.SaturationUp, Part.DryUp -> this.y - 1 - Part.SaturationDown, Part.DryDown -> this.y + 1 + Part.SaturationUp -> this.y - 1 + Part.SaturationDown -> this.y + 1 else -> this.y } diff --git a/src/client/kotlin/xyz/koiro/watersource/api/WaterLevelUiRenderUtils.kt b/src/client/kotlin/xyz/koiro/watersource/api/WaterLevelUiRenderUtils.kt new file mode 100644 index 0000000..938092f --- /dev/null +++ b/src/client/kotlin/xyz/koiro/watersource/api/WaterLevelUiRenderUtils.kt @@ -0,0 +1,17 @@ +package xyz.koiro.watersource.api + +object WaterLevelUiRenderUtils { + val anticlockwiseSaturationParts = listOf( + WaterBallRenderer.Part.SaturationDown, + WaterBallRenderer.Part.SaturationRight, + WaterBallRenderer.Part.SaturationUp, + WaterBallRenderer.Part.SaturationLeft, + ) + + val clockwiseSaturationParts = listOf( + WaterBallRenderer.Part.SaturationDown, + WaterBallRenderer.Part.SaturationLeft, + WaterBallRenderer.Part.SaturationUp, + WaterBallRenderer.Part.SaturationRight, + ) +} \ No newline at end of file diff --git a/src/client/kotlin/xyz/koiro/watersource/event/ItemTooltipEventHandlers.kt b/src/client/kotlin/xyz/koiro/watersource/event/ItemTooltipEventHandlers.kt index ce791be..f84d8da 100644 --- a/src/client/kotlin/xyz/koiro/watersource/event/ItemTooltipEventHandlers.kt +++ b/src/client/kotlin/xyz/koiro/watersource/event/ItemTooltipEventHandlers.kt @@ -6,6 +6,7 @@ import net.minecraft.client.gui.tooltip.TooltipBackgroundRenderer import net.minecraft.util.ActionResult import xyz.koiro.watersource.WSClientConfig import xyz.koiro.watersource.api.WaterBallRenderer +import xyz.koiro.watersource.api.WaterLevelUiRenderUtils import xyz.koiro.watersource.data.HydrationData import xyz.koiro.watersource.data.HydrationDataManager import xyz.koiro.watersource.world.effect.ModStatusEffects @@ -34,7 +35,7 @@ object ItemTooltipEventHandlers { fun drawDry(context: DrawContext, hydrationData: HydrationData, isThirty: Boolean, x: Int, y: Int) { val dryLevel = hydrationData.dryLevel!! - val w = 32 + val w = 42 val h = 11 val fX = x - w - 10 val fY = y - h / 2 @@ -49,11 +50,13 @@ object ItemTooltipEventHandlers { val levelY = fY + 1 val newX = fX + 2 WaterBallRenderer(newX, levelY, isThirty, WaterBallRenderer.Part.Empty).draw(context) - WaterBallRenderer(newX, levelY, isThirty, WaterBallRenderer.Part.DryDown, true).draw(context) + WaterLevelUiRenderUtils.anticlockwiseSaturationParts.forEach { + WaterBallRenderer(newX, levelY, isThirty, it, true).draw(context) + } val tr = MinecraftClient.getInstance().textRenderer val textX = newX + 11 - context.drawText(tr, "-${dryLevel}", textX, levelY + 1, 0x888888, false) + context.drawText(tr, "-${String.format("%.2f", dryLevel.toFloat() / 4f)}", textX, levelY + 1, 0x888888, false) context.matrices.pop() } @@ -64,8 +67,8 @@ object ItemTooltipEventHandlers { val levelCount = ceil(level.toFloat() / 2f).toInt() val isLevelEndHalf = level % 2 != 0 - val satCount = ceil(saturation.toFloat() / 2f).toInt() - val isSatEndHalf = saturation % 2 != 0 + val satCount = ceil(saturation.toFloat() / 4f).toInt() + val satRest = saturation % 4 val emptyCount = max(levelCount, satCount) if (emptyCount <= 4) { @@ -82,11 +85,13 @@ object ItemTooltipEventHandlers { context.matrices.translate(0f, 0f, 401f) val newY = fY + 1 + // Empty for (i in 0.. command's target must be player!", " 命令的目标只能是玩家", ModCommands.RESTORE_ALL_TARGET_ERROR_TRANS_KEY), diff --git a/src/main/kotlin/xyz/koiro/watersource/datagen/ModRecipeGenerator.kt b/src/main/kotlin/xyz/koiro/watersource/datagen/ModRecipeGenerator.kt index 2f1ef08..465f085 100644 --- a/src/main/kotlin/xyz/koiro/watersource/datagen/ModRecipeGenerator.kt +++ b/src/main/kotlin/xyz/koiro/watersource/datagen/ModRecipeGenerator.kt @@ -5,6 +5,7 @@ import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider import net.minecraft.data.server.recipe.RecipeJsonProvider import net.minecraft.data.server.recipe.RecipeProvider import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder +import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder import net.minecraft.fluid.Fluids import net.minecraft.item.Items import net.minecraft.recipe.Ingredient @@ -101,5 +102,23 @@ class ModRecipeGenerator(output: FabricDataOutput?) : FabricRecipeProvider(outpu .pattern("lbl") .pattern("lll") .offerTo(exporter) + + ShapedRecipeJsonBuilder.create(RecipeCategory.MISC, ModItems.WOODEN_FILTER_BLOCK) + .inputWithCriterion('w', ItemTags.LOGS) + .inputWithCriterion('p', ItemTags.PLANKS) + .inputWithCriterion('g', Items.GLASS) + .pattern("wgw") + .pattern("ppp") + .pattern("wgw") + .offerTo(exporter) + + ShapedRecipeJsonBuilder.create(RecipeCategory.MISC, ModItems.IRON_FILTER_BLOCK) + .inputWithCriterion('w', Items.IRON_INGOT) + .inputWithCriterion('p', Items.IRON_BLOCK) + .inputWithCriterion('g', Items.GLASS) + .pattern("wgw") + .pattern("wpw") + .pattern("wgw") + .offerTo(exporter) } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/koiro/watersource/world/attachment/WaterLevelData.kt b/src/main/kotlin/xyz/koiro/watersource/world/attachment/WaterLevelData.kt index 204560b..23ee7ee 100644 --- a/src/main/kotlin/xyz/koiro/watersource/world/attachment/WaterLevelData.kt +++ b/src/main/kotlin/xyz/koiro/watersource/world/attachment/WaterLevelData.kt @@ -8,13 +8,14 @@ import net.minecraft.server.network.ServerPlayerEntity import xyz.koiro.watersource.WSConfig import xyz.koiro.watersource.network.ModNetworking import xyz.koiro.watersource.world.effect.ModStatusEffects +import xyz.koiro.watersource.world.enchantment.MoisturizingEnchantment class WaterLevelData( level: Int = 20, - saturation: Int = 8, + saturation: Int = 16, exhaustion: Float = 0f, maxLevel: Int = 20, - maxSaturation: Int = 20, + maxSaturation: Int = 40, maxExhaustion: Float = 4f, ) { var level = level @@ -38,7 +39,8 @@ class WaterLevelData( * */ fun addExhaustion(amount: Float, player: PlayerEntity) { val effect = player.getStatusEffect(ModStatusEffects.THIRSTY) - var finalAmount = amount * WSConfig.Exhaustion.multiplier + var finalAmount = + amount * WSConfig.Exhaustion.multiplier * MoisturizingEnchantment.getPlayerMoisturizingRatio(player) effect?.let { finalAmount *= WSConfig.Exhaustion.thirstyMultiplier(it.amplifier) } @@ -68,11 +70,11 @@ class WaterLevelData( } /** Consume only water saturation */ - fun dryConsumeWater(amount: Int){ + fun dryConsumeWater(amount: Int) { saturation -= amount } - fun writeBuf(buf: PacketByteBuf): PacketByteBuf{ + fun writeBuf(buf: PacketByteBuf): PacketByteBuf { buf.writeInt(level) buf.writeInt(saturation) buf.writeFloat(exhaustion) @@ -94,11 +96,11 @@ class WaterLevelData( } } - fun updateToClient(user: ServerPlayerEntity){ + fun updateToClient(user: ServerPlayerEntity) { ServerPlayNetworking.send(user, ModNetworking.UPDATE_WATER_DATA_ID, writeBuf(PacketByteBufs.create())) } - fun setData(level: Int = 20, saturation: Int = 8, exhaustion: Float = 0f){ + fun setData(level: Int = 20, saturation: Int = 16, exhaustion: Float = 0f) { this.level = level this.saturation = saturation this.exhaustion = exhaustion diff --git a/src/main/kotlin/xyz/koiro/watersource/world/enchantment/ModEnchantments.kt b/src/main/kotlin/xyz/koiro/watersource/world/enchantment/ModEnchantments.kt new file mode 100644 index 0000000..6b3c948 --- /dev/null +++ b/src/main/kotlin/xyz/koiro/watersource/world/enchantment/ModEnchantments.kt @@ -0,0 +1,15 @@ +package xyz.koiro.watersource.world.enchantment + +import net.minecraft.enchantment.Enchantment +import net.minecraft.registry.Registries +import net.minecraft.registry.Registry +import xyz.koiro.watersource.WaterSource + +object ModEnchantments { + fun active(){} + + val MOISTURIZING = regEnchantment("moisturizing", MoisturizingEnchantment()) + fun regEnchantment(idPath: String, value: Enchantment): Enchantment{ + return Registry.register(Registries.ENCHANTMENT, WaterSource.identifier(idPath), value) + } +} \ No newline at end of file diff --git a/src/main/kotlin/xyz/koiro/watersource/world/enchantment/MoisturizingEnchantment.kt b/src/main/kotlin/xyz/koiro/watersource/world/enchantment/MoisturizingEnchantment.kt new file mode 100644 index 0000000..2b4736c --- /dev/null +++ b/src/main/kotlin/xyz/koiro/watersource/world/enchantment/MoisturizingEnchantment.kt @@ -0,0 +1,37 @@ +package xyz.koiro.watersource.world.enchantment + +import net.minecraft.enchantment.Enchantment +import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.enchantment.EnchantmentTarget +import net.minecraft.entity.EquipmentSlot +import net.minecraft.entity.player.PlayerEntity +import xyz.koiro.watersource.WSConfig +import xyz.koiro.watersource.WaterSource + +class MoisturizingEnchantment() : + Enchantment(Rarity.UNCOMMON, EnchantmentTarget.ARMOR, arrayOf(EquipmentSlot.FEET, EquipmentSlot.HEAD, EquipmentSlot.LEGS, EquipmentSlot.CHEST)) { + override fun getMaxLevel(): Int { + return 3 + } + override fun getMinPower(level: Int): Int { + return 1 + } + + companion object { + fun getPlayerMoisturizingLevelSum(player: PlayerEntity): Int{ + var levelSum = 0 + player.armorItems.forEach { + val enchantments = EnchantmentHelper.fromNbt(it.enchantments) + enchantments.forEach { enchantment, level -> + if (enchantment == ModEnchantments.MOISTURIZING) + levelSum += level + } + } + return levelSum + } + + fun getPlayerMoisturizingRatio(player: PlayerEntity): Float { + return WSConfig.getMoisturizingRatio(getPlayerMoisturizingLevelSum(player)) + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/watersource/textures/gui/hud/icons.png b/src/main/resources/assets/watersource/textures/gui/hud/icons.png index a721dc7bb2b8d9a05e1757b2457c2b8f9a1b429b..8fb86cef4fd4967bd5469e337d4c35a91144613a 100644 GIT binary patch delta 1245 zcmV<31S0#M4&V!rFn>x3S00J&iHTR$(u*Z|zIVnunzi=@m-7>8eIdqJ$MRfuxyf zf)AFy{e0lUx##!I_uQB7`JLZ6zhqG*rGFGzmZg+ZmStHy>e}1e zEA1D4HCp=Y&mBGa_p!0Dhw_`?J13V)D=N{*<$b+pQ>pjtVt;iT_`g&r6jppPR~dIET+>)4V!8=<`~mGWG@XVdw5@g@YGWDRR6yzYa0V{T$P zIy;(TZelvR5AIzxW^>bly7@LY9auHbdgPBU=T2rXZfIh7%rsIR@RQiq(i9`3)3L3kDawPN#J0YVD>F#*8=qBTzJI-ei9vq0Rdlr}Z)j9H*Z>GoV=KE%Pd`X_%YDJmf**9vx0Eo4p z0zCEee=Io#s1@_QA0DZD3b0yC#A31M1z+6;9;|!bUTYQpnvyR&KCG8V;lqQoWc{B~ ziel%ER34dK^+llSf?Xc7yqF*M%S3H$ZIyQUoqy*_#n&!X_6DwBzy45u6MUC6L@XBW z;g0R8*tsL!Uf3DM&K;@PwWH=EKt#li^S@8a`|su^>?=HETCVzp3y z=ebf|{CRub1Hoe=i-?L%hkyNP>gp`UE5G`0t^h3{nKYj4`U)RiYzvkaPQfhql)1HWk z`Jof%i?3Z;@h(91-M=~>o-~{8F8ga-{dj-nzzL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