Skip to content

Commit 7e4b041

Browse files
committed
fix smartglass direction
1 parent f1e2c5a commit 7e4b041

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/PocketPeripheralOwner.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,46 @@ public String getCustomName() {
4242
@Override
4343
public Level getLevel() {
4444
Entity owner = pocket.getEntity();
45-
if (owner == null) return null;
46-
return owner.getCommandSenderWorld();
45+
return owner == null ? null : owner.getCommandSenderWorld();
4746
}
4847

4948
@NotNull
5049
@Override
5150
public BlockPos getPos() {
5251
Entity owner = pocket.getEntity();
53-
if (owner == null) return new BlockPos(0, 0, 0);
54-
return owner.blockPosition();
52+
return owner == null ? BlockPos.ZERO : new BlockPos(owner.getEyePosition());
5553
}
5654

5755
@NotNull
5856
@Override
5957
public Vec3 getCenterPos() {
6058
Entity owner = pocket.getEntity();
61-
if (owner == null) return new Vec3(0, 0, 0);
62-
return owner.position();
59+
return owner == null ? Vec3.ZERO : owner.getEyePosition();
6360
}
6461

6562
@NotNull
6663
@Override
6764
public Direction getFacing() {
68-
Entity owner = pocket.getEntity();
69-
if (owner == null) return Direction.NORTH;
70-
return owner.getDirection();
65+
Vec3 dir = getDirection();
66+
return Direction.getNearest(dir.x, dir.y, dir.z);
7167
}
7268

73-
/**
74-
* Not used for pockets
75-
*/
7669
@NotNull
7770
@Override
7871
public FrontAndTop getOrientation() {
79-
return FrontAndTop.NORTH_UP;
72+
Entity owner = pocket.getEntity();
73+
if (owner == null) {
74+
return FrontAndTop.NORTH_UP;
75+
}
76+
Vec3 up = owner.getUpVector(1.0f);
77+
return FrontAndTop.fromFrontAndTop(getFacing(), Direction.getNearest(up.x, up.y, up.z));
78+
}
79+
80+
@NotNull
81+
@Override
82+
public Vec3 getDirection() {
83+
Entity owner = pocket.getEntity();
84+
return owner == null ? /* North */ new Vec3(0, 0, -1) : owner.getLookAngle();
8085
}
8186

8287
@Nullable

src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/DistanceDetectorPeripheral.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ protected double calculateDistanceImpl() {
257257
if (result.getType() == HitResult.Type.MISS) {
258258
return -1;
259259
}
260-
return result.getLocation().distanceTo(center) - 0.5f;
260+
double distance = result.getLocation().distanceTo(center);
261+
if (this.tileEntity != null) {
262+
distance -= 0.5;
263+
}
264+
return distance;
261265
}
262266

263267
/**

0 commit comments

Comments
 (0)