Skip to content

Commit

Permalink
Submodels use Identifiers now
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Jul 24, 2022
1 parent ac8a284 commit 1a2d2dc
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 92 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ satin_version=1.8.0
sodium_version=mc1.19-0.4.2
iris_version=1.19.x-v1.2.5

mod_version = 6.1.1
mod_version = 6.2.0
maven_group = net.ludocrypt
archives_base_name = limlib
12 changes: 12 additions & 0 deletions src/main/java/net/ludocrypt/limlib/access/BakedModelAccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.ludocrypt.limlib.access;

import java.util.Map;

import net.minecraft.client.render.model.BakedModel;
import net.minecraft.util.Identifier;

public interface BakedModelAccess {

public Map<Identifier, BakedModel> getSubModels();

}
15 changes: 0 additions & 15 deletions src/main/java/net/ludocrypt/limlib/access/ModelAccess.java

This file was deleted.

12 changes: 12 additions & 0 deletions src/main/java/net/ludocrypt/limlib/access/UnbakedModelAccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.ludocrypt.limlib.access;

import java.util.Map;

import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.util.Identifier;

public interface UnbakedModelAccess {

public Map<Identifier, ModelIdentifier> getSubModels();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.fabricmc.loader.api.FabricLoader;
import net.ludocrypt.limlib.access.BakedModelAccess;
import net.ludocrypt.limlib.access.DimensionTypeAccess;
import net.ludocrypt.limlib.access.ModelAccess;
import net.ludocrypt.limlib.access.RenderDataAccess;
import net.ludocrypt.limlib.access.WorldRendererAccess;
import net.ludocrypt.limlib.api.LiminalEffects;
Expand All @@ -35,7 +35,6 @@
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.WorldRenderer.ChunkInfo;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -178,10 +177,7 @@ public void renderBlocks(Framebuffer framebuffer, float tickDelta, MatrixStack m
matrices.push();
matrices.translate(pos.getX() - camera.getPos().getX(), pos.getY() - camera.getPos().getY(), pos.getZ() - camera.getPos().getZ());

BakedModel model = MinecraftClient.getInstance().getBlockRenderManager().getModel(state);
if (((ModelAccess) model).getLiminalQuadRenderer().isPresent()) {
LimlibRendering.LIMINAL_QUAD_RENDERER.get(((ModelAccess) model).getLiminalQuadRenderer().get()).renderModel(model, world, pos, state, matrices, camera);
}
((BakedModelAccess) MinecraftClient.getInstance().getBlockRenderManager().getModel(state)).getSubModels().forEach((id, quads) -> LimlibRendering.LIMINAL_QUAD_RENDERER.get(id).renderModel(quads, world, pos, state, matrices, camera));

matrices.pop();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import net.ludocrypt.limlib.access.ModelAccess;
import net.ludocrypt.limlib.access.BakedModelAccess;
import net.ludocrypt.limlib.access.RenderDataAccess;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.RenderLayer;
Expand All @@ -40,7 +40,7 @@ public class ChunkBuilderBuiltChunkRebuildTaskMixin {
@Inject(method = "Lnet/minecraft/client/render/chunk/ChunkBuilder$BuiltChunk$RebuildTask;render(FFFLnet/minecraft/client/render/chunk/BlockBufferBuilderStorage;)Lnet/minecraft/client/render/chunk/ChunkBuilder$BuiltChunk$RebuildTask$RenderData;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/chunk/ChunkRendererRegion;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;", ordinal = 0, shift = Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD)
private void limlib$render(float cameraX, float cameraY, float cameraZ, BlockBufferBuilderStorage blockBufferBuilderStorage, CallbackInfoReturnable<RenderData> ci, RenderData renderData, int i, BlockPos blockPos, BlockPos blockPos2, ChunkOcclusionDataBuilder chunkOcclusionDataBuilder, ChunkRendererRegion chunkRendererRegion, MatrixStack matrixStack, Set<RenderLayer> set, Random random, BlockRenderManager blockRenderManager, Iterator<BlockPos> var15, BlockPos blockPos3) {
BlockState blockState = chunkRendererRegion.getBlockState(blockPos3);
if (((ModelAccess) blockRenderManager.getModel(blockState)).getLiminalQuadRenderer().isPresent()) {
if (!((BakedModelAccess) blockRenderManager.getModel(blockState)).getSubModels().isEmpty()) {
((RenderDataAccess) (Object) renderData).getCustomQuadData().put(blockPos3.toImmutable(), blockState);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import me.jellysquid.mods.sodium.client.render.pipeline.context.ChunkRenderCacheLocal;
import me.jellysquid.mods.sodium.client.util.task.CancellationSource;
import me.jellysquid.mods.sodium.client.world.WorldSlice;
import net.ludocrypt.limlib.access.ModelAccess;
import net.ludocrypt.limlib.access.BakedModelAccess;
import net.ludocrypt.limlib.access.RenderDataAccess;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder;
Expand All @@ -32,7 +32,7 @@ public class ChunkRenderRebuildTaskMixin {
@Inject(method = "Lme/jellysquid/mods/sodium/client/render/chunk/tasks/ChunkRenderRebuildTask;performBuild(Lme/jellysquid/mods/sodium/client/gl/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationSource;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildResult;", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/BlockPos$Mutable;set(III)Lnet/minecraft/util/math/BlockPos$Mutable;", ordinal = 1, shift = Shift.AFTER, remap = false), locals = LocalCapture.CAPTURE_FAILHARD, remap = false, require = 0)
private void limlib$performBuild$mapped(ChunkBuildContext buildContext, CancellationSource cancellationSource, CallbackInfoReturnable<ChunkBuildResult> ci, ChunkRenderData.Builder renderData, ChunkOcclusionDataBuilder occluder, ChunkRenderBounds.Builder bounds, ChunkBuildBuffers buffers, ChunkRenderCacheLocal cache, WorldSlice slice, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, Mutable blockPos, Mutable offset) {
BlockState blockState = slice.getBlockState(blockPos);
if (((ModelAccess) cache.getBlockModels().getModel(blockState)).getLiminalQuadRenderer().isPresent()) {
if (!((BakedModelAccess) cache.getBlockModels().getModel(blockState)).getSubModels().isEmpty()) {
((RenderDataAccess) (Object) renderData).getCustomQuadData().put(blockPos.toImmutable(), blockState);
}
}
Expand All @@ -41,7 +41,7 @@ public class ChunkRenderRebuildTaskMixin {
@Inject(method = "Lme/jellysquid/mods/sodium/client/render/chunk/tasks/ChunkRenderRebuildTask;performBuild(Lme/jellysquid/mods/sodium/client/gl/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationSource;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildResult;", at = @At(value = "INVOKE", target = "Lnet/minecraft/class_2338$class_2339;method_10103(III)Lnet/minecraft/class_2338$class_2339;", ordinal = 1, shift = Shift.AFTER, remap = false), locals = LocalCapture.CAPTURE_FAILHARD, remap = false, require = 0)
private void limlib$performBuild$unmapped(ChunkBuildContext buildContext, CancellationSource cancellationSource, CallbackInfoReturnable<ChunkBuildResult> ci, ChunkRenderData.Builder renderData, ChunkOcclusionDataBuilder occluder, ChunkRenderBounds.Builder bounds, ChunkBuildBuffers buffers, ChunkRenderCacheLocal cache, WorldSlice slice, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, Mutable blockPos, Mutable offset) {
BlockState blockState = slice.getBlockState(blockPos);
if (((ModelAccess) cache.getBlockModels().getModel(blockState)).getLiminalQuadRenderer().isPresent()) {
if (!((BakedModelAccess) cache.getBlockModels().getModel(blockState)).getSubModels().isEmpty()) {
((RenderDataAccess) (Object) renderData).getCustomQuadData().put(blockPos.toImmutable(), blockState);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import com.google.common.collect.Lists;

import net.fabricmc.loader.api.FabricLoader;
import net.ludocrypt.limlib.access.BakedModelAccess;
import net.ludocrypt.limlib.access.IrisClientAccess;
import net.ludocrypt.limlib.access.ItemRendererAccess;
import net.ludocrypt.limlib.access.ModelAccess;
import net.ludocrypt.limlib.access.WorldRendererAccess;
import net.ludocrypt.limlib.impl.LimlibRendering;
import net.minecraft.client.MinecraftClient;
Expand All @@ -31,20 +31,18 @@ public class ItemRendererMixin implements ItemRendererAccess {

@Inject(method = "Lnet/minecraft/client/render/item/ItemRenderer;renderBakedItemModel(Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/item/ItemStack;IILnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;)V", at = @At("HEAD"))
private void limlib$renderBakedItemModel(BakedModel model, ItemStack stack, int light, int overlay, MatrixStack matrices, VertexConsumer vertices, CallbackInfo ci) {
if (((ModelAccess) model).getLiminalQuadRenderer().isPresent()) {
MinecraftClient client = MinecraftClient.getInstance();
MinecraftClient client = MinecraftClient.getInstance();

boolean isHandRendering = ((WorldRendererAccess) client.worldRenderer).isRenderingHands() || (FabricLoader.getInstance().isModLoaded("iris") && ((IrisClientAccess) client).isHandRenderingActive());
boolean isItemRendering = ((WorldRendererAccess) client.worldRenderer).isRenderingItems();
boolean isHandRendering = ((WorldRendererAccess) client.worldRenderer).isRenderingHands() || (FabricLoader.getInstance().isModLoaded("iris") && ((IrisClientAccess) client).isHandRenderingActive());
boolean isItemRendering = ((WorldRendererAccess) client.worldRenderer).isRenderingItems();

if (isHandRendering || isItemRendering || inGui) {
MatrixStack matrixStack = new MatrixStack();
matrixStack.multiplyPositionMatrix(matrices.peek().getPositionMatrix().copy());
List<Runnable> immediateRenderer = Lists.newArrayList();
LimlibRendering.LIMINAL_QUAD_RENDERER.get(((ModelAccess) model).getLiminalQuadRenderer().get()).renderItemModel(model, client.world, stack.copy(), matrixStack, client.gameRenderer.getCamera(), inGui);
immediateRenderer.forEach(Runnable::run);
immediateRenderer.clear();
}
if (isHandRendering || isItemRendering || inGui) {
MatrixStack matrixStack = new MatrixStack();
matrixStack.multiplyPositionMatrix(matrices.peek().getPositionMatrix().copy());
List<Runnable> immediateRenderer = Lists.newArrayList();
((BakedModelAccess) model).getSubModels().forEach((id, subModel) -> (isHandRendering ? LimlibRendering.LIMINAL_QUAD_RENDERER.get(id).heldItemRenderQueue : isItemRendering ? LimlibRendering.LIMINAL_QUAD_RENDERER.get(id).itemRenderQueue : immediateRenderer).add(() -> LimlibRendering.LIMINAL_QUAD_RENDERER.get(id).renderItemModel(subModel, client.world, stack.copy(), matrixStack, client.gameRenderer.getCamera(), inGui)));
immediateRenderer.forEach(Runnable::run);
immediateRenderer.clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package net.ludocrypt.limlib.mixin.client.render.model;

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

import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;

import net.ludocrypt.limlib.access.ModelAccess;
import com.google.common.collect.Maps;

import net.ludocrypt.limlib.access.BakedModelAccess;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.util.Identifier;

@Mixin(BakedModel.class)
public interface BakedModelMixin extends ModelAccess {

@Override
default Optional<Identifier> getLiminalQuadRenderer() {
return Optional.empty();
}
public interface BakedModelMixin extends BakedModelAccess {

@Override
default void setLiminalQuadRenderer(@Nullable Identifier id) {
default Map<Identifier, BakedModel> getSubModels() {
return Maps.newHashMap();
}

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package net.ludocrypt.limlib.mixin.client.render.model;

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

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

import net.ludocrypt.limlib.access.ModelAccess;
import com.google.common.collect.Maps;

import net.ludocrypt.limlib.access.BakedModelAccess;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.util.Identifier;

@Mixin(targets = { "net/minecraft/client/render/model/BasicBakedModel", "net/minecraft/client/render/model/BuiltinBakedModel", "net/minecraft/client/render/model/MultipartBakedModel", "net/minecraft/client/render/model/WeightedBakedModel", "net/fabricmc/fabric/api/renderer/v1/model/ForwardingBakedModel" })
public class GeneralBakedModelMixin implements ModelAccess {
public class GeneralBakedModelMixin implements BakedModelAccess {

@Unique
private Optional<Identifier> liminalQuadRenderer = Optional.empty();

@Override
public Optional<Identifier> getLiminalQuadRenderer() {
return liminalQuadRenderer;
}
private Map<Identifier, BakedModel> subQuads = Maps.newHashMap();

@Override
public void setLiminalQuadRenderer(Identifier id) {
liminalQuadRenderer = Optional.ofNullable(id);
public Map<Identifier, BakedModel> getSubModels() {
return subQuads;
}

}
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
package net.ludocrypt.limlib.mixin.client.render.model;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.google.common.collect.Maps;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import net.ludocrypt.limlib.access.ModelAccess;
import net.ludocrypt.limlib.access.UnbakedModelAccess;
import net.ludocrypt.limlib.impl.LimlibRendering;
import net.minecraft.client.render.model.json.JsonUnbakedModel;
import net.minecraft.client.render.model.json.ModelElement;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.util.Identifier;

@Mixin(JsonUnbakedModel.Deserializer.class)
public abstract class JsonUnbakedModelDeserializerMixin {

@Inject(method = "Lnet/minecraft/client/render/model/json/JsonUnbakedModel$Deserializer;deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraft/client/render/model/json/JsonUnbakedModel;", at = @At("RETURN"), cancellable = true)
private void limlib$deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext, CallbackInfoReturnable<JsonUnbakedModel> ci) {
Map<Identifier, ModelIdentifier> map = Maps.newHashMap();
JsonObject jsonObject = jsonElement.getAsJsonObject();
if (jsonObject.has("limlib_renderer")) {
if (LimlibRendering.LIMINAL_QUAD_RENDERER.containsId(new Identifier(jsonObject.get("limlib_renderer").getAsString()))) {
((ModelAccess) ci.getReturnValue()).setLiminalQuadRenderer(new Identifier(jsonObject.get("limlib_renderer").getAsString()));
}
if (jsonObject.has("limlib_extra")) {
LimlibRendering.LIMINAL_QUAD_RENDERER.getEntrySet().forEach((entry) -> {
JsonObject limlibExtra = jsonObject.get("limlib_extra").getAsJsonObject();
if (limlibExtra.has(entry.getKey().getValue().toString())) {
JsonObject renderer = limlibExtra.get(entry.getKey().getValue().toString()).getAsJsonObject();
map.put(entry.getKey().getValue(), new ModelIdentifier(renderer.getAsString()));
}
});
}
((UnbakedModelAccess) ci.getReturnValue()).getSubModels().putAll(map);
}

@Shadow
protected abstract List<ModelElement> elementsFromJson(JsonDeserializationContext context, JsonObject json);

}
Loading

0 comments on commit 1a2d2dc

Please sign in to comment.