Xar Block Override Demo

Back

The Demo Instalation

Here is the package xar_block_override_demo which you can unzip and put in the directory Input/Packages.

Then go the package Input/Packages/xar (create it if it does not already exist) and have the file Input/Packages/xar/dependencies.txt read as follows:
wf base
wf xar
wf xar_block_override_demo

Find a Yellow Flower in the World

Load a game that uses the xar package. Find a Small Yellow Flower in the world. It should look normal, like the following:



Overriding the Xar Block 1

Right now the file
xar_block_override_demo/WorldNodes/xar/xar_block_overrides.txt
should read as follows:
#XAR_SMALL_YELLOW_FLOWER block_xar_small_yellow_flower_1
#XAR_SMALL_YELLOW_FLOWER block_xar_small_yellow_flower_2
That is, both lines are commented out (# = comment), so there are no overrides.

Now uncomment the first line so the file is as follows:
XAR_SMALL_YELLOW_FLOWER block_xar_small_yellow_flower_1
#XAR_SMALL_YELLOW_FLOWER block_xar_small_yellow_flower_2
Now load your game and look at the Small Yellow Flower. It should look as follows:


That is, instead of the Small Yellow Flower block being generated the normal way, it is generated by the Lua block script

"xar_block_override_demo/WorldNodes/Nodes/block_xar_small_yellow_flower_1.lua".
Here is the code to that Lua script:
function p.__get_is_solid()
    return false
end

function p.__get_tex()
    return ""
end

function p.__main()
    set_default_block("e")

    create_rect("s", 7,7,0, 7,7,7)
    set_pos(7,7,8, "XAR_LARGE_CANNON_PYRAMID")
    set_pos(7,7,10, "block_meme_welcome_1")
end
That is, this script creates a column of solid "block_s" blocks, with a XAR_LARGE_CANNON_PYRAMID block on top. Floating on top of that is a block_meme_welcome_1 block.

Overriding the Xar Block 2

Now go to the file
xar_block_override_demo/WorldNodes/xar/xar_block_overrides.txt
and change it so it reads as follows:
#XAR_SMALL_YELLOW_FLOWER block_xar_small_yellow_flower_1
XAR_SMALL_YELLOW_FLOWER block_xar_small_yellow_flower_2
Load your game and look at the Small Yellow Flower. It should look as follows:


Here is the code to the Lua script block_xar_small_yellow_flower_2.lua:
function p.__get_is_solid()
    return false
end

function p.__get_tex()
    return ""
end

function p.__main()
    set_default_block("e")

    --Generating the chunk as if
    --it was of type XAR_SMALL_YELLOW_FLOWER.
    create_xar_chunk("XAR_SMALL_YELLOW_FLOWER")

    --Replacing the yellow block in the yellow flower
    --with a meme block.
    for x = 0,15 do
    for y = 0,15 do
    for z = 0,15 do
        if( get_pos(x,y,z) == "XAR_SMALL_YELLOW_FLOWER_ROOM" ) then
            set_pos(x,y,z, "block_meme_welcome_1")
        end
    end end end
end
What is happening here is the block Lua script calls the function

create_xar_chunk("XAR_SMALL_YELLOW_FLOWER")

which generates the block as if it was a XAR_SMALL_YELLOW_FLOWER block. However after this call we replace the XAR_SMALL_YELLOW_FLOWER_ROOM block with a meme block.