Terra (Fabric/Forge/Paper)

Terra (Fabric/Forge/Paper)

74.2k Downloads

Terrascript - Dynamic block

astrsh opened this issue ยท 4 comments

commented

Allow the block argument for the Terrascript block function to be dynamic. Eg. picking a random ore type to be contained in a boulder would require duplicating all the block functions for each ore, which is unwieldy, but with dynamic blocks you could just set the block to a variable and change that variable in one place.

commented

This will be implemented as its own function, dynamicBlock, that way we can more easily cover the documentation in warnings.

commented

alternative to that: what if we just implemented kotlin style switch cases?

when(randomInt(8)) {
    0 -> block(1, 2, 3, "minecraft:stone");
    1 -> block(1, 2, 3, "minecraft:coal_ore");
    2 -> block(1, 2, 3, "minecraft:iron_ore");
    3 -> block(1, 2, 3, "minecraft:gold_ore");
    4 -> block(1, 2, 3, "minecraft:redstone_ore");
    5 -> block(1, 2, 3, "minecraft:diamond_ore");
    6 -> block(1, 2, 3, "minecraft:emerald_ore");
    7 -> block(1, 2, 3, "minecraft:netherrite_block");
    else -> print("h o w");
}

it could also be really useful for the check function.

when(check(1, 2, 3)) {
    "AIR" -> print("is air");
    "OCEAN" -> print("is ocean");
    "LAND" -> {
        print("is land");
        block(1, 2, 3, "minecraft:stone");
    }
    else -> print("error");
}

they can also remove large if chains. For example, from the stronghold.tesf structure:

when {
    check( 13, y + 0, -8) != "LAND" -> fail;
    check(-12, y + 5, -8) != "LAND" -> fail;
    check(-12, y + 0,  8) != "LAND" -> fail;
    check( 13, y + 0,  8) != "LAND" -> fail;
    check( 13, y + 5, -8) != "LAND" -> fail;
    check( 13, y + 5,  8) != "LAND" -> fail;
    check(-11, y + 0, -8) != "LAND" -> fail;
    check(-12, y + 5,  8) != "LAND" -> fail;
}

I would like to note though: I'd much prefer the word with over when, but then again, when makes more sense for the last example. So maybe both? idk.

commented

Also, wouldn't you be able to do this?

str blockType = "";
num block = randomInt(3);
if (block == 0)
    blockType = "minecraft:one";
else if (block == 1)
    blockType = "minecraft:two";
else if (block == 2)
    blockType = "minecraft:three";

block(1, 2, 3, blockType); // use as many of these as you want.
commented

Implemented as dynamicBlock in cda2d46