diff --git a/Minecraft.Client/Gui.cpp b/Minecraft.Client/Gui.cpp index 2b828f2f..d318eb8b 100644 --- a/Minecraft.Client/Gui.cpp +++ b/Minecraft.Client/Gui.cpp @@ -1227,7 +1227,10 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) } lines.push_back(L"State:"); appendProp(L"age"); + appendProp(L"moisture"); appendProp(L"facing"); + appendProp(L"part"); + appendProp(L"occupied"); appendProp(L"north"); appendProp(L"south"); appendProp(L"east"); @@ -1241,8 +1244,14 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) appendProp(L"up"); appendProp(L"extended"); appendProp(L"open"); + appendProp(L"in_wall"); appendProp(L"attached"); appendProp(L"powered"); + appendProp(L"power"); + appendProp(L"triggered"); + appendProp(L"explode"); + appendProp(L"bites"); + appendProp(L"mode"); appendProp(L"delay"); appendProp(L"enabled"); appendProp(L"eye"); diff --git a/Minecraft.World/BasePressurePlateTile.cpp b/Minecraft.World/BasePressurePlateTile.cpp index cd4c821c..986f0752 100644 --- a/Minecraft.World/BasePressurePlateTile.cpp +++ b/Minecraft.World/BasePressurePlateTile.cpp @@ -16,6 +16,32 @@ BasePressurePlateTile::BasePressurePlateTile(int id, const wstring &tex, Materia //updateShape(getDataForSignal(Redstone::SIGNAL_MAX)); } +void BasePressurePlateTile::createBlockStateDefinition() +{ + if (!m_blockStateDefinition) + m_blockStateDefinition = new BlockStateDefinition(this); +} + +int BasePressurePlateTile::defaultBlockState() +{ + return 0; +} + +int BasePressurePlateTile::convertBlockStateToLegacyData(BlockState *state) +{ + return state ? (state->value & 0xF) : 0; +} + +Tile::BlockState BasePressurePlateTile::getBlockState(int data) +{ + return Tile::BlockState(data & 0xF); +} + +Tile::BlockState BasePressurePlateTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + return Tile::BlockState(level->getData(x, y, z) & 0xF); +} + void BasePressurePlateTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr forceEntity) { updateShape(level->getData(x, y, z)); diff --git a/Minecraft.World/BasePressurePlateTile.h b/Minecraft.World/BasePressurePlateTile.h index c0870dab..b094263b 100644 --- a/Minecraft.World/BasePressurePlateTile.h +++ b/Minecraft.World/BasePressurePlateTile.h @@ -12,6 +12,11 @@ protected: public: virtual void updateShape(LevelSource *level, int x, int y, int z, int forceData = -1, shared_ptr forceEntity = shared_ptr()); + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); protected: virtual void updateShape(int data); diff --git a/Minecraft.World/BaseRailTile.cpp b/Minecraft.World/BaseRailTile.cpp index 0494e266..d1297362 100644 --- a/Minecraft.World/BaseRailTile.cpp +++ b/Minecraft.World/BaseRailTile.cpp @@ -32,6 +32,36 @@ BaseRailTile::Rail::Rail(Level *level, int x, int y, int z) } } +void BaseRailTile::createBlockStateDefinition() +{ + if (!m_blockStateDefinition) + m_blockStateDefinition = new BlockStateDefinition(this); +} + +int BaseRailTile::defaultBlockState() +{ + return 0; +} + +int BaseRailTile::convertBlockStateToLegacyData(BlockState *state) +{ + if (!state) return 0; + int mask = RAIL_DIRECTION_MASK | (usesDataBit ? RAIL_DATA_BIT : 0); + return state->value & mask; +} + +Tile::BlockState BaseRailTile::getBlockState(int data) +{ + int mask = RAIL_DIRECTION_MASK | (usesDataBit ? RAIL_DATA_BIT : 0); + return Tile::BlockState(data & mask); +} + +Tile::BlockState BaseRailTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + int mask = RAIL_DIRECTION_MASK | (usesDataBit ? RAIL_DATA_BIT : 0); + return Tile::BlockState(level->getData(x, y, z) & mask); +} + BaseRailTile::Rail::~Rail() { for( size_t i = 0; i < connections.size(); i++ ) diff --git a/Minecraft.World/BaseRailTile.h b/Minecraft.World/BaseRailTile.h index 105ddfde..2e8f639e 100644 --- a/Minecraft.World/BaseRailTile.h +++ b/Minecraft.World/BaseRailTile.h @@ -65,6 +65,11 @@ protected: BaseRailTile(int id, bool usesDataBit); public: using Tile::getResourceCount; + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); bool isUsesDataBit(); virtual AABB *getAABB(Level *level, int x, int y, int z); diff --git a/Minecraft.World/BedTile.cpp b/Minecraft.World/BedTile.cpp index 5597f740..542e1419 100644 --- a/Minecraft.World/BedTile.cpp +++ b/Minecraft.World/BedTile.cpp @@ -21,6 +21,32 @@ BedTile::BedTile(int id) : DirectionalTile(id, Material::cloth, isSolidRender()) iconTop = nullptr; } +void BedTile::createBlockStateDefinition() +{ + if (!m_blockStateDefinition) + m_blockStateDefinition = new BlockStateDefinition(this); +} + +int BedTile::defaultBlockState() +{ + return 0; +} + +int BedTile::convertBlockStateToLegacyData(BlockState *state) +{ + return state ? (state->value & 0xF) : 0; +} + +Tile::BlockState BedTile::getBlockState(int data) +{ + return Tile::BlockState(data & 0xF); +} + +Tile::BlockState BedTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + return Tile::BlockState(level->getData(x, y, z) & 0xF); +} + // 4J Added override void BedTile::updateDefaultShape() { diff --git a/Minecraft.World/BedTile.h b/Minecraft.World/BedTile.h index 0e54ba36..1216f9cd 100644 --- a/Minecraft.World/BedTile.h +++ b/Minecraft.World/BedTile.h @@ -23,6 +23,11 @@ public: static int HEAD_DIRECTION_OFFSETS[4][2]; BedTile(int id); + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); virtual void updateDefaultShape(); virtual bool TestUse(Level *level, int x, int y, int z, shared_ptr player); diff --git a/Minecraft.World/BlockStateDecoder.cpp b/Minecraft.World/BlockStateDecoder.cpp index ff170980..dd8d59ea 100644 --- a/Minecraft.World/BlockStateDecoder.cpp +++ b/Minecraft.World/BlockStateDecoder.cpp @@ -1,3 +1,6 @@ +// extra file dictating the data mappings in the f3 menu +// e.x. facing: north shows up instead of state: 2 + #include "BlockStateDecoder.h" #include "BlockStateDecoderRegistry.h" @@ -7,6 +10,7 @@ #include "FireTile.h" #include "ButtonTile.h" #include "CropTile.h" +#include "BedTile.h" #include "FenceGateTile.h" #include "FenceTile.h" #include "DoorTile.h" @@ -25,6 +29,10 @@ #include "NotGateTile.h" #include "RedlightTile.h" #include "JukeboxTile.h" +#include "CakeTile.h" +#include "DispenserTile.h" +#include "TntTile.h" +#include "BaseRailTile.h" #include "NetherStalkTile.h" #include "ReedTile.h" #include "RepeaterTile.h" @@ -37,6 +45,7 @@ #include "TreeTile2.h" #include "TheEndPortalFrameTile.h" #include "TrapDoorTile.h" +#include "TripWireTile.h" #include "WoodSlabTile.h" #include "TallGrass.h" #include "TallGrass2.h" @@ -154,7 +163,7 @@ static std::wstring tallGrassPropsToString(int composite) static const std::wstring typeNames[] = { L"dead_shrub", L"tall_grass", L"fern" }; std::wstring typeName = (type >= 0 && type < 3) ? typeNames[type] : L"unknown"; std::wstringstream ss; - ss << L"type: " << typeName; + ss << L"variant: " << typeName; return ss.str(); } @@ -165,7 +174,7 @@ static std::wstring tallGrass2PropsToString(int composite) static const std::wstring typeNames[] = { L"sunflower", L"lilac", L"tall_grass", L"large_fern", L"rose_bush", L"peony" }; std::wstring typeName = (type >= 0 && type < TallGrass2::VARIANT_COUNT) ? typeNames[type] : L"unknown"; std::wstringstream ss; - ss << L"type: " << typeName << L"\n"; + ss << L"variant: " << typeName << L"\n"; ss << L"half: " << (upper ? L"upper" : L"lower"); return ss.str(); } @@ -186,10 +195,13 @@ static std::wstring jukeboxPropsToString(int composite) return ss.str(); } -static std::wstring daylightDetectorPropsToString(bool inverted) +static std::wstring daylightDetectorPropsToString(int composite, bool inverted) { std::wstringstream ss; - ss << L"inverted: " << (inverted ? L"true" : L"false"); + int power = composite & 0xF; + ss << L"inverted: " << (inverted ? L"true" : L"false") << L"\n"; + ss << L"power: " << power << L"\n"; + ss << L"powered: " << (power > 0 ? L"true" : L"false"); return ss.str(); } @@ -210,8 +222,110 @@ static std::wstring cauldronPropsToString(int composite) return ss.str(); } -static std::wstring firePropsToString(int composite) { +static std::wstring bedPropsToString(int composite) +{ + int dir = DirectionalTile::getDirection(composite); + static const std::wstring dirNames[] = { L"south", L"west", L"north", L"east" }; + std::wstring facing = (dir >= 0 && dir < 4) ? dirNames[dir] : L"unknown"; + bool head = (composite & BedTile::HEAD_PIECE_DATA) != 0; + bool occupied = (composite & BedTile::OCCUPIED_DATA) != 0; + std::wstringstream ss; + ss << L"facing: " << facing << L"\n"; + ss << L"part: " << (head ? L"head" : L"foot") << L"\n"; + ss << L"occupied: " << (occupied ? L"true" : L"false"); + return ss.str(); +} +static std::wstring railPropsToString(int composite, bool usesDataBit) +{ + int shape = composite & BaseRailTile::RAIL_DIRECTION_MASK; + std::wstring shapeName = L"unknown"; + static const std::wstring shapeNames[] = { + L"north_south", L"east_west", L"ascending_east", L"ascending_west", + L"ascending_north", L"ascending_south", L"south_east", L"south_west", + L"north_west", L"north_east" + }; + if (shape >= 0 && shape < 10) shapeName = shapeNames[shape]; + std::wstringstream ss; + ss << L"shape: " << shapeName; + if (usesDataBit) + { + bool powered = (composite & BaseRailTile::RAIL_DATA_BIT) != 0; + ss << L"\n"; + ss << L"powered: " << (powered ? L"true" : L"false"); + } + return ss.str(); +} + +static std::wstring pressurePlatePropsToString(int composite) +{ + int power = composite & 0xF; + std::wstringstream ss; + ss << L"power: " << power << L"\n"; + ss << L"powered: " << (power > 0 ? L"true" : L"false"); + return ss.str(); +} + +static std::wstring dispenserPropsToString(int composite) +{ + int facing = composite & DispenserTile::FACING_MASK; + bool triggered = (composite & DispenserTile::TRIGGER_BIT) != 0; + std::wstringstream ss; + ss << L"facing: " << facingToString(facing) << L"\n"; + ss << L"triggered: " << (triggered ? L"true" : L"false"); + return ss.str(); +} + +static std::wstring tntPropsToString(int composite) +{ + bool explode = (composite & TntTile::EXPLODE_BIT) != 0; + std::wstringstream ss; + ss << L"explode: " << (explode ? L"true" : L"false"); + return ss.str(); +} + +static std::wstring cakePropsToString(int composite) +{ + int bites = composite & 0x7; + std::wstringstream ss; + ss << L"bites: " << bites; + return ss.str(); +} + +static std::wstring comparatorPropsToString(int composite) +{ + int dir = DirectionalTile::getDirection(composite); + static const std::wstring dirNames[] = { L"south", L"west", L"north", L"east" }; + std::wstring facing = (dir >= 0 && dir < 4) ? dirNames[dir] : L"unknown"; + bool subtract = (composite & 0x4) != 0; + bool powered = (composite & 0x8) != 0; + std::wstringstream ss; + ss << L"facing: " << facing << L"\n"; + ss << L"mode: " << (subtract ? L"subtract" : L"compare") << L"\n"; + ss << L"powered: " << (powered ? L"true" : L"false"); + return ss.str(); +} + +static std::wstring farmPropsToString(int composite) +{ + std::wstringstream ss; + ss << L"moisture: " << (composite & 0x7); + return ss.str(); +} + +static std::wstring redstoneDustPropsToString(int composite) +{ + std::wstringstream ss; + int power = composite & 0xF; + ss << L"power: " << power << L"\n"; + ss << L"powered: " << (power > 0 ? L"true" : L"false"); + return ss.str(); +} + +static std::wstring firePropsToString(int composite) { + std::wstringstream ss; + ss << L"age: " << (composite & FireTile::AGE_MASK); + return ss.str(); } static std::wstring torchPropsToString(int composite) @@ -303,9 +417,13 @@ static std::wstring fenceGatePropsToString(int composite) int dir = DirectionalTile::getDirection(composite); static const std::wstring dirNames[] = { L"south", L"west", L"north", L"east" }; std::wstring facing = (dir >= 0 && dir < 4) ? dirNames[dir] : L"unknown"; + bool powered = (composite & 0x8) != 0; + bool inWall = (composite & 0x10) != 0; std::wstringstream ss; ss << L"facing: " << facing << L"\n"; - ss << L"open: " << (FenceGateTile::isOpen(composite) ? L"true" : L"false"); + ss << L"open: " << (FenceGateTile::isOpen(composite) ? L"true" : L"false") << L"\n"; + ss << L"powered: " << (powered ? L"true" : L"false") << L"\n"; + ss << L"in_wall: " << (inWall ? L"true" : L"false"); return ss.str(); } @@ -488,7 +606,8 @@ static std::wstring tripWirePropsToString(int composite) ss << L"north: " << (((composite & 0x1) != 0) ? L"true" : L"false") << L"\n"; ss << L"south: " << (((composite & 0x2) != 0) ? L"true" : L"false") << L"\n"; ss << L"east: " << (((composite & 0x4) != 0) ? L"true" : L"false") << L"\n"; - ss << L"west: " << (((composite & 0x8) != 0) ? L"true" : L"false"); + ss << L"west: " << (((composite & 0x8) != 0) ? L"true" : L"false") << L"\n"; + ss << L"powered: " << (((composite & TripWireTile::BLOCKSTATE_POWERED_BIT) != 0) ? L"true" : L"false"); return ss.str(); } @@ -594,6 +713,20 @@ static bool registerPlantDecoders() registerDecoder(Tile::cactus_Id, ageDecoder); registerDecoder(Tile::netherStalk_Id, ageDecoder); registerDecoder(Tile::reeds_Id, ageDecoder); + registerDecoder(Tile::bed_Id, [](int composite)->std::wstring { return bedPropsToString(composite); }); + registerDecoder(Tile::rail_Id, [](int composite)->std::wstring { return railPropsToString(composite, false); }); + registerDecoder(Tile::goldenRail_Id, [](int composite)->std::wstring { return railPropsToString(composite, true); }); + registerDecoder(Tile::detectorRail_Id, [](int composite)->std::wstring { return railPropsToString(composite, true); }); + registerDecoder(Tile::activatorRail_Id, [](int composite)->std::wstring { return railPropsToString(composite, true); }); + registerDecoder(Tile::dispenser_Id, [](int composite)->std::wstring { return dispenserPropsToString(composite); }); + registerDecoder(Tile::dropper_Id, [](int composite)->std::wstring { return dispenserPropsToString(composite); }); + registerDecoder(Tile::tnt_Id, [](int composite)->std::wstring { return tntPropsToString(composite); }); + registerDecoder(Tile::cake_Id, [](int composite)->std::wstring { return cakePropsToString(composite); }); + registerDecoder(Tile::pressurePlate_stone_Id, [](int composite)->std::wstring { return pressurePlatePropsToString(composite); }); + registerDecoder(Tile::pressurePlate_wood_Id, [](int composite)->std::wstring { return pressurePlatePropsToString(composite); }); + registerDecoder(Tile::weightedPlate_light_Id, [](int composite)->std::wstring { return pressurePlatePropsToString(composite); }); + registerDecoder(Tile::weightedPlate_heavy_Id, [](int composite)->std::wstring { return pressurePlatePropsToString(composite); }); + registerDecoder(Tile::farmland_Id, [](int composite)->std::wstring { return farmPropsToString(composite); }); registerDecoder(Tile::cocoa_Id, [](int composite)->std::wstring { return cocoaPropsToString(composite); }); registerDecoder(Tile::brewingStand_Id, [](int composite)->std::wstring { return brewingStandPropsToString(composite); }); registerDecoder(Tile::fire_Id, [](int composite)->std::wstring { return firePropsToString(composite); }); @@ -633,6 +766,9 @@ static bool registerPlantDecoders() registerDecoder(Tile::endPortalFrameTile_Id, [](int composite)->std::wstring { return endPortalFramePropsToString(composite); }); registerDecoder(Tile::diode_off_Id, [](int composite)->std::wstring { return repeaterPropsToString(composite, false); }); registerDecoder(Tile::diode_on_Id, [](int composite)->std::wstring { return repeaterPropsToString(composite, true); }); + registerDecoder(Tile::comparator_off_Id, [](int composite)->std::wstring { return comparatorPropsToString(composite); }); + registerDecoder(Tile::comparator_on_Id, [](int composite)->std::wstring { return comparatorPropsToString(composite); }); + registerDecoder(Tile::redStoneDust_Id, [](int composite)->std::wstring { return redstoneDustPropsToString(composite); }); registerDecoder(Tile::hugeMushroom_brown_Id, [](int composite)->std::wstring { return hugeMushroomPropsToString(composite); }); registerDecoder(Tile::hugeMushroom_red_Id, [](int composite)->std::wstring { return hugeMushroomPropsToString(composite); }); registerDecoder(Tile::hopper_Id, [](int composite)->std::wstring { return hopperPropsToString(composite); }); @@ -643,8 +779,8 @@ static bool registerPlantDecoders() registerDecoder(Tile::jungleGate_Id, [](int composite)->std::wstring { return fenceGatePropsToString(composite); }); registerDecoder(Tile::darkGate_Id, [](int composite)->std::wstring { return fenceGatePropsToString(composite); }); registerDecoder(Tile::acaciaGate_Id, [](int composite)->std::wstring { return fenceGatePropsToString(composite); }); - registerDecoder(Tile::daylightDetector_Id, [](int composite)->std::wstring { (void)composite; return daylightDetectorPropsToString(false); }); - registerDecoder(Tile::invertedDaylightDetector_Id, [](int composite)->std::wstring { (void)composite; return daylightDetectorPropsToString(true); }); + registerDecoder(Tile::daylightDetector_Id, [](int composite)->std::wstring { return daylightDetectorPropsToString(composite, false); }); + registerDecoder(Tile::invertedDaylightDetector_Id, [](int composite)->std::wstring { return daylightDetectorPropsToString(composite, true); }); registerDecoder(Tile::snow_Id, [](int composite)->std::wstring { return snowPropsToString(composite); }); registerDecoder(Tile::topSnow_Id, [](int composite)->std::wstring { return snowPropsToString(composite); }); registerDecoder(Tile::cauldron_Id, [](int composite)->std::wstring { return cauldronPropsToString(composite); }); diff --git a/Minecraft.World/CakeTile.cpp b/Minecraft.World/CakeTile.cpp index 0ef4fe18..b77639cf 100644 --- a/Minecraft.World/CakeTile.cpp +++ b/Minecraft.World/CakeTile.cpp @@ -18,6 +18,32 @@ CakeTile::CakeTile(int id) : Tile(id, Material::cake,isSolidRender()) iconInner = nullptr; } +void CakeTile::createBlockStateDefinition() +{ + if (!m_blockStateDefinition) + m_blockStateDefinition = new BlockStateDefinition(this); +} + +int CakeTile::defaultBlockState() +{ + return 0; +} + +int CakeTile::convertBlockStateToLegacyData(BlockState *state) +{ + return state ? (state->value & 0x7) : 0; +} + +Tile::BlockState CakeTile::getBlockState(int data) +{ + return Tile::BlockState(data & 0x7); +} + +Tile::BlockState CakeTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + return Tile::BlockState(level->getData(x, y, z) & 0x7); +} + void CakeTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr forceEntity) // 4J added forceData, forceEntity param { int d = level->getData(x, y, z); diff --git a/Minecraft.World/CakeTile.h b/Minecraft.World/CakeTile.h index 7f03577d..1fe7a3fb 100644 --- a/Minecraft.World/CakeTile.h +++ b/Minecraft.World/CakeTile.h @@ -41,4 +41,9 @@ public: virtual int getResourceCount(Random *random); virtual int getResource(int data, Random *random, int playerBonusLevel); int cloneTileId(Level *level, int x, int y, int z); + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); }; \ No newline at end of file diff --git a/Minecraft.World/CauldronTile.cpp b/Minecraft.World/CauldronTile.cpp index 88890d48..64df67f6 100644 --- a/Minecraft.World/CauldronTile.cpp +++ b/Minecraft.World/CauldronTile.cpp @@ -19,6 +19,32 @@ CauldronTile::CauldronTile(int id) : Tile(id, Material::metal, isSolidRender()) iconBottom = nullptr; } +void CauldronTile::createBlockStateDefinition() +{ + if (!m_blockStateDefinition) + m_blockStateDefinition = new BlockStateDefinition(this); +} + +int CauldronTile::defaultBlockState() +{ + return 0; +} + +int CauldronTile::convertBlockStateToLegacyData(BlockState *state) +{ + return state ? (state->value & 0x3) : 0; +} + +Tile::BlockState CauldronTile::getBlockState(int data) +{ + return Tile::BlockState(data & 0x3); +} + +Tile::BlockState CauldronTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + return Tile::BlockState(level->getData(x, y, z) & 0x3); +} + Icon *CauldronTile::getTexture(int face, int data) { if (face == Facing::UP) diff --git a/Minecraft.World/CauldronTile.h b/Minecraft.World/CauldronTile.h index da810a28..3b21a675 100644 --- a/Minecraft.World/CauldronTile.h +++ b/Minecraft.World/CauldronTile.h @@ -16,6 +16,11 @@ private: public: CauldronTile(int id); + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); using Tile::getTexture; virtual Icon *getTexture(int face, int data); //@Override diff --git a/Minecraft.World/ComparatorTile.cpp b/Minecraft.World/ComparatorTile.cpp index e7d8f178..af3b2fd7 100644 --- a/Minecraft.World/ComparatorTile.cpp +++ b/Minecraft.World/ComparatorTile.cpp @@ -12,6 +12,33 @@ ComparatorTile::ComparatorTile(int id, bool on) : DiodeTile(id, on) _isEntityTile = true; } +void ComparatorTile::createBlockStateDefinition() +{ + if (!m_blockStateDefinition) + m_blockStateDefinition = new BlockStateDefinition(this); +} + +int ComparatorTile::defaultBlockState() +{ + return 0; +} + +int ComparatorTile::convertBlockStateToLegacyData(BlockState *state) +{ + if (!state) return 0; + return state->value & (DirectionalTile::DIRECTION_MASK | BIT_OUTPUT_SUBTRACT | BIT_IS_LIT); +} + +Tile::BlockState ComparatorTile::getBlockState(int data) +{ + return Tile::BlockState(data & (DirectionalTile::DIRECTION_MASK | BIT_OUTPUT_SUBTRACT | BIT_IS_LIT)); +} + +Tile::BlockState ComparatorTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + return Tile::BlockState(level->getData(x, y, z) & (DirectionalTile::DIRECTION_MASK | BIT_OUTPUT_SUBTRACT | BIT_IS_LIT)); +} + int ComparatorTile::getResource(int data, Random *random, int playerBonusLevel) { return Item::comparator_Id; diff --git a/Minecraft.World/ComparatorTile.h b/Minecraft.World/ComparatorTile.h index 3358d3ab..8341cff7 100644 --- a/Minecraft.World/ComparatorTile.h +++ b/Minecraft.World/ComparatorTile.h @@ -13,6 +13,11 @@ private: public: ComparatorTile(int id, bool on); + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); virtual int getResource(int data, Random *random, int playerBonusLevel); virtual int cloneTileId(Level *level, int x, int y, int z); diff --git a/Minecraft.World/DispenserTile.cpp b/Minecraft.World/DispenserTile.cpp index 5098fe30..0ffb76be 100644 --- a/Minecraft.World/DispenserTile.cpp +++ b/Minecraft.World/DispenserTile.cpp @@ -23,6 +23,32 @@ DispenserTile::DispenserTile(int id) : BaseEntityTile(id, Material::stone) iconFrontVertical = nullptr; } +void DispenserTile::createBlockStateDefinition() +{ + if (!m_blockStateDefinition) + m_blockStateDefinition = new BlockStateDefinition(this); +} + +int DispenserTile::defaultBlockState() +{ + return 0; +} + +int DispenserTile::convertBlockStateToLegacyData(BlockState *state) +{ + return state ? (state->value & (FACING_MASK | TRIGGER_BIT)) : 0; +} + +Tile::BlockState DispenserTile::getBlockState(int data) +{ + return Tile::BlockState(data & (FACING_MASK | TRIGGER_BIT)); +} + +Tile::BlockState DispenserTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + return Tile::BlockState(level->getData(x, y, z) & (FACING_MASK | TRIGGER_BIT)); +} + int DispenserTile::getTickDelay(Level *level) { return 4; diff --git a/Minecraft.World/DispenserTile.h b/Minecraft.World/DispenserTile.h index 1205be94..d63fb427 100644 --- a/Minecraft.World/DispenserTile.h +++ b/Minecraft.World/DispenserTile.h @@ -29,6 +29,11 @@ protected: public: virtual int getTickDelay(Level *level); virtual void onPlace(Level *level, int x, int y, int z); + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); private: void recalcLockDir(Level *level, int x, int y, int z); diff --git a/Minecraft.World/DropperTile.cpp b/Minecraft.World/DropperTile.cpp index 180aec2a..cb5a88e4 100644 --- a/Minecraft.World/DropperTile.cpp +++ b/Minecraft.World/DropperTile.cpp @@ -12,6 +12,31 @@ DropperTile::DropperTile(int id) : DispenserTile(id) DISPENSE_BEHAVIOUR = new DefaultDispenseItemBehavior(); } +void DropperTile::createBlockStateDefinition() +{ + DispenserTile::createBlockStateDefinition(); +} + +int DropperTile::defaultBlockState() +{ + return DispenserTile::defaultBlockState(); +} + +int DropperTile::convertBlockStateToLegacyData(BlockState *state) +{ + return DispenserTile::convertBlockStateToLegacyData(state); +} + +Tile::BlockState DropperTile::getBlockState(int data) +{ + return DispenserTile::getBlockState(data); +} + +Tile::BlockState DropperTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + return DispenserTile::getBlockState(level, x, y, z); +} + void DropperTile::registerIcons(IconRegister *iconRegister) { icon = iconRegister->registerIcon(L"furnace_side"); diff --git a/Minecraft.World/DropperTile.h b/Minecraft.World/DropperTile.h index 7769abde..3dbbd0b7 100644 --- a/Minecraft.World/DropperTile.h +++ b/Minecraft.World/DropperTile.h @@ -9,6 +9,11 @@ private: public: DropperTile(int id); + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); virtual void registerIcons(IconRegister *iconRegister); diff --git a/Minecraft.World/FarmTile.cpp b/Minecraft.World/FarmTile.cpp index 39bf685f..66aff7d9 100644 --- a/Minecraft.World/FarmTile.cpp +++ b/Minecraft.World/FarmTile.cpp @@ -16,6 +16,32 @@ FarmTile::FarmTile(int id) : Tile(id, Material::dirt,isSolidRender()) setLightBlock(255); } +void FarmTile::createBlockStateDefinition() +{ + if (!m_blockStateDefinition) + m_blockStateDefinition = new BlockStateDefinition(this); +} + +int FarmTile::defaultBlockState() +{ + return 0; +} + +int FarmTile::convertBlockStateToLegacyData(BlockState *state) +{ + return state ? (state->value & 0x7) : 0; +} + +Tile::BlockState FarmTile::getBlockState(int data) +{ + return Tile::BlockState(data & 0x7); +} + +Tile::BlockState FarmTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + return Tile::BlockState(level->getData(x, y, z) & 0x7); +} + // 4J Added override void FarmTile::updateDefaultShape() { diff --git a/Minecraft.World/FarmTile.h b/Minecraft.World/FarmTile.h index f9b4b031..e70a276f 100644 --- a/Minecraft.World/FarmTile.h +++ b/Minecraft.World/FarmTile.h @@ -16,6 +16,11 @@ private: protected: FarmTile(int id); public: + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); virtual void updateDefaultShape(); // 4J Added override virtual AABB *getAABB(Level *level, int x, int y, int z); virtual bool isSolidRender(bool isServerLevel = false); diff --git a/Minecraft.World/FenceGateTile.cpp b/Minecraft.World/FenceGateTile.cpp index 784c5446..2caf2711 100644 --- a/Minecraft.World/FenceGateTile.cpp +++ b/Minecraft.World/FenceGateTile.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "FenceGateTile.h" #include "AABB.h" +#include "BlockPos.h" #include "net.minecraft.world.level.h" #include "net.minecraft.world.h" #include "net.minecraft.h" @@ -23,17 +24,73 @@ int FenceGateTile::defaultBlockState() int FenceGateTile::convertBlockStateToLegacyData(BlockState *state) { - return state ? (state->value & 0x7) : 0; + if (!state) return 0; + return state->value & (DirectionalTile::DIRECTION_MASK | OPEN_BIT | POWERED_BIT); } Tile::BlockState FenceGateTile::getBlockState(int data) { - return Tile::BlockState(data & 0x7); + return Tile::BlockState(data & (DirectionalTile::DIRECTION_MASK | OPEN_BIT | POWERED_BIT)); } Tile::BlockState FenceGateTile::getBlockState(LevelSource *level, int x, int y, int z) { - return Tile::BlockState(level->getData(x, y, z)); + int data = level->getData(x, y, z) & (DirectionalTile::DIRECTION_MASK | OPEN_BIT | POWERED_BIT); + int dir = DirectionalTile::getDirection(data); + bool inWall = false; + + if (dir == Direction::NORTH || dir == Direction::SOUTH) + { + int westTile = level->getTile(x - 1, y, z); + int eastTile = level->getTile(x + 1, y, z); + inWall = (westTile == Tile::cobbleWall_Id) || (eastTile == Tile::cobbleWall_Id); + } + else + { + int northTile = level->getTile(x, y, z - 1); + int southTile = level->getTile(x, y, z + 1); + inWall = (northTile == Tile::cobbleWall_Id) || (southTile == Tile::cobbleWall_Id); + } + + if (inWall) + { + data |= IN_WALL_BIT; + } + + return Tile::BlockState(data); +} + +void FenceGateTile::fillVirtualBlockStateProperties(Tile::BlockState *state, LevelSource *level, const BlockPos &pos) +{ + if (!state || !level) return; + + int x = pos.getX(); + int y = pos.getY(); + int z = pos.getZ(); + + Tile::BlockState base = getBlockState(level, x, y, z); + state->value = base.value; + + int dir = DirectionalTile::getDirection(base.value); + bool inWall = false; + + if (dir == Direction::NORTH || dir == Direction::SOUTH) + { + int westTile = level->getTile(x - 1, y, z); + int eastTile = level->getTile(x + 1, y, z); + inWall = (westTile == Tile::cobbleWall_Id) || (eastTile == Tile::cobbleWall_Id); + } + else + { + int northTile = level->getTile(x, y, z - 1); + int southTile = level->getTile(x, y, z + 1); + inWall = (northTile == Tile::cobbleWall_Id) || (southTile == Tile::cobbleWall_Id); + } + + if (inWall) + { + state->value |= IN_WALL_BIT; + } } Icon *FenceGateTile::getTexture(int face, int data) diff --git a/Minecraft.World/FenceGateTile.h b/Minecraft.World/FenceGateTile.h index 149f5da3..986b48d4 100644 --- a/Minecraft.World/FenceGateTile.h +++ b/Minecraft.World/FenceGateTile.h @@ -5,6 +5,8 @@ class FenceGateTile : public DirectionalTile { private: static const int OPEN_BIT = 4; + static const int POWERED_BIT = 8; + static const int IN_WALL_BIT = 16; Icon* icon; public: FenceGateTile(int id); @@ -13,6 +15,7 @@ public: virtual int convertBlockStateToLegacyData(BlockState *state) override; virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; virtual Tile::BlockState getBlockState(int data); + void fillVirtualBlockStateProperties(Tile::BlockState *state, LevelSource *level, const BlockPos &pos); Icon *getTexture(int face, int data); virtual bool mayPlace(Level *level, int x, int y, int z); virtual AABB *getAABB(Level *level, int x, int y, int z); diff --git a/Minecraft.World/RedStoneDustTile.cpp b/Minecraft.World/RedStoneDustTile.cpp index f81cf303..d488428d 100644 --- a/Minecraft.World/RedStoneDustTile.cpp +++ b/Minecraft.World/RedStoneDustTile.cpp @@ -31,6 +31,32 @@ RedStoneDustTile::RedStoneDustTile(int id) : Tile(id, Material::decoration,isSol iconLineOver = nullptr; } +void RedStoneDustTile::createBlockStateDefinition() +{ + if (!m_blockStateDefinition) + m_blockStateDefinition = new BlockStateDefinition(this); +} + +int RedStoneDustTile::defaultBlockState() +{ + return 0; +} + +int RedStoneDustTile::convertBlockStateToLegacyData(BlockState *state) +{ + return state ? (state->value & 0xF) : 0; +} + +Tile::BlockState RedStoneDustTile::getBlockState(int data) +{ + return Tile::BlockState(data & 0xF); +} + +Tile::BlockState RedStoneDustTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + return Tile::BlockState(level->getData(x, y, z) & 0xF); +} + // 4J Added override void RedStoneDustTile::updateDefaultShape() { diff --git a/Minecraft.World/RedStoneDustTile.h b/Minecraft.World/RedStoneDustTile.h index 2a647658..edd80a95 100644 --- a/Minecraft.World/RedStoneDustTile.h +++ b/Minecraft.World/RedStoneDustTile.h @@ -25,6 +25,11 @@ private: public: RedStoneDustTile(int id); + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); virtual void updateDefaultShape(); // 4J Added override virtual AABB *getAABB(Level *level, int x, int y, int z); virtual bool isSolidRender(bool isServerLevel = false); diff --git a/Minecraft.World/TntTile.cpp b/Minecraft.World/TntTile.cpp index eff9efae..b1a1a5e7 100644 --- a/Minecraft.World/TntTile.cpp +++ b/Minecraft.World/TntTile.cpp @@ -16,6 +16,32 @@ TntTile::TntTile(int id) : Tile(id, Material::explosive) iconBottom = nullptr; } +void TntTile::createBlockStateDefinition() +{ + if (!m_blockStateDefinition) + m_blockStateDefinition = new BlockStateDefinition(this); +} + +int TntTile::defaultBlockState() +{ + return 0; +} + +int TntTile::convertBlockStateToLegacyData(BlockState *state) +{ + return state ? (state->value & EXPLODE_BIT) : 0; +} + +Tile::BlockState TntTile::getBlockState(int data) +{ + return Tile::BlockState(data & EXPLODE_BIT); +} + +Tile::BlockState TntTile::getBlockState(LevelSource *level, int x, int y, int z) +{ + return Tile::BlockState(level->getData(x, y, z) & EXPLODE_BIT); +} + Icon *TntTile::getTexture(int face, int data) { if (face == Facing::DOWN) return iconBottom; diff --git a/Minecraft.World/TntTile.h b/Minecraft.World/TntTile.h index ac73e64b..22883e12 100644 --- a/Minecraft.World/TntTile.h +++ b/Minecraft.World/TntTile.h @@ -11,6 +11,11 @@ private: public: static const int EXPLODE_BIT = 1; TntTile(int id); + virtual void createBlockStateDefinition() override; + virtual int defaultBlockState() override; + virtual int convertBlockStateToLegacyData(BlockState *state) override; + virtual Tile::BlockState getBlockState(LevelSource *level, int x, int y, int z) override; + virtual Tile::BlockState getBlockState(int data); virtual Icon *getTexture(int face, int data); virtual void onPlace(Level *level, int x, int y, int z); diff --git a/Minecraft.World/TripWireTile.cpp b/Minecraft.World/TripWireTile.cpp index da15453d..7881d376 100644 --- a/Minecraft.World/TripWireTile.cpp +++ b/Minecraft.World/TripWireTile.cpp @@ -40,6 +40,7 @@ Tile::BlockState TripWireTile::getBlockState(LevelSource *level, int x, int y, i if (shouldConnectTo(level, x, y, z, data, Direction::SOUTH)) state |= 0x2; if (shouldConnectTo(level, x, y, z, data, Direction::EAST)) state |= 0x4; if (shouldConnectTo(level, x, y, z, data, Direction::WEST)) state |= 0x8; + if ((data & MASK_POWERED) == MASK_POWERED) state |= BLOCKSTATE_POWERED_BIT; return Tile::BlockState(state); } diff --git a/Minecraft.World/TripWireTile.h b/Minecraft.World/TripWireTile.h index 7315cbd5..04ebb925 100644 --- a/Minecraft.World/TripWireTile.h +++ b/Minecraft.World/TripWireTile.h @@ -10,6 +10,7 @@ public: static const int MASK_SUSPENDED = 0x2; static const int MASK_ATTACHED = 0x4; static const int MASK_DISARMED = 0x8; + static const int BLOCKSTATE_POWERED_BIT = 0x10; TripWireTile(int id); virtual void createBlockStateDefinition() override;