Skip to content

Commit

Permalink
attach no_pitch option
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 16, 2021
1 parent 3129cc3 commit 0ba91f8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public class AttachCommand extends AbstractCommand {

public AttachCommand() {
setName("attach");
setSyntax("attach [<entity>|...] [to:<entity>/cancel] (offset:<offset>) (relative) (yaw_offset:<#.#>) (pitch_offset:<#.#>) (sync_server) (no_rotate) (for:<player>|...)");
setSyntax("attach [<entity>|...] [to:<entity>/cancel] (offset:<offset>) (relative) (yaw_offset:<#.#>) (pitch_offset:<#.#>) (sync_server) (no_rotate/no_pitch) (for:<player>|...)");
setRequiredArguments(2, 9);
isProcedural = false;
}

// <--[command]
// @Name attach
// @Syntax attach [<entity>|...] [to:<entity>/cancel] (offset:<offset>) (relative) (yaw_offset:<#.#>) (pitch_offset:<#.#>) (sync_server) (no_rotate) (for:<player>|...)
// @Syntax attach [<entity>|...] [to:<entity>/cancel] (offset:<offset>) (relative) (yaw_offset:<#.#>) (pitch_offset:<#.#>) (sync_server) (no_rotate/no_pitch) (for:<player>|...)
// @Required 2
// @Maximum 9
// @Short Attaches a list of entities to another entity, for client-visible motion sync.
Expand All @@ -54,6 +54,7 @@ public AttachCommand() {
// Note that you should generally only use 'sync_server' when you exclude the 'for' argument.
//
// Optionally specify 'no_rotate' to retain the attached entity's own rotation and ignore the target rotation.
// Optionally instead specify 'no_pitch' to retain the attached entity's own pitch, but use the target yaw.
//
// Note that attaches involving a player will not be properly visible to that player, but will still be visible to *other* players.
//
Expand Down Expand Up @@ -95,6 +96,10 @@ else if (!scriptEntry.hasObject("no_rotate")
&& arg.matches("no_rotate")) {
scriptEntry.addObject("no_rotate", new ElementTag(true));
}
else if (!scriptEntry.hasObject("no_pitch")
&& arg.matches("no_pitch")) {
scriptEntry.addObject("no_pitch", new ElementTag(true));
}
else if (!scriptEntry.hasObject("yaw_offset")
&& arg.matchesPrefix("yaw_offset")
&& arg.matchesFloat()) {
Expand Down Expand Up @@ -133,6 +138,7 @@ else if (!scriptEntry.hasObject("entities")
scriptEntry.defaultObject("relative", new ElementTag(false));
scriptEntry.defaultObject("sync_server", new ElementTag(false));
scriptEntry.defaultObject("no_rotate", new ElementTag(false));
scriptEntry.defaultObject("no_pitch", new ElementTag(false));
scriptEntry.defaultObject("yaw_offset", new ElementTag(0f));
scriptEntry.defaultObject("pitch_offset", new ElementTag(0f));
}
Expand All @@ -147,12 +153,13 @@ public void execute(final ScriptEntry scriptEntry) {
ElementTag relative = scriptEntry.getElement("relative");
ElementTag sync_server = scriptEntry.getElement("sync_server");
ElementTag no_rotate = scriptEntry.getElement("no_rotate");
ElementTag no_pitch = scriptEntry.getElement("no_pitch");
ElementTag yaw_offset = scriptEntry.getElement("yaw_offset");
ElementTag pitch_offset = scriptEntry.getElement("pitch_offset");
boolean shouldCancel = cancel.asBoolean();
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), ArgumentHelper.debugList("entities", entities), (shouldCancel ? cancel.debug() : target.debug()), relative, offset,
yaw_offset, pitch_offset, sync_server, no_rotate, (forPlayers == null ? "" : ArgumentHelper.debugList("for", forPlayers)));
yaw_offset, pitch_offset, sync_server, no_rotate, no_pitch, (forPlayers == null ? "" : ArgumentHelper.debugList("for", forPlayers)));
}
BiConsumer<EntityTag, UUID> procPlayer = (entity, player) -> {
if (shouldCancel) {
Expand All @@ -169,6 +176,7 @@ public void execute(final ScriptEntry scriptEntry) {
attachment.syncServer = sync_server.asBoolean();
attachment.forPlayer = player;
attachment.noRotate = no_rotate.asBoolean();
attachment.noPitch = no_pitch.asBoolean();
EntityAttachmentHelper.registerAttachment(attachment);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ResourcePackCommand() {
//
// @Usage
// Use to send a resource pack with a pre-known hash.
// - resourcpack url:https://example.com/pack.zip hash:0102030405060708090a0b0c0d0e0f1112131415
// - resourcepack url:https://example.com/pack.zip hash:0102030405060708090a0b0c0d0e0f1112131415
//
// -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class AttachmentData {

public boolean syncServer;

public boolean noRotate;
public boolean noRotate, noPitch;

public BukkitTask checkTask;

Expand Down Expand Up @@ -69,6 +69,9 @@ public void run() {
goal.setYaw(attachLoc.getYaw());
goal.setPitch(attachLoc.getPitch());
}
else if (noPitch) {
goal.setPitch(attached.getLocation().getPitch());
}
attached.teleport(goal);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,10 @@ else if (isRotate) {
yaw = EntityAttachmentHelper.compressAngle(e.getYRot());
pitch = EntityAttachmentHelper.compressAngle(e.getXRot());
}
if (att.noPitch) {
Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
pitch = EntityAttachmentHelper.compressAngle(attachedEntity.getXRot());
}
byte newYaw = yaw;
if (isRotate) {
newYaw = EntityAttachmentHelper.adaptedCompressedAngle(newYaw, att.positionalOffset.getYaw());
Expand Down Expand Up @@ -735,6 +739,10 @@ public void tryProcessTeleportPacketForAttach(ClientboundTeleportEntityPacket pa
yaw = packet.getyRot();
pitch = packet.getxRot();
}
if (att.noPitch) {
Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
pitch = EntityAttachmentHelper.compressAngle(attachedEntity.getXRot());
}
byte newYaw = EntityAttachmentHelper.adaptedCompressedAngle(yaw, att.positionalOffset.getYaw());
pitch = EntityAttachmentHelper.adaptedCompressedAngle(pitch, att.positionalOffset.getPitch());
POS_X_PACKTELENT.setDouble(pNew, resultPos.getX());
Expand Down

0 comments on commit 0ba91f8

Please sign in to comment.