aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/LeverTile.cpp
diff options
context:
space:
mode:
authorLoki Rautio <lokirautio@gmail.com>2026-03-04 03:56:03 -0600
committerLoki Rautio <lokirautio@gmail.com>2026-03-04 03:56:03 -0600
commit42aec6dac53dffa6afe072560a7e1d4986112538 (patch)
tree0836426857391df1b6a83f6368a183f83ec9b104 /Minecraft.World/LeverTile.cpp
parentc9d58eeac7c72f0b3038e084667b4d89a6249fce (diff)
parentef9b6fd500dfabd9463267b0dd9e29577eea8a2b (diff)
Merge branch 'main' into pr/win64-world-saves
# Conflicts: # Minecraft.Client/MinecraftServer.cpp # README.md
Diffstat (limited to 'Minecraft.World/LeverTile.cpp')
-rw-r--r--Minecraft.World/LeverTile.cpp241
1 files changed, 133 insertions, 108 deletions
diff --git a/Minecraft.World/LeverTile.cpp b/Minecraft.World/LeverTile.cpp
index a8231251..eea9e3d3 100644
--- a/Minecraft.World/LeverTile.cpp
+++ b/Minecraft.World/LeverTile.cpp
@@ -1,8 +1,8 @@
#include "stdafx.h"
#include "net.minecraft.world.level.h"
+#include "net.minecraft.world.level.redstone.h"
#include "net.minecraft.h"
#include "LeverTile.h"
-#include "SoundTypes.h"
LeverTile::LeverTile(int id) : Tile(id, Material::decoration,isSolidRender())
{
@@ -35,38 +35,38 @@ int LeverTile::getRenderShape()
bool LeverTile::mayPlace(Level *level, int x, int y, int z, int face)
{
- if (face == 0 && level->isSolidBlockingTile(x, y + 1, z)) return true;
- if (face == 1 && level->isTopSolidBlocking(x, y - 1, z)) return true;
- if (face == 2 && level->isSolidBlockingTile(x, y, z + 1)) return true;
- if (face == 3 && level->isSolidBlockingTile(x, y, z - 1)) return true;
- if (face == 4 && level->isSolidBlockingTile(x + 1, y, z)) return true;
- if (face == 5 && level->isSolidBlockingTile(x - 1, y, z)) return true;
- return false;
+ if (face == Facing::DOWN && level->isSolidBlockingTile(x, y + 1, z)) return true;
+ if (face == Facing::UP && level->isTopSolidBlocking(x, y - 1, z)) return true;
+ if (face == Facing::NORTH && level->isSolidBlockingTile(x, y, z + 1)) return true;
+ if (face == Facing::SOUTH && level->isSolidBlockingTile(x, y, z - 1)) return true;
+ if (face == Facing::WEST && level->isSolidBlockingTile(x + 1, y, z)) return true;
+ if (face == Facing::EAST && level->isSolidBlockingTile(x - 1, y, z)) return true;
+ return false;
}
bool LeverTile::mayPlace(Level *level, int x, int y, int z)
{
- if (level->isSolidBlockingTile(x - 1, y, z))
+ if (level->isSolidBlockingTile(x - 1, y, z))
{
- return true;
- } else if (level->isSolidBlockingTile(x + 1, y, z))
+ return true;
+ } else if (level->isSolidBlockingTile(x + 1, y, z))
{
- return true;
- } else if (level->isSolidBlockingTile(x, y, z - 1))
+ return true;
+ } else if (level->isSolidBlockingTile(x, y, z - 1))
{
- return true;
- } else if (level->isSolidBlockingTile(x, y, z + 1))
+ return true;
+ } else if (level->isSolidBlockingTile(x, y, z + 1))
{
- return true;
- } else if (level->isTopSolidBlocking(x, y - 1, z))
+ return true;
+ } else if (level->isTopSolidBlocking(x, y - 1, z))
{
- return true;
- }
+ return true;
+ }
else if (level->isSolidBlockingTile(x, y + 1, z))
{
return true;
}
- return false;
+ return false;
}
int LeverTile::getPlacedOnFaceDataValue(Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, int itemValue)
@@ -88,6 +88,36 @@ int LeverTile::getPlacedOnFaceDataValue(Level *level, int x, int y, int z, int f
return dir + oldFlip;
}
+void LeverTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance)
+{
+ int data = level->getData(x, y, z);
+ int dir = data & 7;
+ int flip = data & 8;
+
+ if (dir == getLeverFacing(Facing::UP))
+ {
+ if ((Mth::floor(by->yRot * 4 / (360) + 0.5) & 1) == 0)
+ {
+ level->setData(x, y, z, 5 | flip, Tile::UPDATE_CLIENTS);
+ }
+ else
+ {
+ level->setData(x, y, z, 6 | flip, Tile::UPDATE_CLIENTS);
+ }
+ }
+ else if (dir == getLeverFacing(Facing::DOWN))
+ {
+ if ((Mth::floor(by->yRot * 4 / (360) + 0.5) & 1) == 0)
+ {
+ level->setData(x, y, z, 7 | flip, Tile::UPDATE_CLIENTS);
+ }
+ else
+ {
+ level->setData(x, y, z, 0 | flip, Tile::UPDATE_CLIENTS);
+ }
+ }
+}
+
int LeverTile::getLeverFacing(int facing)
{
switch (facing)
@@ -110,65 +140,65 @@ int LeverTile::getLeverFacing(int facing)
void LeverTile::neighborChanged(Level *level, int x, int y, int z, int type)
{
- if (checkCanSurvive(level, x, y, z))
+ if (checkCanSurvive(level, x, y, z))
{
- int dir = level->getData(x, y, z) & 7;
- bool replace = false;
+ int dir = level->getData(x, y, z) & 7;
+ bool replace = false;
- if (!level->isSolidBlockingTile(x - 1, y, z) && dir == 1) replace = true;
- if (!level->isSolidBlockingTile(x + 1, y, z) && dir == 2) replace = true;
- if (!level->isSolidBlockingTile(x, y, z - 1) && dir == 3) replace = true;
+ if (!level->isSolidBlockingTile(x - 1, y, z) && dir == 1) replace = true;
+ if (!level->isSolidBlockingTile(x + 1, y, z) && dir == 2) replace = true;
+ if (!level->isSolidBlockingTile(x, y, z - 1) && dir == 3) replace = true;
if (!level->isSolidBlockingTile(x, y, z + 1) && dir == 4) replace = true;
if (!level->isTopSolidBlocking(x, y - 1, z) && dir == 5) replace = true;
if (!level->isTopSolidBlocking(x, y - 1, z) && dir == 6) replace = true;
if (!level->isSolidBlockingTile(x, y + 1, z) && dir == 0) replace = true;
if (!level->isSolidBlockingTile(x, y + 1, z) && dir == 7) replace = true;
- if (replace)
+ if (replace)
{
- this->spawnResources(level, x, y, z, level->getData(x, y, z), 0);
- level->setTile(x, y, z, 0);
- }
- }
+ spawnResources(level, x, y, z, level->getData(x, y, z), 0);
+ level->removeTile(x, y, z);
+ }
+ }
}
bool LeverTile::checkCanSurvive(Level *level, int x, int y, int z)
{
- if (!mayPlace(level, x, y, z))
+ if (!mayPlace(level, x, y, z))
{
- this->spawnResources(level, x, y, z, level->getData(x, y, z), 0);
- level->setTile(x, y, z, 0);
- return false;
- }
- return true;
+ spawnResources(level, x, y, z, level->getData(x, y, z), 0);
+ level->removeTile(x, y, z);
+ return false;
+ }
+ return true;
}
void LeverTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param
{
- int dir = level->getData(x, y, z) & 7;
- float r = 3 / 16.0f;
- if (dir == 1)
+ int dir = level->getData(x, y, z) & 7;
+ float r = 3 / 16.0f;
+ if (dir == 1)
{
- setShape(0, 0.2f, 0.5f - r, r * 2, 0.8f, 0.5f + r);
- }
+ setShape(0, 0.2f, 0.5f - r, r * 2, 0.8f, 0.5f + r);
+ }
else if (dir == 2)
{
- setShape(1 - r * 2, 0.2f, 0.5f - r, 1, 0.8f, 0.5f + r);
- }
+ setShape(1 - r * 2, 0.2f, 0.5f - r, 1, 0.8f, 0.5f + r);
+ }
else if (dir == 3)
{
- setShape(0.5f - r, 0.2f, 0, 0.5f + r, 0.8f, r * 2);
- }
+ setShape(0.5f - r, 0.2f, 0, 0.5f + r, 0.8f, r * 2);
+ }
else if (dir == 4)
{
- setShape(0.5f - r, 0.2f, 1 - r * 2, 0.5f + r, 0.8f, 1);
- }
+ setShape(0.5f - r, 0.2f, 1 - r * 2, 0.5f + r, 0.8f, 1);
+ }
else if (dir == 5 || dir == 6)
{
- r = 4 / 16.0f;
- setShape(0.5f - r, 0.0f, 0.5f - r, 0.5f + r, 0.6f, 0.5f + r);
- }
+ r = 4 / 16.0f;
+ setShape(0.5f - r, 0.0f, 0.5f - r, 0.5f + r, 0.6f, 0.5f + r);
+ }
else if (dir == 0 || dir == 7)
{
r = 4 / 16.0f;
@@ -176,11 +206,6 @@ void LeverTile::updateShape(LevelSource *level, int x, int y, int z, int forceDa
}
}
-void LeverTile::attack(Level *level, int x, int y, int z, shared_ptr<Player> player)
-{
- use(level, x, y, z, player, 0, 0, 0, 0);
-}
-
// 4J-PB - Adding a TestUse for tooltip display
bool LeverTile::TestUse()
{
@@ -198,7 +223,7 @@ bool LeverTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player
level->playSound(x + 0.5, y + 0.5, z + 0.5, eSoundType_RANDOM_CLICK, 0.3f, open > 0 ? 0.6f : 0.5f);
return false;
}
- if (level->isClientSide)
+ if (level->isClientSide)
{
// 4J - added stuff to play sound in this case too
int data = level->getData(x, y, z);
@@ -208,99 +233,99 @@ bool LeverTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player
return true;
}
- int data = level->getData(x, y, z);
- int dir = data & 7;
- int open = 8 - (data & 8);
+ int data = level->getData(x, y, z);
+ int dir = data & 7;
+ int open = 8 - (data & 8);
- level->setData(x, y, z, dir + open);
- level->setTilesDirty(x, y, z, x, y, z);
+ level->setData(x, y, z, dir + open, Tile::UPDATE_ALL);
+ level->setTilesDirty(x, y, z, x, y, z);
- level->playSound(x + 0.5, y + 0.5, z + 0.5, eSoundType_RANDOM_CLICK, 0.3f, open > 0 ? 0.6f : 0.5f);
+ level->playSound(x + 0.5, y + 0.5, z + 0.5, eSoundType_RANDOM_CLICK, 0.3f, open > 0 ? 0.6f : 0.5f);
- level->updateNeighborsAt(x, y, z, id);
- if (dir == 1)
+ level->updateNeighborsAt(x, y, z, id);
+ if (dir == 1)
{
- level->updateNeighborsAt(x - 1, y, z, id);
- }
+ level->updateNeighborsAt(x - 1, y, z, id);
+ }
else if (dir == 2)
{
- level->updateNeighborsAt(x + 1, y, z, id);
- }
+ level->updateNeighborsAt(x + 1, y, z, id);
+ }
else if (dir == 3)
{
- level->updateNeighborsAt(x, y, z - 1, id);
- }
+ level->updateNeighborsAt(x, y, z - 1, id);
+ }
else if (dir == 4)
{
- level->updateNeighborsAt(x, y, z + 1, id);
- }
+ level->updateNeighborsAt(x, y, z + 1, id);
+ }
else if (dir == 5 || dir == 6)
{
- level->updateNeighborsAt(x, y - 1, z, id);
- }
+ level->updateNeighborsAt(x, y - 1, z, id);
+ }
else if (dir == 0 || dir == 7)
{
level->updateNeighborsAt(x, y + 1, z, id);
}
- return true;
+ return true;
}
void LeverTile::onRemove(Level *level, int x, int y, int z, int id, int data)
{
- if ((data & 8) > 0)
+ if ((data & 8) > 0)
{
- level->updateNeighborsAt(x, y, z, this->id);
- int dir = data & 7;
- if (dir == 1)
+ level->updateNeighborsAt(x, y, z, this->id);
+ int dir = data & 7;
+ if (dir == 1)
{
- level->updateNeighborsAt(x - 1, y, z, this->id);
- }
+ level->updateNeighborsAt(x - 1, y, z, this->id);
+ }
else if (dir == 2)
{
- level->updateNeighborsAt(x + 1, y, z, this->id);
- }
+ level->updateNeighborsAt(x + 1, y, z, this->id);
+ }
else if (dir == 3)
{
- level->updateNeighborsAt(x, y, z - 1, this->id);
- }
+ level->updateNeighborsAt(x, y, z - 1, this->id);
+ }
else if (dir == 4)
{
- level->updateNeighborsAt(x, y, z + 1, this->id);
- }
+ level->updateNeighborsAt(x, y, z + 1, this->id);
+ }
else if (dir == 5 || dir == 6)
{
- level->updateNeighborsAt(x, y - 1, z, this->id);
+ level->updateNeighborsAt(x, y - 1, z, this->id);
}
else if (dir == 0 || dir == 7)
{
level->updateNeighborsAt(x, y + 1, z, this->id);
}
- }
- Tile::onRemove(level, x, y, z, id, data);
+ }
+ Tile::onRemove(level, x, y, z, id, data);
}
-bool LeverTile::getSignal(LevelSource *level, int x, int y, int z, int dir)
+int LeverTile::getSignal(LevelSource *level, int x, int y, int z, int dir)
{
- return (level->getData(x, y, z) & 8) > 0;
+ return (level->getData(x, y, z) & 8) > 0 ? Redstone::SIGNAL_MAX : Redstone::SIGNAL_NONE;
}
-bool LeverTile::getDirectSignal(Level *level, int x, int y, int z, int dir)
+int LeverTile::getDirectSignal(LevelSource *level, int x, int y, int z, int dir)
{
- int data = level->getData(x, y, z);
- if ((data & 8) == 0) return false;
- int myDir = data & 7;
-
- if (myDir == 0 && dir == 0) return true;
- if (myDir == 7 && dir == 0) return true;
- if (myDir == 6 && dir == 1) return true;
- if (myDir == 5 && dir == 1) return true;
- if (myDir == 4 && dir == 2) return true;
- if (myDir == 3 && dir == 3) return true;
- if (myDir == 2 && dir == 4) return true;
- if (myDir == 1 && dir == 5) return true;
-
- return false;
+ int data = level->getData(x, y, z);
+ if ((data & 8) == 0) return Redstone::SIGNAL_NONE;
+ int myDir = data & 7;
+
+ if (myDir == 0 && dir == 0) return Redstone::SIGNAL_MAX;
+ if (myDir == 7 && dir == 0) return Redstone::SIGNAL_MAX;
+ if (myDir == 6 && dir == 1) return Redstone::SIGNAL_MAX;
+ if (myDir == 5 && dir == 1) return Redstone::SIGNAL_MAX;
+ if (myDir == 4 && dir == 2) return Redstone::SIGNAL_MAX;
+ if (myDir == 3 && dir == 3) return Redstone::SIGNAL_MAX;
+ if (myDir == 2 && dir == 4) return Redstone::SIGNAL_MAX;
+ if (myDir == 1 && dir == 5) return Redstone::SIGNAL_MAX;
+
+ return Redstone::SIGNAL_NONE;
}
bool LeverTile::isSignalSource()