use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class VisualCharacterSystem method createAndAttachVisualEntity.
private EntityRef createAndAttachVisualEntity(EntityBuilder entityBuilder, EntityRef characterEntity) {
entityBuilder.setPersistent(false);
entityBuilder.setOwner(characterEntity);
entityBuilder.addOrSaveComponent(new LocationComponent());
EntityRef visualCharacterEntity = entityBuilder.build();
Location.attachChild(characterEntity, visualCharacterEntity, new Vector3f(), new Quat4f(0, 0, 0, 1));
return visualCharacterEntity;
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class CoreCommands method bowlingPrep.
@Command(shortDescription = "Sets up a typical bowling pin arrangement in front of the player. ", helpText = "Spawns the specific block in a regular bowling pin pattern, Throw something at it!", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String bowlingPrep(@Sender EntityRef sender, @CommandParam("blockName") String blockName) {
ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
Vector3f spawnPos = characterLocation.getWorldPosition();
Vector3f offset = characterLocation.getWorldDirection();
offset.scale(5);
spawnPos.add(offset);
BlockFamily block = blockManager.getBlockFamily(blockName);
if (block == null) {
return "Sorry, your block is not found";
}
BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
Vector3f startPos = new Vector3f(spawnPos);
// delta x is the distance between the pins in the rows.
float deltax = 0.5f;
// delta z is the distance between the rows.
float deltaz = 1.0f;
// the height of the drop (to be modified to keep the bowlingPin upright)
float vectorY = 0.0f;
// rownumber loop is for selecting row
for (int rownumber = 0; rownumber < 4; rownumber++) {
// Spawn starting position for Rownumber
startPos.add(deltax * (4 - rownumber), vectorY, deltaz);
// pinPosx loop is for vectorx position of bowling pin in a particular row
for (int pinPosx = 0; pinPosx <= rownumber; pinPosx++) {
EntityRef blockItem = blockItemFactory.newInstance(block);
blockItem.send(new DropItemEvent(startPos));
if (pinPosx < rownumber) {
// drift of position in vector x coordinate, for the last pin stop drifting
startPos.add(2 * deltax, 0, 0);
}
}
// returns to start position
startPos.add(-deltax * (rownumber + 4), 0, 0);
}
return "prepared 10 " + blockName + " in a bowling pin pattern :)";
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class CoreCommands method spawnPrefab.
/**
* Spawns an instance of a prefab in the world
* @param sender Sender of command
* @param prefabName String containing prefab name
* @return String containing final message
*/
@Command(shortDescription = "Spawns an instance of a prefab in the world", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String spawnPrefab(@Sender EntityRef sender, @CommandParam("prefabId") String prefabName) {
ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
Vector3f spawnPos = characterLocation.getWorldPosition();
Vector3f offset = new Vector3f(characterLocation.getWorldDirection());
offset.scale(2);
spawnPos.add(offset);
Vector3f dir = new Vector3f(characterLocation.getWorldDirection());
dir.y = 0;
if (dir.lengthSquared() > 0.001f) {
dir.normalize();
} else {
dir.set(Direction.FORWARD.getVector3f());
}
Quat4f rotation = Quat4f.shortestArcQuat(Direction.FORWARD.getVector3f(), dir);
Optional<Prefab> prefab = Assets.getPrefab(prefabName);
if (prefab.isPresent() && prefab.get().getComponent(LocationComponent.class) != null) {
entityManager.create(prefab.get(), spawnPos, rotation);
return "Done";
} else if (!prefab.isPresent()) {
return "Unknown prefab";
} else {
return "Prefab cannot be spawned (no location component)";
}
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class CoreCommands method bulkDrop.
@Command(shortDescription = "Mass-drops the desired block however many times the player indicates", helpText = "First parameter indicates which block to drop, second parameter how many", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String bulkDrop(@Sender EntityRef sender, @CommandParam("blockName") String blockName, @CommandParam("value") int value) {
// This is a loop which gives the particular amount of block the player wants to spawn
ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
Vector3f spawnPos = characterLocation.getWorldPosition();
Vector3f offset = characterLocation.getWorldDirection();
offset.scale(3);
spawnPos.add(5, 10, 0);
BlockFamily block = blockManager.getBlockFamily(blockName);
if (block == null) {
return "Sorry, your block is not found";
}
BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
if (value > 5000) {
return "Value exceeds the maximum limit of 5000 blocks. your value: " + value + " blocks";
}
for (int i = 0; i < value; i++) {
EntityRef blockItem = blockItemFactory.newInstance(block);
blockItem.send(new DropItemEvent(spawnPos));
}
// this returns the block you have spawned and the amount
return "Dropped " + value + " " + blockName + " Blocks :)";
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class MovementDebugCommands method teleportAllPlayersToPlayer.
@Command(shortDescription = "Teleport all users to specified user", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String teleportAllPlayersToPlayer(@CommandParam("username") String username) {
Vector3f vPlayerLocation = Vector3f.zero();
boolean bPlayerLocationWasFound = false;
EntityRef playerEntity = null;
for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
if (username.equalsIgnoreCase(name.name)) {
LocationComponent locationComponent = clientEntity.getComponent(LocationComponent.class);
if (locationComponent != null) {
vPlayerLocation = locationComponent.getWorldPosition();
bPlayerLocationWasFound = true;
playerEntity = clientEntity;
}
break;
}
}
if (!bPlayerLocationWasFound) {
throw new IllegalArgumentException("No such user '" + username + "'");
}
MovementMode playerMovementMode = MovementMode.NONE;
ClientComponent clientInfo = playerEntity.getComponent(ClientComponent.class);
if (clientInfo != null) {
CharacterMovementComponent playerMovementComponent = clientInfo.character.getComponent(CharacterMovementComponent.class);
if (playerMovementComponent != null) {
playerMovementMode = playerMovementComponent.mode;
}
}
for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
if (clientComp != null) {
clientComp.character.send(new CharacterTeleportEvent(vPlayerLocation));
CharacterMovementComponent characterMovementComponent = clientComp.character.getComponent(CharacterMovementComponent.class);
if (characterMovementComponent != null && playerMovementMode != MovementMode.NONE && playerMovementMode != characterMovementComponent.mode) {
clientComp.character.send(new SetMovementModeEvent(playerMovementMode));
}
}
}
return "All possible players teleported to " + username + " and set to " + playerMovementMode;
}
Aggregations