mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Improvements to VillagerEntity (#2412)
* initial changes to villager * touchup * don't call getPos() twice * whoops, better
This commit is contained in:
parent
8c95e26189
commit
6f93bbfe21
1 changed files with 30 additions and 38 deletions
|
@ -100,55 +100,47 @@ public class VillagerEntity extends AbstractMerchantEntity {
|
|||
|
||||
@Override
|
||||
public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) {
|
||||
if (!metadata.getFlags().getFlag(EntityFlag.SLEEPING)) {
|
||||
// The bed block position, if it exists
|
||||
Vector3i bedPosition;
|
||||
if (!metadata.getFlags().getFlag(EntityFlag.SLEEPING) || (bedPosition = metadata.getPos(EntityData.BED_POSITION, null)) == null) {
|
||||
// No need to worry about extra processing to compensate for sleeping
|
||||
super.moveRelative(session, relX, relY, relZ, rotation, isOnGround);
|
||||
return;
|
||||
}
|
||||
|
||||
int z = 0;
|
||||
int bedId = 0;
|
||||
float bedPositionSubtractorW = 0;
|
||||
float bedPositionSubtractorN = 0;
|
||||
Vector3i bedPosition = metadata.getPos(EntityData.BED_POSITION, null);
|
||||
if (bedPosition != null) {
|
||||
bedId = session.getConnector().getWorldManager().getBlockAt(session, bedPosition);
|
||||
// The bed block
|
||||
int blockId = session.getConnector().getWorldManager().getBlockAt(session, bedPosition);
|
||||
String fullIdentifier = BlockRegistries.JAVA_IDENTIFIERS.get().get(blockId);
|
||||
|
||||
// Set the correct position offset and rotation when sleeping
|
||||
int bedRotation = 0;
|
||||
float xOffset = 0;
|
||||
float zOffset = 0;
|
||||
if (fullIdentifier.contains("facing=south")) {
|
||||
// bed is facing south
|
||||
bedRotation = 180;
|
||||
zOffset = -.5f;
|
||||
} else if (fullIdentifier.contains("facing=east")) {
|
||||
// bed is facing east
|
||||
bedRotation = 90;
|
||||
xOffset = -.5f;
|
||||
} else if (fullIdentifier.contains("facing=west")) {
|
||||
// bed is facing west
|
||||
bedRotation = 270;
|
||||
xOffset = .5f;
|
||||
} else if (fullIdentifier.contains("facing=north")) {
|
||||
// rotation does not change because north is 0
|
||||
zOffset = .5f;
|
||||
}
|
||||
String bedRotationZ = BlockRegistries.JAVA_IDENTIFIERS.get().get(bedId);
|
||||
|
||||
setRotation(rotation);
|
||||
setOnGround(isOnGround);
|
||||
this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ);
|
||||
|
||||
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
||||
moveEntityPacket.setRuntimeEntityId(geyserId);
|
||||
//Sets Villager position and rotation when sleeping
|
||||
Pattern r = Pattern.compile("facing=([a-z]+)");
|
||||
Matcher m = r.matcher(bedRotationZ);
|
||||
if (m.find()) {
|
||||
switch (m.group(0)) {
|
||||
case "facing=south":
|
||||
//bed is facing south
|
||||
z = 180;
|
||||
bedPositionSubtractorW = -.5f;
|
||||
break;
|
||||
case "facing=east":
|
||||
//bed is facing east
|
||||
z = 90;
|
||||
bedPositionSubtractorW = -.5f;
|
||||
break;
|
||||
case "facing=west":
|
||||
//bed is facing west
|
||||
z = 270;
|
||||
bedPositionSubtractorW = .5f;
|
||||
break;
|
||||
case "facing=north":
|
||||
//rotation does not change because north is 0
|
||||
bedPositionSubtractorN = .5f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
moveEntityPacket.setRotation(Vector3f.from(0, 0, z));
|
||||
moveEntityPacket.setPosition(Vector3f.from(position.getX() + bedPositionSubtractorW, position.getY(), position.getZ() + bedPositionSubtractorN));
|
||||
moveEntityPacket.setRotation(Vector3f.from(0, 0, bedRotation));
|
||||
moveEntityPacket.setPosition(Vector3f.from(position.getX() + xOffset, position.getY(), position.getZ() + zOffset));
|
||||
moveEntityPacket.setOnGround(isOnGround);
|
||||
moveEntityPacket.setTeleported(false);
|
||||
session.sendUpstreamPacket(moveEntityPacket);
|
||||
|
|
Loading…
Reference in a new issue