HOOK_CHUNK_GENERATED


Index:
Articles
Classes
Hooks

Quick navigation:
BLOCK_SPREAD
BLOCK_TO_PICKUPS
BREWING_COMPLETED
BREWING_COMPLETING
CHAT
CHUNK_AVAILABLE
CHUNK_GENERATED
CHUNK_GENERATING
CHUNK_UNLOADED
CHUNK_UNLOADING
COLLECTING_PICKUP
CRAFTING_NO_RECIPE
DISCONNECT
ENTITY_ADD_EFFECT
ENTITY_CHANGED_WORLD
ENTITY_CHANGING_WORLD
ENTITY_TELEPORT
EXECUTE_COMMAND
EXPLODED
EXPLODING
HANDSHAKE
HOPPER_PULLING_ITEM
HOPPER_PUSHING_ITEM
KILLED
KILLING
LOGIN
PLAYER_ANIMATION
PLAYER_BREAKING_BLOCK
PLAYER_BROKEN_BLOCK
PLAYER_DESTROYED
PLAYER_EATING
PLAYER_FISHED
PLAYER_FISHING
PLAYER_FOOD_LEVEL_CHANGE
PLAYER_JOINED
PLAYER_LEFT_CLICK
PLAYER_MOVING
PLAYER_PLACED_BLOCK
PLAYER_PLACING_BLOCK
PLAYER_RIGHT_CLICK
PLAYER_RIGHT_CLICKING_ENTITY
PLAYER_SHOOTING
PLAYER_SPAWNED
PLAYER_TOSSING_ITEM
PLAYER_USED_BLOCK
PLAYER_USED_ITEM
PLAYER_USING_BLOCK
PLAYER_USING_ITEM
PLUGINS_LOADED
PLUGIN_MESSAGE
POST_CRAFTING
PRE_CRAFTING
PROJECTILE_HIT_BLOCK
PROJECTILE_HIT_ENTITY
SERVER_PING
SPAWNED_ENTITY
SPAWNED_MONSTER
SPAWNING_ENTITY
SPAWNING_MONSTER
TAKE_DAMAGE
TICK
UPDATED_SIGN
UPDATING_SIGN
WEATHER_CHANGED
WEATHER_CHANGING
WORLD_STARTED
WORLD_TICK

This hook is called when world generator finished its work on a chunk. The chunk data has already been generated and is about to be stored in the world. A plugin may provide some last-minute finishing touches to the generated data. Note that the chunk is not yet stored in the world, so regular cWorld block API will not work! Instead, use the cChunkDesc object received as the parameter.

See also the HOOK_CHUNK_GENERATING hook.


Callback function

The default name for the callback function is OnChunkGenerated. It has the following signature:

function MyOnChunkGenerated(World, ChunkX, ChunkZ, ChunkDesc)

Parameters:

NameTypeNotes
WorldcWorldThe world to which the chunk will be added
ChunkXnumberX-coord of the chunk
ChunkZnumberZ-coord of the chunk
ChunkDesccChunkDescGenerated chunk data. Plugins may still modify the chunk data contained.

If the plugin returns false or no value, Cuberite will call other plugins' callbacks for this event. If a plugin returns true, no other callback is called for this event.

In either case, Cuberite will then store the data from ChunkDesc as the chunk's contents in the world.


Code examples

Registering the callback

cPluginManager:AddHook(cPluginManager.HOOK_CHUNK_GENERATED, MyOnChunkGenerated);

Generate emerald ore

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.

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 Cuberite 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;
				
Generated on 2017-05-27 01:00:06, Build ID Unknown, Commit approx: 73a3c4e3be1916bdd4830e7ce7454035a1f572f6