Skip to content

Commit

Permalink
feat: update water max saturation upto 40
Browse files Browse the repository at this point in the history
  • Loading branch information
gloridifice committed Jun 9, 2024
1 parent 98ecb47 commit 250a1e6
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 51 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/client/kotlin/xyz/koiro/watersource/WSClientConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions src/client/kotlin/xyz/koiro/watersource/api/WaterBallRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
}
Expand All @@ -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) {
Expand All @@ -82,34 +85,39 @@ object ItemTooltipEventHandlers {
context.matrices.translate(0f, 0f, 401f)

val newY = fY + 1
// Empty
for (i in 0..<emptyCount) {
val newX = fX + i * 8 + 1
WaterBallRenderer(newX, newY, isThirty, WaterBallRenderer.Part.Empty).draw(context)
}

// Level
for (i in 0..<levelCount) {
val newX = fX + i * 8 + 1
val isEndAndHalf = i == levelCount - 1 && isLevelEndHalf
val part = if (isEndAndHalf) WaterBallRenderer.Part.LeftHalf else WaterBallRenderer.Part.Full
WaterBallRenderer(newX, newY, isThirty, part).draw(context)
}

for (i in 0..<satCount) {
val newX = fX + i * 8 + 1
val isEndAndHalf = i == satCount - 1 && isSatEndHalf
if (isEndAndHalf) {
WaterBallRenderer(newX, newY, isThirty, WaterBallRenderer.Part.SaturationDown, true).draw(
context
)
} else {
WaterBallRenderer(newX, newY, isThirty, WaterBallRenderer.Part.SaturationUp, true).draw(
context
)
WaterBallRenderer(newX, newY, isThirty, WaterBallRenderer.Part.SaturationDown, true).draw(
context
)
// Saturation
if (WSClientConfig.format.showHydrationSaturationInTooltip)
for (i in 0..<satCount) {
val newX = fX + i * 8 + 1
val isEndAndRest = i == satCount - 1 && satRest != 0
if (isEndAndRest) {
for (j in 0..<satRest) {
WaterBallRenderer(
newX, newY, isThirty,
WaterLevelUiRenderUtils.clockwiseSaturationParts[j],
true
).draw(context)
}
} else {
WaterLevelUiRenderUtils.clockwiseSaturationParts.forEach {
WaterBallRenderer(newX, newY, isThirty, it, true).draw(context)
}
}
}
}
context.matrices.pop()
} else {
val w = 32
Expand All @@ -128,14 +136,23 @@ object ItemTooltipEventHandlers {
val satY = levelY + 10
val newX = fX + 2
WaterBallRenderer(newX, levelY, isThirty, WaterBallRenderer.Part.Empty).draw(context)
WaterBallRenderer(newX, levelY, isThirty, WaterBallRenderer.Part.LeftHalf).draw(context)
WaterBallRenderer(newX, levelY, isThirty, WaterBallRenderer.Part.Full).draw(context)
WaterBallRenderer(newX, satY, isThirty, WaterBallRenderer.Part.Empty).draw(context)
WaterBallRenderer(newX, satY, isThirty, WaterBallRenderer.Part.SaturationDown, true).draw(context)
WaterLevelUiRenderUtils.clockwiseSaturationParts.forEach {
WaterBallRenderer(newX, satY, isThirty, it, true).draw(context)
}

val tr = MinecraftClient.getInstance().textRenderer
val textX = newX + 11
context.drawText(tr, "+${level}", textX, levelY + 1, 0xAAAAAA, false)
context.drawText(tr, "+${saturation}", textX, satY + 1, 0xAAAAAA, false)
context.drawText(tr, "+${String.format("%.1", level.toFloat() / 2f)}", textX, levelY + 1, 0xAAAAAA, false)
context.drawText(
tr,
"+${String.format("%.2", saturation.toFloat() / 4f)}",
textX,
satY + 1,
0xAAAAAA,
false
)

context.matrices.pop()
}
Expand Down
21 changes: 14 additions & 7 deletions src/client/kotlin/xyz/koiro/watersource/render/hud/ModClientHUD.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import net.minecraft.client.gui.DrawContext
import net.minecraft.util.hit.BlockHitResult
import xyz.koiro.watersource.WSClientConfig
import xyz.koiro.watersource.api.WaterBallRenderer
import xyz.koiro.watersource.api.WaterLevelUiRenderUtils
import xyz.koiro.watersource.world.attachment.ModAttachmentTypes
import xyz.koiro.watersource.world.block.entity.FilterBlockEntity
import xyz.koiro.watersource.world.effect.ModStatusEffects
Expand Down Expand Up @@ -66,6 +67,8 @@ object ModClientHUD {
}
} else List(10) { 0 }

context.matrices.push()
context.matrices.translate(0f, 0f, 200f)
// Draw Empties
for (i in 0..<10) {
val x = xStart - i * 8 - 9
Expand All @@ -85,20 +88,24 @@ object ModClientHUD {

if (WSClientConfig.format.showWaterSaturationInBar) {
// Draw Frames (Saturation)
val frameCount = ceil(saturation.toFloat() / 2f).toInt()
val fEndIsHalf = saturation % 2 != 0
val frameCount = ceil(saturation.toFloat() / 4f).toInt()
val restPartCount = saturation % 4
for (i in 0..<frameCount) {
val x = xStart - i * 8 - 9
val isEndAndEndIsHalf = i == frameCount - 1 && fEndIsHalf
val isEndAndEndIsRest = i == frameCount - 1 && restPartCount != 0
val fY = y + yOffsetList[i]
if (isEndAndEndIsHalf) {
WaterBallRenderer(x, fY, isThirty, WaterBallRenderer.Part.SaturationDown).draw(context)
if (isEndAndEndIsRest) {
for (j in 0..<restPartCount) {
WaterBallRenderer(x, fY, isThirty, WaterLevelUiRenderUtils.anticlockwiseSaturationParts[j]).draw(context)
}
} else {
WaterBallRenderer(x, fY, isThirty, WaterBallRenderer.Part.SaturationUp).draw(context)
WaterBallRenderer(x, fY, isThirty, WaterBallRenderer.Part.SaturationDown).draw(context)
WaterLevelUiRenderUtils.anticlockwiseSaturationParts.forEach {
WaterBallRenderer(x, fY, isThirty, it).draw(context)
}
}
}
}
context.matrices.pop()
}
}
}
8 changes: 7 additions & 1 deletion src/main/kotlin/xyz/koiro/watersource/ModItemGroups.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package xyz.koiro.watersource

import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup
import net.minecraft.enchantment.EnchantmentHelper
import net.minecraft.enchantment.EnchantmentLevelEntry
import net.minecraft.fluid.Fluids
import net.minecraft.item.EnchantedBookItem
import net.minecraft.item.ItemStack
import net.minecraft.registry.Registries
import net.minecraft.registry.Registry
import net.minecraft.text.Text
import net.minecraft.village.TradeOffers.EnchantBookFactory
import xyz.koiro.watersource.api.storage.insertFluid
import xyz.koiro.watersource.world.enchantment.ModEnchantments
import xyz.koiro.watersource.world.fluid.ModFluids
import xyz.koiro.watersource.world.item.FluidContainerItem
import xyz.koiro.watersource.world.item.ModItems
Expand Down Expand Up @@ -51,7 +56,8 @@ object ModItemGroups {
},

ModItems.WOODEN_FILTER_BLOCK.simpleStack(),
ModItems.IRON_FILTER_BLOCK.simpleStack()
ModItems.IRON_FILTER_BLOCK.simpleStack(),
EnchantedBookItem.forEnchantment(EnchantmentLevelEntry(ModEnchantments.MOISTURIZING, 3))
)

val MAIN_ITEM_GROUP = Registry.register(
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/xyz/koiro/watersource/WSConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ object WSConfig {
StatusEffectInstance(ModStatusEffects.THIRSTY, 1200)
)

fun getMoisturizingRatio(levelSum: Int): Float {
return 1f / (1f + levelSum.toFloat() * 0.15f)
}

object Exhaustion {
val config
get() = format.exhaustion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ class HydrationDataGenerator(output: DataOutput) : HydrationDataProvider(output)
)
adder.add(
WaterSource.identifier("fluid_purified_water"),
fluid(ModFluids.PURIFIED_WATER, 4, 7)
fluid(ModFluids.PURIFIED_WATER, 4, 10)
)
adder.addItemWithAutoId(ModItems.PURIFIED_WATER_BOTTLE, 4, 7)
adder.addItemWithAutoId(ModItems.PURIFIED_WATER_BOTTLE, 4, 10)

// Vanilla -----------------------
adder.addItemWithAutoId(Items.APPLE, 1, 2)
adder.addItemWithAutoId(Items.APPLE, 1, 3)
adder.addItemWithAutoId(Items.GOLDEN_APPLE, 2, 8)
adder.addItemWithAutoId(Items.ENCHANTED_GOLDEN_APPLE, 4, 10)
adder.addItemWithAutoId(Items.ENCHANTED_GOLDEN_APPLE, 4, 20)
adder.addItemWithAutoId(Items.MUSHROOM_STEW, 1, 1)
adder.addItemWithAutoId(Items.SUSPICIOUS_STEW, 1, 1)
adder.addItemWithAutoId(Items.RABBIT_STEW, 1, 1)
adder.addItemWithAutoId(Items.BEETROOT_SOUP, 1, 1)
adder.addItemWithAutoId(Items.MELON_SLICE, 1, 1)
adder.addItemWithAutoId(Items.GLISTERING_MELON_SLICE, 1, 2)
adder.addItemWithAutoId(Items.SWEET_BERRIES, 1, 0)
adder.addItemWithAutoId(Items.GLOW_BERRIES, 1, 0)
adder.addItemWithAutoId(Items.MELON_SLICE, 1, 2)
adder.addItemWithAutoId(Items.GLISTERING_MELON_SLICE, 1, 3)
adder.addItemWithAutoId(Items.SWEET_BERRIES, 1, 1)
adder.addItemWithAutoId(Items.GLOW_BERRIES, 1, 1)
adder.add(
Identifier("item_potion_water"),
item(Items.POTION, 2, 0, WSConfig.getWaterThirstyProbabilityEffect()).apply { matchList.add(HydrationData.NBTMatch(
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/xyz/koiro/watersource/datagen/ModLanguages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package xyz.koiro.watersource.datagen
import xyz.koiro.watersource.ModCommands
import xyz.koiro.watersource.ModItemGroups
import xyz.koiro.watersource.world.effect.ModStatusEffects
import xyz.koiro.watersource.world.enchantment.ModEnchantments

object ModLanguages {
const val INFO_CAPACITY_KYE = "watersource.info.capacity"
val list = listOf(
Translation("Water Source", "水源", ModItemGroups.MAIN_ITEM_GROUP_TRANSLATION_KEY),
Translation("Thirsty", "口渴", ModStatusEffects.THIRSTY.translationKey),
Translation("Capacity", "容量", INFO_CAPACITY_KYE),
Translation("Moisturizing", "保湿", ModEnchantments.MOISTURIZING.translationKey),

// Commands
Translation("<restoreAll> command's target must be player!", "<restoreAll> 命令的目标只能是玩家", ModCommands.RESTORE_ALL_TARGET_ERROR_TRANS_KEY),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Loading

0 comments on commit 250a1e6

Please sign in to comment.