Remove MixinWorldRenderer and replace with a fabric api. Fixes #2603

This commit is contained in:
modmuss50 2021-11-26 20:31:16 +00:00
parent 90b119cfe6
commit f500b5ddff
5 changed files with 27 additions and 42 deletions

View file

@ -28,13 +28,11 @@ import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientBlockEntityEvents;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
import net.minecraft.client.texture.SpriteAtlasTexture;
import reborncore.api.blockentity.UnloadHandler;
import reborncore.client.HolidayRenderManager;
import reborncore.client.IconSupplier;
import reborncore.client.ItemStackRenderer;
import reborncore.client.StackToolTipHandler;
import reborncore.client.*;
import reborncore.common.fluid.RebornFluidRenderManager;
import reborncore.common.network.ClientBoundPacketHandlers;
@ -48,6 +46,7 @@ public class RebornCoreClient implements ClientModInitializer {
ClientBoundPacketHandlers.init();
HudRenderCallback.EVENT.register(new ItemStackRenderer());
ItemTooltipCallback.EVENT.register(new StackToolTipHandler());
WorldRenderEvents.BLOCK_OUTLINE.register(new BlockOutlineRenderer());
/* register UnloadHandler */
ClientBlockEntityEvents.BLOCK_ENTITY_UNLOAD.register((blockEntity, world) -> {

View file

@ -22,59 +22,44 @@
* SOFTWARE.
*/
package reborncore.mixin.client;
package reborncore.client;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import org.spongepowered.asm.mixin.Final;
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.CallbackInfo;
import net.minecraft.world.World;
import reborncore.common.misc.MultiBlockBreakingTool;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
;
public class BlockOutlineRenderer implements WorldRenderEvents.BlockOutline {
@Mixin(WorldRenderer.class)
public abstract class MixinWorldRenderer {
@Shadow
@Final
private MinecraftClient client;
@Shadow
private ClientWorld world;
@Shadow
private static void drawShapeOutline(MatrixStack matrixStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j) {
throw new AssertionError();
}
@Inject(method = "drawBlockOutline", at = @At("HEAD"), cancellable = true)
private void drawBlockOutline(MatrixStack matrixStack, VertexConsumer vertexConsumer, Entity entity, double d, double e, double f, BlockPos targetPos, BlockState targetBlockState, CallbackInfo info) {
@Override
public boolean onBlockOutline(WorldRenderContext worldRenderContext, WorldRenderContext.BlockOutlineContext context) {
List<VoxelShape> shapes = new ArrayList<>();
if (entity == client.player) {
ClientPlayerEntity clientPlayerEntity = client.player;
World world = context.entity().world;
BlockPos targetPos = context.blockPos();
if (context.entity() == MinecraftClient.getInstance().player) {
ClientPlayerEntity clientPlayerEntity = MinecraftClient.getInstance().player;
ItemStack stack = clientPlayerEntity.getMainHandStack();
if (stack.isEmpty()) {
return;
return true;
}
if (stack.getItem() instanceof MultiBlockBreakingTool) {
Set<BlockPos> blockPosList = ((MultiBlockBreakingTool) stack.getItem()).getBlocksToBreak(stack, clientPlayerEntity.world, targetPos, clientPlayerEntity);
@ -84,22 +69,22 @@ public abstract class MixinWorldRenderer {
}
BlockState blockState = world.getBlockState(pos);
shapes.add(blockState.getOutlineShape(world, pos, ShapeContext.of(entity)).offset(pos.getX() - targetPos.getX(), pos.getY() - targetPos.getY(), pos.getZ() - targetPos.getZ()));
shapes.add(blockState.getOutlineShape(world, pos, ShapeContext.of(clientPlayerEntity)).offset(pos.getX() - targetPos.getX(), pos.getY() - targetPos.getY(), pos.getZ() - targetPos.getZ()));
}
}
}
if (!shapes.isEmpty()) {
VoxelShape shape = targetBlockState.getOutlineShape(world, targetPos, ShapeContext.of(entity));
VoxelShape shape = context.blockState().getOutlineShape(world, targetPos, ShapeContext.of(context.entity()));
for (VoxelShape voxelShape : shapes) {
shape = VoxelShapes.union(shape, voxelShape);
}
drawShapeOutline(matrixStack, vertexConsumer, shape, (double)targetPos.getX() - d, (double)targetPos.getY() - e, (double)targetPos.getZ() - f, 0.0F, 0.0F, 0.0F, 0.4F);
//info.cancel(); // Enable to render a single bounding box around the whole thing
}
WorldRenderer.drawShapeOutline(worldRenderContext.matrixStack(), worldRenderContext.consumers().getBuffer(RenderLayer.getLines()), shape, (double)targetPos.getX() - context.cameraX(), (double)targetPos.getY() - context.cameraY(), (double)targetPos.getZ() - context.cameraZ(), 0.0F, 0.0F, 0.0F, 0.4F);
}
return true;
}
}

View file

@ -5,3 +5,5 @@ accessible method net/minecraft/recipe/ShapedRecipe getPattern (Lcom
accessible method net/minecraft/recipe/ShapedRecipe createPatternMatrix ([Ljava/lang/String;Ljava/util/Map;II)Lnet/minecraft/util/collection/DefaultedList;
accessible method net/minecraft/client/gui/screen/ingame/HandledScreen getSlotAt (DD)Lnet/minecraft/screen/slot/Slot;
accessible method net/minecraft/client/render/WorldRenderer drawShapeOutline (Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Lnet/minecraft/util/shape/VoxelShape;DDDFFFF)V

View file

@ -6,7 +6,6 @@
"MixinGameRenderer",
"MixinItemRenderer",
"MixinDebugRenderer",
"MixinWorldRenderer",
"AccessorModelPredicateProviderRegistry",
"AccessorChatHud",
"AccessorScreen"

View file

@ -1,7 +1,7 @@
{
"required": true,
"package": "reborncore.mixin.common",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_16",
"mixins": [
"AccessorFluidBlock",
"AccessorFoliagePlacerType",