use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterInventorySystem method onSlotButton.
@ReceiveEvent(components = { CharacterComponent.class }, netFilter = RegisterMode.CLIENT)
public void onSlotButton(ToolbarSlotButton event, EntityRef entity) {
localPlayer.getCharacterEntity().send(new ChangeSelectedInventorySlotRequest(event.getSlot()));
event.consume();
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterInventorySystem method ensureTransferSlotIsCreated.
@ReceiveEvent(netFilter = RegisterMode.AUTHORITY)
public void ensureTransferSlotIsCreated(OnAddedComponent event, EntityRef entityRef, CharacterComponent characterComponent) {
EntityRef transferSlot = entityManager.create("core:transferSlot");
characterComponent.movingItem = transferSlot;
entityRef.saveComponent(characterComponent);
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterInventorySystem method onDropItemRequest.
@ReceiveEvent(components = { CharacterComponent.class, InventoryComponent.class }, netFilter = RegisterMode.CLIENT)
public void onDropItemRequest(DropItemButton event, EntityRef entity) {
CharacterHeldItemComponent characterHeldItemComponent = entity.getComponent(CharacterHeldItemComponent.class);
EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
if (selectedItemEntity.equals(EntityRef.NULL)) {
return;
}
// this is a repeating event.
if (event.isDown() && lastTimeThrowInteraction == 0) {
lastTimeThrowInteraction = time.getGameTimeInMs();
return;
}
// resize the crosshair
InventoryHud toolbar = nuiManager.getHUD().getHUDElement("core:InventoryHud", InventoryHud.class);
if (toolbar != null) {
toolbar.setChargeAmount(getDropPower());
}
float dropPower = getDropPower();
// handle when we finally let go
if (!event.isDown()) {
// Compute new position
dropPower *= 150f;
Vector3f position = localPlayer.getViewPosition();
Vector3f direction = localPlayer.getViewDirection();
Vector3f maxAllowedDistanceInDirection = direction.mul(1.5f);
HitResult hitResult = physics.rayTrace(position, direction, 1.5f, StandardCollisionGroup.CHARACTER, StandardCollisionGroup.WORLD);
if (hitResult.isHit()) {
Vector3f possibleNewPosition = hitResult.getHitPoint();
maxAllowedDistanceInDirection = possibleNewPosition.sub(position);
}
Vector3f newPosition = position;
newPosition.add(maxAllowedDistanceInDirection.mul(0.9f));
// send DropItemRequest
Vector3f impulseVector = new Vector3f(direction);
impulseVector.scale(dropPower);
entity.send(new DropItemRequest(selectedItemEntity, entity, impulseVector, newPosition));
characterHeldItemComponent.lastItemUsedTime = time.getGameTimeInMs();
entity.saveComponent(characterHeldItemComponent);
resetDropMark();
}
event.consume();
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterInventorySystem method onChangeSelectedInventorySlotRequested.
@ReceiveEvent(netFilter = RegisterMode.AUTHORITY)
public void onChangeSelectedInventorySlotRequested(ChangeSelectedInventorySlotRequest request, EntityRef character, SelectedInventorySlotComponent selectedInventorySlotComponent) {
if (request.getSlot() >= 0 && request.getSlot() < 10 && request.getSlot() != selectedInventorySlotComponent.slot) {
EntityRef newItem = InventoryUtils.getItemAt(character, request.getSlot());
selectedInventorySlotComponent.slot = request.getSlot();
character.saveComponent(selectedInventorySlotComponent);
character.send(new ChangeHeldItemRequest(newItem));
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class InventoryClientSystem method inventoryChangeAcknowledge.
@ReceiveEvent(components = { InventoryComponent.class })
public void inventoryChangeAcknowledge(InventoryChangeAcknowledgedRequest event, EntityRef entity) {
// TODO: This does not ever get triggered because the event is sent to the client, not the character.
// If it did get triggered, it causes a mess of question mark items.
AbstractMoveItemRequest removedRequest = pendingMoves.remove(event.getChangeId());
if (removedRequest != null) {
destroyClientTempEntities(removedRequest);
}
recalculatePredictedState();
}
Aggregations