Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 to a new branch up to date with master
  • Loading branch information
iProgramMC committed Apr 7, 2024
1 parent 0da5a03 commit f06e1f4
Show file tree
Hide file tree
Showing 14 changed files with 880 additions and 23 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\tile\RedStoneTorchTile.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\source\world\entity\Entity.hpp" />
Expand Down Expand Up @@ -458,6 +459,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\tile\RedStoneTorchTile.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
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 @@ -470,6 +470,9 @@
<ClCompile Include="$(MC_ROOT)\source\world\particle\FireworkParticle.cpp">
<Filter>Source Files\Particle</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\tile\RedStoneTorchTile.cpp">
<Filter>Source Files\Tile</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\source\world\entity\Entity.hpp">
Expand Down Expand Up @@ -796,5 +799,8 @@
<ClInclude Include="$(MC_ROOT)\source\world\entity\Rocket.hpp">
<Filter>Header Files\Entity</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\tile\RedStoneTorchTile.hpp">
<Filter>Header Files\Tile</Filter>
</ClInclude>
</ItemGroup>
</Project>
138 changes: 137 additions & 1 deletion source/client/renderer/TileRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#include "TileRenderer.hpp"
#include "client/app/Minecraft.hpp"
#include "client/renderer/PatchManager.hpp"
#include "world/tile/FireTile.hpp"
#include "world/tile/LiquidTile.hpp"
#include "world/tile/FireTile.hpp"
#include "world/tile/WireTile.hpp"
#include "client/renderer/GrassColor.hpp"
#include "client/renderer/FoliageColor.hpp"

Expand Down Expand Up @@ -1312,6 +1313,139 @@ bool TileRenderer::tesselateFireInWorld(Tile* tile, int x, int y, int z)
return true;
}

bool TileRenderer::tesselateWireInWorld(Tile* tile, int x, int y, int z)
{
int data = m_pLevelSource->getData(x, y, z);
int texture = tile->getTexture(DIR_YPOS, data);

if (m_textureOverride >= 0)
texture = m_textureOverride;

WireTile* pWireTile = (WireTile*)tile;
int connFlags = pWireTile->getConnections(m_pLevelSource, x, y, z);

tile->updateShape(m_pLevelSource, x, y, z);

bool bUsingStraightTexture = false;

// If we are only connected on 2 parallel sides, use the straight wire texture.
const int CF1 = (1 << WireTile::CONN_XN) | (1 << WireTile::CONN_XP);
const int CF2 = (1 << WireTile::CONN_ZN) | (1 << WireTile::CONN_ZP);

if ((connFlags & WireTile::CONN_MASK) == CF1 || (connFlags & WireTile::CONN_MASK) == CF2)
{
texture++;
bUsingStraightTexture = true;
}

float texX = 16.0f * float((texture % 16));
float texY = 16.0f * float((texture / 16));
const float C_RATIO = 1.0f / 256.0f;
const float C_RATIO2 = 1.0f / 16.0f;

float texU_1, texU_2, texV_1, texV_2;
bool bRotateWire = bUsingStraightTexture && (connFlags & (1 << WireTile::CONN_ZP));

AABB aabb = tile->m_aabb;

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);
}
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);
}

Tesselator& t = Tesselator::instance;

// calculate the color based on the wire's current power
float bright = tile->getBrightness(m_pLevelSource, x, y, z);
float power = float(data) / 15.0f;
float rt = power * 0.6f + 0.4f;
if (data == 0)
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;

t.color(bright * rt, bright * gt, bright * bt);

if (bRotateWire)
{
t.vertexUV(float(x) + aabb.max.x, float(y) + 0.01f, float(z) + aabb.max.z, texU_1, texV_2);
t.vertexUV(float(x) + aabb.max.x, float(y) + 0.01f, float(z) + aabb.min.z, texU_2, texV_2);
t.vertexUV(float(x) + aabb.min.x, float(y) + 0.01f, float(z) + aabb.min.z, texU_2, texV_1);
t.vertexUV(float(x) + aabb.min.x, float(y) + 0.01f, float(z) + aabb.max.z, texU_1, texV_1);
}
else
{
t.vertexUV(float(x) + aabb.max.x, float(y) + 0.01f, float(z) + aabb.max.z, texU_2, texV_2);
t.vertexUV(float(x) + aabb.max.x, float(y) + 0.01f, float(z) + aabb.min.z, texU_2, texV_1);
t.vertexUV(float(x) + aabb.min.x, float(y) + 0.01f, float(z) + aabb.min.z, texU_1, texV_1);
t.vertexUV(float(x) + aabb.min.x, float(y) + 0.01f, float(z) + aabb.max.z, texU_1, texV_2);
}

if ((connFlags & WireTile::CONN_ABOVE_MASK) == 0)
return true;

if (!bUsingStraightTexture)
{
texture++;
texX = 16.0f * float((texture % 16));
texY = 16.0f * float((texture / 16));
}

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

if (connFlags & (1 << WireTile::CONN_ABOVE_ZP))
{
t.vertexUV(0.0f + x, 1.0f + y, 0.99f + z, texU_1, texV_1);
t.vertexUV(1.0f + x, 1.0f + y, 0.99f + z, texU_1, texV_2);
t.vertexUV(1.0f + x, 0.0f + y, 0.99f + z, texU_2, texV_2);
t.vertexUV(0.0f + x, 0.0f + y, 0.99f + z, texU_2, texV_1);
}

if (connFlags & (1 << WireTile::CONN_ABOVE_ZN))
{
t.vertexUV(1.0f + x, 1.0f + y, 0.01f + z, texU_1, texV_1);
t.vertexUV(0.0f + x, 1.0f + y, 0.01f + z, texU_1, texV_2);
t.vertexUV(0.0f + x, 0.0f + y, 0.01f + z, texU_2, texV_2);
t.vertexUV(1.0f + x, 0.0f + y, 0.01f + z, texU_2, texV_1);
}

if (connFlags & (1 << WireTile::CONN_ABOVE_XN))
{
t.vertexUV(0.01f + x, 1.0f + y, 0.0f + z, texU_1, texV_1);
t.vertexUV(0.01f + x, 1.0f + y, 1.0f + z, texU_1, texV_2);
t.vertexUV(0.01f + x, 0.0f + y, 1.0f + z, texU_2, texV_2);
t.vertexUV(0.01f + x, 0.0f + y, 0.0f + z, texU_2, texV_1);
}

if (connFlags & (1 << WireTile::CONN_ABOVE_XP))
{
t.vertexUV(0.99f + x, 1.0f + y, 1.0f + z, texU_1, texV_1);
t.vertexUV(0.99f + x, 1.0f + y, 0.0f + z, texU_1, texV_2);
t.vertexUV(0.99f + x, 0.0f + y, 0.0f + z, texU_2, texV_2);
t.vertexUV(0.99f + x, 0.0f + y, 1.0f + z, 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 @@ -1342,6 +1476,8 @@ bool TileRenderer::tesselateInWorld(Tile* tile, int x, int y, int z)
return tesselateDoorInWorld(tile, x, y, z);
case SHAPE_STAIRS:
return tesselateStairsInWorld(tile, x, y, z);
case SHAPE_WIRE:
return tesselateWireInWorld(tile, x, y, z);
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions source/client/renderer/TileRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class TileRenderer
bool tesselateLadderInWorld(Tile*, int x, int y, int z);
bool tesselateTorchInWorld(Tile*, int x, int y, int z);
bool tesselateDoorInWorld(Tile*, int x, int y, int z);
#ifndef ORIGINAL_CODE
bool tesselateFireInWorld(Tile*, int x, int y, int z);
#endif
bool tesselateWireInWorld(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);
#endif
Expand Down
11 changes: 8 additions & 3 deletions source/common/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,17 @@ enum eRenderShape
SHAPE_TORCH,
SHAPE_FIRE,
SHAPE_WATER,
SHAPE_UNK5,
SHAPE_UNK6,
SHAPE_WIRE,
SHAPE_CROPS,
SHAPE_DOOR,
SHAPE_LADDER,
SHAPE_UNK9,
SHAPE_RAIL,
SHAPE_STAIRS,
SHAPE_FENCE,
SHAPE_LEVER,
SHAPE_CACTUS,
SHAPE_BED,
SHAPE_REPEATER,
};

enum eRenderLayer
Expand Down
5 changes: 5 additions & 0 deletions source/world/item/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ void Inventory::prepareCreativeInventory()
addCreativeItem(Item::door_iron->m_itemID);
addCreativeItem(Item::rocket->m_itemID);

// redstone stuff
addCreativeItem(Tile::wire->m_ID);
addCreativeItem(Tile::notGate_off->m_ID);
addCreativeItem(Tile::notGate->m_ID);

for (int i = 0; i < C_MAX_HOTBAR_ITEMS; i++)
m_hotbar[i] = i;
}
Expand Down
Loading

0 comments on commit f06e1f4

Please sign in to comment.