Draw block highlight for specific multipart hit

This commit is contained in:
Shadowfacts 2018-12-29 10:52:53 -05:00
parent 4498feaee1
commit 9f2f8ddf9e
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 41 additions and 3 deletions

View File

@ -0,0 +1,36 @@
package net.shadowfacts.simplemultipart.mixin.client;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.shadowfacts.simplemultipart.SimpleMultipart;
import net.shadowfacts.simplemultipart.container.MultipartContainer;
import net.shadowfacts.simplemultipart.util.MultipartHelper;
import net.shadowfacts.simplemultipart.util.MultipartHitResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
/**
* @author shadowfacts
*/
@Mixin(WorldRenderer.class)
public class MixinWorldRenderer {
@Redirect(method = "drawHighlightedBlockOutline", at = @At(value = "INVOKE", target = "getBoundingShape"))
public VoxelShape getHighlightShape(BlockState state, BlockView world, BlockPos pos) {
if (state.getBlock() == SimpleMultipart.containerBlock || state.getBlock() == SimpleMultipart.tickableContainerBlock) {
MultipartContainer container = (MultipartContainer)world.getBlockEntity(pos);
MultipartHitResult result = MultipartHelper.rayTrace(container, world, pos, MinecraftClient.getInstance().player);
if (result != null && result.view != null) {
return result.view.getState().getBoundingShape(result.view);
}
}
return state.getBoundingShape(world, pos);
}
}

View File

@ -12,6 +12,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.shadowfacts.simplemultipart.SimpleMultipart;
import net.shadowfacts.simplemultipart.container.MultipartContainer;
@ -37,7 +38,7 @@ public class MultipartHelper {
* @param player The player performing the ray trace.
* @return A hit result for the hit multipart. {@ode null} if not part was hit.
*/
public static MultipartHitResult rayTrace(MultipartContainer container, World world, BlockPos pos, PlayerEntity player) {
public static MultipartHitResult rayTrace(MultipartContainer container, BlockView world, BlockPos pos, PlayerEntity player) {
// copied from BoatItem::use
float var6 = MathHelper.lerp(1.0F, player.prevPitch, player.pitch);
float var7 = MathHelper.lerp(1.0F, player.prevYaw, player.yaw);
@ -67,7 +68,7 @@ public class MultipartHelper {
* @param end The end position for the ray.
* @return A hit result for the hit multipart. {@code null} if no part was hit.
*/
public static MultipartHitResult rayTrace(MultipartContainer container, World world, BlockPos pos, Vec3d start, Vec3d end) {
public static MultipartHitResult rayTrace(MultipartContainer container, BlockView world, BlockPos pos, Vec3d start, Vec3d end) {
return container.getParts().stream()
.map(view -> {
VoxelShape shape = view.getState().getBoundingShape(view);

View File

@ -5,7 +5,8 @@
"mixins": [
"MixinBlockRenderManager",
"MixinDebugHud",
"MixinModelLoader"
"MixinModelLoader",
"MixinWorldRenderer"
],
"injectors": {
"defaultRequire": 1