use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ArrowAction method onActivate.
@ReceiveEvent
public void onActivate(ActivateEvent event, EntityRef entity, ArrowActionComponent arrowActionComponent) {
if (time.getGameTime() > lastTime + 1.0f / arrowActionComponent.arrowsPerSecond) {
Vector3f target = event.getHitNormal();
Vector3i blockPos = new Vector3i(target);
Vector3f position = new Vector3f(event.getOrigin());
Vector3f dir = new Vector3f(event.getDirection());
HitResult result;
result = physicsRenderer.rayTrace(position, dir, arrowActionComponent.maxDistance, filter);
Block currentBlock = worldProvider.getBlock(blockPos);
if (currentBlock.isDestructible()) {
EntityBuilder builder = entityManager.newBuilder("Core:defaultBlockParticles");
builder.getComponent(LocationComponent.class).setWorldPosition(target);
builder.build();
}
EntityRef blockEntity = result.getEntity();
blockEntity.send(new DoDamageEvent(arrowActionComponent.damageAmount, arrowActionComponent.damageType));
lastTime = time.getGameTime();
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class BlockDamageAuthoritySystem method beforeDamagedEnsureHealthPresent.
@ReceiveEvent
public void beforeDamagedEnsureHealthPresent(BeforeDamagedEvent event, EntityRef blockEntity, BlockComponent blockComponent) {
if (!blockEntity.hasComponent(HealthComponent.class)) {
Block type = blockComponent.getBlock();
if (type.isDestructible()) {
HealthComponent healthComponent = new HealthComponent(type.getHardness(), type.getHardness() / BLOCK_REGEN_SECONDS, 1.0f);
healthComponent.destroyEntityOnNoHealth = true;
blockEntity.addComponent(healthComponent);
}
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class HealthAuthoritySystem method onCrash.
@ReceiveEvent(components = { HealthComponent.class })
public void onCrash(HorizontalCollisionEvent event, EntityRef entity) {
HealthComponent health = entity.getComponent(HealthComponent.class);
Vector3f vel = new Vector3f(event.getVelocity());
vel.y = 0;
float speed = vel.length();
if (speed > health.horizontalDamageSpeedThreshold) {
int damage = (int) ((speed - health.horizontalDamageSpeedThreshold) * health.excessSpeedDamageMultiplier);
if (damage > 0) {
checkDamage(entity, damage, EngineDamageTypes.PHYSICAL.get(), EntityRef.NULL, EntityRef.NULL);
}
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class HealthAuthoritySystem method onCrash.
@ReceiveEvent
public void onCrash(HorizontalCollisionEvent event, EntityRef entity, CharacterSoundComponent characterSounds, HealthComponent healthComponent) {
Vector3f horizVelocity = new Vector3f(event.getVelocity());
horizVelocity.y = 0;
float velocity = horizVelocity.length();
if (velocity > healthComponent.horizontalDamageSpeedThreshold) {
if (characterSounds.lastSoundTime + CharacterSoundSystem.MIN_TIME < time.getGameTimeInMs()) {
StaticSound sound = random.nextItem(characterSounds.landingSounds);
if (sound != null) {
entity.send(new PlaySoundEvent(sound, characterSounds.landingVolume));
characterSounds.lastSoundTime = time.getGameTimeInMs();
entity.saveComponent(characterSounds);
}
}
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterInventorySystem method onNextItem.
@ReceiveEvent(components = { CharacterComponent.class }, netFilter = RegisterMode.CLIENT)
public void onNextItem(ToolbarNextButton event, EntityRef entity, SelectedInventorySlotComponent selectedInventorySlotComponent) {
int nextSlot = (selectedInventorySlotComponent.slot + 1) % 10;
localPlayer.getCharacterEntity().send(new ChangeSelectedInventorySlotRequest(nextSlot));
event.consume();
}
Aggregations