use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class LocalPlayerSystem method onUseItemButton.
@ReceiveEvent(components = CharacterComponent.class)
public void onUseItemButton(UseItemButton event, EntityRef entity, CharacterHeldItemComponent characterHeldItemComponent) {
if (!event.isDown()) {
return;
}
EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
if (!selectedItemEntity.exists()) {
return;
}
boolean requestIsValid;
if (networkSystem.getMode().isAuthority()) {
// Let the ActivationRequest handler trigger the OnItemUseEvent if this is a local client
requestIsValid = true;
} else {
OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
entity.send(onItemUseEvent);
requestIsValid = !onItemUseEvent.isConsumed();
}
if (requestIsValid) {
localPlayer.activateOwnedEntityAsClient(selectedItemEntity);
entity.saveComponent(characterHeldItemComponent);
event.consume();
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class LocalPlayerSystem method onTargetChanged.
@ReceiveEvent
public void onTargetChanged(PlayerTargetChangedEvent event, EntityRef entity) {
EntityRef target = event.getNewTarget();
hasTarget = target.exists();
if (hasTarget) {
LocationComponent location = target.getComponent(LocationComponent.class);
if (location != null) {
BlockComponent blockComp = target.getComponent(BlockComponent.class);
BlockRegionComponent blockRegion = target.getComponent(BlockRegionComponent.class);
if (blockComp != null || blockRegion != null) {
Vector3f blockPos = location.getWorldPosition(new Vector3f());
Block block = worldProvider.getBlock(blockPos);
aabb.set(block.getBounds(blockPos));
} else {
MeshComponent mesh = target.getComponent(MeshComponent.class);
if (mesh != null && mesh.mesh != null) {
aabb.set(mesh.mesh.getAABB());
aabb.transform(new Matrix4f().translationRotateScale(location.getWorldPosition(new Vector3f()), location.getWorldRotation(new Quaternionf()), location.getWorldScale()));
}
}
}
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class FirstPersonClientSystem method onHeldItemChanged.
@ReceiveEvent
public void onHeldItemChanged(OnChangedComponent event, EntityRef character, CharacterHeldItemComponent heldItemComponent, CharacterComponent characterComponents) {
if (localPlayer.getCharacterEntity().equals(character)) {
EntityRef newItem = heldItemComponent.selectedItem;
linkHeldItemLocationForLocalPlayer(newItem);
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class Location method onDestroyed.
@ReceiveEvent
public void onDestroyed(BeforeRemoveComponent event, EntityRef entity, LocationComponent location) {
if (location.parent.exists()) {
removeChild(location.parent, entity);
}
Iterator<EntityRef> childIterator = location.getChildren().iterator();
while (childIterator.hasNext()) {
EntityRef child = childIterator.next();
LocationComponent childLoc = child.getComponent(LocationComponent.class);
if (childLoc != null) {
Vector3f oldWorldPos = childLoc.getWorldPosition(new Vector3f());
childLoc.parent = EntityRef.NULL;
childLoc.setWorldPosition(oldWorldPos);
child.saveComponent(childLoc);
}
childIterator.remove();
}
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ItemPickupAuthoritySystem method onDropItemEvent.
@ReceiveEvent
public void onDropItemEvent(DropItemEvent event, EntityRef itemEntity, ItemComponent itemComponent) {
for (Component component : itemComponent.pickupPrefab.iterateComponents()) {
Component componentCopy = library.getComponentLibrary().copy(component);
if (componentCopy instanceof LocationComponent) {
((LocationComponent) componentCopy).setWorldPosition(event.getPosition());
}
itemEntity.addOrSaveComponent(componentCopy);
}
if (!itemEntity.hasComponent(LocationComponent.class)) {
itemEntity.addComponent(new LocationComponent(event.getPosition()));
}
}
Aggregations