fix clipboard rotation

This commit is contained in:
Sen 2025-06-26 18:17:58 +02:00
parent 1c6939d61f
commit 720ad59f77
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
2 changed files with 20 additions and 20 deletions

View file

@ -1,25 +1,25 @@
package server.clipboard;
public class BlockTransform {
public class Mat2i {
private final int xx;
private final int zx;
private final int xz;
private final int zz;
public BlockTransform(int theta, boolean x, boolean z) {
int cot = dCos(theta);
int sit = dSin(theta);
this.xx = cot * (x ? -1 : 1);
this.zx = sit * (z ? -1 : 1);
this.xz = -sit * (x ? -1 : 1);
this.zz = cot * (z ? -1 : 1);
public Mat2i(int rotationY, boolean flipX, boolean flipZ) {
int cot = dCos(-rotationY);
int sit = dSin(-rotationY);
this.xx = cot * (flipX ? -1 : 1);
this.zx = sit * (flipZ ? -1 : 1);
this.xz = -sit * (flipX ? -1 : 1);
this.zz = cot * (flipZ ? -1 : 1);
}
public int applyX(int x, int z) {
public int mulX(int x, int z) {
return x * this.xx + z * this.zx;
}
public int applyZ(int x, int z) {
public int mulZ(int x, int z) {
return x * this.xz + z * this.zz;
}

View file

@ -121,7 +121,7 @@ import common.world.BlockArray;
import common.world.State;
import common.world.World;
import server.Server;
import server.clipboard.BlockTransform;
import server.clipboard.Mat2i;
import server.clipboard.ClipboardBlock;
import server.clipboard.ClipboardPlacer;
import server.clipboard.RotationRegistry;
@ -1419,9 +1419,9 @@ public class Player extends User implements ICrafting, Executor, IPlayer
int nz = this.clipboard[0][0].length;
BlockPos to = this.entity.getPosition();
ClipboardPlacer placer = new ClipboardPlacer(this.getEntityWorld());
BlockTransform transform = null;
Mat2i transform = null;
if(this.rotation != 0 || this.flipX || this.flipZ) {
transform = new BlockTransform(-this.rotation, this.flipX, this.flipZ);
transform = new Mat2i(this.rotation, this.flipX, this.flipZ);
}
else {
to = to.add(this.selOffset);
@ -1434,21 +1434,21 @@ public class Player extends User implements ICrafting, Executor, IPlayer
}
else {
ClipboardBlock block = transformBlock(transform, this.clipboard[x][y][z]);
placer.setBlock(to.add(transform.applyX(x + this.selOffset.getX(), z + this.selOffset.getZ()), y + this.selOffset.getY(),
transform.applyZ(x + this.selOffset.getX(), z + this.selOffset.getZ())), block);
placer.setBlock(to.add(transform.mulX(x + this.selOffset.getX(), z + this.selOffset.getZ()), y + this.selOffset.getY(),
transform.mulZ(x + this.selOffset.getX(), z + this.selOffset.getZ())), block);
}
}
}
}
if(transform != null) {
to = to.add(transform.applyX(this.selOffset.getX(), this.selOffset.getZ()), this.selOffset.getY(), transform.applyZ(this.selOffset.getX(), this.selOffset.getZ()));
to = to.add(transform.mulX(this.selOffset.getX(), this.selOffset.getZ()), this.selOffset.getY(), transform.mulZ(this.selOffset.getX(), this.selOffset.getZ()));
}
placer.commit();
this.addHotbar(TextColor.YELLOW + "Zwischenablage wurde bei %d, %d, %d eingefügt", to.getX(), to.getY(), to.getZ());
return true;
}
private static ClipboardBlock transformBlock(BlockTransform transform, ClipboardBlock block) {
private static ClipboardBlock transformBlock(Mat2i transform, ClipboardBlock block) {
RotationValue[] state = RotationRegistry.getRotation(block.getState().getBlock());
if(state == null)
return block;
@ -1469,9 +1469,9 @@ public class Player extends User implements ICrafting, Executor, IPlayer
return (x1 / l1) * (x2 / l2) + (z1 / l1) * (z2 / l2);
}
private static RotationValue getNewRotation(BlockTransform transform, RotationValue[] state, RotationValue value) {
int x = transform.applyX(value.getX(), value.getZ());
int z = transform.applyZ(value.getX(), value.getZ());
private static RotationValue getNewRotation(Mat2i transform, RotationValue[] state, RotationValue value) {
int x = transform.mulX(value.getX(), value.getZ());
int z = transform.mulZ(value.getX(), value.getZ());
RotationValue newValue = null;
double closest = -2;
for(RotationValue v : state) {