From 423f2fab6b6005316ccb291cd538d8b162357930 Mon Sep 17 00:00:00 2001 From: Koiro <1165997495@qq.com> Date: Mon, 17 Jun 2024 21:41:00 +0800 Subject: [PATCH] fix: player init bug by mixin --- build.gradle | 153 ++++++++++-------- gradle.properties | 2 +- .../render/blockentity/FilterBERenderer.kt | 3 +- .../koiro/watersource/mixin/ExampleMixin.java | 15 -- .../watersource/mixin/PlayerEntityMixin.java | 8 +- .../xyz/koiro/watersource/ModItemGroups.kt | 2 + .../api/storage/FluidStorageData.kt | 4 + .../api/storage/ItemFluidDataExt.kt | 20 +-- .../api/storage/ItemStorageData.kt | 6 +- ...StrainerFilteringFluidRecipeJsonBuilder.kt | 3 +- .../StrainerFilteringItemRecipeJsonBuilder.kt | 2 +- .../world/block/entity/FilterBlockEntity.kt | 3 +- .../world/item/FluidContainerItem.kt | 9 +- .../koiro/watersource/world/item/Strainer.kt | 4 +- .../recipe/StrainerFilteringFluidRecipe.kt | 22 ++- .../world/recipe/StrainerFilteringRecipe.kt | 2 +- src/main/resources/watersource.mixins.json | 1 - 17 files changed, 133 insertions(+), 126 deletions(-) delete mode 100644 src/main/java/xyz/koiro/watersource/mixin/ExampleMixin.java diff --git a/build.gradle b/build.gradle index 8540d96..29f22fc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,68 +1,72 @@ plugins { - id 'fabric-loom' version '1.6-SNAPSHOT' - id 'maven-publish' - id "org.jetbrains.kotlin.jvm" version "2.0.0" - id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.0' - + id 'fabric-loom' version '1.6-SNAPSHOT' + id 'maven-publish' + id "org.jetbrains.kotlin.jvm" version "2.0.0" + id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.0' +// id 'com.github.johnrengelman.shadow' version '8.1.1' } version = project.mod_version + "+" + project.mc_version + "-fabric" + "-" + project.build_state group = project.maven_group base { - archivesName = project.archives_base_name + archivesName = project.archives_base_name } repositories { - maven { - name = 'Xander Maven' - url = 'https://maven.isxander.dev/releases' - } - maven { - // location of the maven that hosts JEI files before January 2023 - name = "Progwml6's maven" - url = "https://dvs1.progwml6.com/files/maven/" - } - maven { - // location of the maven that hosts JEI files since January 2023 - name = "Jared's maven" - url = "https://maven.blamejared.com/" - } - maven { - // location of a maven mirror for JEI files, as a fallback - name = "ModMaven" - url = "https://modmaven.dev" - } + maven { + name = 'Xander Maven' + url = 'https://maven.isxander.dev/releases' + } + maven { + // location of the maven that hosts JEI files before January 2023 + name = "Progwml6's maven" + url = "https://dvs1.progwml6.com/files/maven/" + } + maven { + // location of the maven that hosts JEI files since January 2023 + name = "Jared's maven" + url = "https://maven.blamejared.com/" + } + maven { + // location of a maven mirror for JEI files, as a fallback + name = "ModMaven" + url = "https://modmaven.dev" + } } loom { splitEnvironmentSourceSets() - mods { - "watersource" { - sourceSet sourceSets.main - sourceSet sourceSets.client - } - } + mods { + "watersource" { + sourceSet sourceSets.main + sourceSet sourceSets.client + } + } } fabricApi { - configureDataGeneration() + configureDataGeneration() } +//shadowJar { +// configurations = [project.configurations.shadow] exclude("META-INF") +//} + dependencies { - minecraft "com.mojang:minecraft:${project.mc_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0' + minecraft "com.mojang:minecraft:${project.mc_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0' - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}" + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}" - // toml - implementation 'com.akuleshov7:ktoml-core:0.5.1' - implementation 'com.akuleshov7:ktoml-file:0.5.1' + // toml + include(implementation('com.akuleshov7:ktoml-core-jvm:0.5.1')) + include(implementation('com.akuleshov7:ktoml-file-jvm:0.5.1')) // // compile against the JEI API but do not include it at runtime // modCompileOnlyApi("mezz.jei:jei-${mc_version}-common-api:${jei_version}") @@ -71,53 +75,60 @@ dependencies { // modRuntimeOnly("mezz.jei:jei-${mc_version}-fabric:${jei_version}") } +remapJar { +// nestedJars.from('com.akuleshov7:ktoml-core:0.5.1') + addNestedDependencies = true +// include()) +// include(implementation('com.akuleshov7:ktoml-file:0.5.1')) +} + processResources { - inputs.property "version", project.version + inputs.property "version", project.version - filesMatching("fabric.mod.json") { - expand "version": project.version - } + filesMatching("fabric.mod.json") { + expand "version": project.version + } } tasks.withType(JavaCompile).configureEach { - it.options.release = 21 + it.options.release = 21 } tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { - kotlinOptions { - jvmTarget = 21 - } + kotlinOptions { + jvmTarget = 21 + } } java { - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. - withSourcesJar() + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } jar { - from("LICENSE") { - rename { "${it}_${project.base.archivesName.get()}"} - } + from("LICENSE") { + rename { "${it}_${project.base.archivesName.get()}" } + } } // configure the maven publication publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. - } + publications { + mavenJava(MavenPublication) { + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 3a49cce..e27547a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ loader_version=0.15.10 fabric_kotlin_version=1.11.0+kotlin.2.0.0 # Mod Properties -mod_version=2.0.0 +mod_version=2.1.4 build_state=beta maven_group=xyz.koiro.watersource archives_base_name=watersource diff --git a/src/client/kotlin/xyz/koiro/watersource/render/blockentity/FilterBERenderer.kt b/src/client/kotlin/xyz/koiro/watersource/render/blockentity/FilterBERenderer.kt index 7b2c1e5..bb8674a 100644 --- a/src/client/kotlin/xyz/koiro/watersource/render/blockentity/FilterBERenderer.kt +++ b/src/client/kotlin/xyz/koiro/watersource/render/blockentity/FilterBERenderer.kt @@ -1,6 +1,7 @@ package xyz.koiro.watersource.render.blockentity import com.mojang.blaze3d.systems.RenderSystem +import net.fabricmc.fabric.impl.client.indigo.renderer.helper.ColorHelper import net.minecraft.client.MinecraftClient import net.minecraft.client.render.RenderLayer import net.minecraft.client.render.VertexConsumerProvider @@ -62,7 +63,7 @@ class FilterBERenderer : BlockEntityRenderer { matrices.push() RenderSystem.enableBlend() - val consumer = vertexConsumers.getBuffer(RenderLayer.getGlintTranslucent()) + val consumer = vertexConsumers.getBuffer(RenderLayer.getCutout()) val u0 = fluidSprite.minU val v0 = fluidSprite.minV val u1 = fluidSprite.maxU diff --git a/src/main/java/xyz/koiro/watersource/mixin/ExampleMixin.java b/src/main/java/xyz/koiro/watersource/mixin/ExampleMixin.java deleted file mode 100644 index 6b39b9f..0000000 --- a/src/main/java/xyz/koiro/watersource/mixin/ExampleMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package xyz.koiro.watersource.mixin; - -import net.minecraft.server.MinecraftServer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MinecraftServer.class) -public class ExampleMixin { - @Inject(at = @At("HEAD"), method = "loadWorld") - private void init(CallbackInfo info) { - // This code is injected into the start of MinecraftServer.loadWorld()V - } -} \ No newline at end of file diff --git a/src/main/java/xyz/koiro/watersource/mixin/PlayerEntityMixin.java b/src/main/java/xyz/koiro/watersource/mixin/PlayerEntityMixin.java index 92a58f0..7412021 100644 --- a/src/main/java/xyz/koiro/watersource/mixin/PlayerEntityMixin.java +++ b/src/main/java/xyz/koiro/watersource/mixin/PlayerEntityMixin.java @@ -21,16 +21,16 @@ private void onJump(final CallbackInfo info){ } } - @Inject(at = @At(value = "INVOKE"), method = "readCustomDataFromNbt") - private void onReadCustomNbt(final NbtCompound nbt, final CallbackInfo info){ + @Inject(at = @At(value = "RETURN"), method = "readCustomDataFromNbt") + private void readCustomDataFromNbt(final NbtCompound nbt, final CallbackInfo info){ var player = (net.minecraft.entity.player.PlayerEntity) (Object) this; if (player instanceof ServerPlayerEntity serverPlayer) { ActionResult result = ModServerEvents.INSTANCE.getPLAYER_READ_CUSTOM_NBT().invoker().interact(serverPlayer, nbt); } } - @Inject(at = @At(value = "INVOKE"), method = "writeCustomDataToNbt") - private void onWriteCustomNbt(final NbtCompound nbt, final CallbackInfo info){ + @Inject(at = @At(value = "RETURN"), method = "writeCustomDataToNbt") + private void writeCustomDataToNbt(final NbtCompound nbt, final CallbackInfo info){ var player = (net.minecraft.entity.player.PlayerEntity) (Object) this; if (player instanceof ServerPlayerEntity serverPlayer) { ActionResult result = ModServerEvents.INSTANCE.getPLAYER_WRITE_CUSTOM_NBT().invoker().interact(serverPlayer, nbt); diff --git a/src/main/kotlin/xyz/koiro/watersource/ModItemGroups.kt b/src/main/kotlin/xyz/koiro/watersource/ModItemGroups.kt index aa767b5..bf02d85 100644 --- a/src/main/kotlin/xyz/koiro/watersource/ModItemGroups.kt +++ b/src/main/kotlin/xyz/koiro/watersource/ModItemGroups.kt @@ -9,7 +9,9 @@ import net.minecraft.registry.Registries import net.minecraft.registry.Registry import net.minecraft.text.Text import xyz.koiro.watersource.api.simpleStack +import xyz.koiro.watersource.api.storage.FluidStorageData import xyz.koiro.watersource.api.storage.insertFluid +import xyz.koiro.watersource.world.datacomponent.ModDataComponentTypes import xyz.koiro.watersource.world.enchantment.ModEnchantments import xyz.koiro.watersource.world.fluid.ModFluids import xyz.koiro.watersource.world.item.ModItems diff --git a/src/main/kotlin/xyz/koiro/watersource/api/storage/FluidStorageData.kt b/src/main/kotlin/xyz/koiro/watersource/api/storage/FluidStorageData.kt index 00c3ffa..07acb01 100644 --- a/src/main/kotlin/xyz/koiro/watersource/api/storage/FluidStorageData.kt +++ b/src/main/kotlin/xyz/koiro/watersource/api/storage/FluidStorageData.kt @@ -32,6 +32,10 @@ class FluidStorageData( return ret } + fun copy(): FluidStorageData{ + return FluidStorageData(fluid, amount, capacity) + } + fun isBlank(): Boolean { return amount == 0L || fluid == Fluids.EMPTY } diff --git a/src/main/kotlin/xyz/koiro/watersource/api/storage/ItemFluidDataExt.kt b/src/main/kotlin/xyz/koiro/watersource/api/storage/ItemFluidDataExt.kt index 361b2ab..f5da4b8 100644 --- a/src/main/kotlin/xyz/koiro/watersource/api/storage/ItemFluidDataExt.kt +++ b/src/main/kotlin/xyz/koiro/watersource/api/storage/ItemFluidDataExt.kt @@ -35,15 +35,8 @@ fun ItemStack.extractFluid(amount: Long): Long? { fun ItemStack.getOrCreateFluidStorageData(): FluidStorageData? { val item = this.item if (item is FluidContainerItem) { - val data = this.get(ModDataComponentTypes.FLUID_STORAGE) - return if (data != null) { - data - } else { - // Init - val ret = FluidStorageData(Fluids.EMPTY, 0, item.capacity) - this.set(ModDataComponentTypes.FLUID_STORAGE, ret) - ret - } + val data = this.getOrDefault(ModDataComponentTypes.FLUID_STORAGE, FluidStorageData(Fluids.EMPTY, 0, item.capacity)) + return data } return null } @@ -52,9 +45,12 @@ fun ItemStack.getOrCreateFluidStorageData(): FluidStorageData? { * Modify fluid storage and apply for nbt if item is `FluidContainer` * */ fun ItemStack.modifyFluidStorage(action: (ItemStack, FluidStorageData) -> Unit) { - this.getOrCreateFluidStorageData()?.let { - action(this, it) - this.set(ModDataComponentTypes.FLUID_STORAGE, it) + this.getOrCreateFluidStorageData()?.let { data -> + this.apply(ModDataComponentTypes.FLUID_STORAGE, data) { + val applied = it.copy() + action(this, applied) + applied + } } } diff --git a/src/main/kotlin/xyz/koiro/watersource/api/storage/ItemStorageData.kt b/src/main/kotlin/xyz/koiro/watersource/api/storage/ItemStorageData.kt index ec58fca..73bb9ac 100644 --- a/src/main/kotlin/xyz/koiro/watersource/api/storage/ItemStorageData.kt +++ b/src/main/kotlin/xyz/koiro/watersource/api/storage/ItemStorageData.kt @@ -6,6 +6,7 @@ import net.minecraft.nbt.NbtCompound import net.minecraft.nbt.NbtOps import net.minecraft.registry.RegistryWrapper.WrapperLookup import java.util.Optional +import java.util.Stack import kotlin.jvm.optionals.getOrNull class ItemStorageData(var stack: ItemStack = ItemStack.EMPTY) { @@ -29,7 +30,8 @@ class ItemStorageData(var stack: ItemStack = ItemStack.EMPTY) { stack = ItemStack.EMPTY } - fun writeNbt(lookup: WrapperLookup, nbtCompound: NbtCompound) { - CODEC.encode(this, lookup.getOps(NbtOps.INSTANCE), nbtCompound).getOrThrow() + fun writeNbt(lookup: WrapperLookup): NbtCompound { + val a = CODEC.encode(this, lookup.getOps(NbtOps.INSTANCE), NbtCompound()).getOrThrow() + return a as NbtCompound } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/koiro/watersource/datagen/recipe/StrainerFilteringFluidRecipeJsonBuilder.kt b/src/main/kotlin/xyz/koiro/watersource/datagen/recipe/StrainerFilteringFluidRecipeJsonBuilder.kt index 5f848d0..153e328 100644 --- a/src/main/kotlin/xyz/koiro/watersource/datagen/recipe/StrainerFilteringFluidRecipeJsonBuilder.kt +++ b/src/main/kotlin/xyz/koiro/watersource/datagen/recipe/StrainerFilteringFluidRecipeJsonBuilder.kt @@ -41,8 +41,7 @@ class StrainerFilteringFluidRecipeJsonBuilder( return Items.APPLE } - override fun offerTo(exporter: RecipeExporter, recipeId: Identifier) { - exporter.accept(recipeId, StrainerFilteringFluidRecipe(inFluid, outFluid, strainer), advancementBuilder?.build(recipeId.withPrefixedPath("recipes/"))) + exporter.accept(id, StrainerFilteringFluidRecipe(inFluid, outFluid, strainer), advancementBuilder?.build(recipeId.withPrefixedPath("recipes/"))) } } diff --git a/src/main/kotlin/xyz/koiro/watersource/datagen/recipe/StrainerFilteringItemRecipeJsonBuilder.kt b/src/main/kotlin/xyz/koiro/watersource/datagen/recipe/StrainerFilteringItemRecipeJsonBuilder.kt index 074b7c3..535f8b2 100644 --- a/src/main/kotlin/xyz/koiro/watersource/datagen/recipe/StrainerFilteringItemRecipeJsonBuilder.kt +++ b/src/main/kotlin/xyz/koiro/watersource/datagen/recipe/StrainerFilteringItemRecipeJsonBuilder.kt @@ -42,6 +42,6 @@ class StrainerFilteringItemRecipeJsonBuilder( } override fun offerTo(exporter: RecipeExporter, recipeId: Identifier) { - exporter.accept(recipeId, StrainerFilteringItemRecipe(input, output, cost, strainer), advancementBuilder?.build(recipeId.withPrefixedPath("recipes/"))) + exporter.accept(id, StrainerFilteringItemRecipe(input, output, cost, strainer), advancementBuilder?.build(recipeId.withPrefixedPath("recipes/"))) } } diff --git a/src/main/kotlin/xyz/koiro/watersource/world/block/entity/FilterBlockEntity.kt b/src/main/kotlin/xyz/koiro/watersource/world/block/entity/FilterBlockEntity.kt index ca3acbe..18b4444 100644 --- a/src/main/kotlin/xyz/koiro/watersource/world/block/entity/FilterBlockEntity.kt +++ b/src/main/kotlin/xyz/koiro/watersource/world/block/entity/FilterBlockEntity.kt @@ -85,8 +85,7 @@ class FilterBlockEntity(pos: BlockPos, state: BlockState, var capacity: Long, va super.writeNbt(nbt, registryLookup) if (nbt == null || registryLookup == null) return nbt.putBoolean("isUp", isUp) - val strainerNbt = NbtCompound() - strainerStorage.writeNbt(registryLookup, strainerNbt) + val strainerNbt = strainerStorage.writeNbt(registryLookup) nbt.put("strainer", strainerNbt) nbt.putBoolean("isWorking", isWorking) nbt.putInt("ticks", filterTicks) diff --git a/src/main/kotlin/xyz/koiro/watersource/world/item/FluidContainerItem.kt b/src/main/kotlin/xyz/koiro/watersource/world/item/FluidContainerItem.kt index 5221630..e11a9a8 100644 --- a/src/main/kotlin/xyz/koiro/watersource/world/item/FluidContainerItem.kt +++ b/src/main/kotlin/xyz/koiro/watersource/world/item/FluidContainerItem.kt @@ -19,13 +19,16 @@ import xyz.koiro.watersource.api.storage.FluidStorageData import xyz.koiro.watersource.api.storage.getOrCreateFluidStorageData import xyz.koiro.watersource.api.storage.insertFluid import xyz.koiro.watersource.api.storage.setFluidStorage +import xyz.koiro.watersource.world.datacomponent.ModDataComponentTypes import kotlin.math.round open class FluidContainerItem( settings: Settings, val capacity: Long, val emptyContainer: (() -> ItemStack)? = null -) : Item(settings.maxDamage((capacity / WSConfig.UNIT_DRINK_VOLUME).toInt())) { +) : Item( + settings.maxDamage((capacity / WSConfig.UNIT_DRINK_VOLUME).toInt()) +) { fun canInsert(itemStack: ItemStack, fluid: Fluid, amount: Long, currentData: FluidStorageData): Boolean { return fluid == currentData.fluid || currentData.isBlank() @@ -36,8 +39,8 @@ open class FluidContainerItem( val amount = it.amount val maxDamage = stack.maxDamage val damage = round((1 - amount.toDouble() / capacity.toDouble()) * maxDamage).toInt() - if (damage >= maxDamage){ - if (emptyContainer != null){ + if (damage >= maxDamage) { + if (emptyContainer != null) { playerEntity.setStackInHand(hand, emptyContainer.invoke()) } else stack.damage = maxDamage } else { diff --git a/src/main/kotlin/xyz/koiro/watersource/world/item/Strainer.kt b/src/main/kotlin/xyz/koiro/watersource/world/item/Strainer.kt index 330d881..dd72731 100644 --- a/src/main/kotlin/xyz/koiro/watersource/world/item/Strainer.kt +++ b/src/main/kotlin/xyz/koiro/watersource/world/item/Strainer.kt @@ -10,11 +10,11 @@ import xyz.koiro.watersource.WSConfig import kotlin.math.ceil class Strainer(settings: Settings?) : Item(settings) { - fun calCostDamage(strainerStack: ItemStack, volume: Long): Int { + open fun calCostDamage(strainerStack: ItemStack, volume: Long): Int { return ceil(volume.toDouble() / WSConfig.UNIT_DRINK_VOLUME.toDouble()).toInt() } - fun getUsedStrainer(strainerStack: ItemStack, cost: Int): ItemStack { + open fun getUsedStrainer(strainerStack: ItemStack, cost: Int): ItemStack { val remainedStrainer = if (strainerStack.damage + cost >= strainerStack.maxDamage) { ItemStack(ModItems.WASTE_STRAINER) } else { diff --git a/src/main/kotlin/xyz/koiro/watersource/world/recipe/StrainerFilteringFluidRecipe.kt b/src/main/kotlin/xyz/koiro/watersource/world/recipe/StrainerFilteringFluidRecipe.kt index 7f0f6d2..077f802 100644 --- a/src/main/kotlin/xyz/koiro/watersource/world/recipe/StrainerFilteringFluidRecipe.kt +++ b/src/main/kotlin/xyz/koiro/watersource/world/recipe/StrainerFilteringFluidRecipe.kt @@ -1,20 +1,26 @@ package xyz.koiro.watersource.world.recipe import com.mojang.serialization.Codec +import com.mojang.serialization.DynamicOps import com.mojang.serialization.MapCodec import com.mojang.serialization.codecs.RecordCodecBuilder import net.minecraft.fluid.Fluid import net.minecraft.inventory.RecipeInputInventory import net.minecraft.item.ItemStack +import net.minecraft.item.Items +import net.minecraft.nbt.NbtOps import net.minecraft.network.RegistryByteBuf import net.minecraft.recipe.Ingredient import net.minecraft.recipe.RecipeSerializer import net.minecraft.recipe.book.CraftingRecipeCategory import net.minecraft.registry.Registries +import net.minecraft.registry.RegistryOps import net.minecraft.registry.RegistryWrapper +import net.minecraft.util.collection.DefaultedList import xyz.koiro.watersource.api.storage.getOrCreateFluidStorageData import xyz.koiro.watersource.api.storage.modifyFluidStorage import xyz.koiro.watersource.api.identifier +import xyz.koiro.watersource.api.simpleStack import xyz.koiro.watersource.api.toIdentifier import xyz.koiro.watersource.world.item.Strainer @@ -54,17 +60,15 @@ class StrainerFilteringFluidRecipe( val codec = RecordCodecBuilder.mapCodec { instance -> val grouped = instance.group( - Codec.STRING.fieldOf("fluidIn") - .forGetter { it.inFluid.identifier().toString() }, - Codec.STRING.fieldOf("fluidOut") - .forGetter { it.outFluid.identifier().toString() }, + Registries.FLUID.codec.fieldOf("input").forGetter { it.inFluid } , + Registries.FLUID.codec.fieldOf("output").forGetter { it.outFluid } , Ingredient.DISALLOW_EMPTY_CODEC.fieldOf("strainer") .forGetter { it.strainer } ) - return@mapCodec grouped.apply(instance) { fluidInId, fluidOutId, strainer -> + return@mapCodec grouped.apply(instance) { fluidIn, fluidOut, strainer -> StrainerFilteringFluidRecipe( - Registries.FLUID.get(fluidInId.toIdentifier()), - Registries.FLUID.get(fluidOutId.toIdentifier()), + fluidIn, + fluidOut, strainer ) } @@ -78,7 +82,9 @@ class StrainerFilteringFluidRecipe( val inId = buf.readString() val outId = buf.readString() val strainer = Ingredient.PACKET_CODEC.decode(buf) - return StrainerFilteringFluidRecipe(Registries.FLUID.get(inId.toIdentifier()), Registries.FLUID.get(outId.toIdentifier()), strainer) + val fluidIn = Registries.FLUID.get(inId.toIdentifier()) + val fluidOut = Registries.FLUID.get(outId.toIdentifier()) + return StrainerFilteringFluidRecipe(fluidIn, fluidOut, strainer) } override fun write(buf: RegistryByteBuf, recipe: StrainerFilteringFluidRecipe) { diff --git a/src/main/kotlin/xyz/koiro/watersource/world/recipe/StrainerFilteringRecipe.kt b/src/main/kotlin/xyz/koiro/watersource/world/recipe/StrainerFilteringRecipe.kt index 56364c6..327efb4 100644 --- a/src/main/kotlin/xyz/koiro/watersource/world/recipe/StrainerFilteringRecipe.kt +++ b/src/main/kotlin/xyz/koiro/watersource/world/recipe/StrainerFilteringRecipe.kt @@ -55,7 +55,7 @@ abstract class StrainerFilteringRecipe( } override fun getRemainder(inventory: RecipeInputInventory): DefaultedList { - val defaultedList = DefaultedList.ofSize(inventory.size(), ItemStack(Items.APPLE)) + val defaultedList = DefaultedList.ofSize(inventory.size(), ItemStack.EMPTY) for (i in defaultedList.indices) { val item = inventory.getStack(i).item if (!item.hasRecipeRemainder()) continue diff --git a/src/main/resources/watersource.mixins.json b/src/main/resources/watersource.mixins.json index 761bbf2..3e8ce18 100644 --- a/src/main/resources/watersource.mixins.json +++ b/src/main/resources/watersource.mixins.json @@ -3,7 +3,6 @@ "package": "xyz.koiro.watersource.mixin", "compatibilityLevel": "JAVA_21", "mixins": [ - "ExampleMixin", "PlayerEntityMixin", "ItemMixin" ],