summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/APIDump
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 03d90a8fb..586c3ae03 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -2182,6 +2182,43 @@ end;
<p>
In either case, MCServer will then store the data from ChunkDesc as the chunk's contents in the world.
]],
+ CodeExamples =
+ {
+ {
+ Title = "Generate emerald ore",
+ Desc = "This example callback function generates one block of emerald ore in each chunk, under the condition that the randomly chosen location is in an ExtremeHills biome.",
+ Code = [[
+function OnChunkGenerated(a_World, a_ChunkX, a_ChunkZ, a_ChunkDesc)
+ -- Generate a psaudorandom value that is always the same for the same X/Z pair, but is otherwise random enough:
+ -- This is actually similar to how MCServer does its noise functions
+ local PseudoRandom = (a_ChunkX * 57 + a_ChunkZ) * 57 + 19785486
+ PseudoRandom = PseudoRandom * 8192 + PseudoRandom;
+ PseudoRandom = ((PseudoRandom * (PseudoRandom * PseudoRandom * 15731 + 789221) + 1376312589) % 0x7fffffff;
+ PseudoRandom = PseudoRandom / 7;
+
+ -- Based on the PseudoRandom value, choose a location for the ore:
+ local OreX = PseudoRandom % 16;
+ local OreY = 2 + ((PseudoRandom / 16) % 20);
+ local OreZ = (PseudoRandom / 320) % 16;
+
+ -- Check if the location is in ExtremeHills:
+ if (a_ChunkDesc:GetBiome(OreX, OreZ) ~= biExtremeHills) then
+ return false;
+ end
+
+ -- Only replace allowed blocks with the ore:
+ local CurrBlock = a_ChunDesc:GetBlockType(OreX, OreY, OreZ);
+ if (
+ (CurrBlock == E_BLOCK_STONE) or
+ (CurrBlock == E_BLOCK_DIRT) or
+ (CurrBlock == E_BLOCK_GRAVEL)
+ ) then
+ a_ChunkDesc:SetBlockTypeMeta(OreX, OreY, OreZ, E_BLOCK_EMERALD_ORE, 0);
+ end
+end;
+ ]],
+ },
+ } , -- CodeExamples
}, -- HOOK_CHUNK_GENERATED
}, -- Hooks[]