Skip to content

Commit

Permalink
24w34a (#4046)
Browse files Browse the repository at this point in the history
Co-authored-by: PepperCode1 <44146161+peppercode1@users.noreply.github.com>
  • Loading branch information
modmuss50 and PepperCode1 committed Aug 21, 2024
1 parent 236902d commit 2be8990
Show file tree
Hide file tree
Showing 39 changed files with 140 additions and 475 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,37 @@
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ChunkSerializer;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ProtoChunk;
import net.minecraft.world.chunk.SerializedChunk;
import net.minecraft.world.poi.PointOfInterestStorage;
import net.minecraft.world.storage.StorageKey;

import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget;
import net.fabricmc.fabric.impl.attachment.AttachmentTargetImpl;

@Mixin(ChunkSerializer.class)
abstract class ChunkSerializerMixin {
@Mixin(SerializedChunk.class)
abstract class SerializedChunkMixin {
// Adding a mutable record field like this is likely a bad idea, but I cannot see a better way.
@Unique
@Nullable
private NbtCompound attachmentNbtData;

@Inject(method = "method_61794", at = @At("RETURN"))
private static void storeAttachmentNbtData(HeightLimitView heightLimitView, DynamicRegistryManager dynamicRegistryManager, NbtCompound nbt, CallbackInfoReturnable<ChunkSerializer> cir, @Share("attachmentDataNbt") LocalRef<NbtCompound> attachmentDataNbt) {
final ChunkSerializer serializer = cir.getReturnValue();
@Inject(method = "fromNbt", at = @At("RETURN"))
private static void storeAttachmentNbtData(HeightLimitView heightLimitView, DynamicRegistryManager dynamicRegistryManager, NbtCompound nbt, CallbackInfoReturnable<SerializedChunk> cir, @Share("attachmentDataNbt") LocalRef<NbtCompound> attachmentDataNbt) {
final SerializedChunk serializer = cir.getReturnValue();

if (serializer == null) {
return;
}

if (nbt.contains(AttachmentTarget.NBT_ATTACHMENT_KEY, NbtElement.COMPOUND_TYPE)) {
((ChunkSerializerMixin) (Object) serializer).attachmentNbtData = nbt.getCompound(AttachmentTarget.NBT_ATTACHMENT_KEY);
((SerializedChunkMixin) (Object) serializer).attachmentNbtData = nbt.getCompound(AttachmentTarget.NBT_ATTACHMENT_KEY);
}
}

@Inject(method = "deserialize", at = @At("RETURN"))
@Inject(method = "convert", at = @At("RETURN"))
private void setAttachmentDataInChunk(ServerWorld serverWorld, PointOfInterestStorage pointOfInterestStorage, StorageKey storageKey, ChunkPos chunkPos, CallbackInfoReturnable<ProtoChunk> cir) {
ProtoChunk chunk = cir.getReturnValue();

Expand All @@ -71,11 +71,11 @@ private void setAttachmentDataInChunk(ServerWorld serverWorld, PointOfInterestSt
}
}

@Inject(method = "method_61793", at = @At("RETURN"))
private static void storeAttachmentNbtData(ServerWorld world, Chunk chunk, CallbackInfoReturnable<ChunkSerializer> cir) {
@Inject(method = "fromChunk", at = @At("RETURN"))
private static void storeAttachmentNbtData(ServerWorld world, Chunk chunk, CallbackInfoReturnable<SerializedChunk> cir) {
var nbt = new NbtCompound();
((AttachmentTargetImpl) chunk).fabric_writeAttachmentsToNbt(nbt, world.getRegistryManager());
((ChunkSerializerMixin) (Object) cir.getReturnValue()).attachmentNbtData = nbt.getCompound(AttachmentTarget.NBT_ATTACHMENT_KEY);
((SerializedChunkMixin) (Object) cir.getReturnValue()).attachmentNbtData = nbt.getCompound(AttachmentTarget.NBT_ATTACHMENT_KEY);
}

@Inject(method = "serialize", at = @At("RETURN"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"AttachmentTargetsMixin",
"BannerBlockEntityMixin",
"BlockEntityMixin",
"ChunkSerializerMixin",
"SerializedChunkMixin",
"EntityMixin",
"ServerWorldMixin",
"WorldChunkMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public void onInitialize() {
}

private static ArmorMaterial createTestArmorMaterial() {
return new ArmorMaterial(Util.make(new EnumMap<>(ArmorItem.Type.class), (map) -> {
map.put(ArmorItem.Type.BOOTS, 1);
map.put(ArmorItem.Type.LEGGINGS, 2);
map.put(ArmorItem.Type.CHESTPLATE, 3);
map.put(ArmorItem.Type.HELMET, 1);
map.put(ArmorItem.Type.BODY, 3);
}),
0,
return new ArmorMaterial(
Util.make(new EnumMap<>(ArmorItem.Type.class), (map) -> {
map.put(ArmorItem.Type.BOOTS, 1);
map.put(ArmorItem.Type.LEGGINGS, 2);
map.put(ArmorItem.Type.CHESTPLATE, 3);
map.put(ArmorItem.Type.HELMET, 1);
map.put(ArmorItem.Type.BODY, 3);
}),
SoundEvents.ITEM_ARMOR_EQUIP_LEATHER,
(stack) -> stack.getItem() == Items.LEATHER,
List.of(new ArmorMaterial.Layer(Identifier.of("fabric-item-api-v1-testmod", "wood"))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void onChunkUnload(int x, int z, PacketByteBuf buf, NbtCompound tag, Con
}
}

@Inject(method = "unload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientChunkManager$ClientChunkMap;compareAndSet(ILnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/world/chunk/WorldChunk;)Lnet/minecraft/world/chunk/WorldChunk;"), locals = LocalCapture.CAPTURE_FAILHARD)
@Inject(method = "unload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientChunkManager$ClientChunkMap;method_62893(ILnet/minecraft/world/chunk/WorldChunk;)V"), locals = LocalCapture.CAPTURE_FAILHARD)
private void onChunkUnload(ChunkPos pos, CallbackInfo ci, int i, WorldChunk chunk) {
ClientChunkEvents.CHUNK_UNLOAD.invoker().onChunkUnload(this.world, chunk);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public DelegatingUnbakedModel(Identifier delegate) {
}

@Override
public void method_62326(class_10103 arg, class_10102 arg2) {
arg.method_62642(delegate);
public void resolve(Resolver resolver, ModelType modelType) {
resolver.resolve(delegate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void addExtraModels(Consumer<Identifier> extraModelConsumer) {
}
}

public BlockStatesLoader.class_10095 loadBlockStateModels() {
public BlockStatesLoader.BlockStateDefinition loadBlockStateModels() {
Map<ModelIdentifier, BlockStatesLoader.BlockModel> map = new HashMap<>();

pluginContext.blockStateResolvers.forEach((block, resolver) -> {
Expand All @@ -105,7 +105,7 @@ public BlockStatesLoader.class_10095 loadBlockStateModels() {
resolveBlockStates(resolver, block, output);
});

return new BlockStatesLoader.class_10095(map);
return new BlockStatesLoader.BlockStateDefinition(map);
}

private void resolveBlockStates(BlockStateResolver resolver, Block block, BiConsumer<BlockState, UnbakedModel> output) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.class_10097;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.client.render.model.BlockStatesLoader;
import net.minecraft.client.render.model.ReferencedModelsCollector;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.resource.ResourceManager;
Expand Down Expand Up @@ -79,14 +79,14 @@ private CompletableFuture<Void> resetEventDispatcherFuture(CompletableFuture<Voi
}

@ModifyExpressionValue(method = "reload", at = @At(value = "INVOKE", target = "net/minecraft/client/render/model/BakedModelManager.reloadBlockStates(Lnet/minecraft/client/render/model/BlockStatesLoader;Lnet/minecraft/resource/ResourceManager;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
private CompletableFuture<BlockStatesLoader.class_10095> hookBlockStateModelLoading(CompletableFuture<BlockStatesLoader.class_10095> modelsFuture) {
CompletableFuture<BlockStatesLoader.class_10095> resolvedModelsFuture = eventDispatcherFuture.thenApplyAsync(ModelLoadingEventDispatcher::loadBlockStateModels);
private CompletableFuture<BlockStatesLoader.BlockStateDefinition> hookBlockStateModelLoading(CompletableFuture<BlockStatesLoader.BlockStateDefinition> modelsFuture) {
CompletableFuture<BlockStatesLoader.BlockStateDefinition> resolvedModelsFuture = eventDispatcherFuture.thenApplyAsync(ModelLoadingEventDispatcher::loadBlockStateModels);
return modelsFuture.thenCombine(resolvedModelsFuture, (models, resolvedModels) -> {
Map<ModelIdentifier, BlockStatesLoader.BlockModel> map = models.models();

if (!(map instanceof HashMap)) {
map = new HashMap<>(map);
models = new BlockStatesLoader.class_10095(map);
models = new BlockStatesLoader.BlockStateDefinition(map);
}

map.putAll(resolvedModels.models());
Expand All @@ -102,17 +102,17 @@ private CompletableFuture<BlockStatesLoader.class_10095> hookBlockStateModelLoad
ordinal = 0,
remap = false
))
private CompletableFuture<class_10097> hookModelDiscovery(
CompletableFuture<BlockStatesLoader.class_10095> self,
private CompletableFuture<ReferencedModelsCollector> hookModelDiscovery(
CompletableFuture<BlockStatesLoader.BlockStateDefinition> self,
CompletionStage<Map<Identifier, UnbakedModel>> otherFuture,
BiFunction<BlockStatesLoader.class_10095, Map<Identifier, UnbakedModel>, class_10097> function,
BiFunction<BlockStatesLoader.BlockStateDefinition, Map<Identifier, UnbakedModel>, ReferencedModelsCollector> function,
Executor executor) {
CompletableFuture<Pair<BlockStatesLoader.class_10095, Map<Identifier, UnbakedModel>>> pairFuture = self.thenCombine(otherFuture, Pair::new);
CompletableFuture<Pair<BlockStatesLoader.BlockStateDefinition, Map<Identifier, UnbakedModel>>> pairFuture = self.thenCombine(otherFuture, Pair::new);
return pairFuture.thenCombineAsync(eventDispatcherFuture, (pair, eventDispatcher) -> {
ModelLoadingEventDispatcher.CURRENT.set(eventDispatcher);
class_10097 class_10097 = function.apply(pair.getLeft(), pair.getRight());
ReferencedModelsCollector referencedModelsCollector = function.apply(pair.getLeft(), pair.getRight());
ModelLoadingEventDispatcher.CURRENT.remove();
return class_10097;
return referencedModelsCollector;
}, executor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.Baker;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.ModelBaker;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
Expand All @@ -39,16 +39,16 @@
import net.fabricmc.fabric.impl.client.model.loading.ModelLoaderHooks;
import net.fabricmc.fabric.impl.client.model.loading.ModelLoadingEventDispatcher;

@Mixin(targets = "net/minecraft/client/render/model/ModelLoader$BakerImpl")
@Mixin(targets = "net/minecraft/client/render/model/ModelBaker$BakerImpl")
abstract class ModelLoaderBakerImplMixin implements BakerImplHooks {
@Shadow
@Final
private ModelLoader field_40571;
private ModelBaker field_40571;
@Shadow
@Final
private Function<SpriteIdentifier, Sprite> textureGetter;

@WrapOperation(method = "bake(Lnet/minecraft/util/Identifier;Lnet/minecraft/client/render/model/ModelBakeSettings;)Lnet/minecraft/client/render/model/BakedModel;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ModelLoader$BakerImpl;bake(Lnet/minecraft/client/render/model/UnbakedModel;Lnet/minecraft/client/render/model/ModelBakeSettings;)Lnet/minecraft/client/render/model/BakedModel;"))
@WrapOperation(method = "bake(Lnet/minecraft/util/Identifier;Lnet/minecraft/client/render/model/ModelBakeSettings;)Lnet/minecraft/client/render/model/BakedModel;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ModelBaker$BakerImpl;bake(Lnet/minecraft/client/render/model/UnbakedModel;Lnet/minecraft/client/render/model/ModelBakeSettings;)Lnet/minecraft/client/render/model/BakedModel;"))
private BakedModel wrapInnerBake(@Coerce Baker self, UnbakedModel unbakedModel, ModelBakeSettings settings, Operation<BakedModel> operation, Identifier id) {
ModelLoadingEventDispatcher dispatcher = ((ModelLoaderHooks) this.field_40571).fabric_getDispatcher();
unbakedModel = dispatcher.modifyModelBeforeBake(unbakedModel, id, null, textureGetter, settings, self);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.class_10096;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.Baker;
import net.minecraft.client.render.model.MissingModel;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.ModelBaker;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.ModelIdentifier;
Expand All @@ -43,7 +43,7 @@
import net.fabricmc.fabric.impl.client.model.loading.ModelLoadingConstants;
import net.fabricmc.fabric.impl.client.model.loading.ModelLoadingEventDispatcher;

@Mixin(ModelLoader.class)
@Mixin(ModelBaker.class)
abstract class ModelLoaderMixin implements ModelLoaderHooks {
@Unique
@Nullable
Expand All @@ -54,13 +54,13 @@ private void onReturnInit(CallbackInfo ci) {
fabric_eventDispatcher = ModelLoadingEventDispatcher.CURRENT.get();
}

@WrapOperation(method = "method_61072(Lnet/minecraft/client/render/model/ModelLoader$SpriteGetter;Lnet/minecraft/client/util/ModelIdentifier;Lnet/minecraft/client/render/model/UnbakedModel;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ModelLoader$BakerImpl;bake(Lnet/minecraft/client/render/model/UnbakedModel;Lnet/minecraft/client/render/model/ModelBakeSettings;)Lnet/minecraft/client/render/model/BakedModel;"))
private BakedModel wrapSingleOuterBake(@Coerce Baker baker, UnbakedModel unbakedModel, ModelBakeSettings settings, Operation<BakedModel> operation, ModelLoader.SpriteGetter spriteGetter, ModelIdentifier id) {
@WrapOperation(method = "method_61072", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ModelBaker$BakerImpl;bake(Lnet/minecraft/client/render/model/UnbakedModel;Lnet/minecraft/client/render/model/ModelBakeSettings;)Lnet/minecraft/client/render/model/BakedModel;"))
private BakedModel wrapSingleOuterBake(@Coerce Baker baker, UnbakedModel unbakedModel, ModelBakeSettings settings, Operation<BakedModel> operation, ModelBaker.SpriteGetter spriteGetter, ModelIdentifier id) {
if (fabric_eventDispatcher == null) {
return operation.call(baker, unbakedModel, settings);
}

if (ModelLoadingConstants.isResourceModelId(id) || id.equals(class_10096.field_53661)) {
if (ModelLoadingConstants.isResourceModelId(id) || id.equals(MissingModel.MODEL_ID)) {
// Call the baker instead of the operation to ensure the baked model is cached and doesn't end up going
// through events twice.
// This ignores the UnbakedModel in field_53662 (top-level model map) but it should be the same as the one in field_53663 (resource model map).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,46 @@
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.class_10097;
import net.minecraft.client.render.model.BlockStatesLoader;
import net.minecraft.client.render.model.ReferencedModelsCollector;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.util.Identifier;

import net.fabricmc.fabric.impl.client.model.loading.ModelLoadingConstants;
import net.fabricmc.fabric.impl.client.model.loading.ModelLoadingEventDispatcher;

@Mixin(class_10097.class)
abstract class class_10097Mixin {
@Mixin(ReferencedModelsCollector.class)
abstract class ReferencedModelsCollectorMixin {
@Unique
@Nullable
private ModelLoadingEventDispatcher fabric_eventDispatcher;

@Shadow
abstract UnbakedModel method_62638(Identifier identifier);
abstract UnbakedModel computeResolvedModel(Identifier identifier);

@Shadow
abstract void method_62635(ModelIdentifier modelIdentifier, UnbakedModel unbakedModel);
abstract void addTopLevelModel(ModelIdentifier modelIdentifier, UnbakedModel unbakedModel);

@Inject(method = "<init>", at = @At("RETURN"))
private void onReturnInit(CallbackInfo ci) {
fabric_eventDispatcher = ModelLoadingEventDispatcher.CURRENT.get();
}

@Inject(method = "method_62632", at = @At("RETURN"))
private void onAddStandardModels(BlockStatesLoader.class_10095 blockStateModels, CallbackInfo ci) {
@Inject(method = "addBlockStates", at = @At("RETURN"))
private void onAddStandardModels(BlockStatesLoader.BlockStateDefinition blockStateModels, CallbackInfo ci) {
if (fabric_eventDispatcher == null) {
return;
}

fabric_eventDispatcher.addExtraModels(id -> {
ModelIdentifier modelId = ModelLoadingConstants.toResourceModelId(id);
UnbakedModel unbakedModel = method_62638(id);
method_62635(modelId, unbakedModel);
UnbakedModel unbakedModel = computeResolvedModel(id);
addTopLevelModel(modelId, unbakedModel);
});
}

@ModifyVariable(method = "method_62640", at = @At(value = "STORE", ordinal = 0), ordinal = 0)
@ModifyVariable(method = "getModel", at = @At(value = "STORE", ordinal = 0), ordinal = 0)
@Nullable
private UnbakedModel onLoadResourceModel(@Nullable UnbakedModel model, Identifier id) {
if (fabric_eventDispatcher == null) {
Expand All @@ -80,7 +80,7 @@ private UnbakedModel onLoadResourceModel(@Nullable UnbakedModel model, Identifie
return fabric_eventDispatcher.modifyModelOnLoad(model, id, null);
}

@ModifyVariable(method = "method_62635", at = @At("HEAD"), argsOnly = true)
@ModifyVariable(method = "addTopLevelModel", at = @At("HEAD"), argsOnly = true)
private UnbakedModel onAddTopLevelModel(UnbakedModel model, ModelIdentifier modelId) {
if (fabric_eventDispatcher == null) {
return model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"compatibilityLevel": "JAVA_21",
"client": [
"BakedModelManagerMixin",
"class_10097Mixin",
"ReferencedModelsCollectorMixin",
"ModelLoaderBakerImplMixin",
"ModelLoaderMixin"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import net.minecraft.block.Blocks;
import net.minecraft.block.CropBlock;
import net.minecraft.block.HorizontalConnectingBlock;
import net.minecraft.class_10096;
import net.minecraft.client.render.block.BlockModels;
import net.minecraft.client.render.entity.PlayerEntityRenderer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.MissingModel;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.resource.ResourceType;
Expand Down Expand Up @@ -86,7 +86,7 @@ public void onInitializeClient() {
ModelIdentifier id = context.topLevelId();

if (id != null && id.equals(fenceId)) {
return new DelegatingUnbakedModel(class_10096.field_53660);
return new DelegatingUnbakedModel(MissingModel.ID);
}

return model;
Expand All @@ -98,7 +98,7 @@ public void onInitializeClient() {
Identifier id = context.resourceId();

if (id != null && id.equals(BROWN_GLAZED_TERRACOTTA_MODEL_ID)) {
return context.baker().getOrLoadModel(class_10096.field_53660);
return context.baker().getModel(MissingModel.ID);
}

return model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,9 @@ public void onInitialize() {
// Synced via PacketCodecs.registry
RegistryAttributeHolder.get(Registries.ARMOR_MATERIAL)
.addAttribute(RegistryAttribute.SYNCED);

// Synced via PacketCodecs.registry
RegistryAttributeHolder.get(Registries.field_53967)
.addAttribute(RegistryAttribute.SYNCED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import net.minecraft.world.ChunkSerializer;
import net.minecraft.world.chunk.SerializedChunk;

@Mixin(ChunkSerializer.class)
public class ChunkSerializerMixin {
@Mixin(SerializedChunk.class)
public class SerializedChunkMixin {
@Redirect(method = "readStructureReferences", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V", remap = false))
private static void log(Logger logger, String msg, Object identifier, Object chunkPos) {
// Drop to debug log level.
Expand Down
Loading

0 comments on commit 2be8990

Please sign in to comment.