Search in sources :

Example 61 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method setup.

@Before
public void setup() {
    context.put(NetworkSystem.class, mock(NetworkSystem.class));
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = (PojoEntityManager) context.get(EntityManager.class);
    PrefabData protoPrefab = new PrefabData();
    protoPrefab.addComponent(new StringComponent("Test"));
    prefab = Assets.generateAsset(new ResourceUrn("unittest:myprefab"), protoPrefab, Prefab.class);
}
Also used : PrefabData(org.terasology.entitySystem.prefab.PrefabData) StringComponent(org.terasology.entitySystem.stubs.StringComponent) NetworkSystem(org.terasology.network.NetworkSystem) ResourceUrn(org.terasology.assets.ResourceUrn) Prefab(org.terasology.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.entitySystem.prefab.internal.PojoPrefab) Before(org.junit.Before)

Example 62 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class HeightMapSurfaceHeightProvider method reloadHeightmap.

private void reloadHeightmap() {
    logger.info("Reading height map '{}'", configuration.heightMap);
    ResourceUrn urn = new ResourceUrn("core", configuration.heightMap);
    Texture texture = Assets.getTexture(urn).get();
    ByteBuffer[] bb = texture.getData().getBuffers();
    IntBuffer intBuf = bb[0].asIntBuffer();
    mapWidth = texture.getWidth();
    mapHeight = texture.getHeight();
    heightmap = new float[mapWidth][mapHeight];
    while (intBuf.position() < intBuf.limit()) {
        int pos = intBuf.position();
        long val = intBuf.get() & 0xFFFFFFFFL;
        heightmap[pos % mapWidth][pos / mapWidth] = val / (256 * 256 * 256 * 256f);
    }
}
Also used : IntBuffer(java.nio.IntBuffer) ResourceUrn(org.terasology.assets.ResourceUrn) Texture(org.terasology.rendering.assets.texture.Texture) ByteBuffer(java.nio.ByteBuffer)

Example 63 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class HealthCommands method restoreCollisionDamage.

@Command(shortDescription = "Restore default collision damage values", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String restoreCollisionDamage(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    Optional<Prefab> prefab = Assets.get(new ResourceUrn("engine:player"), Prefab.class);
    HealthComponent healthDefault = prefab.get().getComponent(HealthComponent.class);
    HealthComponent health = clientComp.character.getComponent(HealthComponent.class);
    if (health != null && healthDefault != null) {
        health.fallingDamageSpeedThreshold = healthDefault.fallingDamageSpeedThreshold;
        health.horizontalDamageSpeedThreshold = healthDefault.horizontalDamageSpeedThreshold;
        health.excessSpeedDamageMultiplier = healthDefault.excessSpeedDamageMultiplier;
        clientComp.character.saveComponent(health);
    }
    return "Normal collision damage values restored";
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) ClientComponent(org.terasology.network.ClientComponent) Prefab(org.terasology.entitySystem.prefab.Prefab) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 64 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class InventoryUIClientSystem method onToggleInventory.

/*
     * At the activation of the inventory the current dialog needs to be closed instantly.
     *
     * The close of the dialog triggers {@link #onScreenLayerClosed} which resets the
     * interactionTarget.
     */
@ReceiveEvent(components = ClientComponent.class, priority = EventPriority.PRIORITY_HIGH)
public void onToggleInventory(InventoryButton event, EntityRef entity, ClientComponent clientComponent) {
    if (event.getState() != ButtonState.DOWN) {
        return;
    }
    EntityRef character = clientComponent.character;
    ResourceUrn activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);
    if (activeInteractionScreenUri != null) {
        InteractionUtil.cancelInteractionAsClient(character);
    // do not consume the event, so that the inventory will still open
    }
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 65 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class ItemCommands method give.

@Command(shortDescription = "Adds an item or block to your inventory", helpText = "Puts the desired number of the given item or block with the given shape into your inventory", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String give(@Sender EntityRef client, @CommandParam("prefabId or blockName") String itemPrefabName, @CommandParam(value = "amount", required = false) Integer amount, @CommandParam(value = "blockShapeName", required = false) String shapeUriParam) {
    int itemAmount = amount != null ? amount : 1;
    if (itemAmount < 1) {
        return "Requested zero (0) items / blocks!";
    }
    Set<ResourceUrn> matches = assetManager.resolve(itemPrefabName, Prefab.class);
    if (matches.size() == 1) {
        Prefab prefab = assetManager.getAsset(matches.iterator().next(), Prefab.class).orElse(null);
        if (prefab != null && prefab.getComponent(ItemComponent.class) != null) {
            EntityRef playerEntity = client.getComponent(ClientComponent.class).character;
            for (int quantityLeft = itemAmount; quantityLeft > 0; quantityLeft--) {
                EntityRef item = entityManager.create(prefab);
                if (!inventoryManager.giveItem(playerEntity, playerEntity, item)) {
                    item.destroy();
                    itemAmount -= quantityLeft;
                    break;
                }
            }
            return "You received " + (itemAmount > 1 ? itemAmount + " items of " : "an item of ") + // TODO Use item display name
            prefab.getName() + (shapeUriParam != null ? " (Item can not have a shape)" : "");
        }
    } else if (matches.size() > 1) {
        StringBuilder builder = new StringBuilder();
        builder.append("Requested item \"");
        builder.append(itemPrefabName);
        builder.append("\": matches ");
        Joiner.on(" and ").appendTo(builder, matches);
        builder.append(". Please fully specify one.");
        return builder.toString();
    }
    // If no no matches are found for items, try blocks
    String message = blockCommands.giveBlock(client, itemPrefabName, amount, shapeUriParam);
    if (message != null) {
        return message;
    }
    return "Could not find an item or block matching \"" + itemPrefabName + "\"";
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) Prefab(org.terasology.entitySystem.prefab.Prefab) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Aggregations

ResourceUrn (org.terasology.assets.ResourceUrn)65 Before (org.junit.Before)10 BlockFamilyDefinitionData (org.terasology.world.block.loader.BlockFamilyDefinitionData)10 AssetManager (org.terasology.assets.management.AssetManager)9 Prefab (org.terasology.entitySystem.prefab.Prefab)9 SymmetricBlockFamilyFactory (org.terasology.world.block.family.SymmetricBlockFamilyFactory)9 Command (org.terasology.logic.console.commandSystem.annotations.Command)8 EntityRef (org.terasology.entitySystem.entity.EntityRef)7 PrefabData (org.terasology.entitySystem.prefab.PrefabData)7 BlockUri (org.terasology.world.block.BlockUri)7 Name (org.terasology.naming.Name)6 Texture (org.terasology.rendering.assets.texture.Texture)6 BlockManagerImpl (org.terasology.world.block.internal.BlockManagerImpl)6 NullWorldAtlas (org.terasology.world.block.tiles.NullWorldAtlas)6 ByteBuffer (java.nio.ByteBuffer)5 Test (org.junit.Test)5 SimpleUri (org.terasology.engine.SimpleUri)5 IOException (java.io.IOException)4 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)4 BiomeManager (org.terasology.world.biomes.BiomeManager)4