Add client command source properties (#1518)

* Add extra fields to FabricClientCommandSource

* Re-add `getPlayer`

* Fix style errors

* Make the meta property a `Map`

* Update Javadoc

* Implement requested changes

* Fix styling errors

* Implement requested changes

* Implement requested changes

* Implement requested changes
This commit is contained in:
Fred 2021-07-23 18:06:18 +02:00 committed by GitHub
parent 25611bb75a
commit fc9d06d347
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,7 +20,10 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -58,10 +61,49 @@ public interface FabricClientCommandSource extends CommandSource {
*/
ClientPlayerEntity getPlayer();
/**
* Gets the entity that used the command.
*
* @return the entity
*/
default Entity getEntity() {
return getPlayer();
}
/**
* Gets the position from where the command has been executed.
*
* @return the position
*/
default Vec3d getPosition() {
return getPlayer().getPos();
}
/**
* Gets the rotation of the entity that used the command.
*
* @return the rotation
*/
default Vec2f getRotation() {
return getPlayer().getRotationClient();
}
/**
* Gets the world where the player used the command.
*
* @return the world
*/
ClientWorld getWorld();
/**
* Gets the meta property under {@code key} that was assigned to this source.
*
* <p>This method should return the same result for every call with the same {@code key}.
*
* @param key the meta key
* @return the meta
*/
default Object getMeta(String key) {
return null;
}
}