Skip to content

Commit

Permalink
* Add repeater support
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Apr 8, 2024
1 parent ca90302 commit 711461d
Show file tree
Hide file tree
Showing 12 changed files with 402 additions and 3 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 @@ -350,6 +350,7 @@
<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\DiodeTile.cpp" />
<ClCompile Include="..\..\..\..\source\world\tile\LeverTile.cpp" />
<ClCompile Include="..\..\..\..\source\world\tile\PressurePlateTile.cpp" />
<ClCompile Include="..\..\..\..\source\world\tile\RedStoneTorchTile.cpp" />
Expand Down Expand Up @@ -465,6 +466,7 @@
<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\DiodeTile.hpp" />
<ClInclude Include="..\..\..\..\source\world\tile\LeverTile.hpp" />
<ClInclude Include="..\..\..\..\source\world\tile\PressurePlateTile.hpp" />
<ClInclude Include="..\..\..\..\source\world\tile\RedStoneTorchTile.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 @@ -485,6 +485,9 @@
<ClCompile Include="..\..\..\..\source\world\item\RedstoneItem.cpp">
<Filter>Source Files\Item</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\tile\DiodeTile.cpp">
<Filter>Source Files\Tile</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\source\world\entity\Entity.hpp">
Expand Down Expand Up @@ -826,5 +829,8 @@
<ClInclude Include="..\..\..\..\source\world\item\RedstoneItem.hpp">
<Filter>Header Files\Item</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\tile\DiodeTile.hpp">
<Filter>Header Files\Tile</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ add_library(reminecraftpe-core STATIC
world/tile/LeverTile.cpp
world/tile/ButtonTile.cpp
world/tile/PressurePlateTile.cpp
world/tile/DiodeTile.cpp
renderer/GL/GL.cpp
)
target_include_directories(reminecraftpe-core PUBLIC . ..)
Expand Down
94 changes: 94 additions & 0 deletions source/client/renderer/TileRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "world/tile/LiquidTile.hpp"
#include "world/tile/FireTile.hpp"
#include "world/tile/WireTile.hpp"
#include "world/tile/DiodeTile.hpp"
#include "client/renderer/GrassColor.hpp"
#include "client/renderer/FoliageColor.hpp"

Expand Down Expand Up @@ -1592,6 +1593,97 @@ bool TileRenderer::tesselateLeverInWorld(Tile* tile, int x, int y, int z)
return true;
}

bool TileRenderer::tesselateDiodeInWorld(Tile* tile, int x, int y, int z)
{
constexpr float C_RATIO = 1.0f / 256.0f;
int data = m_pLevelSource->getData(x, y, z);
int rot = (data & 0b0011);
int del = (data & 0b1100) >> 2;

// This renders the sides of the repeater.
tesselateBlockInWorld(tile, x, y, z);

float bright = tile->getBrightness(m_pLevelSource, x, y, z);
if (Tile::lightEmission[tile->m_ID] > 0)
bright = (bright + 1.0f) * 0.5f;

Tesselator& t = Tesselator::instance;
t.color(bright, bright, bright);

constexpr float offsY = -0.1875f;
float offsX1 = 0, offsZ1 = 0, offsX2 = 0, offsZ2 = 0;

switch (rot)
{
case 0:
offsZ2 = -0.3125f;
offsZ1 = DiodeTile::m_particleOffsets[del];
break;
case 2:
offsZ2 = 0.3125f;
offsZ1 = -DiodeTile::m_particleOffsets[del];
break;
case 3:
offsX2 = -0.3125f;
offsX1 = DiodeTile::m_particleOffsets[del];
break;
case 1:
offsX2 = 0.3125f;
offsX1 = -DiodeTile::m_particleOffsets[del];
break;
}

tesselateTorch(tile, float(x) + offsX1, float(y) + offsY, float(z) + offsZ1, 0.0f, 0.0f);
tesselateTorch(tile, float(x) + offsX2, float(y) + offsY, float(z) + offsZ2, 0.0f, 0.0f);

int texture = tile->getTexture(DIR_YPOS);
int texX = (texture & 0x0F) << 4;
int texY = (texture & 0xF0);

float texU_1 = C_RATIO * float(texX);
float texU_2 = C_RATIO * float(texX + 15.99f);
float texV_1 = C_RATIO * float(texY);
float texV_2 = C_RATIO * float(texY + 15.99f);

float v1x, v2x, v3x, v4x;
float v1z, v2z, v3z, v4z;
float vy = float(y) + 0.125f;

switch (rot) {
case 0:
default:
v4x = v3x = float(x + 1);
v2x = v1x = float(x + 0);
v4z = v1z = float(z + 0);
v3z = v2z = float(z + 1);
break;
case 2:
v4x = v3x = float(x + 0);
v2x = v1x = float(x + 1);
v4z = v1z = float(z + 1);
v3z = v2z = float(z + 0);
break;
case 3:
v4x = v1x = float(x + 0);
v3x = v2x = float(x + 1);
v4z = v3z = float(x + 0);
v2z = v1z = float(x + 1);
break;
case 1:
v4x = v1x = float(x + 1);
v3x = v2x = float(x + 0);
v4z = v3z = float(z + 1);
v2z = v1z = float(z + 0);
break;
}

t.vertexUV(v1x, vy, v1z, texU_1, texV_1);
t.vertexUV(v2x, vy, v2z, texU_1, texV_2);
t.vertexUV(v3x, vy, v3z, texU_2, texV_2);
t.vertexUV(v4x, vy, v4z, texU_2, texV_1);
return true;
}

bool TileRenderer::tesselateInWorld(Tile* tile, int x, int y, int z)
{
int shape = tile->getRenderShape();
Expand Down Expand Up @@ -1626,6 +1718,8 @@ bool TileRenderer::tesselateInWorld(Tile* tile, int x, int y, int z)
return tesselateWireInWorld(tile, x, y, z);
case SHAPE_LEVER:
return tesselateLeverInWorld(tile, x, y, z);
case SHAPE_DIODE:
return tesselateDiodeInWorld(tile, x, y, z);
}

return false;
Expand Down
1 change: 1 addition & 0 deletions source/client/renderer/TileRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TileRenderer
bool tesselateFireInWorld(Tile*, int x, int y, int z);
bool tesselateWireInWorld(Tile*, int x, int y, int z);
bool tesselateLeverInWorld(Tile*, int x, int y, int z);
bool tesselateDiodeInWorld(Tile*, int x, int y, int z);

#ifdef ENH_USE_OWN_AO
bool tesselateBlockInWorldWithAmbienceOcclusionV2(Tile*, int x, int y, int z, float r, float g, float b);
Expand Down
5 changes: 4 additions & 1 deletion source/common/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ enum // Textures
TEXTURE_NONE126,
TEXTURE_NONE127,

TEXTURE_DIODE_OFF = 131,
TEXTURE_DIODE_ON = 147,

TEXTURE_LAPIS = 144,
TEXTURE_ORE_LAPIS = 160,

Expand Down Expand Up @@ -547,7 +550,7 @@ enum eRenderShape
SHAPE_LEVER,
SHAPE_CACTUS,
SHAPE_BED,
SHAPE_REPEATER,
SHAPE_DIODE,
};

enum eRenderLayer
Expand Down
2 changes: 2 additions & 0 deletions source/world/item/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void Inventory::prepareCreativeInventory()
addCreativeItem(Tile::button->m_ID);
addCreativeItem(Tile::plate_stone->m_ID);
addCreativeItem(Tile::plate_wood->m_ID);
addCreativeItem(Tile::repeater_off->m_ID);
addCreativeItem(Tile::repeater_on->m_ID);

for (int i = 0; i < C_MAX_HOTBAR_ITEMS; i++)
m_hotbar[i] = i;
Expand Down
4 changes: 2 additions & 2 deletions source/world/tile/ButtonTile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ void ButtonTile::destroy(Level* level, int x, int y, int z, int pdir)
Tile::destroy(level, x, y, z, pdir);
}

int ButtonTile::getDirectSignal(LevelSource* level, int x, int y, int z, int dir)
int ButtonTile::getSignal(LevelSource* level, int x, int y, int z, int dir)
{
return (level->getData(x, y, z) & 0x8) > 0;
}

int ButtonTile::getSignal(LevelSource* level, int x, int y, int z, int dir)
int ButtonTile::getDirectSignal(LevelSource* level, int x, int y, int z, int dir)
{
int data = level->getData(x, y, z);
if (~data & 0x8)
Expand Down
Loading

0 comments on commit 711461d

Please sign in to comment.