Skip to content

Commit

Permalink
part 3: less silly rotation handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 9, 2018
1 parent 6eaa93c commit 7586a8b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
Expand Up @@ -34,6 +34,7 @@
import org.bukkit.util.Vector;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -226,7 +227,7 @@ public BiomeNMS getBiomeNMS(Biome biome) {
public HashMap<UUID, UUID> attachmentsA = new HashMap<UUID, UUID>(); // Key follows value
public HashMap<UUID, UUID> attachments2 = new HashMap<UUID, UUID>(); // Value follows key
public HashMap<UUID, Vector> attachmentOffsets = new HashMap<>();
public HashMap<UUID, Vector> attachmentRotations = new HashMap<>();
public HashSet<UUID> attachmentRotations = new HashSet<>();
public HashMap<UUID, Vector> visiblePositions = new HashMap<>();

@Override
Expand All @@ -244,7 +245,7 @@ public void forceAttachMove(Entity a, Entity b, Vector offset, boolean matchRota
attachments2.put(b.getUniqueId(), a.getUniqueId());
attachmentOffsets.put(a.getUniqueId(), offset);
if (matchRotation) {
attachmentRotations.put(a.getUniqueId(), new Vector((((CraftEntity) b).getHandle()).pitch, (((CraftEntity) b).getHandle()).yaw, 0));
attachmentRotations.add(a.getUniqueId());
}
}
}
Expand Up @@ -146,13 +146,13 @@ else if (packet instanceof PacketPlayOutEntity) {
ENTITY_ID_PACKENT.setInt(pNew, target.getEntityId());
Vector offset = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentOffsets.get(att);
if (offset != null && (packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMove || packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)) {
Vector rotationBasis = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentRotations.get(att);
boolean rotationBasis = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentRotations.contains(att);
Vector goalPosition;
if (rotationBasis == null) {
if (!rotationBasis) {
goalPosition = new Vector(e.locX, e.locY, e.locZ).add(offset);
}
else {
goalPosition = new Vector(e.locX, e.locY, e.locZ).add(NMSHandler.fixOffset(offset, rotationBasis.getY() - e.yaw, rotationBasis.getX() - e.pitch));
goalPosition = new Vector(e.locX, e.locY, e.locZ).add(NMSHandler.fixOffset(offset, -e.yaw, e.pitch));
}
Vector oldPos = ((Handler_v1_12_R1) NMSHandler.getInstance()).visiblePositions.get(target.getUniqueId());
if (oldPos == null) {
Expand Down Expand Up @@ -235,13 +235,13 @@ else if (packet instanceof PacketPlayOutEntityTeleport) {
Vector offset = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentOffsets.get(att);
Vector resultPos = new Vector(POS_X_PACKTELENT.getDouble(pNew), POS_Y_PACKTELENT.getDouble(pNew), POS_Z_PACKTELENT.getDouble(pNew));
if (offset != null) {
Vector rotationBasis = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentRotations.get(att);
boolean rotationBasis = ((Handler_v1_12_R1) NMSHandler.getInstance()).attachmentRotations.contains(att);
Vector goalOffset;
if (rotationBasis == null) {
if (!rotationBasis) {
goalOffset = offset;
}
else {
goalOffset = NMSHandler.fixOffset(offset, rotationBasis.getY() - e.yaw, rotationBasis.getX() - e.pitch);
goalOffset = NMSHandler.fixOffset(offset, -e.yaw, e.pitch);
}
POS_X_PACKTELENT.setDouble(pNew, POS_X_PACKTELENT.getDouble(pNew) + goalOffset.getX());
POS_Y_PACKTELENT.setDouble(pNew, POS_Y_PACKTELENT.getDouble(pNew) + goalOffset.getY());
Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.bukkit.util.Vector;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -226,7 +227,7 @@ public BiomeNMS getBiomeNMS(Biome biome) {
public HashMap<UUID, UUID> attachmentsA = new HashMap<UUID, UUID>(); // Key follows value
public HashMap<UUID, UUID> attachments2 = new HashMap<UUID, UUID>(); // Value follows key
public HashMap<UUID, Vector> attachmentOffsets = new HashMap<>();
public HashMap<UUID, Vector> attachmentRotations = new HashMap<>();
public HashSet<UUID> attachmentRotations = new HashSet<>();
public HashMap<UUID, Vector> visiblePositions = new HashMap<>();

@Override
Expand All @@ -244,7 +245,7 @@ public void forceAttachMove(Entity a, Entity b, Vector offset, boolean matchRota
attachments2.put(b.getUniqueId(), a.getUniqueId());
attachmentOffsets.put(a.getUniqueId(), offset);
if (matchRotation) {
attachmentRotations.put(a.getUniqueId(), new Vector((((CraftEntity) b).getHandle()).pitch, (((CraftEntity) b).getHandle()).yaw, 0));
attachmentRotations.add(a.getUniqueId());
}
}
}
Expand Up @@ -157,13 +157,13 @@ else if (packet instanceof PacketPlayOutEntity) {
ENTITY_ID_PACKENT.setInt(pNew, target.getEntityId());
Vector offset = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentOffsets.get(att);
if (offset != null && (packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMove || packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)) {
Vector rotationBasis = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentRotations.get(att);
boolean rotationBasis = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentRotations.contains(att);
Vector goalPosition;
if (rotationBasis == null) {
if (!rotationBasis) {
goalPosition = new Vector(e.locX, e.locY, e.locZ).add(offset);
}
else {
goalPosition = new Vector(e.locX, e.locY, e.locZ).add(NMSHandler.fixOffset(offset, rotationBasis.getY() - e.yaw, rotationBasis.getX() - e.pitch));
goalPosition = new Vector(e.locX, e.locY, e.locZ).add(NMSHandler.fixOffset(offset, -e.yaw, e.pitch));
}
Vector oldPos = ((Handler_v1_13_R2) NMSHandler.getInstance()).visiblePositions.get(target.getUniqueId());
if (oldPos == null) {
Expand Down Expand Up @@ -246,13 +246,13 @@ else if (packet instanceof PacketPlayOutEntityTeleport) {
Vector offset = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentOffsets.get(att);
Vector resultPos = new Vector(POS_X_PACKTELENT.getDouble(pNew), POS_Y_PACKTELENT.getDouble(pNew), POS_Z_PACKTELENT.getDouble(pNew));
if (offset != null) {
Vector rotationBasis = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentRotations.get(att);
boolean rotationBasis = ((Handler_v1_13_R2) NMSHandler.getInstance()).attachmentRotations.contains(att);
Vector goalOffset;
if (rotationBasis == null) {
if (!rotationBasis) {
goalOffset = offset;
}
else {
goalOffset = NMSHandler.fixOffset(offset, rotationBasis.getY() - e.yaw, rotationBasis.getX() - e.pitch);
goalOffset = NMSHandler.fixOffset(offset, -e.yaw, e.pitch);
}
POS_X_PACKTELENT.setDouble(pNew, POS_X_PACKTELENT.getDouble(pNew) + goalOffset.getX());
POS_Y_PACKTELENT.setDouble(pNew, POS_Y_PACKTELENT.getDouble(pNew) + goalOffset.getY());
Expand Down

0 comments on commit 7586a8b

Please sign in to comment.