From 8a3ce40b468f244b4ec79faacb4b4eb987df286b Mon Sep 17 00:00:00 2001 From: Fireblade <3+fireblade@noreply.neolegacy.dev> Date: Fri, 19 Jun 2026 02:40:47 -0400 Subject: [PATCH] fix: half slab --- Minecraft.World/GrassTile.cpp | 22 +++++++---- Minecraft.World/HalfSlabTile.cpp | 67 +++++++++++--------------------- 2 files changed, 38 insertions(+), 51 deletions(-) diff --git a/Minecraft.World/GrassTile.cpp b/Minecraft.World/GrassTile.cpp index 61460727..710cbc6f 100644 --- a/Minecraft.World/GrassTile.cpp +++ b/Minecraft.World/GrassTile.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "../Minecraft.Client/Minecraft.h" #include "GrassTile.h" +#include "HalfSlabTile.h" #include "net.minecraft.world.level.h" #include "net.minecraft.world.level.biome.h" #include "net.minecraft.h" @@ -96,7 +97,16 @@ void GrassTile::tick(Level *level, int x, int y, int z, Random *random) { if (level->isClientSide) return; - if (level->getRawBrightness(x, y + 1, z) < MIN_BRIGHTNESS && Tile::lightBlock[level->getTile(x, y + 1, z)] > 2) + int aboveTileId = level->getTile(x, y + 1, z); + Material* above = level->getMaterial(x, y + 1, z); + bool aboveIsTopSlab = false; + if (Tile::tiles[aboveTileId] != nullptr) + { + HalfSlabTile *aboveSlab = dynamic_cast(Tile::tiles[aboveTileId]); + aboveIsTopSlab = aboveSlab != nullptr && (level->getData(x, y + 1, z) & HalfSlabTile::TOP_SLOT_BIT) != 0; + } + + if (!aboveIsTopSlab && level->getRawBrightness(x, y + 1, z) < MIN_BRIGHTNESS && Tile::lightBlock[aboveTileId] > 2) { level->setTileAndUpdate(x, y, z, Tile::dirt_Id); } @@ -123,12 +133,10 @@ void GrassTile::tick(Level *level, int x, int y, int z, Random *random) // using isSolid() here is wrong because non full blocks like iron bars, // fences, walls are also flagged as solid by their material - int aboveTileId = level->getTile(x, y + 1, z); - Material* above = level->getMaterial(x, y + 1, z); - if (above->isLiquid() || Tile::lightBlock[aboveTileId] > 2) - { - level->setTileAndUpdate(x, y, z, Tile::dirt_Id); - } + if (!aboveIsTopSlab && (above->isLiquid() || Tile::lightBlock[aboveTileId] > 2)) + { + level->setTileAndUpdate(x, y, z, Tile::dirt_Id); + } } int GrassTile::getResource(int data, Random *random, int playerBonusLevel) diff --git a/Minecraft.World/HalfSlabTile.cpp b/Minecraft.World/HalfSlabTile.cpp index 5798e8a6..cfc69751 100644 --- a/Minecraft.World/HalfSlabTile.cpp +++ b/Minecraft.World/HalfSlabTile.cpp @@ -113,54 +113,33 @@ bool HalfSlabTile::isCubeShaped() return isFullSize() != 0; } -bool HalfSlabTile::shouldRenderFace( - LevelSource *level, int x, int y, int z, int face) +bool HalfSlabTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face) { - - if (isFullSize()) - return Tile::shouldRenderFace(level, x, y, z, face); + if (isFullSize()) return Tile::shouldRenderFace(level, x, y, z, face); - - if (face != Facing::UP && face != Facing::DOWN - && !Tile::shouldRenderFace(level, x, y, z, face)) - return false; + if (face != Facing::UP && face != Facing::DOWN && !Tile::shouldRenderFace(level, x, y, z, face)) + { + return false; + } - int oppFace = Facing::getOpposite(face); - int nx = x, ny = y, nz = z; - - if (oppFace == Facing::DOWN) ny--; - if (oppFace == Facing::UP) ny++; - if (oppFace == Facing::NORTH) nz--; - if (oppFace == Facing::SOUTH) nz++; - if (oppFace == Facing::WEST) nx--; - if (oppFace == Facing::EAST) nx++; + int ox = x, oy = y, oz = z; + ox += Facing::STEP_X[Facing::OPPOSITE_FACING[face]]; + oy += Facing::STEP_Y[Facing::OPPOSITE_FACING[face]]; + oz += Facing::STEP_Z[Facing::OPPOSITE_FACING[face]]; - int currentData = level->getData(x, y, z); - int neighborData = level->getData(nx, ny, nz); - int currentTile = level->getTile(x, y, z); - int neighborTile = level->getTile(nx, ny, nz); - - bool currentIsUpper = (currentData & TOP_SLOT_BIT) != 0; - bool neighborIsUpper = (neighborData & TOP_SLOT_BIT) != 0; - - bool currentIsSlab = isHalfSlab(currentTile); - bool neighborIsSlab = isHalfSlab(neighborTile); - - - if (neighborIsSlab && neighborIsUpper) - { - if (face == Facing::DOWN) - return true; - if (face == Facing::UP && !Tile::shouldRenderFace(level, x, y, z, face)) - return currentIsSlab && !currentIsUpper ? false : true; - return !(currentIsSlab && currentIsUpper); - } - - if (face == Facing::UP || (face == Facing::DOWN - && Tile::shouldRenderFace(level, x, y, z, face))) - return true; - - return !(currentIsSlab && !currentIsUpper); + boolean isUpper = (level->getData(ox, oy, oz) & TOP_SLOT_BIT) != 0; + if (isUpper) + { + if (face == Facing::DOWN) return true; + if (face == Facing::UP && Tile::shouldRenderFace(level, x, y, z, face)) return true; + return !(isHalfSlab(level->getTile(x, y, z)) && (level->getData(x, y, z) & TOP_SLOT_BIT) != 0); + } + else + { + if (face == Facing::UP) return true; + if (face == Facing::DOWN && Tile::shouldRenderFace(level, x, y, z, face)) return true; + return !(isHalfSlab(level->getTile(x, y, z)) && (level->getData(x, y, z) & TOP_SLOT_BIT) == 0); + } } int HalfSlabTile::getSpawnResourcesAuxValue(int data)