Skip to content

Commit

Permalink
25w05a
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Jan 29, 2025
1 parent 9eb1c5c commit 2dd063d
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@
[
"minecraft:glow_lichen",
"minecraft:patch_tall_grass_2",
"minecraft:patch_bush",
"minecraft:trees_plains",
"minecraft:flower_plains",
"minecraft:patch_grass_plain",
"minecraft:brown_mushroom_normal",
"minecraft:red_mushroom_normal",
"minecraft:patch_pumpkin",
"minecraft:patch_sugar_cane",
"minecraft:patch_pumpkin"
"minecraft:patch_firefly_bush_near_water"
],
[
"minecraft:freeze_top_layer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@

package net.fabricmc.fabric.impl.attachment;

import org.jetbrains.annotations.Nullable;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Decoder;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Encoder;

import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.nbt.NbtOps;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.PersistentState;

Expand All @@ -37,20 +42,27 @@ public AttachmentPersistentState(ServerWorld world) {
this.wasSerialized = worldTarget.fabric_hasPersistentAttachments();
}

public static AttachmentPersistentState read(ServerWorld world, @Nullable NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
((AttachmentTargetImpl) world).fabric_readAttachmentsFromNbt(nbt, wrapperLookup);
return new AttachmentPersistentState(world);
// TODO 1.21.5 look at making this more idiomatic
public static Codec<AttachmentPersistentState> codec(ServerWorld world) {
return Codec.of(new Encoder<>() {
@Override
public <T> DataResult<T> encode(AttachmentPersistentState input, DynamicOps<T> ops, T prefix) {
NbtCompound nbtCompound = new NbtCompound();
((AttachmentTargetImpl) world).fabric_writeAttachmentsToNbt(nbtCompound, world.getRegistryManager());
return DataResult.success((T) nbtCompound);
}
}, new Decoder<>() {
@Override
public <T> DataResult<Pair<AttachmentPersistentState, T>> decode(DynamicOps<T> ops, T input) {
((AttachmentTargetImpl) world).fabric_readAttachmentsFromNbt((NbtCompound) ops.convertTo(NbtOps.INSTANCE, input), world.getRegistryManager());
return DataResult.success(Pair.of(new AttachmentPersistentState(world), ops.empty()));
}
});
}

@Override
public boolean isDirty() {
// Only write data if there are attachments, or if we previously wrote data.
return wasSerialized || worldTarget.fabric_hasPersistentAttachments();
}

@Override
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
worldTarget.fabric_writeAttachmentsToNbt(nbt, wrapperLookup);
return nbt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.class_10741;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.MutableWorldProperties;
import net.minecraft.world.PersistentState;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;

Expand Down Expand Up @@ -65,12 +65,13 @@ protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey<World>
private void createAttachmentsPersistentState(CallbackInfo ci) {
// Force persistent state creation
ServerWorld world = (ServerWorld) (Object) this;
var type = new PersistentState.Type<>(
var type = new class_10741<>(
AttachmentPersistentState.ID,
() -> new AttachmentPersistentState(world),
(nbt, wrapperLookup) -> AttachmentPersistentState.read(world, nbt, server.getRegistryManager()),
AttachmentPersistentState.codec(world),
null // Object builder API 12.1.0 and later makes this a no-op
);
world.getPersistentStateManager().getOrCreate(type, AttachmentPersistentState.ID);
world.getPersistentStateManager().getOrCreate(type);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,25 @@ void testBlockEntityPersistence() {
@Test
void testWorldPersistentState() {
// Trying to simulate actual saving and loading for the world is too hard
DynamicRegistryManager drm = mockDRM();

ServerWorld world = mockAndDisableSync(ServerWorld.class);
when(world.getRegistryManager()).thenReturn(drm);

AttachmentPersistentState state = new AttachmentPersistentState(world);
assertFalse(world.hasAttached(PERSISTENT));
assertFalse(state.isDirty());

int expected = 1;
world.setAttached(PERSISTENT, expected);
NbtCompound fakeSave = state.writeNbt(new NbtCompound(), mockDRM());
assertTrue(state.isDirty());
NbtCompound fakeSave = (NbtCompound) AttachmentPersistentState.codec(world).encodeStart(RegistryOps.of(NbtOps.INSTANCE, drm), state).getOrThrow();
assertEquals("{\"fabric:attachments\":{\"example:persistent\":1}}", fakeSave.toString());

world = mockAndDisableSync(ServerWorld.class);
AttachmentPersistentState.read(world, fakeSave, mockDRM());
when(world.getRegistryManager()).thenReturn(drm);

AttachmentPersistentState.codec(world).decode(RegistryOps.of(NbtOps.INSTANCE, drm), fakeSave).getOrThrow();
assertTrue(world.hasAttached(PERSISTENT));
assertEquals(expected, world.getAttached(PERSISTENT));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void beforeDamage(ServerWorld world, DamageSource source, float amount,
}

@Inject(method = "damage", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD)
private void afterDamage(ServerWorld world, DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir, float dealt, boolean blocked) {
private void afterDamage(ServerWorld world, DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir, float dealt, float f, boolean blocked) {
if (!isDead()) {
ServerLivingEntityEvents.AFTER_DAMAGE.invoker().afterDamage((LivingEntity) (Object) this, source, dealt, amount, blocked);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
Expand Down Expand Up @@ -145,7 +144,7 @@ TestData<RegistryEntry<TestEnvironmentDefinition>> testData(Registry<TestEnviron

TestInstance testInstance(Registry<TestEnvironmentDefinition> testEnvironmentDefinitionRegistry) {
return new FunctionTestInstance(
Registries.TEST_FUNCTION.getEntry(identifier()).get(),
RegistryKey.of(RegistryKeys.TEST_FUNCTION, identifier()),
testData(testEnvironmentDefinitionRegistry)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.class_10721;
import net.minecraft.client.render.TexturedRenderLayers;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.util.SpriteMapper;
import net.minecraft.util.Identifier;

import net.fabricmc.fabric.impl.object.builder.client.SignTypeTextureHelper;
Expand All @@ -36,13 +36,13 @@ private static void onReturnClinit(CallbackInfo ci) {
SignTypeTextureHelper.shouldAddTextures = true;
}

@Redirect(method = "createSignTextureId", at = @At(value = "INVOKE", target = "Lnet/minecraft/class_10721;method_67274(Ljava/lang/String;)Lnet/minecraft/client/util/SpriteIdentifier;"))
private static SpriteIdentifier redirectSignVanillaId(class_10721 instance, String name) {
return instance.method_67273(Identifier.of(name));
@Redirect(method = "createSignTextureId", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/SpriteMapper;mapVanilla(Ljava/lang/String;)Lnet/minecraft/client/util/SpriteIdentifier;"))
private static SpriteIdentifier redirectSignVanillaId(SpriteMapper instance, String name) {
return instance.map(Identifier.of(name));
}

@Redirect(method = "createHangingSignTextureId", at = @At(value = "INVOKE", target = "Lnet/minecraft/class_10721;method_67274(Ljava/lang/String;)Lnet/minecraft/client/util/SpriteIdentifier;"))
private static SpriteIdentifier redirectHangingVanillaId(class_10721 instance, String name) {
return instance.method_67273(Identifier.of(name));
@Redirect(method = "createHangingSignTextureId", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/SpriteMapper;mapVanilla(Ljava/lang/String;)Lnet/minecraft/client/util/SpriteIdentifier;"))
private static SpriteIdentifier redirectHangingVanillaId(SpriteMapper instance, String name) {
return instance.map(Identifier.of(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ abstract class WoodTypeMixin {
private static void onReturnRegister(WoodType type, CallbackInfoReturnable<WoodType> cir) {
if (SignTypeTextureHelper.shouldAddTextures) {
final Identifier identifier = Identifier.of(type.name());
TexturedRenderLayers.SIGN_TYPE_TEXTURES.put(type, TexturedRenderLayers.field_56363.method_67273(identifier));
TexturedRenderLayers.HANGING_SIGN_TYPE_TEXTURES.put(type, TexturedRenderLayers.field_56364.method_67273(identifier));
TexturedRenderLayers.SIGN_TYPE_TEXTURES.put(type, TexturedRenderLayers.SIGN_SPRITE_MAPPER.map(identifier));
TexturedRenderLayers.HANGING_SIGN_TYPE_TEXTURES.put(type, TexturedRenderLayers.HANGING_SIGN_SPRITE_MAPPER.map(identifier));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import java.util.Objects;

import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import net.minecraft.class_10741;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.PersistentState;

Expand All @@ -44,10 +46,13 @@ private static class TestState extends PersistentState {
/**
* We are testing that null can be passed as the dataFixType.
*/
private static final PersistentState.Type<TestState> TYPE = new Type<>(TestState::new, TestState::fromTag, null);
private static final Codec<TestState> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.fieldOf("value").forGetter(TestState::getValue)
).apply(instance, TestState::new));
private static final class_10741<TestState> TYPE = new class_10741<>(ObjectBuilderTestConstants.id("test_state").toString().replace(":", "_"), TestState::new, CODEC, null);

public static TestState getOrCreate(ServerWorld world) {
return world.getPersistentStateManager().getOrCreate(TestState.TYPE, ObjectBuilderTestConstants.id("test_state").toString().replace(":", "_"));
return world.getPersistentStateManager().getOrCreate(TestState.TYPE);
}

private String value = "";
Expand All @@ -67,15 +72,5 @@ public void setValue(String value) {
this.value = value;
markDirty();
}

@Override
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
nbt.putString("value", value);
return nbt;
}

private static TestState fromTag(NbtCompound tag, RegistryWrapper.WrapperLookup wrapperLookup) {
return new TestState(tag.getString("value"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@Mixin(AtlasSourceManager.class)
public interface AtlasSourceManagerAccessor {
@Accessor("field_56377")
@Accessor("ID_MAPPER")
static Codecs.IdMapper<Identifier, MapCodec<? extends AtlasSource>> getAtlasSourceCodecs() {
throw new AssertionError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void load(ResourceManager resourceManager, SpriteRegions regions) {
}

@Override
public MapCodec<? extends AtlasSource> method_67288() {
public MapCodec<? extends AtlasSource> getCodec() {
return CODEC;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import net.minecraft.class_10712;
import net.minecraft.component.ComponentChanges;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.TooltipDisplayComponent;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.util.Unit;
Expand All @@ -48,7 +48,7 @@ public void testFlowing() {
@Test
public void testWithComponentChanges() {
FluidVariant variant = FluidVariant.of(Fluids.WATER, ComponentChanges.builder()
.add(DataComponentTypes.TOOLTIP_DISPLAY, class_10712.field_56318)
.add(DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplayComponent.DEFAULT)
.build());

FluidVariant newVariant = variant.withComponentChanges(ComponentChanges.builder()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2560M
org.gradle.parallel=true

version=0.115.1
minecraft_version=25w04a
minecraft_version=25w05a
yarn_version=+build.1
loader_version=0.16.10
installer_version=1.0.1
Expand Down

0 comments on commit 2dd063d

Please sign in to comment.