mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-06-26 11:25:41 +00:00
TU19: merge Minecraft.World/Blocks
This commit is contained in:
153
Minecraft.World/Blocks/PoweredRailTile.cpp
Normal file
153
Minecraft.World/Blocks/PoweredRailTile.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
#include "../Platform/stdafx.h"
|
||||
#include "../Headers/net.minecraft.world.h"
|
||||
#include "../Headers/net.minecraft.world.level.h"
|
||||
#include "PoweredRailTile.h"
|
||||
|
||||
PoweredRailTile::PoweredRailTile(int id) : BaseRailTile(id, true) {}
|
||||
|
||||
Icon* PoweredRailTile::getTexture(int face, int data) {
|
||||
if ((data & RAIL_DATA_BIT) == 0) {
|
||||
return icon;
|
||||
} else {
|
||||
return iconPowered;
|
||||
}
|
||||
}
|
||||
|
||||
void PoweredRailTile::registerIcons(IconRegister* iconRegister) {
|
||||
BaseRailTile::registerIcons(iconRegister);
|
||||
iconPowered = iconRegister->registerIcon(getIconName() + L"_powered");
|
||||
}
|
||||
|
||||
bool PoweredRailTile::findPoweredRailSignal(Level* level, int x, int y, int z,
|
||||
int data, bool std::forward,
|
||||
int searchDepth) {
|
||||
if (searchDepth >= 8) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int dir = data & RAIL_DIRECTION_MASK;
|
||||
|
||||
bool checkBelow = true;
|
||||
switch (dir) {
|
||||
case DIR_FLAT_Z:
|
||||
if (std::forward) {
|
||||
z++;
|
||||
} else {
|
||||
z--;
|
||||
}
|
||||
break;
|
||||
case DIR_FLAT_X:
|
||||
if (std::forward) {
|
||||
x--;
|
||||
} else {
|
||||
x++;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (std::forward) {
|
||||
x--;
|
||||
} else {
|
||||
x++;
|
||||
y++;
|
||||
checkBelow = false;
|
||||
}
|
||||
dir = DIR_FLAT_X;
|
||||
break;
|
||||
case 3:
|
||||
if (std::forward) {
|
||||
x--;
|
||||
y++;
|
||||
checkBelow = false;
|
||||
} else {
|
||||
x++;
|
||||
}
|
||||
dir = DIR_FLAT_X;
|
||||
break;
|
||||
case 4:
|
||||
if (std::forward) {
|
||||
z++;
|
||||
} else {
|
||||
z--;
|
||||
y++;
|
||||
checkBelow = false;
|
||||
}
|
||||
dir = DIR_FLAT_Z;
|
||||
break;
|
||||
case 5:
|
||||
if (std::forward) {
|
||||
z++;
|
||||
y++;
|
||||
checkBelow = false;
|
||||
} else {
|
||||
z--;
|
||||
}
|
||||
dir = DIR_FLAT_Z;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isSameRailWithPower(level, x, y, z, std::forward, searchDepth, dir)) {
|
||||
return true;
|
||||
}
|
||||
if (checkBelow && isSameRailWithPower(level, x, y - 1, z, std::forward,
|
||||
searchDepth, dir)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PoweredRailTile::isSameRailWithPower(Level* level, int x, int y, int z,
|
||||
bool std::forward, int searchDepth,
|
||||
int dir) {
|
||||
int tile = level->getTile(x, y, z);
|
||||
|
||||
if (tile == id) {
|
||||
int tileData = level->getData(x, y, z);
|
||||
int myDir = tileData & RAIL_DIRECTION_MASK;
|
||||
|
||||
if (dir == DIR_FLAT_X &&
|
||||
(myDir == DIR_FLAT_Z || myDir == 4 || myDir == 5)) {
|
||||
return false;
|
||||
}
|
||||
if (dir == DIR_FLAT_Z &&
|
||||
(myDir == DIR_FLAT_X || myDir == 2 || myDir == 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((tileData & RAIL_DATA_BIT) != 0) {
|
||||
if (level->hasNeighborSignal(x, y, z)) {
|
||||
return true;
|
||||
} else {
|
||||
return findPoweredRailSignal(level, x, y, z, tileData,
|
||||
std::forward, searchDepth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void PoweredRailTile::updateState(Level* level, int x, int y, int z, int data,
|
||||
int dir, int type) {
|
||||
bool signal = level->hasNeighborSignal(x, y, z);
|
||||
signal = signal || findPoweredRailSignal(level, x, y, z, data, true, 0) ||
|
||||
findPoweredRailSignal(level, x, y, z, data, false, 0);
|
||||
|
||||
bool changed = false;
|
||||
if (signal && (data & RAIL_DATA_BIT) == 0) {
|
||||
level->setData(x, y, z, dir | RAIL_DATA_BIT, Tile::UPDATE_ALL);
|
||||
changed = true;
|
||||
} else if (!signal && (data & RAIL_DATA_BIT) != 0) {
|
||||
level->setData(x, y, z, dir, Tile::UPDATE_ALL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
// usually the level only updates neighbors that are in the same
|
||||
// y plane as the current tile, but sloped rails may need to
|
||||
// update tiles above or below it as well
|
||||
if (changed) {
|
||||
level->updateNeighborsAt(x, y - 1, z, id);
|
||||
if (dir == 2 || dir == 3 || dir == 4 || dir == 5) {
|
||||
level->updateNeighborsAt(x, y + 1, z, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user