From 1767c635fe6b2fca4c7034ae163c10b5741d5408 Mon Sep 17 00:00:00 2001 From: Lord_Cambion Date: Fri, 27 Mar 2026 19:38:19 +0100 Subject: [PATCH] reworked the mossyclobblestone feature --- Minecraft.World/BlockBlobFeature.cpp | 64 ++++++++++++++++++++++++++++ Minecraft.World/BlockBlobFeature.h | 13 ++++++ Minecraft.World/CMakeLists.txt | 2 +- Minecraft.World/TaigaBiome.cpp | 15 ++----- 4 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 Minecraft.World/BlockBlobFeature.cpp create mode 100644 Minecraft.World/BlockBlobFeature.h diff --git a/Minecraft.World/BlockBlobFeature.cpp b/Minecraft.World/BlockBlobFeature.cpp new file mode 100644 index 00000000..8a854a09 --- /dev/null +++ b/Minecraft.World/BlockBlobFeature.cpp @@ -0,0 +1,64 @@ +#include "stdafx.h" +#include "BlockBlobFeature.h" +#include "net.minecraft.world.level.h" +#include "net.minecraft.world.level.tile.h" + +BlockBlobFeature::BlockBlobFeature(int blockId, int startRadius) : Feature(false) +{ + this->blockId = blockId; + this->startRadius = startRadius; +} + +bool BlockBlobFeature::place(Level *level, Random *random, int x, int y, int z) +{ + while (true) + { + if (y > 3) + { + int tileBelow = level->getTile(x, y - 1, z); + if (tileBelow != 0 && (tileBelow == Tile::grass_Id || tileBelow == Tile::dirt_Id || tileBelow == Tile::stone_Id)) + { + break; + } + } + + if (y <= 3) + { + return false; + } + y--; + } + + int radius = this->startRadius; + + for (int step = 0; radius >= 0 && step < 3; ++step) + { + int rX = radius + random->nextInt(2); + int rY = radius + random->nextInt(2); + int rZ = radius + random->nextInt(2); + + float limit = (float)(rX + rY + rZ) * 0.333F + 0.5F; + + for (int dx = x - rX; dx <= x + rX; ++dx) + { + for (int dy = y - rY; dy <= y + rY; ++dy) + { + for (int dz = z - rZ; dz <= z + rZ; ++dz) + { + float distSq = (dx - x) * (dx - x) + (dy - y) * (dy - y) + (dz - z) * (dz - z); + + if (distSq <= limit * limit) + { + placeBlock(level, dx, dy, dz, this->blockId); + } + } + } + } + + x += -(radius + 1) + random->nextInt(2 + radius * 2); + y += -random->nextInt(2); + z += -(radius + 1) + random->nextInt(2 + radius * 2); + } + + return true; +} \ No newline at end of file diff --git a/Minecraft.World/BlockBlobFeature.h b/Minecraft.World/BlockBlobFeature.h new file mode 100644 index 00000000..ff4f20d7 --- /dev/null +++ b/Minecraft.World/BlockBlobFeature.h @@ -0,0 +1,13 @@ +#pragma once +#include "Feature.h" + +class BlockBlobFeature : public Feature +{ +private: + int blockId; + int startRadius; + +public: + BlockBlobFeature(int blockId, int startRadius); + bool place(Level* level, Random* random, int x, int y, int z)override;; +}; \ No newline at end of file diff --git a/Minecraft.World/CMakeLists.txt b/Minecraft.World/CMakeLists.txt index e73e38a8..1f3223ef 100644 --- a/Minecraft.World/CMakeLists.txt +++ b/Minecraft.World/CMakeLists.txt @@ -11,7 +11,7 @@ set(MINECRAFT_WORLD_SOURCES ${SOURCES_COMMON} ) -add_library(Minecraft.World STATIC ${MINECRAFT_WORLD_SOURCES} "IceSpikeFeature.cpp" "IceSpikeFeature.h") +add_library(Minecraft.World STATIC ${MINECRAFT_WORLD_SOURCES} "IceSpikeFeature.cpp" "IceSpikeFeature.h" "BlockBlobFeature.h" "BlockBlobFeature.cpp") target_include_directories(Minecraft.World PRIVATE diff --git a/Minecraft.World/TaigaBiome.cpp b/Minecraft.World/TaigaBiome.cpp index 23de618f..7300a2a8 100644 --- a/Minecraft.World/TaigaBiome.cpp +++ b/Minecraft.World/TaigaBiome.cpp @@ -10,6 +10,7 @@ #include "Level.h" #include "Random.h" #include "MegaPineTreeFeature.h" +#include TaigaBiome::TaigaBiome(int id, int type) : Biome(id) { @@ -52,23 +53,15 @@ void TaigaBiome::decorate(Level *level, Random *random, int xo, int zo) { if (type == 1 || type == 2) { + BlockBlobFeature mossyBoulder(Tile::mossyCobblestone_Id, 0); int count = random->nextInt(3); for (int i = 0; i < count; ++i) { int x = xo + random->nextInt(16) + 8; int z = zo + random->nextInt(16) + 8; int y = level->getHeightmap(x, z); - - for (int dx = -1; dx <= 1; ++dx) { - for (int dy = -1; dy <= 1; ++dy) { - for (int dz = -1; dz <= 1; ++dz) { - int tileAt = level->getTile(x + dx, y + dy, z + dz); - if (random->nextInt(4) != 0 && (tileAt == 0 || tileAt == Tile::grass_Id)) { - level->setTileAndData(x + dx, y + dy, z + dz, Tile::mossyCobblestone_Id, 0, Tile::UPDATE_CLIENTS); - } - } - } - } + + mossyBoulder.place(level, random, x, y, z); } }