aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-06-20 17:38:13 +0800
committershedaniel <daniel@shedaniel.me>2022-06-28 03:21:12 +0800
commit3ef8089dd5fb071592a6a104efec41b5ab0a05d8 (patch)
treefba11118ba7d37329365183d1d733b2f352331ac /runtime
parent97dafeba13f188dffc2666f0351faa007bbe3dec (diff)
downloadRoughlyEnoughItems-3ef8089dd5fb071592a6a104efec41b5ab0a05d8.tar.gz
RoughlyEnoughItems-3ef8089dd5fb071592a6a104efec41b5ab0a05d8.tar.bz2
RoughlyEnoughItems-3ef8089dd5fb071592a6a104efec41b5ab0a05d8.zip
Fix DraggingContext forcibly centering the component
Diffstat (limited to 'runtime')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java10
1 files 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<FloatingRectangle> 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() {