-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8d4aea
commit 4cc522e
Showing
11 changed files
with
687 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
server/src/main/java/com/soulfiremc/server/util/EntityMovement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.soulfiremc.server.util; | ||
|
||
import org.cloudburstmc.math.vector.Vector3d; | ||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PositionElement; | ||
|
||
import java.util.List; | ||
|
||
public record EntityMovement(Vector3d pos, Vector3d deltaMovement, float yRot, float xRot) { | ||
public static EntityMovement toAbsolute(EntityMovement current, EntityMovement packet, List<PositionElement> relative) { | ||
var x = relative.contains(PositionElement.X) ? current.pos().getX() + packet.pos().getX() : packet.pos().getX(); | ||
var y = relative.contains(PositionElement.Y) ? current.pos().getY() + packet.pos().getY() : packet.pos().getY(); | ||
var z = relative.contains(PositionElement.Z) ? current.pos().getZ() + packet.pos().getZ() : packet.pos().getZ(); | ||
var yRot = | ||
relative.contains(PositionElement.Y_ROT) | ||
? current.yRot() + packet.yRot() | ||
: packet.yRot(); | ||
var xRot = | ||
relative.contains(PositionElement.X_ROT) | ||
? current.xRot() + packet.xRot() | ||
: packet.xRot(); | ||
var deltaMovement = packet.deltaMovement(); | ||
if (relative.contains(PositionElement.ROTATE_DELTA)) { | ||
var k = current.yRot() - yRot; | ||
var l = current.xRot() - xRot; | ||
deltaMovement = VectorHelper.xRot(deltaMovement, (float) Math.toRadians(l)); | ||
deltaMovement = VectorHelper.yRot(deltaMovement, (float) Math.toRadians(k)); | ||
} | ||
|
||
return new EntityMovement(Vector3d.from(x, y, z), Vector3d.from( | ||
relative.contains(PositionElement.DELTA_X) ? current.deltaMovement().getX() + deltaMovement.getX() : deltaMovement.getX(), | ||
relative.contains(PositionElement.DELTA_Y) ? current.deltaMovement().getY() + deltaMovement.getY() : deltaMovement.getY(), | ||
relative.contains(PositionElement.DELTA_Z) ? current.deltaMovement().getZ() + deltaMovement.getZ() : deltaMovement.getZ() | ||
), yRot, xRot); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
server/src/main/java/com/soulfiremc/server/util/mcstructs/BlockHitResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.soulfiremc.server.util.mcstructs; | ||
|
||
import org.cloudburstmc.math.vector.Vector3d; | ||
import org.cloudburstmc.math.vector.Vector3i; | ||
|
||
public class BlockHitResult extends HitResult { | ||
private final Direction direction; | ||
private final Vector3i blockPos; | ||
private final boolean miss; | ||
private final boolean inside; | ||
private final boolean worldBorderHit; | ||
|
||
public static BlockHitResult miss(Vector3d location, Direction direction, Vector3i pos) { | ||
return new BlockHitResult(true, location, direction, pos, false, false); | ||
} | ||
|
||
public BlockHitResult(Vector3d arg, Direction arg2, Vector3i arg3, boolean bl) { | ||
this(false, arg, arg2, arg3, bl, false); | ||
} | ||
|
||
public BlockHitResult(Vector3d arg, Direction arg2, Vector3i arg3, boolean bl, boolean bl2) { | ||
this(false, arg, arg2, arg3, bl, bl2); | ||
} | ||
|
||
private BlockHitResult(boolean bl, Vector3d arg, Direction arg2, Vector3i arg3, boolean bl2, boolean bl3) { | ||
super(arg); | ||
this.miss = bl; | ||
this.direction = arg2; | ||
this.blockPos = arg3; | ||
this.inside = bl2; | ||
this.worldBorderHit = bl3; | ||
} | ||
|
||
public BlockHitResult withDirection(Direction newFace) { | ||
return new BlockHitResult(this.miss, this.location, newFace, this.blockPos, this.inside, this.worldBorderHit); | ||
} | ||
|
||
public BlockHitResult withPosition(Vector3i pos) { | ||
return new BlockHitResult(this.miss, this.location, this.direction, pos, this.inside, this.worldBorderHit); | ||
} | ||
|
||
public BlockHitResult hitBorder() { | ||
return new BlockHitResult(this.miss, this.location, this.direction, this.blockPos, this.inside, true); | ||
} | ||
|
||
public Vector3i getVector3i() { | ||
return this.blockPos; | ||
} | ||
|
||
public Direction getDirection() { | ||
return this.direction; | ||
} | ||
|
||
@Override | ||
public HitResult.Type getType() { | ||
return this.miss ? HitResult.Type.MISS : HitResult.Type.BLOCK; | ||
} | ||
|
||
public boolean isInside() { | ||
return this.inside; | ||
} | ||
|
||
public boolean isWorldBorderHit() { | ||
return this.worldBorderHit; | ||
} | ||
} |
Oops, something went wrong.