[TerrainGenerator] Portals added.
This commit is contained in:
parent
602e85f3d4
commit
2555d89fa2
@ -101,6 +101,7 @@ This list is non exhaustive.
|
||||
![](screenshot2.png?raw=true)
|
||||
![](screenshot3.png?raw=true)
|
||||
![](screenshot4.png?raw=true)
|
||||
![](screenshot5.png?raw=true)
|
||||
|
||||
## Credits
|
||||
|
||||
|
@ -38,12 +38,14 @@ Biome::Biome(u16 id, const std::string &stringID, const std::string &label) {
|
||||
void Biome::serialize(sf::Packet &packet) const {
|
||||
packet << m_id << m_stringID << m_label << m_params
|
||||
<< m_topBlockID << m_groundBlockID << m_deepBlockID << m_beachBlockID << m_liquidBlockID
|
||||
<< m_portalBlockID << m_portalFrameBlockID
|
||||
<< m_flora << m_ores << m_trees;
|
||||
}
|
||||
|
||||
void Biome::deserialize(sf::Packet &packet) {
|
||||
packet >> m_id >> m_stringID >> m_label >> m_params
|
||||
>> m_topBlockID >> m_groundBlockID >> m_deepBlockID >> m_beachBlockID >> m_liquidBlockID
|
||||
>> m_portalBlockID >> m_portalFrameBlockID
|
||||
>> m_flora >> m_ores >> m_trees;
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,8 @@ class Biome : public ISerializable {
|
||||
u16 getDeepBlockID() const { return m_deepBlockID; }
|
||||
u16 getBeachBlockID() const { return m_beachBlockID; }
|
||||
u16 getLiquidBlockID() const { return m_liquidBlockID; }
|
||||
u16 getPortalBlockID() const { return m_portalBlockID; }
|
||||
u16 getPortalFrameBlockID() const { return m_portalFrameBlockID; }
|
||||
|
||||
const std::vector<PlacementEntry::Flora> &getFlora() const { return m_flora; }
|
||||
const std::vector<PlacementEntry::Ore> &getOres() const { return m_ores; }
|
||||
@ -67,6 +69,8 @@ class Biome : public ISerializable {
|
||||
void setDeepBlockID(u16 value) { m_deepBlockID = value; }
|
||||
void setBeachBlockID(u16 value) { m_beachBlockID = value; }
|
||||
void setLiquidBlockID(u16 value) { m_liquidBlockID = value; }
|
||||
void setPortalBlockID(u16 value) { m_portalBlockID = value; }
|
||||
void setPortalFrameBlockID(u16 value) { m_portalFrameBlockID = value; }
|
||||
|
||||
PlacementEntry::Flora &addFlora() { m_flora.emplace_back(); return m_flora.back(); }
|
||||
PlacementEntry::Ore &addOre() { m_ores.emplace_back(); return m_ores.back(); }
|
||||
@ -85,6 +89,8 @@ class Biome : public ISerializable {
|
||||
u16 m_deepBlockID;
|
||||
u16 m_beachBlockID;
|
||||
u16 m_liquidBlockID;
|
||||
u16 m_portalBlockID;
|
||||
u16 m_portalFrameBlockID;
|
||||
|
||||
std::vector<PlacementEntry::Flora> m_flora;
|
||||
std::vector<PlacementEntry::Ore> m_ores;
|
||||
|
@ -39,6 +39,8 @@ mod:biome {
|
||||
deep_block = "default:stone",
|
||||
beach_block = "default:sand",
|
||||
liquid_block = "default:water",
|
||||
portal_block = "default:portal",
|
||||
portal_frame_block = "default:obsidian",
|
||||
|
||||
trees = {
|
||||
{
|
||||
@ -102,7 +104,9 @@ mod:biome {
|
||||
ground_block = "default:sand",
|
||||
deep_block = "default:stone",
|
||||
beach_block = "default:sand",
|
||||
liquid_block = "default:water"
|
||||
liquid_block = "default:water",
|
||||
portal_block = "default:portal",
|
||||
portal_frame_block = "default:obsidian",
|
||||
}
|
||||
|
||||
mod:biome {
|
||||
@ -118,6 +122,8 @@ mod:biome {
|
||||
ground_block = "default:netherrack",
|
||||
deep_block = "default:netherrack",
|
||||
beach_block = "default:soul_sand",
|
||||
liquid_block = "default:lava"
|
||||
liquid_block = "default:lava",
|
||||
portal_block = "default:portal",
|
||||
portal_frame_block = "default:obsidian",
|
||||
}
|
||||
|
||||
|
@ -204,11 +204,15 @@ mod:block {
|
||||
|
||||
on_block_activated = function(pos, player, world, client, server, screen_width, screen_height, gui_scale)
|
||||
local dim = (player:dimension() + 1) % 2
|
||||
local pos = {x = 0, y = 0, z = 20}
|
||||
local pos = {
|
||||
x = math.floor(player:x()),
|
||||
y = math.floor(player:y()),
|
||||
z = math.floor(player:z())
|
||||
}
|
||||
|
||||
server:send_player_change_dimension(client.id, pos.x, pos.y, pos.z, dim, client)
|
||||
player:set_dimension(dim)
|
||||
player:set_position(pos.x, pos.y, pos.z)
|
||||
-- player:set_position(pos.x, pos.y, pos.z)
|
||||
end,
|
||||
}
|
||||
|
||||
@ -263,3 +267,11 @@ mod:block {
|
||||
},
|
||||
}
|
||||
|
||||
mod:block {
|
||||
id = "obsidian",
|
||||
name = "Obsidian",
|
||||
tiles = "obsidian.png",
|
||||
|
||||
hardness = 2,
|
||||
}
|
||||
|
||||
|
BIN
mods/default/textures/blocks/obsidian.png
Normal file
BIN
mods/default/textures/blocks/obsidian.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/default/textures_mc/blocks/obsidian.png
Normal file
BIN
mods/default/textures_mc/blocks/obsidian.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 489 B |
BIN
screenshot5.png
Normal file
BIN
screenshot5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 MiB |
@ -90,6 +90,9 @@ void ScriptEngine::initUsertypes() {
|
||||
m_lua.new_usertype<Player>("Player",
|
||||
"inventory", &Player::inventory,
|
||||
|
||||
"x", &Player::x,
|
||||
"y", &Player::y,
|
||||
"z", &Player::z,
|
||||
"set_position", &Player::setPosition,
|
||||
|
||||
"dimension", &Player::dimension,
|
||||
|
@ -96,6 +96,8 @@ inline void LuaBiomeLoader::loadBiomeBlocks(Biome &biome, const sol::table &tabl
|
||||
biome.setDeepBlockID(Registry::getInstance().getBlockFromStringID(table["deep_block"]).id());
|
||||
biome.setBeachBlockID(Registry::getInstance().getBlockFromStringID(table["beach_block"]).id());
|
||||
biome.setLiquidBlockID(Registry::getInstance().getBlockFromStringID(table["liquid_block"]).id());
|
||||
biome.setPortalBlockID(Registry::getInstance().getBlockFromStringID(table["portal_block"]).id());
|
||||
biome.setPortalFrameBlockID(Registry::getInstance().getBlockFromStringID(table["portal_frame_block"]).id());
|
||||
}
|
||||
|
||||
inline void LuaBiomeLoader::loadTreePlacementEntries(Biome &biome, const sol::table &table) const {
|
||||
|
@ -118,8 +118,25 @@ void TerrainGenerator::fastNoiseGeneration(ServerChunk &chunk) const {
|
||||
break;
|
||||
}
|
||||
|
||||
// FIXME: This is a temporary portal generation
|
||||
// This code should be replaced by a proper "feature" implementation
|
||||
// which will also allow making stuff like villages easier
|
||||
bool placedPortal = false;
|
||||
if (chunk.getBlock(x, y, z - 1) == biome.getTopBlockID() && rand() % 4096 == 0) {
|
||||
for (int ix = 0 ; ix < 4 ; ++ix) {
|
||||
for (int iz = 0 ; iz < 5 ; ++iz) {
|
||||
if (ix == 0 || iz == 0 || ix == 3 || iz == 4)
|
||||
chunk.setBlockRaw(x + ix, y, z + iz, biome.getPortalFrameBlockID());
|
||||
else
|
||||
chunk.setBlockRaw(x + ix, y, z + iz, biome.getPortalBlockID());
|
||||
}
|
||||
}
|
||||
|
||||
placedPortal = true;
|
||||
}
|
||||
|
||||
// Otherwise set sunlight.
|
||||
if (!placedFlora && z == CHUNK_HEIGHT - 1) {
|
||||
if (!placedFlora && !placedPortal && z == CHUNK_HEIGHT - 1) {
|
||||
chunk.lightmap().addSunlight(x, y, z, 15);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user