1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 11:10:29 +00:00

Add highlight rendering for monitors and cables

This commit is contained in:
SquidDev 2019-06-02 18:09:28 +01:00
parent c221502ec9
commit 725dfa764f
4 changed files with 47 additions and 27 deletions

View File

@ -13,9 +13,9 @@ import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
@ -34,12 +34,10 @@ public final class CableHighlightRenderer
*
* @see WorldRenderer#drawHighlightedBlockOutline(Entity, HitResult, int, float)
*/
public static boolean drawHighlight()
public static boolean drawHighlight( Camera camera, BlockHitResult hit )
{
MinecraftClient mc = MinecraftClient.getInstance();
if( mc.hitResult == null || mc.hitResult.getType() != HitResult.Type.BLOCK ) return false;
BlockPos pos = ((BlockHitResult) mc.hitResult).getBlockPos();
BlockPos pos = hit.getBlockPos();
World world = mc.world;
BlockState state = world.getBlockState( pos );
@ -50,9 +48,6 @@ public final class CableHighlightRenderer
return false;
}
PlayerEntity player = mc.player;
float partialTicks = mc.getTickDelta();
GlStateManager.enableBlend();
GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
GlStateManager.lineWidth( Math.max( 2.5F, mc.window.getFramebufferWidth() / 1920.0F * 2.5F ) );
@ -62,15 +57,11 @@ public final class CableHighlightRenderer
GlStateManager.pushMatrix();
GlStateManager.scalef( 1.0F, 1.0F, 0.999F );
double x = player.prevX + (player.x - player.prevX) * partialTicks;
double y = player.prevY + (player.y - player.prevY) * partialTicks;
double z = player.prevZ + (player.z - player.prevZ) * partialTicks;
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), mc.hitResult.getPos().subtract( pos.getX(), pos.getY(), pos.getZ() ) )
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getPos().subtract( pos.getX(), pos.getY(), pos.getZ() ) )
? CableShapes.getModemShape( state )
: CableShapes.getCableShape( state );
WorldRenderer.drawShapeOutline( shape, pos.getX() - x, pos.getY() - y, pos.getZ() - z, 0.0F, 0.0F, 0.0F, 0.4F );
WorldRenderer.drawShapeOutline( shape, pos.getX() - camera.getPos().getX(), pos.getY() - camera.getPos().getY(), pos.getZ() - camera.getPos().getZ(), 0.0F, 0.0F, 0.0F, 0.4F );
GlStateManager.popMatrix();
GlStateManager.matrixMode( GL11.GL_MODELVIEW );

View File

@ -11,11 +11,10 @@ import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
@ -33,12 +32,12 @@ public final class MonitorHighlightRenderer
{
}
public static boolean drawHighlight()
public static boolean drawHighlight( Camera camera, BlockHitResult hit )
{
MinecraftClient mc = MinecraftClient.getInstance();
if( mc.hitResult == null || mc.hitResult.getType() != HitResult.Type.BLOCK ) return false;
if( mc.player.isSneaking() ) return false;
BlockPos pos = ((BlockHitResult) mc.hitResult).getBlockPos();
BlockPos pos = hit.getBlockPos();
World world = mc.world;
BlockEntity tile = world.getBlockEntity( pos );
@ -62,13 +61,7 @@ public final class MonitorHighlightRenderer
GlStateManager.depthMask( false );
GlStateManager.pushMatrix();
PlayerEntity player = mc.player;
float partialTicks = mc.getTickDelta();
double x = player.prevX + (player.x - player.prevX) * partialTicks;
double y = player.prevY + (player.y - player.prevY) * partialTicks;
double z = player.prevZ + (player.z - player.prevZ) * partialTicks;
GlStateManager.translated( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() );
GlStateManager.translated( pos.getX() - camera.getPos().getX(), pos.getY() - camera.getPos().getY(), pos.getZ() - camera.getPos().getZ() );
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBufferBuilder();

View File

@ -0,0 +1,35 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.mixin;
import dan200.computercraft.client.render.CableHighlightRenderer;
import dan200.computercraft.client.render.MonitorHighlightRenderer;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin( WorldRenderer.class )
public class MixinWorldRenderer
{
@Inject( method = "drawHighlightedBlockOutline", cancellable = true, at = @At( "HEAD" ) )
public void drawHighlightedBlockOutline( Camera camera, HitResult hit, int flag, CallbackInfo info )
{
if( flag != 0 || hit.getType() != HitResult.Type.BLOCK ) return;
BlockHitResult blockHit = (BlockHitResult) hit;
if( CableHighlightRenderer.drawHighlight( camera, blockHit ) ||
MonitorHighlightRenderer.drawHighlight( camera, blockHit ) )
{
info.cancel();
}
}
}

View File

@ -6,7 +6,8 @@
"MixinFirstPersonRenderer",
"MixinItemFrameEntityRenderer",
"MixinMinecraftGame",
"MixinScreen"
"MixinScreen",
"MixinWorldRenderer"
],
"injectors": {
"defaultRequire": 1