From f1348735974d025d480fadba49719141db1ff92c Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Wed, 8 Dec 2021 11:11:08 +0100 Subject: [PATCH] Fix components not being saved upon bucketing --- build.gradle | 12 ++++- .../cca/mixin/chunk/common/MixinChunk.java | 4 +- .../MixinThreadedAnvilChunkStorage.java | 5 +- .../mixin/chunk/common/MixinWorldChunk.java | 9 ++-- .../mixin/entity/common/BucketableMixin.java | 49 ++++++++++++++++++ .../mixins.cardinal_components_entity.json | 1 + changelog.md | 7 +++ gradle.properties | 8 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../tests/entity/CcaEntityTestSuite.java | 50 +++++++++++++++++++ src/testmod/resources/fabric.mod.json | 1 + 11 files changed, 133 insertions(+), 15 deletions(-) create mode 100644 cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/BucketableMixin.java create mode 100644 src/testmod/java/dev/onyxstudios/componenttest/tests/entity/CcaEntityTestSuite.java diff --git a/build.gradle b/build.gradle index 2dbfe1f3..9623f3c6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,5 @@ import net.fabricmc.loom.task.RemapJarTask -import java.nio.charset.StandardCharsets import java.time.Year plugins { @@ -253,6 +252,15 @@ subprojects { p -> licenseFormatAll.dependsOn("${p.path}:licenseFormat") } subprojects.each { remapJar.dependsOn("${it.path}:remapJar") } repositories { + maven { + name = 'Ladysnake Mods' + url = 'https://ladysnake.jfrog.io/artifactory/mods' + content { + includeGroup 'io.github.ladysnake' + includeGroupByRegex 'dev\\.emi.*' + includeGroupByRegex 'io\\.github\\.onyxstudios.*' + } + } maven { name = "JitPack" url = "https://jitpack.io" @@ -277,6 +285,8 @@ dependencies { modRuntimeOnly fabricApi.module("fabric-tag-extensions-v0", fabric_api_version) modRuntimeOnly fabricApi.module("fabric-tool-attribute-api-v1", fabric_api_version) modRuntimeOnly fabricApi.module("fabric-events-interaction-v0", fabric_api_version) + modCompileOnly "io.github.ladysnake:elmendorf:${elmendorf_version}" + modRuntimeOnly "io.github.ladysnake:elmendorf:${elmendorf_version}" testCompileOnly "com.google.code.findbugs:jsr305:3.0.2" diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunk.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunk.java index 6814783f..967410fe 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunk.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinChunk.java @@ -32,7 +32,7 @@ import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.ChunkSection; import net.minecraft.world.chunk.UpgradeData; -import net.minecraft.world.gen.chunk.Blender; +import net.minecraft.world.gen.chunk.BlendingData; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -45,7 +45,7 @@ public class MixinChunk implements ComponentProvider { private ComponentContainer components; @Inject(method = "", at = @At("RETURN")) - private void initComponents(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry biome, long inhabitedTime, ChunkSection[] sectionArrayInitializer, Blender blendingData, CallbackInfo ci) { + private void initComponents(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry biome, long inhabitedTime, ChunkSection[] sectionArrayInitializer, BlendingData blendingData, CallbackInfo ci) { this.components = StaticChunkComponentPlugin.createContainer((Chunk) (Object) this); } diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinThreadedAnvilChunkStorage.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinThreadedAnvilChunkStorage.java index e97bf3bc..c36b0c00 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinThreadedAnvilChunkStorage.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinThreadedAnvilChunkStorage.java @@ -24,7 +24,6 @@ import com.mojang.datafixers.DataFixer; import dev.onyxstudios.cca.api.v3.chunk.ChunkSyncCallback; -import net.minecraft.network.Packet; import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ThreadedAnvilChunkStorage; @@ -36,11 +35,11 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.io.File; +import java.nio.file.Path; @Mixin(ThreadedAnvilChunkStorage.class) public abstract class MixinThreadedAnvilChunkStorage extends VersionedChunkStorage { - public MixinThreadedAnvilChunkStorage(File file, DataFixer dataFixer, boolean bl) { + public MixinThreadedAnvilChunkStorage(Path file, DataFixer dataFixer, boolean bl) { super(file, dataFixer, bl); } diff --git a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java index 3750ee72..15c35fc5 100644 --- a/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java +++ b/cardinal-components-chunk/src/main/java/dev/onyxstudios/cca/mixin/chunk/common/MixinWorldChunk.java @@ -43,7 +43,7 @@ import net.minecraft.world.chunk.ProtoChunk; import net.minecraft.world.chunk.UpgradeData; import net.minecraft.world.chunk.WorldChunk; -import net.minecraft.world.gen.chunk.Blender; +import net.minecraft.world.gen.chunk.BlendingData; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -53,11 +53,10 @@ import java.util.Collections; import java.util.Iterator; -import java.util.function.Consumer; @Mixin(WorldChunk.class) public abstract class MixinWorldChunk extends Chunk implements ComponentProvider { - public MixinWorldChunk(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry biome, long inhabitedTime, @Nullable ChunkSection[] sectionArrayInitializer, @Nullable Blender blendingData) { + public MixinWorldChunk(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry biome, long inhabitedTime, @Nullable ChunkSection[] sectionArrayInitializer, @Nullable BlendingData blendingData) { super(pos, upgradeData, heightLimitView, biome, inhabitedTime, sectionArrayInitializer, blendingData); } @@ -83,8 +82,8 @@ public CustomPayloadS2CPacket toComponentPacket( return new CustomPayloadS2CPacket(ComponentsChunkNetworking.PACKET_ID, buf); } - @Inject(method = "(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/ProtoChunk;Ljava/util/function/Consumer;)V", at = @At("RETURN")) - private void copyFromProto(ServerWorld world, ProtoChunk proto, Consumer consumer, CallbackInfo ci) { + @Inject(method = "(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/ProtoChunk;Lnet/minecraft/world/chunk/WorldChunk$EntityLoader;)V", at = @At("RETURN")) + private void copyFromProto(ServerWorld world, ProtoChunk proto, WorldChunk.EntityLoader entityLoader, CallbackInfo ci) { this.getComponentContainer().copyFrom(ComponentProvider.fromChunk(proto).getComponentContainer()); } } diff --git a/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/BucketableMixin.java b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/BucketableMixin.java new file mode 100644 index 00000000..03f4f5d4 --- /dev/null +++ b/cardinal-components-entity/src/main/java/dev/onyxstudios/cca/mixin/entity/common/BucketableMixin.java @@ -0,0 +1,49 @@ +/* + * Cardinal-Components-API + * Copyright (C) 2019-2021 OnyxStudios + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + * OR OTHER DEALINGS IN THE SOFTWARE. + */ +package dev.onyxstudios.cca.mixin.entity.common; + +import dev.onyxstudios.cca.api.v3.component.ComponentProvider; +import net.minecraft.entity.Bucketable; +import net.minecraft.entity.mob.MobEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +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(Bucketable.class) +public interface BucketableMixin { + @Inject(method = "copyDataToStack(Lnet/minecraft/entity/mob/MobEntity;Lnet/minecraft/item/ItemStack;)V", at = @At("RETURN")) + private static void writeComponentsToStack(MobEntity entity, ItemStack stack, CallbackInfo ci) { + NbtCompound nbt = stack.getNbt(); + if (nbt != null) { + ComponentProvider.fromEntity(entity).getComponentContainer().toTag(nbt); + } + } + + @Inject(method = "copyDataFromNbt(Lnet/minecraft/entity/mob/MobEntity;Lnet/minecraft/nbt/NbtCompound;)V", at = @At("RETURN")) + private static void readComponentsFromStack(MobEntity entity, NbtCompound nbt, CallbackInfo ci) { + ComponentProvider.fromEntity(entity).getComponentContainer().fromTag(nbt); + } +} diff --git a/cardinal-components-entity/src/main/resources/mixins.cardinal_components_entity.json b/cardinal-components-entity/src/main/resources/mixins.cardinal_components_entity.json index b2b12df2..04b5c65f 100644 --- a/cardinal-components-entity/src/main/resources/mixins.cardinal_components_entity.json +++ b/cardinal-components-entity/src/main/resources/mixins.cardinal_components_entity.json @@ -4,6 +4,7 @@ "compatibilityLevel": "JAVA_8", "package": "dev.onyxstudios.cca.mixin.entity", "mixins": [ + "common.BucketableMixin", "common.MixinEntity", "common.MixinEntityTrackerEntry", "common.MixinPlayerManager", diff --git a/changelog.md b/changelog.md index e3bd47cd..623acaa9 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,10 @@ +------------------------------------------------------ +Version 4.0.1 +------------------------------------------------------ +**Fixes** +- Fixed cardinal-components-chunk crashing at launch +- Fixed components not being saved when bucketing entities + ------------------------------------------------------ Version 4.0.0 ------------------------------------------------------ diff --git a/gradle.properties b/gradle.properties index 484768cc..423604ee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,15 +2,17 @@ org.gradle.jvmargs = -Xmx3G #see https://modmuss50.me/fabric.html -minecraft_version=1.18-pre1 -yarn_mappings=8 +minecraft_version=1.18 +yarn_mappings=1 loader_version=0.12.5 #Fabric api fabric_api_version=0.42.2+1.18 +elmendorf_version=0.3.0 + #Publishing -mod_version = 4.0.0 +mod_version = 4.0.1 curseforge_id = 318449 curseforge_versions = 1.18-Snapshot changelog_url = https://github.com/OnyxStudios/Cardinal-Components-API/blob diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e5338d37..e750102e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/testmod/java/dev/onyxstudios/componenttest/tests/entity/CcaEntityTestSuite.java b/src/testmod/java/dev/onyxstudios/componenttest/tests/entity/CcaEntityTestSuite.java new file mode 100644 index 00000000..69cd278c --- /dev/null +++ b/src/testmod/java/dev/onyxstudios/componenttest/tests/entity/CcaEntityTestSuite.java @@ -0,0 +1,50 @@ +/* + * Cardinal-Components-API + * Copyright (C) 2019-2021 OnyxStudios + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + * OR OTHER DEALINGS IN THE SOFTWARE. + */ +package dev.onyxstudios.componenttest.tests.entity; + +import dev.onyxstudios.componenttest.content.vita.Vita; +import io.github.ladysnake.elmendorf.GameTestUtil; +import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; +import net.minecraft.entity.Bucketable; +import net.minecraft.entity.EntityType; +import net.minecraft.item.EntityBucketItem; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.test.GameTest; +import net.minecraft.test.TestContext; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; + +public class CcaEntityTestSuite implements FabricGameTest { + @GameTest(structureName = EMPTY_STRUCTURE) + public void bucketableWorks(TestContext ctx) { + var player = GameTestUtil.spawnPlayer(ctx, 1, 1, 1); + player.setStackInHand(Hand.MAIN_HAND, new ItemStack(Items.WATER_BUCKET)); + BlockPos pos = new BlockPos(2, 2, 2); + var axolotl = ctx.spawnMob(EntityType.AXOLOTL, pos); + Vita.get(axolotl).setVitality(3); + Bucketable.tryBucket(player, Hand.MAIN_HAND, axolotl); + ((EntityBucketItem) Items.AXOLOTL_BUCKET).onEmptied(player, ctx.getWorld(), player.getStackInHand(Hand.MAIN_HAND), ctx.getAbsolutePos(pos)); + ctx.expectEntityWithDataEnd(pos, EntityType.AXOLOTL, a -> Vita.get(a).getVitality(), 3); + } +} diff --git a/src/testmod/resources/fabric.mod.json b/src/testmod/resources/fabric.mod.json index 6ee29b92..6ad65307 100644 --- a/src/testmod/resources/fabric.mod.json +++ b/src/testmod/resources/fabric.mod.json @@ -20,6 +20,7 @@ ], "fabric-gametest": [ "dev.onyxstudios.componenttest.tests.CcaTestSuite", + "dev.onyxstudios.componenttest.tests.entity.CcaEntityTestSuite", "dev.onyxstudios.cca.internal.base.ComponentRegistryImplTest", "dev.onyxstudios.cca.internal.base.QualifiedComponentFactoryTest" ]