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

259 lines
7.7 KiB
C++

#include "stdafx.h"
#include "net.minecraft.network.packet.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.level.tile.entity.h"
#include "TileEntity.h"
#include "PistonPieceEntity.h"
TileEntity::idToCreateMapType TileEntity::idCreateMap = unordered_map<wstring, tileEntityCreateFn>();
TileEntity::classToIdMapType TileEntity::classIdMap = unordered_map<eINSTANCEOF, wstring, eINSTANCEOFKeyHash, eINSTANCEOFKeyEq>();
void TileEntity::staticCtor()
{
TileEntity::setId(FurnaceTileEntity::create, eTYPE_FURNACETILEENTITY, L"Furnace");
TileEntity::setId(ChestTileEntity::create, eTYPE_CHESTTILEENTITY, L"Chest");
TileEntity::setId(EnderChestTileEntity::create, eTYPE_ENDERCHESTTILEENTITY, L"EnderChest");
TileEntity::setId(JukeboxTile::Entity::create, eTYPE_RECORDPLAYERTILE, L"RecordPlayer");
TileEntity::setId(DispenserTileEntity::create, eTYPE_DISPENSERTILEENTITY, L"Trap");
TileEntity::setId(DropperTileEntity::create, eTYPE_DROPPERTILEENTITY, L"Dropper");
TileEntity::setId(SignTileEntity::create, eTYPE_SIGNTILEENTITY, L"Sign");
TileEntity::setId(MobSpawnerTileEntity::create, eTYPE_MOBSPAWNERTILEENTITY, L"MobSpawner");
TileEntity::setId(MusicTileEntity::create, eTYPE_MUSICTILEENTITY, L"Music");
TileEntity::setId(PistonPieceEntity::create, eTYPE_PISTONPIECEENTITY, L"Piston");
TileEntity::setId(BrewingStandTileEntity::create, eTYPE_BREWINGSTANDTILEENTITY, L"Cauldron");
TileEntity::setId(EnchantmentTableEntity::create, eTYPE_ENCHANTMENTTABLEENTITY, L"EnchantTable");
TileEntity::setId(TheEndPortalTileEntity::create, eTYPE_THEENDPORTALTILEENTITY, L"Airportal");
TileEntity::setId(CommandBlockEntity::create, eTYPE_COMMANDBLOCKTILEENTITY, L"Control");
TileEntity::setId(BeaconTileEntity::create, eTYPE_BEACONTILEENTITY, L"Beacon");
TileEntity::setId(SkullTileEntity::create,eTYPE_SKULLTILEENTITY, L"Skull");
TileEntity::setId(DaylightDetectorTileEntity::create, eTYPE_DAYLIGHTDETECTORTILEENTITY, L"DLDetector");
TileEntity::setId(HopperTileEntity::create, eTYPE_HOPPERTILEENTITY, L"Hopper");
TileEntity::setId(ComparatorTileEntity::create, eTYPE_COMPARATORTILEENTITY, L"Comparator");
TileEntity::setId(BannerTileEntity::create, eTYPE_BANNERTILEENTITY, L"Banner");
TileEntity::setId(FlowerPotTileEntity::create, eTYPE_FLOWERPOTTILEENTITY, L"FlowerPot");
TileEntity::setId(TheEndGatewayTileEntity::create, eTYPE_THEENDGATEWAYTILEENTITY, L"EndGateway");
TileEntity::setId(ShulkerBoxTileEntity::create, eTYPE_SHULKERBOXTILEENTITY, L"ShulkerBox");
}
void TileEntity::setId(tileEntityCreateFn createFn, eINSTANCEOF clas, wstring id)
{
// 4J Stu - Java has classIdMap.containsKey(id) which would never work as id is not of the type of the key in classIdMap
// I have changed to use idClassMap instead so that we can still search from the string key
// TODO 4J Stu - Exceptions
if (idCreateMap.find(id) != idCreateMap.end() ) {}//throw new IllegalArgumentException("Duplicate id: " + id);
idCreateMap.insert( idToCreateMapType::value_type(id, createFn) );
classIdMap.insert( classToIdMapType::value_type( clas, id ) );
}
TileEntity::TileEntity()
{
level = nullptr;
x = y = z = 0;
remove = false;
data = -1;
tile = nullptr;
renderRemoveStage = e_RenderRemoveStageKeep;
}
Level *TileEntity::getLevel()
{
return level;
}
void TileEntity::setLevel(Level *level)
{
this->level = level;
}
bool TileEntity::hasLevel()
{
return level != nullptr;
}
void TileEntity::load(CompoundTag *tag)
{
x = tag->getInt(L"x");
y = tag->getInt(L"y");
z = tag->getInt(L"z");
}
void TileEntity::save(CompoundTag *tag)
{
auto it = classIdMap.find(this->GetType());
if ( it == classIdMap.end() )
{
// TODO 4J Stu - Some sort of exception handling
//throw new RuntimeException(this->getClass() + " is missing a mapping! This is a bug!");
return;
}
tag->putString(L"id", ( (*it).second ) );
tag->putInt(L"x", x);
tag->putInt(L"y", y);
tag->putInt(L"z", z);
}
void TileEntity::tick()
{
}
wstring TileEntity::getLegacyId(const wstring &id)
{
static const unordered_map<wstring, wstring> modernIds = {
{ L"minecraft:furnace", L"Furnace" },
{ L"minecraft:lit_furnace", L"Furnace" },
{ L"minecraft:chest", L"Chest" },
{ L"minecraft:trapped_chest", L"Chest" },
{ L"minecraft:ender_chest", L"EnderChest" },
{ L"minecraft:jukebox", L"RecordPlayer" },
{ L"minecraft:dispenser", L"Trap" },
{ L"minecraft:dropper", L"Dropper" },
{ L"minecraft:sign", L"Sign" },
{ L"minecraft:standing_sign", L"Sign" },
{ L"minecraft:wall_sign", L"Sign" },
{ L"minecraft:mob_spawner", L"MobSpawner" },
{ L"minecraft:noteblock", L"Music" },
{ L"minecraft:note_block", L"Music" },
{ L"minecraft:piston", L"Piston" },
{ L"minecraft:brewing_stand", L"Cauldron" },
{ L"minecraft:enchanting_table", L"EnchantTable" },
{ L"minecraft:enchantment_table", L"EnchantTable" },
{ L"minecraft:end_portal", L"Airportal" },
{ L"minecraft:command_block", L"Control" },
{ L"minecraft:beacon", L"Beacon" },
{ L"minecraft:skull", L"Skull" },
{ L"minecraft:daylight_detector", L"DLDetector" },
{ L"minecraft:hopper", L"Hopper" },
{ L"minecraft:comparator", L"Comparator" },
{ L"minecraft:banner", L"Banner" },
{ L"minecraft:flower_pot", L"FlowerPot" },
{ L"minecraft:end_gateway", L"EndGateway" },
{ L"minecraft:shulker_box", L"ShulkerBox" },
};
auto it = modernIds.find(id);
return it != modernIds.end() ? it->second : id;
}
shared_ptr<TileEntity> TileEntity::loadStatic(CompoundTag *tag)
{
shared_ptr<TileEntity> entity = nullptr;
if (idCreateMap.find(tag->getString(L"id")) == idCreateMap.end()) tag->putString(L"id", getLegacyId(tag->getString(L"id")));
auto it = idCreateMap.find(tag->getString(L"id"));
if (it != idCreateMap.end())
entity = shared_ptr<TileEntity>(it->second());
if (entity != nullptr)
{
entity->load(tag);
}
else
{
#ifdef _DEBUG
app.DebugPrintf("Skipping TileEntity with id %ls.\n" , tag->getString(L"id").c_str() );
#endif
}
return entity;
}
int TileEntity::getData()
{
if (data == -1) data = level->getData(x, y, z);
return data;
}
void TileEntity::setData(int data, int updateFlags)
{
this->data = data;
level->setData(x, y, z, data, updateFlags);
}
void TileEntity::setChanged()
{
if (level != nullptr)
{
data = level->getData(x, y, z);
level->tileEntityChanged(x, y, z, shared_from_this());
if (getTile() != nullptr) level->updateNeighbourForOutputSignal(x, y, z, getTile()->id);
}
}
double TileEntity::distanceToSqr(double xPlayer, double yPlayer, double zPlayer)
{
double xd = (x + 0.5) - xPlayer;
double yd = (y + 0.5) - yPlayer;
double zd = (z + 0.5) - zPlayer;
return xd * xd + yd * yd + zd * zd;
}
double TileEntity::getViewDistance()
{
return 64 * 64;
}
Tile *TileEntity::getTile()
{
if( tile == nullptr ) tile = Tile::tiles[level->getTile(x, y, z)];
return tile;
}
shared_ptr<Packet> TileEntity::getUpdatePacket()
{
return nullptr;
}
bool TileEntity::isRemoved()
{
return remove;
}
void TileEntity::setRemoved()
{
remove = true;
}
void TileEntity::clearRemoved()
{
remove = false;
}
bool TileEntity::triggerEvent(int b0, int b1)
{
return false;
}
void TileEntity::clearCache()
{
tile = nullptr;
data = -1;
}
void TileEntity::setRenderRemoveStage( unsigned char stage )
{
renderRemoveStage = stage;
}
bool TileEntity::shouldRemoveForRender()
{
return (renderRemoveStage == e_RenderRemoveStageRemove);
}
void TileEntity::upgradeRenderRemoveStage()
{
if( renderRemoveStage == e_RenderRemoveStageFlaggedAtChunk )
{
renderRemoveStage = e_RenderRemoveStageRemove;
}
}
// 4J Added
void TileEntity::clone(shared_ptr<TileEntity> tileEntity)
{
tileEntity->level = this->level;
tileEntity->x = this->x;
tileEntity->y = this->y;
tileEntity->z = this->z;
tileEntity->data = this->data;
tileEntity->tile = this->tile;
}