use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class ExplosionAuthoritySystem method onActivate.
@ReceiveEvent
public void onActivate(ActivateEvent event, EntityRef entity, ExplosionActionComponent explosionComp) {
Vector3f origin = null;
switch(explosionComp.relativeTo) {
case Self:
LocationComponent loc = entity.getComponent(LocationComponent.class);
if (loc != null) {
origin = loc.getWorldPosition();
}
break;
case Instigator:
origin = event.getInstigatorLocation();
break;
default:
origin = event.getTargetLocation();
break;
}
if (origin == null) {
return;
}
doExplosion(explosionComp, origin, EntityRef.NULL);
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class EntityAwareWorldProvider method createBlockEntity.
private EntityRef createBlockEntity(Vector3i blockPosition, Block block) {
EntityBuilder builder = entityManager.newBuilder(block.getPrefab().orElse(null));
builder.addComponent(new LocationComponent(blockPosition.toVector3f()));
builder.addComponent(new BlockComponent(block, blockPosition));
boolean isTemporary = isTemporaryBlock(builder, block);
if (!isTemporary && !builder.hasComponent(NetworkComponent.class)) {
builder.addComponent(new NetworkComponent());
}
EntityRef blockEntity;
if (isTemporary) {
blockEntity = builder.buildWithoutLifecycleEvents();
temporaryBlockEntities.add(blockEntity);
} else {
blockEntity = builder.build();
}
blockEntityLookup.put(new Vector3i(blockPosition), blockEntity);
return blockEntity;
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class BlockSelectionSystem method onStartSelectionAtEntity.
@ReceiveEvent(components = { LocationComponent.class })
public void onStartSelectionAtEntity(SetBlockSelectionStartingPointEvent event, EntityRef entity) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
if (null == locationComponent) {
// entity isn't LocationComponent, which shouldn't ever be the case
return;
}
BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
if (null == blockSelectionComponent) {
// event did not provide a BlockSelection component to modify
return;
}
Vector3f worldPosition = locationComponent.getWorldPosition();
Vector3i startPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z);
blockSelectionComponent.startPosition = startPosition;
Vector3i endPosition = startPosition;
blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition);
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class BlockSelectionSystem method onEndSelectionAtEntity.
@ReceiveEvent(components = { LocationComponent.class })
public void onEndSelectionAtEntity(SetBlockSelectionEndingPointEvent event, EntityRef entity) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
if (null == locationComponent) {
// entity isn't LocationComponent, which shouldn't ever be the case
return;
}
BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
if (null == blockSelectionComponent) {
// event did not provide a BlockSelection component to modify
return;
}
Vector3f worldPosition = locationComponent.getWorldPosition();
Vector3i endPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z);
Vector3i startPosition = blockSelectionComponent.startPosition;
if (null == startPosition) {
startPosition = endPosition;
}
blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition);
}
use of org.terasology.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class BlockCommands method replaceBlock.
@Command(shortDescription = "Replaces a block in front of user", helpText = "Replaces a block in front of the user at the specified max distance", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public void replaceBlock(@Sender EntityRef sender, @CommandParam("blockName") String uri, @CommandParam(value = "maxDistance", required = false) Integer maxDistanceParam) {
int maxDistance = maxDistanceParam != null ? maxDistanceParam : 12;
EntityRef playerEntity = sender.getComponent(ClientComponent.class).character;
EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(playerEntity);
LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
Set<ResourceUrn> matchingUris = Assets.resolveAssetUri(uri, BlockFamilyDefinition.class);
targetSystem.updateTarget(gazeLocation.getWorldPosition(), gazeLocation.getWorldDirection(), maxDistance);
EntityRef target = targetSystem.getTarget();
BlockComponent targetLocation = target.getComponent(BlockComponent.class);
if (matchingUris.size() == 1) {
Optional<BlockFamilyDefinition> def = Assets.get(matchingUris.iterator().next(), BlockFamilyDefinition.class);
if (def.isPresent()) {
BlockFamily blockFamily = blockManager.getBlockFamily(uri);
Block block = blockManager.getBlock(blockFamily.getURI());
world.setBlock(targetLocation.getPosition(), block);
} else if (matchingUris.size() > 1) {
StringBuilder builder = new StringBuilder();
builder.append("Non-unique shape name, possible matches: ");
Iterator<ResourceUrn> shapeUris = sortItems(matchingUris).iterator();
while (shapeUris.hasNext()) {
builder.append(shapeUris.next().toString());
if (shapeUris.hasNext()) {
builder.append(", ");
}
}
}
}
}
Aggregations