Files
neoLegacy/Minecraft.World/DoorTile.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

454 lines
12 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.phys.h"
#include "DoorTile.h"
#include "LevelEvent.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.h"
#include "net.minecraft.h"
static std::map<wstring, int> doorItemMap = {
{ L"doorWood", Item::wooden_door_Id },
{ L"doorIron", Item::iron_door_Id },
{ L"doorSpruce", Item::spruce_door_Id },
{ L"doorBirch", Item::birch_door_Id },
{ L"doorJungle", Item::jungle_door_Id },
{ L"doorAcacia", Item::acacia_door_Id },
{ L"doorDark", Item::dark_oak_door_Id }
};
DoorTile::DoorTile(int id, Material *material, const wstring& doorType) : Tile(id, material,isSolidRender())
{
setLightBlock(0);
this->doorType = doorType;
float r = 0.5f;
float h = 1.0f;
Tile::setShape(0.5f - r, 0, 0.5f - r, 0.5f + r, h, 0.5f + r);
}
Icon *DoorTile::getTexture(int face, int data)
{
return iconBottom[TEXTURE_NORMAL];
}
Icon *DoorTile::getTexture(LevelSource *level, int x, int y, int z, int face)
{
if (face == Facing::UP || face == Facing::DOWN) return iconBottom[TEXTURE_NORMAL];
int compositeData = getCompositeData(level, x, y, z);
int dir = compositeData & C_DIR_MASK;
bool isOpen = (compositeData & C_OPEN_MASK) != 0;
bool flip = false;
bool upper = (compositeData & C_IS_UPPER_MASK) != 0;
if (isOpen)
{
if (dir == 0 && face == 2) flip = !flip;
else if (dir == 1 && face == 5) flip = !flip;
else if (dir == 2 && face == 3) flip = !flip;
else if (dir == 3 && face == 4) flip = !flip;
}
else
{
if (dir == 0 && face == 5) flip = !flip;
else if (dir == 1 && face == 3) flip = !flip;
else if (dir == 2 && face == 4) flip = !flip;
else if (dir == 3 && face == 2) flip = !flip;
if ((compositeData & C_RIGHT_HINGE_MASK) != 0) flip = !flip;
}
if (upper)
{
return iconTop[flip ? TEXTURE_FLIPPED : TEXTURE_NORMAL];
}
else
{
return iconBottom[flip ? TEXTURE_FLIPPED : TEXTURE_NORMAL];
}
}
void DoorTile::registerIcons(IconRegister *iconRegister)
{
iconTop[TEXTURE_NORMAL] = iconRegister->registerIcon(getIconName() + L"_upper");
iconBottom[TEXTURE_NORMAL] = iconRegister->registerIcon(getIconName() + L"_lower");
iconTop[TEXTURE_FLIPPED] = new FlippedIcon(iconTop[TEXTURE_NORMAL], true, false);
iconBottom[TEXTURE_FLIPPED] = new FlippedIcon(iconBottom[TEXTURE_NORMAL], true, false);
}
bool DoorTile::blocksLight()
{
return false;
}
bool DoorTile::isSolidRender(bool isServerLevel)
{
return false;
}
bool DoorTile::isCubeShaped()
{
return false;
}
int DoorTile::getRenderShape()
{
return Tile::SHAPE_DOOR;
}
AABB *DoorTile::getTileAABB(Level *level, int x, int y, int z)
{
updateShape(level, x, y, z);
AABB *retval = Tile::getTileAABB(level, x, y, z);
return retval;
}
AABB *DoorTile::getAABB(Level *level, int x, int y, int z)
{
updateShape(level, x, y, z);
AABB *retval = Tile::getAABB(level, x, y, z);
return retval;
}
void DoorTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param
{
setShape(getCompositeData(level,x, y, z));
}
int DoorTile::getDir(LevelSource *level, int x, int y, int z)
{
return getCompositeData(level, x, y, z) & C_DIR_MASK;
}
bool DoorTile::isOpen(LevelSource *level, int x, int y, int z)
{
return (getCompositeData(level, x, y, z) & C_OPEN_MASK) != 0;
}
void DoorTile::setShape(int compositeData)
{
float r = 3 / 16.0f;
Tile::setShape(0, 0, 0, 1, 2, 1);
int dir = compositeData & C_DIR_MASK;
bool open = (compositeData & C_OPEN_MASK) != 0;
bool hasRightHinge = (compositeData & C_RIGHT_HINGE_MASK) != 0;
if (dir == 0)
{
if (open)
{
if (!hasRightHinge) setShape(0, 0, 0, 1, 1, r);
else setShape(0, 0, 1 - r, 1, 1, 1);
}
else setShape(0, 0, 0, r, 1, 1);
}
else if (dir == 1)
{
if (open)
{
if (!hasRightHinge) setShape(1 - r, 0, 0, 1, 1, 1);
else setShape(0, 0, 0, r, 1, 1);
}
else setShape(0, 0, 0, 1, 1, r);
}
else if (dir == 2)
{
if (open)
{
if (!hasRightHinge) setShape(0, 0, 1 - r, 1, 1, 1);
else setShape(0, 0, 0, 1, 1, r);
}
else setShape(1 - r, 0, 0, 1, 1, 1);
}
else if (dir == 3)
{
if (open)
{
if (!hasRightHinge) setShape(0, 0, 0, r, 1, 1);
else setShape(1 - r, 0, 0, 1, 1, 1);
}
else setShape(0, 0, 1 - r, 1, 1, 1);
}
}
void DoorTile::attack(Level *level, int x, int y, int z, shared_ptr<Player> player)
{
// Fix for #92957 - TU11: Content: Multiplayer: Wooden Doors splits in half and glitch in open / close motion while being mined.
// In lastest PC version this is commented out, so do that now to fix bug above
//use(level, x, y, z, player);
}
// 4J-PB - Adding a TestUse for tooltip display
bool DoorTile::isWoodenDoor(int tileId)
{
return tileId == Tile::wooden_door_Id || tileId == Tile::spruce_door_Id || tileId == Tile::birch_door_Id || tileId == Tile::jungle_door_Id || tileId == Tile::acacia_door_Id || tileId == Tile::dark_oak_door_Id;
}
bool DoorTile::TestUse()
{
return isWoodenDoor(id);
}
bool DoorTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly/*=false*/) // 4J added soundOnly param
{
if (soundOnly)
{
// 4J - added - just do enough to play the sound
if (material != Material::metal)
{
bool willOpen = (getCompositeData(level, x, y, z) & C_OPEN_MASK) == 0;
level->levelEvent(player, getToggleSound(willOpen), x, y, z, 0);
}
return false;
}
if (material == Material::metal) return true;
int compositeData = getCompositeData(level, x, y, z);
int lowerData = compositeData & C_LOWER_DATA_MASK;
lowerData ^= 4;
bool nowOpen = (compositeData & C_OPEN_MASK) == 0;
if ((compositeData & C_IS_UPPER_MASK) == 0)
{
level->setData(x, y, z, lowerData, Tile::UPDATE_CLIENTS);
level->setTilesDirty(x, y, z, x, y, z);
}
else
{
level->setData(x, y - 1, z, lowerData, Tile::UPDATE_CLIENTS);
level->setTilesDirty(x, y - 1, z, x, y, z);
}
level->levelEvent(player, getToggleSound(nowOpen), x, y, z, 0);
return true;
}
void DoorTile::setOpen(Level *level, int x, int y, int z, bool shouldOpen)
{
int compositeData = getCompositeData(level, x, y, z);
bool isOpen = (compositeData & C_OPEN_MASK) != 0;
if (isOpen == shouldOpen) return;
int lowerData = compositeData & C_LOWER_DATA_MASK;
lowerData ^= 4;
if ((compositeData & C_IS_UPPER_MASK) == 0)
{
level->setData(x, y, z, lowerData, Tile::UPDATE_CLIENTS);
level->setTilesDirty(x, y, z, x, y, z);
}
else
{
level->setData(x, y - 1, z, lowerData, Tile::UPDATE_CLIENTS);
level->setTilesDirty(x, y - 1, z, x, y, z);
}
level->levelEvent(nullptr, getToggleSound(shouldOpen), x, y, z, 0);
}
void DoorTile::neighborChanged(Level *level, int x, int y, int z, int type)
{
int data = level->getData(x, y, z);
if ((data & UPPER_BIT) == 0)
{
bool spawn = false;
if (level->getTile(x, y + 1, z) != id)
{
level->removeTile(x, y, z);
spawn = true;
}
if (!level->isTopSolidBlocking(x, y - 1, z))
{
level->removeTile(x, y, z);
spawn = true;
if (level->getTile(x, y + 1, z) == id)
{
level->removeTile(x, y + 1, z);
}
}
if (spawn)
{
if (!level->isClientSide)
{
spawnResources(level, x, y, z, data, 0);
}
}
else
{
bool signal = level->hasNeighborSignal(x, y, z) || level->hasNeighborSignal(x, y + 1, z);
if ((signal || (type > 0 && Tile::tiles[type]->isSignalSource())) && type != id)
{
setOpen(level, x, y, z, signal);
}
}
}
else
{
if (level->getTile(x, y - 1, z) != id)
{
level->removeTile(x, y, z);
}
if (type > 0 && type != id)
{
neighborChanged(level, x, y - 1, z, type);
}
}
}
int DoorTile::getResource(int data, Random *random, int playerBonusLevel)
{
if ((data & 8) != 0) return 0;
return doorItemMap[doorType];
}
HitResult *DoorTile::clip(Level *level, int xt, int yt, int zt, Vec3 *a, Vec3 *b)
{
updateShape(level, xt, yt, zt);
return Tile::clip(level, xt, yt, zt, a, b);
}
bool DoorTile::mayPlace(Level *level, int x, int y, int z)
{
if (y >= Level::maxBuildHeight - 1) return false;
return (level->isTopSolidBlocking(x, y - 1, z) && Tile::mayPlace(level, x, y, z) && Tile::mayPlace(level, x, y + 1, z));
}
bool DoorTile::isOpen(int data)
{
return (data & 4) != 0;
}
int DoorTile::getPistonPushReaction()
{
return Material::PUSH_DESTROY;
}
int DoorTile::getCompositeData(LevelSource *level, int x, int y, int z)
{
int data = level->getData(x, y, z);
bool isUpper = (data & UPPER_BIT) != 0;
int lowerData;
int upperData;
if (isUpper)
{
lowerData = level->getData(x, y - 1, z);
upperData = data;
}
else
{
lowerData = data;
upperData = level->getData(x, y + 1, z);
}
// bits: dir, dir, open/closed, isUpper, isRightHinge
bool isRightHinge = (upperData & 1) != 0;
return (lowerData & C_LOWER_DATA_MASK) | (isUpper ? 8 : 0) | (isRightHinge ? 16 : 0);
}
int DoorTile::cloneTileId(Level *level, int x, int y, int z)
{
return doorItemMap[doorType];
}
void DoorTile::playerWillDestroy(Level *level, int x, int y, int z, int data, shared_ptr<Player> player)
{
if (player->abilities.instabuild)
{
if ((data & UPPER_BIT) != 0)
{
if (level->getTile(x, y - 1, z) == id)
{
level->removeTile(x, y - 1, z);
}
}
}
}
void DoorTile::createBlockStateDefinition()
{
if (!m_blockStateDefinition)
m_blockStateDefinition = new BlockStateDefinition(this);
}
int DoorTile::defaultBlockState()
{
return 0; // closed
}
Tile::BlockState DoorTile::getBlockState(LevelSource *level, int x, int y, int z)
{
int composite = getCompositeData(level, x, y, z);
return Tile::BlockState(composite);
}
int DoorTile::convertBlockStateToLegacyData(BlockState *state)
{
if (!state) return 0;
int composite = state->value;
if (composite & C_IS_UPPER_MASK)
{
int base = (composite & C_RIGHT_HINGE_MASK) ? 9 : 8;
if (composite & C_OPEN_MASK) base |= 2;
return base;
}
else
{
int base = composite & C_DIR_MASK;
if (composite & C_OPEN_MASK) base |= 4;
return base;
}
}
Tile::BlockState DoorTile::getBlockState(int data)
{
int composite = 0;
if ((data & UPPER_BIT) == 0) {
composite = data & C_LOWER_DATA_MASK;
} else {
composite = C_IS_UPPER_MASK;
if ((data & 1) != 0) composite |= C_RIGHT_HINGE_MASK;
}
return Tile::BlockState(composite);
}
void DoorTile::fillVirtualBlockStateProperties(Tile::BlockState *state, LevelSource *level, const BlockPos &pos)
{
if (!state) return;
int composite = getCompositeData(level, pos.getX(), pos.getY(), pos.getZ());
state->value = composite;
}
bool DoorTile::use(Level *level, const BlockPos &pos, Tile::BlockState *state, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly)
{
if (soundOnly)
{
if (material != Material::metal)
level->levelEvent(player, getToggleSound((getCompositeData(level, pos.getX(), pos.getY(), pos.getZ()) & C_OPEN_MASK) == 0), pos.getX(), pos.getY(), pos.getZ(), 0);
return false;
}
if (material == Material::metal) return true;
int composite = state ? state->value : getCompositeData(level, pos.getX(), pos.getY(), pos.getZ());
bool nowOpen = (composite & C_OPEN_MASK) == 0;
int lowerData = composite & C_LOWER_DATA_MASK;
lowerData ^= 4;
if ((composite & C_IS_UPPER_MASK) == 0) {
level->setData(pos.getX(), pos.getY(), pos.getZ(), lowerData, Tile::UPDATE_CLIENTS);
level->setTilesDirty(pos.getX(), pos.getY(), pos.getZ(), pos.getX(), pos.getY(), pos.getZ());
} else {
level->setData(pos.getX(), pos.getY() - 1, pos.getZ(), lowerData, Tile::UPDATE_CLIENTS);
level->setTilesDirty(pos.getX(), pos.getY() - 1, pos.getZ(), pos.getX(), pos.getY(), pos.getZ());
}
level->levelEvent(player, getToggleSound(nowOpen), pos.getX(), pos.getY(), pos.getZ(), 0);
return true;
}
int DoorTile::getToggleSound(bool open)
{
if (material == Material::metal) return open ? LevelEvent::SOUND_OPEN_IRON_DOOR : LevelEvent::SOUND_CLOSE_IRON_DOOR;
return open ? LevelEvent::SOUND_OPEN_WOODEN_DOOR : LevelEvent::SOUND_CLOSE_WOODEN_DOOR;
}