Files
neoLegacy/Minecraft.World/RoofTreeFeature.cpp
T
Tranqlmao 9abd52985e TU53 + Bug Fixes (Many)
Patch Notes:
Blocks
+ Colored shulker boxes
+ Concrete powder
+ Concrete
+ Glazed terracotta
Items
+ Shulker shell
+ Iron nugget
UI Changes
+ Added Custom Controls to Keyboard & Mouse, as well as Controller
+ Added Custom SuperFlat
+ Added Edit Server Menu
+ Added Firework Crafting
Feature Changes
+ Host Options
+ Added Pick Block
+ Added off-hand slot for maps and arrows.
Bug Fixes & changes
+ TU47: Banner hitbox wrong (and inventory model fixed)
+ TU47/48: Ice not melting properly
+ TU48: Dead bushes not dropping sticks
+ TU48: Guardians and polar bears not dropping cooked fish when on fire
+ TU48: Bonus chest missing saplings and seeds
+ TU48: Frosted ice obtainable
+ TU48: Hoppers not collecting items
+ TU48: Wither skeletons spawning in 2-high gaps
+ TU48: End crystals exploding with “TNT Explodes” off
+ TU48: Tamed ocelots staying hostile
+ TU48: Signs not placing on tall grass
+ TU51: Skeleton hitbox wrong
+ TU53: Fall damage in shallow water
+ TU53: Squids not spawning in man-made pools
+ Elytra has been improved to be more accurate to the source material
+ Removed Spectral Arrow from crafting
+ Fixed several broken item descriptions
+ You can no longer cook Pufferfish or Clownfish
+ Fixed scaling issue with paperdoll and chat
+ Iron and gold armor can now be smelted into nuggets.
+ More items can now be used as fuel in a furnace.
+ Using a firework rocket while gliding with elytra will now give the player a boost.
+ Changed the color of dyes, wool, carpets, and banners.
+ Reordered all colored blocks and items in the Creative inventory. Banners now have the same order of colors as all other colored blocks and items.
+ Fishing rods can now hook on entities without causing knockback or pseudo-damage.
+ Fixed banner crafting
+ Fixed Map colors for certain blocks
+ Fixed Path block height
+ Fixed String block issues
+ Fixed Item frame culling.
+ Fixed Tutorial world NBT/Block State issues
+ Fixed World Slider
+ Fixed Enderman AI
+ Fixed Player animation bug
+ HUD Flash text changes
+ Generation accuracy changes
+ Many other small accuracy changes and fixes
2026-11-24 13:44:06 -05:00

204 lines
6.7 KiB
C++

#include "stdafx.h"
#include "RoofTreeFeature.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "TreeTile2.h"
#include "LeafTile2.h"
#include <cmath>
#include <algorithm>
RoofTreeFeature::RoofTreeFeature(bool doUpdate) : Feature(doUpdate) {
}
static bool isReplaceable(int tile) {
return tile == 0 ||
tile == Tile::tallgrass_Id ||
tile == Tile::sapling_Id ||
tile == Tile::grass_Id ||
tile == Tile::dirt_Id ||
tile == Tile::leaves_Id ||
tile == Tile::leaves2_Id;
}
bool RoofTreeFeature::checkSpace(Level *worldIn, int x, int y, int z, int height) {
for (int dy = 0; dy <= height + 1; ++dy) {
int radius = 1;
if (dy == 0) radius = 0;
if (dy >= height - 1) radius = 2;
for (int dx = -radius; dx <= radius; ++dx) {
for (int dz = -radius; dz <= radius; ++dz) {
if (dy == 0 && dx == 0 && dz == 0) continue;
int tile = worldIn->getTile(x + dx, y + dy, z + dz);
if (tile != 0 && !isReplaceable(tile)) {
return false;
}
if (tile == Tile::flowing_water_Id) {
return false;
}
}
}
}
return true;
}
void RoofTreeFeature::placeLog(Level *worldIn, int x, int y, int z) {
int tile = worldIn->getTile(x, y, z);
if (tile == 0 || tile == Tile::leaves_Id || tile == Tile::leaves2_Id || tile == Tile::tallgrass_Id) {
placeBlock(worldIn, x, y, z, Tile::log2_Id, TreeTile2::DARK_TRUNK);
}
}
void RoofTreeFeature::placeLeaf(Level *worldIn, int x, int y, int z) {
int tile = worldIn->getTile(x, y, z);
if (tile == 0) {
placeBlock(worldIn, x, y, z, Tile::leaves2_Id, 1);
}
}
bool RoofTreeFeature::place(Level *level, Random *rand, int x, int y, int z) {
int height = rand->nextInt(3);
height += rand->nextInt(2) + 6;
int startX = x, startY = y, startZ = z;
if (startY < 1 || startY + height + 1 >= Level::maxBuildHeight) return false;
if (level->getTile(startX, startY - 1, startZ) != Tile::grass_Id &&
level->getTile(startX, startY - 1, startZ) != Tile::dirt_Id) return false;
if (startY >= Level::maxBuildHeight - height - 1) return false;
if (!checkSpace(level, startX, startY, startZ, height)) return false;
if (app.getLevelGenerationOptions() != nullptr) {
LevelGenerationOptions *options = app.getLevelGenerationOptions();
int radius = 4;
if (options->checkIntersects(x - radius, y - 1, z - radius,
x + radius + 1, y + height, z + radius + 1))
return false;
}
placeBlock(level, startX, startY - 1, startZ, Tile::dirt_Id, 0);
placeBlock(level, startX + 1, startY - 1, startZ, Tile::dirt_Id, 0);
placeBlock(level, startX, startY - 1, startZ + 1, Tile::dirt_Id, 0);
placeBlock(level, startX + 1, startY - 1, startZ + 1, Tile::dirt_Id, 0);
int face = rand->nextInt(4);
int dx = 0, dz = 0;
if (face == 0) dz = -1;
else if (face == 1) dx = 1;
else if (face == 2) dz = 1;
else if (face == 3) dx = -1;
int bendHeight = height - rand->nextInt(4);
int bendLength = 2 - rand->nextInt(3);
int trunkX = startX, trunkZ = startZ;
int topY = startY + height - 1;
for (int dy = 0; dy < height; ++dy) {
if (dy >= bendHeight && bendLength > 0) {
trunkX += dx;
trunkZ += dz;
--bendLength;
}
int currentY = startY + dy;
int centre = level->getTile(trunkX, currentY, trunkZ);
if (centre == 0 || centre == Tile::leaves_Id || centre == Tile::leaves2_Id) {
placeLog(level, trunkX, currentY, trunkZ);
placeLog(level, trunkX + 1, currentY, trunkZ);
placeLog(level, trunkX, currentY, trunkZ + 1);
placeLog(level, trunkX + 1, currentY, trunkZ + 1);
topY = currentY;
}
}
for (int i3 = -2; i3 <= 0; ++i3) {
for (int l3 = -2; l3 <= 0; ++l3) {
int yOffset = -1;
placeLeaf(level, trunkX + i3, topY + yOffset, trunkZ + l3);
placeLeaf(level, trunkX + 1 - i3, topY + yOffset, trunkZ + l3);
placeLeaf(level, trunkX + i3, topY + yOffset, trunkZ + 1 - l3);
placeLeaf(level, trunkX + 1 - i3, topY + yOffset, trunkZ + 1 - l3);
if ((i3 > -2 || l3 > -1) && (i3 != -1 || l3 != -2)) {
yOffset = 1;
placeLeaf(level, trunkX + i3, topY + yOffset, trunkZ + l3);
placeLeaf(level, trunkX + 1 - i3, topY + yOffset, trunkZ + l3);
placeLeaf(level, trunkX + i3, topY + yOffset, trunkZ + 1 - l3);
placeLeaf(level, trunkX + 1 - i3, topY + yOffset, trunkZ + 1 - l3);
}
}
}
if (rand->nextInt(2) == 0) {
placeLeaf(level, trunkX, topY + 2, trunkZ);
placeLeaf(level, trunkX + 1, topY + 2, trunkZ);
placeLeaf(level, trunkX + 1, topY + 2, trunkZ + 1);
placeLeaf(level, trunkX, topY + 2, trunkZ + 1);
}
for (int dxOff = -3; dxOff <= 4; ++dxOff) {
for (int dzOff = -3; dzOff <= 4; ++dzOff) {
if ((dxOff == -3 || dxOff == 4) && (dzOff == -3 || dzOff == 4))
continue;
if (std::abs(dxOff) < 3 || std::abs(dzOff) < 3) {
placeLeaf(level, trunkX + dxOff, topY, trunkZ + dzOff);
}
}
}
for (int dxOff = -1; dxOff <= 2; ++dxOff) {
for (int dzOff = -1; dzOff <= 2; ++dzOff) {
if ((dxOff < 0 || dxOff > 1 || dzOff < 0 || dzOff > 1) && rand->nextInt(3) <= 0) {
int branchLength = rand->nextInt(3) + 2;
for (int l = 0; l < branchLength; ++l) {
placeLog(level, startX + dxOff, topY - l - 1, startZ + dzOff);
}
for (int lx = -1; lx <= 1; ++lx) {
for (int lz = -1; lz <= 1; ++lz) {
placeLeaf(level, trunkX + dxOff + lx, topY, trunkZ + dzOff + lz);
}
}
for (int lx = -2; lx <= 2; ++lx) {
for (int lz = -2; lz <= 2; ++lz) {
if (std::abs(lx) != 2 || std::abs(lz) != 2) {
placeLeaf(level, trunkX + dxOff + lx, topY - 1, trunkZ + dzOff + lz);
}
}
}
}
}
}
return true;
}