From 3867b082542afc5bc4530f7ff9dce72fcfa98a7f Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 20 Jun 2022 17:38:13 +0800 Subject: Fix DraggingContext forcibly centering the component --- .../rei/impl/client/gui/dragging/CurrentDraggingStack.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java index c8b7d4546..add5f947b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java @@ -43,6 +43,7 @@ import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.Nullable; @@ -87,7 +88,9 @@ public class CurrentDraggingStack extends Widget implements LateRenderable, Drag entry.bounds.update(delta); int width = entry.component.getWidth(); int height = entry.component.getHeight(); - entry.bounds.setTo(new FloatingRectangle(mouseX - width / 2, mouseY - height / 2, width, height), Util.getMillis() - entry.startDragging < 100 && width * height > 1000 ? 80 : 10); + Vec2 mouseStartOffset = entry.mouseStartOffset; + entry.bounds.setTo(new FloatingRectangle(mouseX - width / 2 - mouseStartOffset.x, mouseY - height / 2 - mouseStartOffset.y, width, height), + 30); entry.component.render(matrices, entry.bounds.value().getBounds(), mouseX, mouseY, delta); matrices.popPose(); @@ -203,8 +206,9 @@ public class CurrentDraggingStack extends Widget implements LateRenderable, Drag @Nullable public Point getCurrentPosition() { if (!isDraggingComponent()) return null; + Vec2 mouseStartOffset = entry.mouseStartOffset; FloatingRectangle rectangle = entry.bounds.value(); - return new Point(rectangle.getCenterX(), rectangle.getCenterY()); + return new Point(rectangle.getCenterX() + mouseStartOffset.x, rectangle.getCenterY() + mouseStartOffset.y); } @Override @@ -235,6 +239,7 @@ public class CurrentDraggingStack extends Widget implements LateRenderable, Drag private final Point start; private long startDragging = -1; private final ValueAnimator bounds; + private final Vec2 mouseStartOffset; private boolean dragging = false; private DraggableBoundsProvider boundsProvider; @@ -243,6 +248,7 @@ public class CurrentDraggingStack extends Widget implements LateRenderable, Drag this.start = start; this.bounds = ValueAnimator.ofFloatingRectangle() .setAs(component.getOriginBounds(start).getFloatingBounds()); + this.mouseStartOffset = new Vec2((float) (start.x - bounds.value().getCenterX()), (float) (start.y - bounds.value().getCenterY())); } public DraggableBoundsProvider getBoundsProvider() { -- cgit