use of org.terasology.entitySystem.event.ReceiveEvent in project Anatomy by Terasology.
the class SkeletalAuthoritySystem method onRegen.
@ReceiveEvent
public void onRegen(DelayedActionTriggeredEvent event, EntityRef entityRef) {
BoneComponent boneComponent = entityRef.getComponent(BoneComponent.class);
String partID = event.getActionId().substring(SKELETAL_REGEN_PREFIX.length());
PartSkeletalDetails partDetails = boneComponent.parts.get(partID);
if (partDetails.health >= 0 && partDetails.health != partDetails.maxHealth && partDetails.regenRate != 0) {
int healAmount = 0;
healAmount = regenerateHealth(partDetails, healAmount);
partDetails.health += healAmount;
entityRef.saveComponent(boneComponent);
entityRef.send(new BoneHealthChangedEvent(partID));
}
delayManager.addDelayedAction(entityRef, SKELETAL_REGEN_PREFIX + partID, (long) (1000 / partDetails.regenRate));
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ServerViewDistanceSystem method onChangeViewDistanceChanged.
@ReceiveEvent(components = ClientComponent.class)
public void onChangeViewDistanceChanged(ViewDistanceChangedEvent request, EntityRef entity) {
Client client = networkSystem.getOwner(entity);
if (client != null) {
client.setViewDistanceMode(request.getNewViewRange());
chunkProvider.updateRelevanceEntity(entity, client.getViewDistance().getChunkDistance());
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ItemPickupAuthoritySystem method onBumpGiveItemToEntity.
@ReceiveEvent
public void onBumpGiveItemToEntity(CollideEvent event, EntityRef entity, PickupComponent pickupComponent) {
if (pickupComponent.timeDropped + pickupComponent.timeToPickUp < time.getGameTimeInMs()) {
GiveItemEvent giveItemEvent = new GiveItemEvent(event.getOtherEntity());
entity.send(giveItemEvent);
if (giveItemEvent.isHandled()) {
// remove all the components added from the pickup prefab
ItemComponent itemComponent = entity.getComponent(ItemComponent.class);
if (itemComponent != null) {
for (Component component : itemComponent.pickupPrefab.iterateComponents()) {
entity.removeComponent(component.getClass());
}
}
}
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class PlayerNameTagSystem method onCharacterActivation.
/**
* Listening for {@link org.terasology.logic.players.event.OnPlayerSpawnedEvent} does not work, as it is an
* authority event that does not get processed at clients. That is why we listen for the activation.
*/
@ReceiveEvent(components = CharacterComponent.class)
public void onCharacterActivation(OnActivatedComponent event, EntityRef characterEntity, CharacterComponent characterComponent) {
EntityRef ownerEntity = networkSystem.getOwnerEntity(characterEntity);
if (ownerEntity == null) {
// NPC
return;
}
ClientComponent clientComponent = ownerEntity.getComponent(ClientComponent.class);
if (clientComponent == null) {
logger.warn("Can't create player based name tag for character as owner has no client component");
return;
}
if (clientComponent.local) {
// the character belongs to the local player and does not need a name tag
return;
}
EntityRef clientInfoEntity = clientComponent.clientInfo;
DisplayNameComponent displayNameComponent = clientInfoEntity.getComponent(DisplayNameComponent.class);
if (displayNameComponent == null) {
logger.error("Can't create player based name tag for character as client info has no DisplayNameComponent");
return;
}
String name = displayNameComponent.name;
float yOffset = characterComponent.nameTagOffset;
Color color = Color.WHITE;
ColorComponent colorComponent = clientInfoEntity.getComponent(ColorComponent.class);
if (colorComponent != null) {
color = colorComponent.color;
}
NameTagComponent nameTagComponent = characterEntity.getComponent(NameTagComponent.class);
boolean newComponent = nameTagComponent == null;
if (nameTagComponent == null) {
nameTagComponent = new NameTagComponent();
}
nameTagComponent.text = name;
nameTagComponent.textColor = color;
nameTagComponent.yOffset = yOffset;
if (newComponent) {
characterEntity.addComponent(nameTagComponent);
} else {
characterEntity.saveComponent(nameTagComponent);
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class PlayerNameTagSystem method onDisplayNameChange.
@ReceiveEvent
public void onDisplayNameChange(OnChangedComponent event, EntityRef clientInfoEntity, DisplayNameComponent displayNameComponent) {
ClientInfoComponent clientInfoComp = clientInfoEntity.getComponent(ClientInfoComponent.class);
if (clientInfoComp == null) {
// not a client info object
return;
}
EntityRef clientEntity = clientInfoComp.client;
if (!clientEntity.exists()) {
// offline players aren't visible: nothing to do
return;
}
ClientComponent clientComponent = clientEntity.getComponent(ClientComponent.class);
if (clientComponent == null) {
logger.warn("Can't update name tag as client entity lacks ClietnComponent");
return;
}
EntityRef characterEntity = clientComponent.character;
if (characterEntity == null || !characterEntity.exists()) {
// player has no character, nothing to do
return;
}
NameTagComponent nameTagComponent = characterEntity.getComponent(NameTagComponent.class);
if (nameTagComponent == null) {
// local players don't have a name tag
return;
}
nameTagComponent.text = displayNameComponent.name;
characterEntity.saveComponent(nameTagComponent);
}
Aggregations