From b2fdb92f9f5d5417b118f7f3b41d590d110bacad Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Mon, 8 Apr 2024 12:16:30 +0300 Subject: [PATCH] * Make redstone dust hitbox work like MC Java --- .../windows/projects/World/World.vcxproj | 2 + .../projects/World/World.vcxproj.filters | 6 +++ source/client/renderer/TileRenderer.cpp | 32 ++++++++------ source/world/item/Inventory.cpp | 2 +- source/world/item/Item.cpp | 5 +++ source/world/item/RedstoneItem.cpp | 43 +++++++++++++++++++ source/world/item/RedstoneItem.hpp | 18 ++++++++ .../ExternalFileLevelStorageSource.cpp | 1 + .../level/storage/LevelStorageSource.cpp | 8 ---- source/world/particle/ParticleEngine.cpp | 2 +- source/world/tile/RedStoneTorchTile.cpp | 2 +- source/world/tile/WireTile.cpp | 18 ++++---- source/world/tile/WireTile.hpp | 1 + 13 files changed, 105 insertions(+), 35 deletions(-) create mode 100644 source/world/item/RedstoneItem.cpp create mode 100644 source/world/item/RedstoneItem.hpp diff --git a/platforms/windows/projects/World/World.vcxproj b/platforms/windows/projects/World/World.vcxproj index ce1514c9..cc893aeb 100644 --- a/platforms/windows/projects/World/World.vcxproj +++ b/platforms/windows/projects/World/World.vcxproj @@ -348,6 +348,7 @@ + @@ -462,6 +463,7 @@ + diff --git a/platforms/windows/projects/World/World.vcxproj.filters b/platforms/windows/projects/World/World.vcxproj.filters index 789d136d..61b7f945 100644 --- a/platforms/windows/projects/World/World.vcxproj.filters +++ b/platforms/windows/projects/World/World.vcxproj.filters @@ -482,6 +482,9 @@ Source Files\Tile + + Source Files\Item + @@ -820,5 +823,8 @@ Header Files\Tile + + Header Files\Item + \ No newline at end of file diff --git a/source/client/renderer/TileRenderer.cpp b/source/client/renderer/TileRenderer.cpp index 9144f257..70fa906f 100644 --- a/source/client/renderer/TileRenderer.cpp +++ b/source/client/renderer/TileRenderer.cpp @@ -1346,22 +1346,28 @@ bool TileRenderer::tesselateWireInWorld(Tile* tile, int x, int y, int z) float texU_1, texU_2, texV_1, texV_2; bool bRotateWire = bUsingStraightTexture && (connFlags & (1 << WireTile::CONN_ZP)); - AABB aabb = tile->m_aabb; + float cxn = 0.0f, cxp = 1.0f, czn = 0.0f, czp = 1.0f; + if (~connFlags & (1 << WireTile::CONN_XN)) cxn += 5.0f / 16.0f; + if (~connFlags & (1 << WireTile::CONN_XP)) cxp -= 5.0f / 16.0f; + if (~connFlags & (1 << WireTile::CONN_ZN)) czn += 5.0f / 16.0f; + if (~connFlags & (1 << WireTile::CONN_ZP)) czp -= 5.0f / 16.0f; + + AABB aabb = AABB(cxn, 0.0f, czn, cxp, 0.0625f, czp); if (bRotateWire) { // this is kind of hacky. - texU_1 = C_RATIO2 * aabb.min.z + C_RATIO * (texX); - texU_2 = C_RATIO2 * aabb.max.z + C_RATIO * (texX); - texV_1 = C_RATIO2 * aabb.min.x + C_RATIO * (texY); - texV_2 = C_RATIO2 * aabb.max.x + C_RATIO * (texY); + texU_1 = C_RATIO2 * aabb.min.z + C_RATIO * texX; + texU_2 = C_RATIO2 * aabb.max.z + C_RATIO * texX; + texV_1 = C_RATIO2 * aabb.min.x + C_RATIO * texY; + texV_2 = C_RATIO2 * aabb.max.x + C_RATIO * texY; } else { - texU_1 = C_RATIO2 * aabb.min.x + C_RATIO * (texX); - texU_2 = C_RATIO2 * aabb.max.x + C_RATIO * (texX); - texV_1 = C_RATIO2 * aabb.min.z + C_RATIO * (texY); - texV_2 = C_RATIO2 * aabb.max.z + C_RATIO * (texY); + texU_1 = C_RATIO2 * aabb.min.x + C_RATIO * texX; + texU_2 = C_RATIO2 * aabb.max.x + C_RATIO * texX; + texV_1 = C_RATIO2 * aabb.min.z + C_RATIO * texY; + texV_2 = C_RATIO2 * aabb.max.z + C_RATIO * texY; } Tesselator& t = Tesselator::instance; @@ -1371,13 +1377,11 @@ bool TileRenderer::tesselateWireInWorld(Tile* tile, int x, int y, int z) float power = float(data) / 15.0f; float rt = power * 0.6f + 0.4f; if (data == 0) - rt = 0.3F; + rt = 0.3f; float gt = power * power * 0.7f - 0.5f; float bt = power * power * 0.6f - 0.7f; - if (gt < 0.0f) - gt = 0.0f; - if (bt < 0.0f) - bt = 0.0f; + if (gt < 0.0f) gt = 0.0f; + if (bt < 0.0f) bt = 0.0f; t.color(bright * rt, bright * gt, bright * bt); diff --git a/source/world/item/Inventory.cpp b/source/world/item/Inventory.cpp index b32494e8..6900e941 100644 --- a/source/world/item/Inventory.cpp +++ b/source/world/item/Inventory.cpp @@ -81,7 +81,7 @@ void Inventory::prepareCreativeInventory() addCreativeItem(Item::rocket->m_itemID); // redstone stuff - addCreativeItem(Tile::wire->m_ID); + addCreativeItem(Item::redStone->m_itemID); addCreativeItem(Tile::notGate->m_ID); addCreativeItem(Tile::lever->m_ID); addCreativeItem(Tile::button->m_ID); diff --git a/source/world/item/Item.cpp b/source/world/item/Item.cpp index 454249ab..c7325a1d 100644 --- a/source/world/item/Item.cpp +++ b/source/world/item/Item.cpp @@ -13,6 +13,7 @@ #include "TileItem.hpp" #include "TilePlanterItem.hpp" #include "RocketItem.hpp" +#include "RedstoneItem.hpp" #define ITEM(x) ((x) - 256) @@ -199,6 +200,10 @@ void Item::initItems() Item::rocket = NEW_X_ITEMN(RocketItem, ITEM_ROCKET) ->setIcon(14, 2) ->setDescriptionId("rocket"); + + Item::redStone = NEW_X_ITEMN(RedstoneItem, ITEM_REDSTONE) + ->setIcon(8, 3) + ->setDescriptionId("redstone"); } int Item::getIcon(ItemInstance* pInstance) diff --git a/source/world/item/RedstoneItem.cpp b/source/world/item/RedstoneItem.cpp new file mode 100644 index 00000000..26a7d82f --- /dev/null +++ b/source/world/item/RedstoneItem.cpp @@ -0,0 +1,43 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#include "RedstoneItem.hpp" +#include "world/level/Level.hpp" +#include "world/entity/Player.hpp" +#include "world/tile/Tile.hpp" + +RedstoneItem::RedstoneItem(int id) : Item(id) +{ +} + +bool RedstoneItem::useOn(ItemInstance* inst, Player* player, Level* level, int x, int y, int z, int dir) +{ + if (level->getTile(x, y, z) != Tile::topSnow->m_ID) + { + switch (dir) + { + case DIR_YNEG: y--; break; + case DIR_YPOS: y++; break; + case DIR_ZNEG: z--; break; + case DIR_ZPOS: z++; break; + case DIR_XNEG: x--; break; + case DIR_XPOS: x++; break; + } + } + + if (level->getTile(x, y, z) != TILE_AIR) + return false; + + if (Tile::wire->mayPlace(level, x, y, z)) + { + level->setTile(x, y, z, Tile::wire->m_ID); + inst->m_amount--; + } + + return true; +} diff --git a/source/world/item/RedstoneItem.hpp b/source/world/item/RedstoneItem.hpp new file mode 100644 index 00000000..a4006924 --- /dev/null +++ b/source/world/item/RedstoneItem.hpp @@ -0,0 +1,18 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ +#pragma once + +#include "Item.hpp" + +class RedstoneItem : public Item +{ +public: + RedstoneItem(int id); + + virtual bool useOn(ItemInstance*, Player*, Level*, int, int, int, int); +}; diff --git a/source/world/level/storage/ExternalFileLevelStorageSource.cpp b/source/world/level/storage/ExternalFileLevelStorageSource.cpp index 53eaa5ee..aefd235d 100644 --- a/source/world/level/storage/ExternalFileLevelStorageSource.cpp +++ b/source/world/level/storage/ExternalFileLevelStorageSource.cpp @@ -58,6 +58,7 @@ void ExternalFileLevelStorageSource::getLevelList(std::vector& vls LOG_I("Entry: %s", de->d_name); + // TODO: Should really use _DIRENT_HAVE_D_TYPE #if defined( __HAIKU__ ) std::string temp = m_worldsPath + '/' + de->d_name; diff --git a/source/world/level/storage/LevelStorageSource.cpp b/source/world/level/storage/LevelStorageSource.cpp index 0fe53e8a..a1b0b011 100644 --- a/source/world/level/storage/LevelStorageSource.cpp +++ b/source/world/level/storage/LevelStorageSource.cpp @@ -14,12 +14,4 @@ LevelStorageSource::~LevelStorageSource() void LevelStorageSource::getLevelList(std::vector& vec) { - // @TODO: complete mock -#ifndef ORIGINAL_CODE - vec.push_back(LevelSummary("Level1", "Level-1", 12345, 1234567)); - vec.push_back(LevelSummary("Level2", "Level-2", 23456, 2345678)); - vec.push_back(LevelSummary("Level3", "Level-3", 34567, 3456789)); - vec.push_back(LevelSummary("Level4", "Level-4", 45678, 4567890)); - vec.push_back(LevelSummary("Level5", "Level-5", 56789, 5678901)); -#endif } diff --git a/source/world/particle/ParticleEngine.cpp b/source/world/particle/ParticleEngine.cpp index 9ce1c2b1..c25de9e6 100644 --- a/source/world/particle/ParticleEngine.cpp +++ b/source/world/particle/ParticleEngine.cpp @@ -96,7 +96,7 @@ void ParticleEngine::crack(int x, int y, int z, int dir) break; default: // @TODO: dont know what they do for the undefined case - posX = float(x); posY = float(y); posZ = float(z); + posX = float(x); posY = float(y); posZ = float(z); break; } diff --git a/source/world/tile/RedStoneTorchTile.cpp b/source/world/tile/RedStoneTorchTile.cpp index cfdbd9be..1f2a7f50 100644 --- a/source/world/tile/RedStoneTorchTile.cpp +++ b/source/world/tile/RedStoneTorchTile.cpp @@ -20,7 +20,7 @@ RedStoneTorchTile::RedStoneTorchTile(int id, int texture, Material* pMtl) : Torc bool RedStoneTorchTile::isSignalSource() { - return m_bActive; + return true; } int RedStoneTorchTile::getTickDelay() diff --git a/source/world/tile/WireTile.cpp b/source/world/tile/WireTile.cpp index f4e7a732..09992838 100644 --- a/source/world/tile/WireTile.cpp +++ b/source/world/tile/WireTile.cpp @@ -251,16 +251,7 @@ void WireTile::updateWires(Level* level, int x, int y, int z) void WireTile::updateShape(LevelSource* level, int x, int y, int z) { - int connFlags = getConnections(level, x, y, z); - - // cut off parts of the texture if needed - float cxn = 0.0f, cxp = 1.0f, czn = 0.0f, czp = 1.0f; - if (~connFlags & (1 << CONN_XN)) cxn += 5.0f / 16.0f; - if (~connFlags & (1 << CONN_XP)) cxp -= 5.0f / 16.0f; - if (~connFlags & (1 << CONN_ZN)) czn += 5.0f / 16.0f; - if (~connFlags & (1 << CONN_ZP)) czp -= 5.0f / 16.0f; - - m_aabb = AABB(cxn, 0.0f, czn, cxp, 0.1f, czp); + m_aabb = AABB(0.0f, 0.0f, 0.0f, 1.0f, 0.0625f, 1.0f); } AABB* WireTile::getAABB(Level* level, int x, int y, int z) @@ -377,6 +368,13 @@ int WireTile::getDirectSignal(LevelSource* level, int x, int y, int z, int dir) return false; } +int WireTile::getColor(LevelSource*, int, int, int) +{ + // TODO: Why do I need to swap red, green, and blue? + // Everything seems to be wrong. Consider fixing it + return 0x000080; +} + int WireTile::getRenderShape() { return SHAPE_WIRE; diff --git a/source/world/tile/WireTile.hpp b/source/world/tile/WireTile.hpp index 4b72c11e..9e55666b 100644 --- a/source/world/tile/WireTile.hpp +++ b/source/world/tile/WireTile.hpp @@ -50,6 +50,7 @@ class WireTile : public Tile void neighborChanged(Level*, int x, int y, int z, int id) override; int getSignal(LevelSource*, int x, int y, int z, int dir) override; int getDirectSignal(LevelSource*, int x, int y, int z, int dir) override; + int getColor(LevelSource*, int, int, int) override; bool isSignalSource(LevelSource*, int x, int y, int z); int getConnections(LevelSource*, int x, int y, int z);