Draw block highlight for specific multipart hit
This commit is contained in:
parent
4498feaee1
commit
9f2f8ddf9e
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
|
import net.minecraft.world.BlockView;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
import net.shadowfacts.simplemultipart.SimpleMultipart;
|
||||||
import net.shadowfacts.simplemultipart.container.MultipartContainer;
|
import net.shadowfacts.simplemultipart.container.MultipartContainer;
|
||||||
|
@ -37,7 +38,7 @@ public class MultipartHelper {
|
||||||
* @param player The player performing the ray trace.
|
* @param player The player performing the ray trace.
|
||||||
* @return A hit result for the hit multipart. {@ode null} if not part was hit.
|
* @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
|
// copied from BoatItem::use
|
||||||
float var6 = MathHelper.lerp(1.0F, player.prevPitch, player.pitch);
|
float var6 = MathHelper.lerp(1.0F, player.prevPitch, player.pitch);
|
||||||
float var7 = MathHelper.lerp(1.0F, player.prevYaw, player.yaw);
|
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.
|
* @param end The end position for the ray.
|
||||||
* @return A hit result for the hit multipart. {@code null} if no part was hit.
|
* @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()
|
return container.getParts().stream()
|
||||||
.map(view -> {
|
.map(view -> {
|
||||||
VoxelShape shape = view.getState().getBoundingShape(view);
|
VoxelShape shape = view.getState().getBoundingShape(view);
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"MixinBlockRenderManager",
|
"MixinBlockRenderManager",
|
||||||
"MixinDebugHud",
|
"MixinDebugHud",
|
||||||
"MixinModelLoader"
|
"MixinModelLoader",
|
||||||
|
"MixinWorldRenderer"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|
Loading…
Reference in New Issue