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);
}
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);
}
}
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";
}
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
}
}
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 + "\"";
}
Aggregations