use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class AwaitCharacterSpawn method step.
@Override
public boolean step() {
ComponentSystemManager componentSystemManager = context.get(ComponentSystemManager.class);
for (UpdateSubscriberSystem updater : componentSystemManager.iterateUpdateSubscribers()) {
updater.update(0.0f);
}
LocalPlayer localPlayer = context.get(LocalPlayer.class);
ClientComponent client = localPlayer.getClientEntity().getComponent(ClientComponent.class);
if (client != null && client.character.exists()) {
client.character.send(new AwaitedLocalCharacterSpawnEvent());
return true;
} else {
chunkProvider.update();
}
return false;
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class AbstractState method createLocalPlayer.
protected static void createLocalPlayer(Context context) {
EngineEntityManager entityManager = context.get(EngineEntityManager.class);
EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
LocalPlayer localPlayer = new LocalPlayer();
localPlayer.setRecordAndReplayClasses(context.get(DirectionAndOriginPosRecorderList.class), context.get(RecordAndReplayCurrentStatus.class));
context.put(LocalPlayer.class, localPlayer);
localPlayer.setClientEntity(localPlayerEntity);
}
use of org.terasology.engine.network.ClientComponent 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(new Vector3f());
Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
offset.mul(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.engine.network.ClientComponent 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(new Vector3f());
Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
offset.mul(2);
spawnPos.add(offset);
Vector3f dir = characterLocation.getWorldDirection(new Vector3f());
dir.y = 0;
if (dir.lengthSquared() > 0.001f) {
dir.normalize();
} else {
dir.set(Direction.FORWARD.asVector3f());
}
return Assets.getPrefab(prefabName).map(prefab -> {
LocationComponent loc = prefab.getComponent(LocationComponent.class);
if (loc != null) {
entityManager.create(prefab, spawnPos);
return "Done";
} else {
return "Prefab cannot be spawned (no location component)";
}
}).orElse("Unknown prefab");
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class InteractionSystem method onInteractionStartPredicted.
@ReceiveEvent(components = InteractionScreenComponent.class)
public void onInteractionStartPredicted(InteractionStartPredicted event, EntityRef container, InteractionScreenComponent interactionScreenComponent) {
EntityRef investigator = event.getInstigator();
CharacterComponent characterComponent = investigator.getComponent(CharacterComponent.class);
if (characterComponent == null) {
logger.error("Interaction start predicted for entity without character component");
return;
}
ClientComponent controller = characterComponent.controller.getComponent(ClientComponent.class);
if (controller != null && controller.local) {
nuiManager.closeAllScreens();
nuiManager.pushScreen(interactionScreenComponent.screen);
}
}
Aggregations