From 7cd149ba0610e6f9d40a7ef55916a19055c52a9a Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Fri, 7 Oct 2022 19:33:10 +0200 Subject: [PATCH] Pick a side - Ponder's Identify mode now supports blocks with ray-specific pick block results --- .../create/foundation/ponder/PonderScene.java | 20 ++++++++++++------- .../ponder/element/WorldSectionElement.java | 5 +++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java index 3598a9492..37978e7a8 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java @@ -35,6 +35,7 @@ import com.simibubi.create.foundation.ponder.ui.PonderUI; import com.simibubi.create.foundation.render.ForcedDiffuseState; import com.simibubi.create.foundation.render.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.BlockFace; import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.animation.LerpedFloat; @@ -134,14 +135,14 @@ public class PonderScene { } public Pair rayTraceScene(Vec3 from, Vec3 to) { - MutableObject> nearestHit = new MutableObject<>(); + MutableObject>> nearestHit = new MutableObject<>(); MutableDouble bestDistance = new MutableDouble(0); forEach(WorldSectionElement.class, wse -> { wse.resetSelectedBlock(); if (!wse.isVisible()) return; - Pair rayTrace = wse.rayTrace(world, from, to); + Pair rayTrace = wse.rayTrace(world, from, to); if (rayTrace == null) return; double distanceTo = rayTrace.getFirst() @@ -149,15 +150,20 @@ public class PonderScene { if (nearestHit.getValue() != null && distanceTo >= bestDistance.getValue()) return; - nearestHit.setValue(Pair.of(wse, rayTrace.getSecond())); + nearestHit.setValue(Pair.of(wse, rayTrace)); bestDistance.setValue(distanceTo); }); if (nearestHit.getValue() == null) return Pair.of(ItemStack.EMPTY, null); - BlockPos selectedPos = nearestHit.getValue() + Pair selectedHit = nearestHit.getValue() .getSecond(); + BlockPos selectedPos = selectedHit.getSecond() + .getPos(); + Direction selectedFace = selectedHit.getSecond() + .getFace(); + Vec3 selectedVec = selectedHit.getFirst(); BlockPos origin = new BlockPos(basePlateOffsetX, 0, basePlateOffsetZ); if (!world.getBounds() @@ -176,9 +182,9 @@ public class PonderScene { .getFirst() .selectBlock(selectedPos); BlockState blockState = world.getBlockState(selectedPos); - ItemStack pickBlock = blockState.getCloneItemStack( - new BlockHitResult(VecHelper.getCenterOf(selectedPos), Direction.UP, selectedPos, true), world, selectedPos, - Minecraft.getInstance().player); + ItemStack pickBlock = + blockState.getCloneItemStack(new BlockHitResult(selectedVec, selectedFace, selectedPos, true), world, + selectedPos, Minecraft.getInstance().player); return Pair.of(pickBlock, selectedPos); } diff --git a/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java b/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java index f1afaeb47..19056286d 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/element/WorldSectionElement.java @@ -26,6 +26,7 @@ import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.render.SuperRenderTypeBuffer; import com.simibubi.create.foundation.render.TileEntityRenderHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.BlockFace; import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.outliner.AABBOutline; @@ -181,7 +182,7 @@ public class WorldSectionElement extends AnimatedSceneElement { BlockPos worldPos; } - public Pair rayTrace(PonderWorld world, Vec3 source, Vec3 target) { + public Pair rayTrace(PonderWorld world, Vec3 source, Vec3 target) { world.setMask(this.section); Vec3 transformedTarget = reverseTransformVec(target); BlockHitResult rayTraceBlocks = world.clip(new ClipContext(reverseTransformVec(source), transformedTarget, @@ -199,7 +200,7 @@ public class WorldSectionElement extends AnimatedSceneElement { / source.subtract(target) .lengthSqr(); Vec3 actualHit = VecHelper.lerp((float) t, target, source); - return Pair.of(actualHit, rayTraceBlocks.getBlockPos()); + return Pair.of(actualHit, new BlockFace(rayTraceBlocks.getBlockPos(), rayTraceBlocks.getDirection())); } private Vec3 reverseTransformVec(Vec3 in) {