2018-12-20 00:39:10 +00:00
|
|
|
package net.shadowfacts.simplemultipart.mixin.client;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.block.RenderTypeBlock;
|
2018-12-20 01:23:04 +00:00
|
|
|
import net.minecraft.client.render.BufferBuilder;
|
2018-12-20 00:39:10 +00:00
|
|
|
import net.minecraft.client.render.block.BlockRenderManager;
|
|
|
|
import net.minecraft.client.render.block.BlockRenderer;
|
|
|
|
import net.minecraft.client.render.model.BakedModel;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.ExtendedBlockView;
|
2018-12-20 01:33:20 +00:00
|
|
|
import net.shadowfacts.simplemultipart.client.util.RenderStateProvider;
|
2018-12-20 00:39:10 +00:00
|
|
|
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 java.util.Random;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
@Mixin(BlockRenderManager.class)
|
|
|
|
public abstract class MixinBlockRenderManager {
|
|
|
|
|
|
|
|
@Shadow
|
|
|
|
private BlockRenderer renderer;
|
|
|
|
|
|
|
|
@Shadow
|
|
|
|
public abstract BakedModel getModel(BlockState var1);
|
|
|
|
|
2018-12-20 01:23:04 +00:00
|
|
|
@Inject(at = @At("HEAD"), method = "tesselateBlock", cancellable = true)
|
|
|
|
public void tesselateBlock(BlockState state, BlockPos pos, ExtendedBlockView world, BufferBuilder buffer, Random random, CallbackInfoReturnable<Boolean> info) {
|
2018-12-20 00:39:10 +00:00
|
|
|
Block block = state.getBlock();
|
|
|
|
if (state.getRenderType() == RenderTypeBlock.MODEL && block instanceof RenderStateProvider) {
|
|
|
|
RenderStateProvider provider = (RenderStateProvider)block;
|
|
|
|
BlockState renderState = provider.getStateForRendering(state, pos, world);
|
|
|
|
|
|
|
|
BakedModel model = getModel(state);
|
|
|
|
boolean result = renderer.tesselate(world, model, renderState, pos, buffer, true, random, state.getPosRandom(pos));
|
|
|
|
info.setReturnValue(result);
|
|
|
|
info.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|