Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Rotation arg for Teleport and Spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenmai committed Oct 18, 2017
1 parent 8933b81 commit abb84a3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
Expand Up @@ -24,15 +24,16 @@ public class SpawnCommand extends AbstractCommand {
// @Name spawn
// @Arguments <entity type> <location> [map of properties]
// @Short spawns a new entity.
// @Updated 2016/09/26
// @Updated 2017/10/18
// @Group Entity
// @Minimum 2
// @Maximum 3
// @Named rotation (LocationTag) Sets the entity's rotation.
// @Tag <[spawn_success]> (BooleanTag) returns whether the spawn passed.
// @Tag <[spawn_entity]> (EntityTag) returns the entity that was spawned (only if the spawn passed).
// @Description
// Spawns an entity at the specified location. Optionally, specify a MapTag of properties
// to spawn the entity with those values automatically set on it.
// Spawns an entity at the specified location. Optionally, specify rotation and a
// MapTag of properties to spawn the entity with those values automatically set on it.
// Related information: <@link explanation Entity Types>entity types<@/link>.
// @Example
// # Spawns a sheep that feels the burn.
Expand Down Expand Up @@ -88,11 +89,24 @@ public void execute(CommandQueue queue, CommandEntry entry) {
}
}
}
if (queue.shouldShowGood()) {
queue.outGood("Spawning an entity of type "
+ ColorSet.emphasis + entityType.getId() + ColorSet.good
+ " with the following properties: " + ColorSet.emphasis + propertyMap.debug()
+ " at location " + ColorSet.emphasis + locationTag.debug() + ColorSet.good + "...");
if (entry.namedArgs.containsKey("rotation")) {
LocationTag rot = LocationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "rotation"));
entity.setTransform(entity.getTransform().setRotation(rot.getInternal().toVector3d()));
if (queue.shouldShowGood()) {
queue.outGood("Spawning an entity of type " + ColorSet.emphasis + entityType.getId()
+ ColorSet.good + " with the following properties: " + ColorSet.emphasis
+ propertyMap.debug() + ColorSet.good + " at location " + ColorSet.emphasis
+ locationTag.debug() + ColorSet.good + " and rotation " + ColorSet.emphasis
+ rot.debug() + ColorSet.good + "...");
}
}
else {
if (queue.shouldShowGood()) {
queue.outGood("Spawning an entity of type " + ColorSet.emphasis + entityType.getId()
+ ColorSet.good + " with the following properties: " + ColorSet.emphasis
+ propertyMap.debug() + ColorSet.good + " at location " + ColorSet.emphasis
+ locationTag.debug() + ColorSet.good + "...");
}
}
boolean passed = location.world.spawnEntity(entity);
// TODO: "Cause" argument!
Expand Down
Expand Up @@ -13,12 +13,13 @@ public class TeleportCommand extends AbstractCommand {
// @Name teleport
// @Arguments <entity> <location>
// @Short teleports the entity to a location.
// @Updated 2016/09/05
// @Updated 2017/10/18
// @Group Entity
// @Minimum 2
// @Maximum 2
// @Named rotation (LocationTag) Sets the entity's rotation.
// @Description
// Teleports the entity to a location.
// Teleports the entity to a location. Optionally specify a rotation.
// TODO: Explain more!
// @Example
// # This example teleports the player five blocks upward
Expand Down Expand Up @@ -49,10 +50,24 @@ public int getMaximumArguments() {
public void execute(CommandQueue queue, CommandEntry entry) {
EntityTag ent = EntityTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
LocationTag loc = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
if (queue.shouldShowGood()) {
queue.outGood("Teleporting " + ColorSet.emphasis + ent.debug() + ColorSet.good
+ " to " + ColorSet.emphasis + loc.debug() + ColorSet.good + "!");
if (entry.namedArgs.containsKey("rotation")) {
LocationTag rot = LocationTag.getFor(queue.error, entry.getNamedArgumentObject(queue, "rotation"));
ent.getInternal().setTransform(ent.getInternal().getTransform()
.setLocation(loc.getInternal().toLocation())
.setRotation(rot.getInternal().toVector3d())); // TODO: use the returned boolean?
if (queue.shouldShowGood()) {
queue.outGood("Teleporting " + ColorSet.emphasis + ent.debug() + ColorSet.good
+ " to location " + ColorSet.emphasis + loc.debug() + ColorSet.good
+ " and rotation " + ColorSet.emphasis + rot.debug() + "!");
}
}
ent.getInternal().setLocation(loc.getInternal().toLocation()); // TODO: use the returned boolean?
else {
ent.getInternal().setLocation(loc.getInternal().toLocation()); // TODO: use the returned boolean?
if (queue.shouldShowGood()) {
queue.outGood("Teleporting " + ColorSet.emphasis + ent.debug() + ColorSet.good
+ " to location " + ColorSet.emphasis + loc.debug() + ColorSet.good + "!");
}
}

}
}

0 comments on commit abb84a3

Please sign in to comment.