Skip to content

Commit

Permalink
24w07a
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Feb 14, 2024
1 parent 44ed7ba commit 548b1e1
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,33 @@

package net.fabricmc.fabric.test.biome;

import net.minecraft.registry.Registerable;
import net.minecraft.registry.RegistryBuilder;
import net.minecraft.registry.RegistryEntryLookup;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.ConfiguredFeatures;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.PlacedFeature;
import net.minecraft.world.gen.feature.PlacedFeatures;
import net.minecraft.world.gen.placementmodifier.BiomePlacementModifier;
import net.minecraft.world.gen.placementmodifier.SquarePlacementModifier;

import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;

public class DataGeneratorEntrypoint implements net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint {
public static final RegistryKey<ConfiguredFeature<?, ?>> COMMON_DESERT_WELL = RegistryKey.of(
RegistryKeys.CONFIGURED_FEATURE,
new Identifier(FabricBiomeTest.MOD_ID, "fab_desert_well")
);
public static final RegistryKey<PlacedFeature> PLACED_COMMON_DESERT_WELL = RegistryKey.of(
RegistryKeys.PLACED_FEATURE,
new Identifier(FabricBiomeTest.MOD_ID, "fab_desert_well")
);

@Override
public void onInitializeDataGenerator(FabricDataGenerator dataGenerator) {
FabricDataGenerator.Pack pack = dataGenerator.createPack();
Expand All @@ -31,6 +52,24 @@ public void onInitializeDataGenerator(FabricDataGenerator dataGenerator) {

@Override
public void buildRegistry(RegistryBuilder registryBuilder) {
registryBuilder.addRegistry(RegistryKeys.CONFIGURED_FEATURE, this::bootstrapConfiguredFeatures);
registryBuilder.addRegistry(RegistryKeys.PLACED_FEATURE, this::bootstrapPlacedFeatures);
registryBuilder.addRegistry(RegistryKeys.BIOME, TestBiomes::bootstrap);
}

private void bootstrapConfiguredFeatures(Registerable<ConfiguredFeature<?, ?>> registerable) {
ConfiguredFeatures.register(registerable, COMMON_DESERT_WELL, Feature.DESERT_WELL);
}

private void bootstrapPlacedFeatures(Registerable<PlacedFeature> registerable) {
RegistryEntryLookup<ConfiguredFeature<?, ?>> configuredFeatures = registerable.getRegistryLookup(RegistryKeys.CONFIGURED_FEATURE);
RegistryEntry<ConfiguredFeature<?, ?>> commonDesertWell = configuredFeatures.getOrThrow(COMMON_DESERT_WELL);

// The placement config is taken from the vanilla desert well, but no randomness
PlacedFeatures.register(registerable, PLACED_COMMON_DESERT_WELL, commonDesertWell,
SquarePlacementModifier.of(),
PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP,
BiomePlacementModifier.of()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package net.fabricmc.fabric.test.biome;

import static net.fabricmc.fabric.test.biome.DataGeneratorEntrypoint.PLACED_COMMON_DESERT_WELL;

import com.google.common.base.Preconditions;

import net.minecraft.registry.RegistryKey;
Expand All @@ -25,8 +27,6 @@
import net.minecraft.world.biome.BiomeKeys;
import net.minecraft.world.biome.source.util.MultiNoiseUtil;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.PlacedFeature;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
Expand All @@ -48,15 +48,6 @@
public class FabricBiomeTest implements ModInitializer {
public static final String MOD_ID = "fabric-biome-api-v1-testmod";

public static final RegistryKey<ConfiguredFeature<?, ?>> COMMON_DESERT_WELL = RegistryKey.of(
RegistryKeys.CONFIGURED_FEATURE,
new Identifier(FabricBiomeTest.MOD_ID, "fab_desert_well")
);
public static final RegistryKey<PlacedFeature> PLACED_COMMON_DESERT_WELL = RegistryKey.of(
RegistryKeys.PLACED_FEATURE,
new Identifier(FabricBiomeTest.MOD_ID, "fab_desert_well")
);

@Override
public void onInitialize() {
Preconditions.checkArgument(NetherBiomes.canGenerateInNether(BiomeKeys.NETHER_WASTES));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,10 @@

package net.fabricmc.fabric.test.biome;

import java.util.List;
import java.util.concurrent.CompletableFuture;

import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.PlacedFeature;
import net.minecraft.world.gen.feature.PlacedFeatures;
import net.minecraft.world.gen.placementmodifier.BiomePlacementModifier;
import net.minecraft.world.gen.placementmodifier.SquarePlacementModifier;

import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider;
Expand All @@ -41,17 +31,9 @@ public WorldgenProvider(FabricDataOutput output, CompletableFuture<RegistryWrapp

@Override
protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) {
final RegistryWrapper.Impl<Biome> biomeRegistry = registries.getWrapperOrThrow(RegistryKeys.BIOME);

entries.addAll(biomeRegistry);

ConfiguredFeature<?, ?> COMMON_DESERT_WELL = new ConfiguredFeature<>(Feature.DESERT_WELL, DefaultFeatureConfig.INSTANCE);

RegistryEntry<ConfiguredFeature<?, ?>> featureRef = entries.add(FabricBiomeTest.COMMON_DESERT_WELL, COMMON_DESERT_WELL);

// The placement config is taken from the vanilla desert well, but no randomness
PlacedFeature PLACED_COMMON_DESERT_WELL = new PlacedFeature(featureRef, List.of(SquarePlacementModifier.of(), PlacedFeatures.MOTION_BLOCKING_HEIGHTMAP, BiomePlacementModifier.of()));
entries.add(FabricBiomeTest.PLACED_COMMON_DESERT_WELL, PLACED_COMMON_DESERT_WELL);
entries.addAll(registries.getWrapperOrThrow(RegistryKeys.BIOME));
entries.add(registries.getWrapperOrThrow(RegistryKeys.CONFIGURED_FEATURE), DataGeneratorEntrypoint.COMMON_DESERT_WELL);
entries.add(registries.getWrapperOrThrow(RegistryKeys.PLACED_FEATURE), DataGeneratorEntrypoint.PLACED_COMMON_DESERT_WELL);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package net.fabricmc.fabric.mixin.content.registry;

import com.llamalad7.mixinextras.sugar.Local;
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.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import net.minecraft.block.BlockState;
import net.minecraft.entity.ai.pathing.LandPathNodeMaker;
Expand All @@ -36,8 +36,8 @@ public class LandPathNodeMakerMixin {
/**
* Overrides the node type for the specified position, if the position is a direct target in a path.
*/
@Inject(method = "getCommonNodeType", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/BlockView;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private static void getCommonNodeType(BlockView world, BlockPos pos, CallbackInfoReturnable<PathNodeType> cir, BlockState state) {
@Inject(method = "getCommonNodeType", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getBlock()Lnet/minecraft/block/Block;"), cancellable = true)
private static void getCommonNodeType(BlockView world, BlockPos pos, CallbackInfoReturnable<PathNodeType> cir, @Local BlockState state) {
PathNodeType nodeType = LandPathNodeTypesRegistry.getPathNodeType(state, world, pos, false);

if (nodeType != null) {
Expand All @@ -48,9 +48,9 @@ private static void getCommonNodeType(BlockView world, BlockPos pos, CallbackInf
/**
* Overrides the node type for the specified position, if the position is found as neighbor block in a path.
*/
@Inject(method = "getNodeTypeFromNeighbors", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/BlockView;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private static void getNodeTypeFromNeighbors(BlockView world, BlockPos.Mutable pos, PathNodeType nodeType, CallbackInfoReturnable<PathNodeType> cir, int i, int j, int k, int l, int m, int n, BlockState state) {
PathNodeType neighborNodeType = LandPathNodeTypesRegistry.getPathNodeType(state, world, pos, true);
@Inject(method = "getNodeTypeFromNeighbors", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/ai/pathing/LandPathNodeMaker;getCommonNodeType(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/entity/ai/pathing/PathNodeType;"), cancellable = true)
private static void getNodeTypeFromNeighbors(BlockView world, BlockPos.Mutable pos, PathNodeType nodeType, CallbackInfoReturnable<PathNodeType> cir) {
PathNodeType neighborNodeType = LandPathNodeTypesRegistry.getPathNodeType(world.getBlockState(pos), world, pos, true);

if (neighborNodeType != null) {
cir.setReturnValue(neighborNodeType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void serializeAttachmentData(NbtCompound nbt, RegistryWrapper.Wrap
Codec<Object> codec = (Codec<Object>) type.persistenceCodec();

if (codec != null) {
RegistryOps<NbtElement> registryOps = RegistryOps.of(NbtOps.INSTANCE, wrapperLookup);
RegistryOps<NbtElement> registryOps = wrapperLookup.method_57093(NbtOps.INSTANCE);
codec.encodeStart(registryOps, entry.getValue())
.get()
.ifRight(partial -> {
Expand Down Expand Up @@ -81,7 +81,7 @@ public static IdentityHashMap<AttachmentType<?>, Object> deserializeAttachmentDa
Codec<?> codec = type.persistenceCodec();

if (codec != null) {
RegistryOps<NbtElement> registryOps = RegistryOps.of(NbtOps.INSTANCE, wrapperLookup);
RegistryOps<NbtElement> registryOps = wrapperLookup.method_57093(NbtOps.INSTANCE);
codec.parse(registryOps, compound.get(key))
.get()
.ifRight(partial -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import java.util.IdentityHashMap;
import java.util.Map;
Expand All @@ -45,9 +45,13 @@
import net.minecraft.entity.MarkerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtOps;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.RegistryOps;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.ProtoChunk;
import net.minecraft.world.chunk.WorldChunk;

Expand Down Expand Up @@ -134,11 +138,11 @@ void testStaticReadWrite() {
map.put(dummy, 0.5d);
var fakeSave = new NbtCompound();

AttachmentSerializingImpl.serializeAttachmentData(fakeSave, null, map);
AttachmentSerializingImpl.serializeAttachmentData(fakeSave, mockDRM(), map);
assertTrue(fakeSave.contains(AttachmentTarget.NBT_ATTACHMENT_KEY, NbtElement.COMPOUND_TYPE));
assertTrue(fakeSave.getCompound(AttachmentTarget.NBT_ATTACHMENT_KEY).contains(dummy.identifier().toString()));

map = AttachmentSerializingImpl.deserializeAttachmentData(fakeSave, null);
map = AttachmentSerializingImpl.deserializeAttachmentData(fakeSave, mockDRM());
assertEquals(1, map.size());
Map.Entry<AttachmentType<?>, Object> entry = map.entrySet().stream().findFirst().orElseThrow();
// in this case the key should be the exact same object
Expand All @@ -150,19 +154,19 @@ void testStaticReadWrite() {
@Test
void deserializeNull() {
var nbt = new NbtCompound();
assertNull(AttachmentSerializingImpl.deserializeAttachmentData(nbt, null));
assertNull(AttachmentSerializingImpl.deserializeAttachmentData(nbt, mockDRM()));

nbt.put(new Identifier("test").toString(), new NbtCompound());
assertNull(AttachmentSerializingImpl.deserializeAttachmentData(nbt, null));
assertNull(AttachmentSerializingImpl.deserializeAttachmentData(nbt, mockDRM()));
}

@Test
void serializeNullOrEmpty() {
var nbt = new NbtCompound();
AttachmentSerializingImpl.serializeAttachmentData(nbt, null, null);
AttachmentSerializingImpl.serializeAttachmentData(nbt, mockDRM(), null);
assertFalse(nbt.contains(AttachmentTarget.NBT_ATTACHMENT_KEY));

AttachmentSerializingImpl.serializeAttachmentData(nbt, null, new IdentityHashMap<>());
AttachmentSerializingImpl.serializeAttachmentData(nbt, mockDRM(), new IdentityHashMap<>());
assertFalse(nbt.contains(AttachmentTarget.NBT_ATTACHMENT_KEY));
}

Expand Down Expand Up @@ -192,17 +196,19 @@ void testEntityCopy() {

@Test
void testEntityPersistence() {
Entity entity = new MarkerEntity(EntityType.MARKER, mock());
DynamicRegistryManager drm = mockDRM();
World mockWorld = mock(World.class);
when(mockWorld.getRegistryManager()).thenReturn(drm);
Entity entity = new MarkerEntity(EntityType.MARKER, mockWorld);
assertFalse(entity.hasAttached(PERSISTENT));

int expected = 1;
entity.setAttached(PERSISTENT, expected);
NbtCompound fakeSave = new NbtCompound();
entity.writeNbt(fakeSave);

entity = spy(new MarkerEntity(EntityType.MARKER, mock())); // fresh object, like on restart
entity = new MarkerEntity(EntityType.MARKER, mockWorld); // fresh object, like on restart
entity.setChangeListener(mock());
doNothing().when(entity).calculateDimensions();
entity.readNbt(fakeSave);
assertTrue(entity.hasAttached(PERSISTENT));
assertEquals(expected, entity.getAttached(PERSISTENT));
Expand All @@ -215,9 +221,9 @@ void testBlockEntityPersistence() {

int expected = 1;
blockEntity.setAttached(PERSISTENT, expected);
NbtCompound fakeSave = blockEntity.createNbtWithId(null);
NbtCompound fakeSave = blockEntity.createNbtWithId(mockDRM());

blockEntity = BlockEntity.createFromNbt(BlockPos.ORIGIN, mock(), fakeSave, null);
blockEntity = BlockEntity.createFromNbt(BlockPos.ORIGIN, mock(), fakeSave, mockDRM());
assertNotNull(blockEntity);
assertTrue(blockEntity.hasAttached(PERSISTENT));
assertEquals(expected, blockEntity.getAttached(PERSISTENT));
Expand All @@ -232,10 +238,10 @@ void testWorldPersistentState() {

int expected = 1;
world.setAttached(PERSISTENT, expected);
NbtCompound fakeSave = state.writeNbt(new NbtCompound(), null);
NbtCompound fakeSave = state.writeNbt(new NbtCompound(), mockDRM());

world = mock(ServerWorld.class, CALLS_REAL_METHODS);
AttachmentPersistentState.read(world, fakeSave, null);
AttachmentPersistentState.read(world, fakeSave, mockDRM());
assertTrue(world.hasAttached(PERSISTENT));
assertEquals(expected, world.getAttached(PERSISTENT));
}
Expand All @@ -244,4 +250,10 @@ void testWorldPersistentState() {
* Chunk serializing is coupled with world saving in ChunkSerializer which is too much of a pain to mock,
* so testing is handled by the testmod instead.
*/

private static DynamicRegistryManager mockDRM() {
DynamicRegistryManager drm = mock(DynamicRegistryManager.class);
when(drm.method_57093(any())).thenReturn((RegistryOps<Object>) (Object) RegistryOps.of(NbtOps.INSTANCE, drm));
return drm;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public CompletableFuture<?> run(DataWriter writer) {
generateAdvancement(advancements::add);

return this.registryLookup.thenCompose(lookup -> {
RegistryOps<JsonElement> ops = RegistryOps.of(JsonOps.INSTANCE, lookup);
RegistryOps<JsonElement> ops = lookup.method_57093(JsonOps.INSTANCE);
final List<CompletableFuture<?>> futures = new ArrayList<>();

for (AdvancementEntry advancement : advancements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected FabricCodecDataProvider(FabricDataOutput dataOutput, CompletableFuture
public CompletableFuture<?> run(DataWriter writer) {
return this.registriesFuture.thenCompose(lookup -> {
Map<Identifier, JsonElement> entries = new HashMap<>();
RegistryOps<JsonElement> ops = RegistryOps.of(JsonOps.INSTANCE, lookup);
RegistryOps<JsonElement> ops = lookup.method_57093(JsonOps.INSTANCE);

BiConsumer<Identifier, T> provider = (id, value) -> {
JsonElement json = this.convert(id, value, ops);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public CompletableFuture<?> run(DataWriter writer) {
return entries;
})
.thenCompose(entries -> {
final RegistryOps<JsonElement> dynamicOps = RegistryOps.of(JsonOps.INSTANCE, registries);
final RegistryOps<JsonElement> dynamicOps = registries.method_57093(JsonOps.INSTANCE);
ArrayList<CompletableFuture<?>> futures = new ArrayList<>();

for (RegistryEntries<?> registryEntries : entries.queuedEntries.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void accept(Identifier recipeId, Recipe<?> recipe, @Nullable AdvancementE
throw new IllegalStateException("Duplicate recipe " + identifier);
}

RegistryOps<JsonElement> registryOps = RegistryOps.of(JsonOps.INSTANCE, wrapperLookup);
RegistryOps<JsonElement> registryOps = wrapperLookup.method_57093(JsonOps.INSTANCE);
JsonObject recipeJson = Util.getResult(Recipe.CODEC.encodeStart(registryOps, recipe), IllegalStateException::new).getAsJsonObject();
ConditionJsonProvider[] conditions = FabricDataGenHelper.consumeConditions(recipe);
ConditionJsonProvider.write(recipeJson, conditions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static CompletableFuture<?> run(
});

return registryLookup.thenCompose(lookup -> {
RegistryOps<JsonElement> ops = RegistryOps.of(JsonOps.INSTANCE, lookup);
RegistryOps<JsonElement> ops = lookup.method_57093(JsonOps.INSTANCE);
final List<CompletableFuture<?>> futures = new ArrayList<>();

for (Map.Entry<Identifier, LootTable> entry : builders.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private static void getTestFunction(Method method, CallbackInfoReturnable<TestFu
gameTest.required(),
gameTest.requiredSuccesses(),
gameTest.maxAttempts(),
gameTest.method_57098(),
FabricGameTestHelper.getTestMethodInvoker(method)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public BoxBlockEntity(BlockPos blockPos, BlockState blockState) {
}

@Override
protected DefaultedList<ItemStack> method_11282() {
protected DefaultedList<ItemStack> getHeldStacks() {
return items;
}

@Override
protected void setInvStackList(DefaultedList<ItemStack> list) {
protected void setHeldStacks(DefaultedList<ItemStack> list) {
this.items = list;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void testBadBrewingStandIsValid(TestContext context) {
/**
* Regression test for <a href="https://github.com/FabricMC/fabric/issues/2810">double chest wrapper only updating modified halves</a>.
*/
@GameTest(templateName = "fabric-transfer-api-v1-testmod:double_chest_comparators")
@GameTest(templateName = "fabric-transfer-api-v1-testmod:double_chest_comparators", method_57098 = true)
public void testDoubleChestComparator(TestContext context) {
BlockPos chestPos = new BlockPos(2, 2, 2);
Storage<ItemVariant> storage = ItemStorage.SIDED.find(context.getWorld(), context.getAbsolutePos(chestPos), Direction.UP);
Expand Down

0 comments on commit 548b1e1

Please sign in to comment.