Search in sources :

Example 16 with LocationComponent

use of org.terasology.engine.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(new Vector3f()), gazeLocation.getWorldDirection(new Vector3f()), 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(", ");
                }
            }
        }
    }
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) BlockComponent(org.terasology.engine.world.block.BlockComponent) Vector3f(org.joml.Vector3f) Iterator(java.util.Iterator) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 17 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent 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 (Vector3ic 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(new Vector3f()), 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(new Vector3f()), RoundingMode.HALF_UP);
            commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 18 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class ByteCodeReflectFactoryTest method testCreateConstructorObjectWithPublicConstructor.

@Test
public void testCreateConstructorObjectWithPublicConstructor() throws NoSuchMethodException {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    ObjectConstructor<LocationComponent> constructor = reflectFactory.createConstructor(LocationComponent.class);
    LocationComponent locationComponent = constructor.construct();
    assertNotNull(locationComponent);
}
Also used : ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Test(org.junit.jupiter.api.Test)

Example 19 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class IterateComponentsBenchmark method iterateMultipleComponent.

@Benchmark
public void iterateMultipleComponent(StateObject state) {
    for (EntityRef entity : state.entityManager.getEntitiesWith(MeshComponent.class, LocationComponent.class)) {
        LocationComponent loc = entity.getComponent(LocationComponent.class);
        MeshComponent meshComp = entity.getComponent(MeshComponent.class);
        loc.getLocalPosition();
    }
}
Also used : MeshComponent(org.terasology.engine.rendering.logic.MeshComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 20 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class IterateComponentsBenchmark method iterateSingleComponent.

@Benchmark
public void iterateSingleComponent(StateObject state) {
    for (EntityRef entity : state.entityManager.getEntitiesWith(LocationComponent.class)) {
        LocationComponent loc = entity.getComponent(LocationComponent.class);
        loc.getLocalPosition();
    }
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Aggregations

LocationComponent (org.terasology.engine.logic.location.LocationComponent)65 Vector3f (org.joml.Vector3f)46 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)40 Quaternionf (org.joml.Quaternionf)18 ClientComponent (org.terasology.engine.network.ClientComponent)17 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)9 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)9 Matrix4f (org.joml.Matrix4f)7 Vector3i (org.joml.Vector3i)6 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)5 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)5 Vector3fc (org.joml.Vector3fc)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)4 CharacterHeldItemComponent (org.terasology.engine.logic.characters.CharacterHeldItemComponent)4 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)4 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)4 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)4 Bone (org.terasology.engine.rendering.assets.skeletalmesh.Bone)4 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)4 Component (org.terasology.gestalt.entitysystem.component.Component)4