Skip to content

Commit

Permalink
Fixed AE2 terminal not rendering correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSpring committed Jul 13, 2024
1 parent c0fa8c1 commit 1efb23f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -16,8 +18,20 @@

@Mixin(FabricBakedModel.class)
public interface FabricBakedModelMixin {
/**
* @author BluSpring
* @reason Otherwise, Forge models wouldn't get rendered correctly.
*/
@Overwrite(remap = false)
public default boolean isVanillaAdapter() {
return false;
}

@Inject(method = "emitBlockQuads", at = @At("HEAD"))
private void kilt$storeVariables(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier<RandomSource> randomSupplier, RenderContext context, CallbackInfo ci) {
if (!(blockView instanceof ClientLevel))
return;

FRAPIThreadedStorage.LEVEL.set(blockView);
FRAPIThreadedStorage.POS.set(pos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.ChunkRenderTypeSet;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.client.model.data.ModelDataManager;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -24,6 +25,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import xyz.bluspring.kilt.helpers.FRAPIThreadedStorage;
import xyz.bluspring.kilt.injections.client.renderer.ItemBlockRenderTypesInjection;

import java.util.LinkedList;
import java.util.List;
Expand All @@ -47,11 +49,16 @@ public class VanillaModelEncoderMixin {
if (modelDataManager == null)
return original.call(model, state, direction, randomSource);

mappedRenderTypes.set(new LinkedList<>());

var modelData = model.getModelData(level, pos, state, modelDataManager.getAt(new ChunkPos(pos)).getOrDefault(pos, ModelData.EMPTY));
var renderTypes = model.getRenderTypes(state, randomSource, modelData);

if (modelData == ModelData.EMPTY && (renderTypes.isEmpty() ||
// TODO: this may cause performance issues, and might not actually be what we want, so.
ChunkRenderTypeSet.intersection(ItemBlockRenderTypesInjection.getRenderLayers(state), renderTypes).asList().size() == renderTypes.asList().size())
)
return original.call(model, state, direction, randomSource);

mappedRenderTypes.set(new LinkedList<>());
var list = new LinkedList<BakedQuad>();

for (RenderType renderType : renderTypes) {
Expand All @@ -70,9 +77,12 @@ public class VanillaModelEncoderMixin {
@ModifyArg(method = "emitBlockQuads", at = @At(value = "INVOKE", target = "Lnet/fabricmc/fabric/api/renderer/v1/mesh/QuadEmitter;fromVanilla(Lnet/minecraft/client/renderer/block/model/BakedQuad;Lnet/fabricmc/fabric/api/renderer/v1/material/RenderMaterial;Lnet/minecraft/core/Direction;)Lnet/fabricmc/fabric/api/renderer/v1/mesh/QuadEmitter;"))
private static RenderMaterial kilt$useMappedRenderType(RenderMaterial material, @Share("renderTypes") LocalRef<List<RenderType>> mappedRenderTypes, @Local(ordinal = 2) int j) {
var mapped = mappedRenderTypes.get();
if (mapped == null)
if (mapped == null || mapped.isEmpty())
return material;

if (j >= mapped.size())
mappedRenderTypes.set(null);

var renderType = mapped.get(j);

// TODO: figure out a way to check all other values
Expand Down

0 comments on commit 1efb23f

Please sign in to comment.