Skip to content

Commit

Permalink
Fix components not being saved upon bucketing
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Dec 8, 2021
1 parent e37cca4 commit f134873
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 15 deletions.
12 changes: 11 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import net.fabricmc.loom.task.RemapJarTask

import java.nio.charset.StandardCharsets
import java.time.Year

plugins {
Expand Down Expand Up @@ -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"
Expand All @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,7 +45,7 @@ public class MixinChunk implements ComponentProvider {
private ComponentContainer components;

@Inject(method = "<init>", at = @At("RETURN"))
private void initComponents(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry<Biome> biome, long inhabitedTime, ChunkSection[] sectionArrayInitializer, Blender blendingData, CallbackInfo ci) {
private void initComponents(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry<Biome> biome, long inhabitedTime, ChunkSection[] sectionArrayInitializer, BlendingData blendingData, CallbackInfo ci) {
this.components = StaticChunkComponentPlugin.createContainer((Chunk) (Object) this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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> biome, long inhabitedTime, @Nullable ChunkSection[] sectionArrayInitializer, @Nullable Blender blendingData) {
public MixinWorldChunk(ChunkPos pos, UpgradeData upgradeData, HeightLimitView heightLimitView, Registry<Biome> biome, long inhabitedTime, @Nullable ChunkSection[] sectionArrayInitializer, @Nullable BlendingData blendingData) {
super(pos, upgradeData, heightLimitView, biome, inhabitedTime, sectionArrayInitializer, blendingData);
}

Expand All @@ -83,8 +82,8 @@ public <C extends AutoSyncedComponent> CustomPayloadS2CPacket toComponentPacket(
return new CustomPayloadS2CPacket(ComponentsChunkNetworking.PACKET_ID, buf);
}

@Inject(method = "<init>(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<WorldChunk> consumer, CallbackInfo ci) {
@Inject(method = "<init>(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());
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_8",
"package": "dev.onyxstudios.cca.mixin.entity",
"mixins": [
"common.BucketableMixin",
"common.MixinEntity",
"common.MixinEntityTrackerEntry",
"common.MixinPlayerManager",
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/testmod/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down

0 comments on commit f134873

Please sign in to comment.