Skip to content

Commit

Permalink
* Make redstone dust hitbox work like MC Java
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Apr 8, 2024
1 parent b1a2a9d commit b2fdb92
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 35 deletions.
2 changes: 2 additions & 0 deletions platforms/windows/projects/World/World.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@
<ClCompile Include="$(MC_ROOT)\source\world\entity\Cow.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\Creeper.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\Pig.cpp" />
<ClCompile Include="..\..\..\..\source\world\item\RedstoneItem.cpp" />
<ClCompile Include="..\..\..\..\source\world\tile\ButtonTile.cpp" />
<ClCompile Include="..\..\..\..\source\world\tile\LeverTile.cpp" />
<ClCompile Include="..\..\..\..\source\world\tile\PressurePlateTile.cpp" />
Expand Down Expand Up @@ -462,6 +463,7 @@
<ClInclude Include="$(MC_ROOT)\source\world\entity\Creeper.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\Pig.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\Rocket.hpp" />
<ClInclude Include="..\..\..\..\source\world\item\RedstoneItem.hpp" />
<ClInclude Include="..\..\..\..\source\world\tile\ButtonTile.hpp" />
<ClInclude Include="..\..\..\..\source\world\tile\LeverTile.hpp" />
<ClInclude Include="..\..\..\..\source\world\tile\PressurePlateTile.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions platforms/windows/projects/World/World.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@
<ClCompile Include="..\..\..\..\source\world\tile\ButtonTile.cpp">
<Filter>Source Files\Tile</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\item\RedstoneItem.cpp">
<Filter>Source Files\Item</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\source\world\entity\Entity.hpp">
Expand Down Expand Up @@ -820,5 +823,8 @@
<ClInclude Include="..\..\..\..\source\world\tile\ButtonTile.hpp">
<Filter>Header Files\Tile</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\item\RedstoneItem.hpp">
<Filter>Header Files\Item</Filter>
</ClInclude>
</ItemGroup>
</Project>
32 changes: 18 additions & 14 deletions source/client/renderer/TileRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion source/world/item/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions source/world/item/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "TileItem.hpp"
#include "TilePlanterItem.hpp"
#include "RocketItem.hpp"
#include "RedstoneItem.hpp"

#define ITEM(x) ((x) - 256)

Expand Down Expand Up @@ -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)
Expand Down
43 changes: 43 additions & 0 deletions source/world/item/RedstoneItem.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
18 changes: 18 additions & 0 deletions source/world/item/RedstoneItem.hpp
Original file line number Diff line number Diff line change
@@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void ExternalFileLevelStorageSource::getLevelList(std::vector<LevelSummary>& 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;

Expand Down
8 changes: 0 additions & 8 deletions source/world/level/storage/LevelStorageSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,4 @@ LevelStorageSource::~LevelStorageSource()

void LevelStorageSource::getLevelList(std::vector<LevelSummary>& 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
}
2 changes: 1 addition & 1 deletion source/world/particle/ParticleEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion source/world/tile/RedStoneTorchTile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RedStoneTorchTile::RedStoneTorchTile(int id, int texture, Material* pMtl) : Torc

bool RedStoneTorchTile::isSignalSource()
{
return m_bActive;
return true;
}

int RedStoneTorchTile::getTickDelay()
Expand Down
18 changes: 8 additions & 10 deletions source/world/tile/WireTile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions source/world/tile/WireTile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b2fdb92

Please sign in to comment.