diff options
| author | Loki Rautio <lokirautio@gmail.com> | 2026-03-04 03:56:03 -0600 |
|---|---|---|
| committer | Loki Rautio <lokirautio@gmail.com> | 2026-03-04 03:56:03 -0600 |
| commit | 42aec6dac53dffa6afe072560a7e1d4986112538 (patch) | |
| tree | 0836426857391df1b6a83f6368a183f83ec9b104 /Minecraft.World/DetectorRailTile.cpp | |
| parent | c9d58eeac7c72f0b3038e084667b4d89a6249fce (diff) | |
| parent | ef9b6fd500dfabd9463267b0dd9e29577eea8a2b (diff) | |
Merge branch 'main' into pr/win64-world-saves
# Conflicts:
# Minecraft.Client/MinecraftServer.cpp
# README.md
Diffstat (limited to 'Minecraft.World/DetectorRailTile.cpp')
| -rw-r--r-- | Minecraft.World/DetectorRailTile.cpp | 117 |
1 files changed, 75 insertions, 42 deletions
diff --git a/Minecraft.World/DetectorRailTile.cpp b/Minecraft.World/DetectorRailTile.cpp index e01ec259..16265ceb 100644 --- a/Minecraft.World/DetectorRailTile.cpp +++ b/Minecraft.World/DetectorRailTile.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" +#include "net.minecraft.world.inventory.h" #include "net.minecraft.world.level.h" +#include "net.minecraft.world.level.redstone.h" #include "net.minecraft.world.entity.h" #include "net.minecraft.world.entity.item.h" #include "net.minecraft.world.phys.h" @@ -7,13 +9,13 @@ #include "DetectorRailTile.h" #include "net.minecraft.h" -DetectorRailTile::DetectorRailTile(int id) : RailTile(id, true) +DetectorRailTile::DetectorRailTile(int id) : BaseRailTile(id, true) { setTicking(true); icons = NULL; } -int DetectorRailTile::getTickDelay() +int DetectorRailTile::getTickDelay(Level *level) { return 20; } @@ -25,79 +27,110 @@ bool DetectorRailTile::isSignalSource() void DetectorRailTile::entityInside(Level *level, int x, int y, int z, shared_ptr<Entity> entity) { - if (level->isClientSide) + if (level->isClientSide) { - return; - } + return; + } - int data = level->getData(x, y, z); - if ((data & RAIL_DATA_BIT) != 0) + int data = level->getData(x, y, z); + if ((data & RAIL_DATA_BIT) != 0) { - return; - } + return; + } - checkPressed(level, x, y, z, data); + checkPressed(level, x, y, z, data); } void DetectorRailTile::tick(Level *level, int x, int y, int z, Random *random) { - if (level->isClientSide) return; + if (level->isClientSide) return; - int data = level->getData(x, y, z); - if ((data & RAIL_DATA_BIT) == 0) + int data = level->getData(x, y, z); + if ((data & RAIL_DATA_BIT) == 0) { - return; - } + return; + } - checkPressed(level, x, y, z, data); + checkPressed(level, x, y, z, data); } -bool DetectorRailTile::getSignal(LevelSource *level, int x, int y, int z, int dir) +int DetectorRailTile::getSignal(LevelSource *level, int x, int y, int z, int dir) { - return (level->getData(x, y, z) & RAIL_DATA_BIT) != 0; + return (level->getData(x, y, z) & RAIL_DATA_BIT) != 0 ? Redstone::SIGNAL_MAX : Redstone::SIGNAL_NONE; } -bool DetectorRailTile::getDirectSignal(Level *level, int x, int y, int z, int facing) +int DetectorRailTile::getDirectSignal(LevelSource *level, int x, int y, int z, int facing) { - if ((level->getData(x, y, z) & RAIL_DATA_BIT) == 0) return false; - return (facing == Facing::UP); + if ((level->getData(x, y, z) & RAIL_DATA_BIT) == 0) return Redstone::SIGNAL_NONE; + return (facing == Facing::UP) ? Redstone::SIGNAL_MAX : Redstone::SIGNAL_NONE; } void DetectorRailTile::checkPressed(Level *level, int x, int y, int z, int currentData) { - bool wasPressed = (currentData & RAIL_DATA_BIT) != 0; - bool shouldBePressed = false; + bool wasPressed = (currentData & RAIL_DATA_BIT) != 0; + bool shouldBePressed = false; - float b = 2 / 16.0f; + float b = 2 / 16.0f; vector<shared_ptr<Entity> > *entities = level->getEntitiesOfClass(typeid(Minecart), AABB::newTemp(x + b, y, z + b, x + 1 - b, y + 1 - b, z + 1 - b)); - if (!entities->empty()) + if (!entities->empty()) { - shouldBePressed = true; - } + shouldBePressed = true; + } - if (shouldBePressed && !wasPressed) + if (shouldBePressed && !wasPressed) { - level->setData(x, y, z, currentData | RAIL_DATA_BIT); - level->updateNeighborsAt(x, y, z, id); - level->updateNeighborsAt(x, y - 1, z, id); - level->setTilesDirty(x, y, z, x, y, z); - } - if (!shouldBePressed && wasPressed) + level->setData(x, y, z, currentData | RAIL_DATA_BIT, Tile::UPDATE_ALL); + level->updateNeighborsAt(x, y, z, id); + level->updateNeighborsAt(x, y - 1, z, id); + level->setTilesDirty(x, y, z, x, y, z); + } + if (!shouldBePressed && wasPressed) { - level->setData(x, y, z, currentData & RAIL_DIRECTION_MASK); - level->updateNeighborsAt(x, y, z, id); - level->updateNeighborsAt(x, y - 1, z, id); - level->setTilesDirty(x, y, z, x, y, z); - } + level->setData(x, y, z, currentData & RAIL_DIRECTION_MASK, Tile::UPDATE_ALL); + level->updateNeighborsAt(x, y, z, id); + level->updateNeighborsAt(x, y - 1, z, id); + level->setTilesDirty(x, y, z, x, y, z); + } - if (shouldBePressed) + if (shouldBePressed) { - level->addToTickNextTick(x, y, z, id, getTickDelay()); - } + level->addToTickNextTick(x, y, z, id, getTickDelay(level)); + } + + level->updateNeighbourForOutputSignal(x, y, z, id); delete entities; } +void DetectorRailTile::onPlace(Level *level, int x, int y, int z) +{ + BaseRailTile::onPlace(level, x, y, z); + checkPressed(level, x, y, z, level->getData(x, y, z)); +} + +bool DetectorRailTile::hasAnalogOutputSignal() +{ + return true; +} + +int DetectorRailTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir) +{ + if ((level->getData(x, y, z) & RAIL_DATA_BIT) > 0) + { + float b = 2 / 16.0f; + vector<shared_ptr<Entity> > *entities = level->getEntitiesOfClass(typeid(Minecart), AABB::newTemp(x + b, y, z + b, x + 1 - b, y + 1 - b, z + 1 - b), EntitySelector::CONTAINER_ENTITY_SELECTOR); + + if (entities->size() > 0) + { + shared_ptr<Entity> out = entities->at(0); + delete entities; + return AbstractContainerMenu::getRedstoneSignalFromContainer(dynamic_pointer_cast<Container>(out)); + } + } + + return Redstone::SIGNAL_NONE; +} + void DetectorRailTile::registerIcons(IconRegister *iconRegister) { icons = new Icon*[2]; |
