use of org.terasology.entitySystem.event.ReceiveEvent in project Anatomy by Terasology.
the class SkeletalAuthoritySystem method onBoneDamage.
@ReceiveEvent
public void onBoneDamage(AnatomyPartImpactedEvent event, EntityRef entityRef, AnatomyComponent anatomyComponent, BoneComponent boneComponent) {
PartSkeletalDetails partDetails = boneComponent.parts.get(event.getTargetPart().id);
// Check if the part contains bone.
int damageAmount = event.getAmount();
if (partDetails != null) {
if (event.getDamageType().getName().equals("Equipment:bluntDamage")) {
damageAmount *= bluntDamageMultiplier;
}
partDetails.health -= damageAmount;
if (partDetails.health < 0) {
partDetails.health = 0;
}
partDetails.nextRegenTick = time.getGameTimeInMs() + TeraMath.floorToInt(partDetails.waitBeforeRegen * 1000);
entityRef.saveComponent(boneComponent);
entityRef.send(new BoneHealthChangedEvent(event.getTargetPart().id));
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Anatomy by Terasology.
the class AnatomySystem method onDamage.
@ReceiveEvent
public void onDamage(OnDamagedEvent event, EntityRef entity, AnatomyComponent comp) {
if (comp != null) {
List<String> keys = new ArrayList<>(comp.parts.keySet());
// Randomly assign damage to a part, until positional damage is introduced.
AnatomyPartTag partTag = comp.parts.get(keys.get(random.nextInt(0, keys.size() - 1)));
entity.send(new AnatomyPartImpactedEvent(event.getDamageAmount(), partTag, event.getType(), event.getInstigator()));
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class SkeletonRenderer method newSkeleton.
@ReceiveEvent(components = { SkeletalMeshComponent.class, LocationComponent.class })
public void newSkeleton(OnActivatedComponent event, EntityRef entity) {
SkeletalMeshComponent skeleton = entity.getComponent(SkeletalMeshComponent.class);
if (skeleton.mesh == null) {
return;
}
if (skeleton.boneEntities == null) {
skeleton.boneEntities = Maps.newHashMap();
for (Bone bone : skeleton.mesh.getBones()) {
LocationComponent loc = new LocationComponent();
EntityRef parent = (bone.getParent() != null) ? skeleton.boneEntities.get(bone.getParent().getName()) : entity;
EntityRef boneEntity = entityManager.create(loc);
Location.attachChild(parent, boneEntity);
loc.setLocalPosition(bone.getLocalPosition());
loc.setLocalRotation(bone.getLocalRotation());
if (bone.getParent() == null) {
skeleton.rootBone = boneEntity;
}
skeleton.boneEntities.put(bone.getName(), boneEntity);
}
entity.saveComponent(skeleton);
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class BlockEntitySystem method defaultDropsHandling.
@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void defaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, ActAsBlockComponent blockComponent) {
if (blockComponent.block != null) {
if (entity.hasComponent(BlockRegionComponent.class)) {
BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
if (blockComponent.dropBlocksInRegion) {
// loop through all the blocks in this region and drop them
for (Vector3i location : blockRegion.region) {
Block blockInWorld = worldProvider.getBlock(location);
commonDefaultDropsHandling(event, entity, location, blockInWorld.getBlockFamily().getArchetypeBlock());
}
} else {
// just drop the ActAsBlock block
Vector3i location = new Vector3i(blockRegion.region.center(), RoundingMode.HALF_UP);
commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
}
} else if (entity.hasComponent(LocationComponent.class)) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
Vector3i location = new Vector3i(locationComponent.getWorldPosition(), RoundingMode.HALF_UP);
commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
}
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class NeighbourBlockFamilyUpdateSystem method blockUpdate.
@ReceiveEvent(components = { BlockComponent.class })
public void blockUpdate(OnChangedBlock event, EntityRef blockEntity) {
if (largeBlockUpdateCount > 0) {
blocksUpdatedInLargeBlockUpdate.add(event.getBlockPosition());
} else {
Vector3i blockLocation = event.getBlockPosition();
processUpdateForBlockLocation(blockLocation);
}
}
Aggregations