Skip to content

Commit

Permalink
24w13a (#3676)
Browse files Browse the repository at this point in the history
Fixes #3669

Co-authored-by: Drex <[email protected]>
  • Loading branch information
modmuss50 and DrexHD authored Mar 27, 2024
1 parent e78eae2 commit b21c00c
Show file tree
Hide file tree
Showing 32 changed files with 145 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.function.Supplier;

import com.google.common.base.Suppliers;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -49,7 +49,7 @@ public class TheEndBiomeSourceMixin extends BiomeSourceMixin {
@Shadow
@Mutable
@Final
static Codec<TheEndBiomeSource> CODEC;
static MapCodec<TheEndBiomeSource> CODEC;

@Unique
private Supplier<TheEndBiomeData.Overrides> overrides;
Expand All @@ -66,7 +66,7 @@ public class TheEndBiomeSourceMixin extends BiomeSourceMixin {
*/
@Inject(method = "<clinit>", at = @At("TAIL"))
private static void modifyCodec(CallbackInfo ci) {
CODEC = RecordCodecBuilder.create((instance) -> {
CODEC = RecordCodecBuilder.mapCodec((instance) -> {
return instance.group(RegistryOps.getEntryLookupCodec(RegistryKeys.BIOME)).apply(instance, instance.stable(TheEndBiomeSource::createVanilla));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"minecraft:suspicious_stew",
"minecraft:sweet_berries",
"minecraft:glow_berries",
"minecraft:honey_bottle"
"minecraft:honey_bottle",
"minecraft:ominous_bottle"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ public static void serializeAttachmentData(NbtCompound nbt, RegistryWrapper.Wrap
if (codec != null) {
RegistryOps<NbtElement> registryOps = wrapperLookup.getOps(NbtOps.INSTANCE);
codec.encodeStart(registryOps, entry.getValue())
.get()
.ifRight(partial -> {
.ifError(partial -> {
LOGGER.warn("Couldn't serialize attachment " + type.identifier() + ", skipping. Error:");
LOGGER.warn(partial.message());
})
.ifLeft(serialized -> compound.put(type.identifier().toString(), serialized));
.ifSuccess(serialized -> compound.put(type.identifier().toString(), serialized));
}
}

Expand All @@ -83,12 +82,11 @@ public static IdentityHashMap<AttachmentType<?>, Object> deserializeAttachmentDa
if (codec != null) {
RegistryOps<NbtElement> registryOps = wrapperLookup.getOps(NbtOps.INSTANCE);
codec.parse(registryOps, compound.get(key))
.get()
.ifRight(partial -> {
.ifError(partial -> {
LOGGER.warn("Couldn't deserialize attachment " + type.identifier() + ", skipping. Error:");
LOGGER.warn(partial.message());
})
.ifLeft(
.ifSuccess(
deserialized -> attachments.put(type, deserialized)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
abstract class BlockEntityMixin implements AttachmentTargetImpl {
@Inject(
method = "method_17897", // lambda body in BlockEntity#createFromNbt
at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;readNbt(Lnet/minecraft/nbt/NbtCompound;Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;)V")
at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;method_58690(Lnet/minecraft/nbt/NbtCompound;Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;)V")
)
private static void readBlockEntityAttachments(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup, String string, BlockEntity blockEntity, CallbackInfoReturnable<BlockEntity> cir) {
((AttachmentTargetImpl) blockEntity).fabric_readAttachmentsFromNbt(nbt, wrapperLookup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import net.minecraft.registry.RegistryOps;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
Expand Down Expand Up @@ -94,7 +93,7 @@ public CompletableFuture<?> run(DataWriter writer) {
throw new IllegalStateException("Duplicate advancement " + advancement.id());
}

JsonObject advancementJson = Util.getResult(Advancement.CODEC.encodeStart(ops, advancement.value()), IllegalStateException::new).getAsJsonObject();
JsonObject advancementJson = Advancement.CODEC.encodeStart(ops, advancement.value()).getOrThrow(IllegalStateException::new).getAsJsonObject();
ConditionJsonProvider.write(advancementJson, FabricDataGenHelper.consumeConditions(advancement));
futures.add(DataProvider.writeToPath(writer, advancementJson, getOutputPath(advancement)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public CompletableFuture<?> run(DataWriter writer) {

private JsonElement convert(Identifier id, T value, DynamicOps<JsonElement> ops) {
DataResult<JsonElement> dataResult = this.codec.encodeStart(ops, value);
return dataResult.get()
.mapRight(partial -> "Invalid entry %s: %s".formatted(id, partial.message()))
.orThrow();
return dataResult
.mapError(message -> "Invalid entry %s: %s".formatted(id, message))
.getOrThrow();
}

private CompletableFuture<?> write(DataWriter writer, Map<Identifier, JsonElement> entries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import net.minecraft.registry.RegistryOps;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
Expand Down Expand Up @@ -100,14 +99,14 @@ public void accept(Identifier recipeId, Recipe<?> recipe, @Nullable AdvancementE
}

RegistryOps<JsonElement> registryOps = wrapperLookup.getOps(JsonOps.INSTANCE);
JsonObject recipeJson = Util.getResult(Recipe.CODEC.encodeStart(registryOps, recipe), IllegalStateException::new).getAsJsonObject();
JsonObject recipeJson = Recipe.CODEC.encodeStart(registryOps, recipe).getOrThrow(IllegalStateException::new).getAsJsonObject();
ConditionJsonProvider[] conditions = FabricDataGenHelper.consumeConditions(recipe);
ConditionJsonProvider.write(recipeJson, conditions);

list.add(DataProvider.writeToPath(writer, recipeJson, recipesPathResolver.resolveJson(identifier)));

if (advancement != null) {
JsonObject advancementJson = Util.getResult(Advancement.CODEC.encodeStart(registryOps, advancement.value()), IllegalStateException::new).getAsJsonObject();
JsonObject advancementJson = Advancement.CODEC.encodeStart(registryOps, advancement.value()).getOrThrow(IllegalStateException::new).getAsJsonObject();
ConditionJsonProvider.write(advancementJson, conditions);
list.add(DataProvider.writeToPath(writer, advancementJson, advancementsPathResolver.resolveJson(getRecipeIdentifier(advancement.id()))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import net.minecraft.registry.RegistryOps;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;
Expand Down Expand Up @@ -72,7 +71,7 @@ public static CompletableFuture<?> run(
final List<CompletableFuture<?>> futures = new ArrayList<>();

for (Map.Entry<Identifier, LootTable> entry : builders.entrySet()) {
JsonObject tableJson = (JsonObject) Util.getResult(LootTable.CODEC.encodeStart(ops, entry.getValue()), IllegalStateException::new);
JsonObject tableJson = (JsonObject) LootTable.CODEC.encodeStart(ops, entry.getValue()).getOrThrow(IllegalStateException::new);
ConditionJsonProvider.write(tableJson, conditionMap.remove(entry.getKey()));
futures.add(DataProvider.writeToPath(writer, tableJson, getOutputPath(fabricDataOutput, entry.getKey())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package net.fabricmc.fabric.impl.dimension;

import java.util.Map;
import java.util.Optional;

import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.util.Pair;
Expand Down Expand Up @@ -65,15 +66,19 @@ public <T> DataResult<Map<K, V>> decode(final DynamicOps<T> ops, final MapLike<T
final DataResult<K> k = keyCodec().parse(ops, pair.getFirst());
final DataResult<V> v = elementCodec().parse(ops, pair.getSecond());

k.get().ifRight(kPartialResult -> {
LOGGER.error("Failed to decode key {} from {} {}", k, pair, kPartialResult);
});
v.get().ifRight(vPartialResult -> {
LOGGER.error("Failed to decode value {} from {} {}", v, pair, vPartialResult);
});
Optional<K> optionalK = k.result();
Optional<V> optionalV = v.result();

if (k.get().left().isPresent() && v.get().left().isPresent()) {
builder.put(k.get().left().get(), v.get().left().get());
if (optionalK.isEmpty()) {
LOGGER.error("Failed to decode key {} from {} {}", k, pair, k.resultOrPartial());
}

if (optionalV.isEmpty()) {
LOGGER.error("Failed to decode value {} from {} {}", k, pair, v.resultOrPartial());
}

if (optionalK.isPresent() && optionalV.isPresent()) {
builder.put(optionalK.get(), optionalV.get());
} else {
// ignore failure
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class TaggedChoiceTypeMixin<K> implements TaggedChoiceTypeExtension {
* This will avoid deserialization failure from DFU when upgrading level.dat that contains mod custom generator types.
*/
@Inject(
method = "getCodec", at = @At("HEAD"), cancellable = true, remap = false
method = "getMapCodec", at = @At("HEAD"), cancellable = true, remap = false
)
private void onGetCodec(K k, CallbackInfoReturnable<DataResult<? extends Codec<?>>> cir) {
if (failSoft) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import net.minecraft.block.BlockState;
Expand All @@ -44,7 +44,7 @@
import net.minecraft.world.gen.noise.NoiseConfig;

public class VoidChunkGenerator extends ChunkGenerator {
public static final Codec<VoidChunkGenerator> CODEC = RecordCodecBuilder.create((instance) ->
public static final MapCodec<VoidChunkGenerator> CODEC = RecordCodecBuilder.mapCodec((instance) ->
instance.group(RegistryOps.getEntryLookupCodec(RegistryKeys.BIOME))
.apply(instance, instance.stable(VoidChunkGenerator::new)));

Expand All @@ -53,7 +53,7 @@ public VoidChunkGenerator(RegistryEntryLookup<Biome> biomeRegistry) {
}

@Override
protected Codec<? extends ChunkGenerator> getCodec() {
protected MapCodec<? extends ChunkGenerator> getCodec() {
return CODEC;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void onInitialize() {
LootPool pool = LootPool.builder()
.with(ItemEntry.builder(Items.GOLD_INGOT).build())
.conditionally(SurvivesExplosionLootCondition.builder().build())
.apply(SetNameLootFunction.builder(Text.literal("Gold from White Wool")).build())
.apply(SetNameLootFunction.builder(Text.literal("Gold from White Wool"), SetNameLootFunction.class_9475.CUSTOM_NAME).build())
.build();

tableBuilder.pool(pool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ public FabricEntityTypeBuilder<T> requires(FeatureFlag... requiredFeatures) {
public EntityType<T> build() {
// Modded DFU is a dream, currently not possible without screwing it up.

return new FabricEntityType<>(this.factory, this.spawnGroup, this.saveable, this.summonable, this.fireImmune, this.spawnableFarFromPlayer, this.specificSpawnBlocks, dimensions, trackRange, trackedUpdateRate, forceTrackedVelocityUpdates, this.requiredFeatures);
//TODO 1.20.5, new field
return new FabricEntityType<>(this.factory, this.spawnGroup, this.saveable, this.summonable, this.fireImmune, this.spawnableFarFromPlayer, this.specificSpawnBlocks, dimensions, 1, trackRange, trackedUpdateRate, forceTrackedVelocityUpdates, this.requiredFeatures);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
public class FabricEntityType<T extends Entity> extends EntityType<T> {
private final Boolean alwaysUpdateVelocity;

public FabricEntityType(EntityType.EntityFactory<T> factory, SpawnGroup spawnGroup, boolean bl, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet<Block> spawnBlocks, EntityDimensions entityDimensions, int maxTrackDistance, int trackTickInterval, Boolean alwaysUpdateVelocity, FeatureSet featureSet) {
super(factory, spawnGroup, bl, summonable, fireImmune, spawnableFarFromPlayer, spawnBlocks, entityDimensions, maxTrackDistance, trackTickInterval, featureSet);
public FabricEntityType(EntityType.EntityFactory<T> factory, SpawnGroup spawnGroup, boolean bl, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet<Block> spawnBlocks, EntityDimensions entityDimensions, float field_50125, int maxTrackDistance, int trackTickInterval, Boolean alwaysUpdateVelocity, FeatureSet featureSet) {
super(factory, spawnGroup, bl, summonable, fireImmune, spawnableFarFromPlayer, spawnBlocks, entityDimensions, field_50125, maxTrackDistance, trackTickInterval, featureSet);
this.alwaysUpdateVelocity = alwaysUpdateVelocity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.function.Function;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;

import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
Expand Down Expand Up @@ -69,7 +70,7 @@ public static DefaultParticleType simple(boolean alwaysSpawn) {
* @param codec The codec for serialization.
* @param packetCodec The packet codec for network serialization.
*/
public static <T extends ParticleEffect> ParticleType<T> complex(ParticleEffect.Factory<T> factory, final Function<ParticleType<T>, Codec<T>> codecGetter, final Codec<T> codec, final PacketCodec<? super RegistryByteBuf, T> packetCodec) {
public static <T extends ParticleEffect> ParticleType<T> complex(ParticleEffect.Factory<T> factory, final Function<ParticleType<T>, Codec<T>> codecGetter, final MapCodec<T> codec, final PacketCodec<? super RegistryByteBuf, T> packetCodec) {
return complex(false, factory, codec, packetCodec);
}

Expand All @@ -81,10 +82,10 @@ public static <T extends ParticleEffect> ParticleType<T> complex(ParticleEffect.
* @param codec The codec for serialization.
* @param packetCodec The packet codec for network serialization.
*/
public static <T extends ParticleEffect> ParticleType<T> complex(boolean alwaysSpawn, ParticleEffect.Factory<T> factory, final Codec<T> codec, final PacketCodec<? super RegistryByteBuf, T> packetCodec) {
public static <T extends ParticleEffect> ParticleType<T> complex(boolean alwaysSpawn, ParticleEffect.Factory<T> factory, final MapCodec<T> codec, final PacketCodec<? super RegistryByteBuf, T> packetCodec) {
return new ParticleType<T>(alwaysSpawn, factory) {
@Override
public Codec<T> getCodec() {
public MapCodec<T> getCodec() {
return codec;
}

Expand All @@ -103,7 +104,7 @@ public PacketCodec<? super RegistryByteBuf, T> getPacketCodec() {
* @param codecGetter A function that, given the newly created type, returns the codec for serialization.
* @param packetCodecGetter A function that, given the newly created type, returns the packet codec for network serialization.
*/
public static <T extends ParticleEffect> ParticleType<T> complex(ParticleEffect.Factory<T> factory, final Function<ParticleType<T>, Codec<T>> codecGetter, final Function<ParticleType<T>, PacketCodec<? super RegistryByteBuf, T>> packetCodecGetter) {
public static <T extends ParticleEffect> ParticleType<T> complex(ParticleEffect.Factory<T> factory, final Function<ParticleType<T>, MapCodec<T>> codecGetter, final Function<ParticleType<T>, PacketCodec<? super RegistryByteBuf, T>> packetCodecGetter) {
return complex(false, factory, codecGetter, packetCodecGetter);
}

Expand All @@ -116,10 +117,10 @@ public static <T extends ParticleEffect> ParticleType<T> complex(ParticleEffect.
* @param codecGetter A function that, given the newly created type, returns the codec for serialization.
* @param packetCodecGetter A function that, given the newly created type, returns the packet codec for network serialization.
*/
public static <T extends ParticleEffect> ParticleType<T> complex(boolean alwaysSpawn, ParticleEffect.Factory<T> factory, final Function<ParticleType<T>, Codec<T>> codecGetter, final Function<ParticleType<T>, PacketCodec<? super RegistryByteBuf, T>> packetCodecGetter) {
public static <T extends ParticleEffect> ParticleType<T> complex(boolean alwaysSpawn, ParticleEffect.Factory<T> factory, final Function<ParticleType<T>, MapCodec<T>> codecGetter, final Function<ParticleType<T>, PacketCodec<? super RegistryByteBuf, T>> packetCodecGetter) {
return new ParticleType<T>(alwaysSpawn, factory) {
@Override
public Codec<T> getCodec() {
public MapCodec<T> getCodec() {
return codecGetter.apply(this);
}

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

package net.fabricmc.fabric.api.recipe.v1.ingredient;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import org.jetbrains.annotations.Nullable;

import net.minecraft.network.RegistryByteBuf;
Expand Down Expand Up @@ -64,7 +64,7 @@ static CustomIngredientSerializer<?> get(Identifier identifier) {
* @see Ingredient#ALLOW_EMPTY_CODEC
* @see Ingredient#DISALLOW_EMPTY_CODEC
*/
Codec<T> getCodec(boolean allowEmpty);
MapCodec<T> getCodec(boolean allowEmpty);

/**
* {@return the packet codec for serializing this ingredient}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;

import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
Expand All @@ -29,15 +30,14 @@
import net.fabricmc.fabric.api.recipe.v1.ingredient.CustomIngredientSerializer;

public class AllIngredient extends CombinedIngredient {
private static final Codec<AllIngredient> ALLOW_EMPTY_CODEC = createCodec(Ingredient.ALLOW_EMPTY_CODEC);
private static final Codec<AllIngredient> DISALLOW_EMPTY_CODEC = createCodec(Ingredient.DISALLOW_EMPTY_CODEC);
private static final MapCodec<AllIngredient> ALLOW_EMPTY_CODEC = createCodec(Ingredient.ALLOW_EMPTY_CODEC);
private static final MapCodec<AllIngredient> DISALLOW_EMPTY_CODEC = createCodec(Ingredient.DISALLOW_EMPTY_CODEC);

private static Codec<AllIngredient> createCodec(Codec<Ingredient> ingredientCodec) {
private static MapCodec<AllIngredient> createCodec(Codec<Ingredient> ingredientCodec) {
return ingredientCodec
.listOf()
.fieldOf("ingredients")
.xmap(AllIngredient::new, AllIngredient::getIngredients)
.codec();
.xmap(AllIngredient::new, AllIngredient::getIngredients);
}

public static final CustomIngredientSerializer<AllIngredient> SERIALIZER =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;

import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
Expand All @@ -29,15 +30,14 @@
import net.fabricmc.fabric.api.recipe.v1.ingredient.CustomIngredientSerializer;

public class AnyIngredient extends CombinedIngredient {
private static final Codec<AnyIngredient> ALLOW_EMPTY_CODEC = createCodec(Ingredient.ALLOW_EMPTY_CODEC);
private static final Codec<AnyIngredient> DISALLOW_EMPTY_CODEC = createCodec(Ingredient.DISALLOW_EMPTY_CODEC);
private static final MapCodec<AnyIngredient> ALLOW_EMPTY_CODEC = createCodec(Ingredient.ALLOW_EMPTY_CODEC);
private static final MapCodec<AnyIngredient> DISALLOW_EMPTY_CODEC = createCodec(Ingredient.DISALLOW_EMPTY_CODEC);

private static Codec<AnyIngredient> createCodec(Codec<Ingredient> ingredientCodec) {
private static MapCodec<AnyIngredient> createCodec(Codec<Ingredient> ingredientCodec) {
return ingredientCodec
.listOf()
.fieldOf("ingredients")
.xmap(AnyIngredient::new, AnyIngredient::getIngredients)
.codec();
.xmap(AnyIngredient::new, AnyIngredient::getIngredients);
}

public static final CustomIngredientSerializer<AnyIngredient> SERIALIZER =
Expand Down
Loading

0 comments on commit b21c00c

Please sign in to comment.