the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 187 lines 3.3 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.h" 3#include "net.minecraft.world.level.h" 4#include "PoweredRailTile.h" 5 6PoweredRailTile::PoweredRailTile(int id) : BaseRailTile(id, true) 7{ 8} 9 10Icon *PoweredRailTile::getTexture(int face, int data) 11{ 12 if ((data & RAIL_DATA_BIT) == 0) 13 { 14 return icon; 15 } 16 else 17 { 18 return iconPowered; 19 } 20} 21 22void PoweredRailTile::registerIcons(IconRegister *iconRegister) 23{ 24 BaseRailTile::registerIcons(iconRegister); 25 iconPowered = iconRegister->registerIcon(getIconName() + L"_powered"); 26} 27 28bool PoweredRailTile::findPoweredRailSignal(Level *level, int x, int y, int z, int data, bool forward, int searchDepth) 29{ 30 if (searchDepth >= 8) 31 { 32 return false; 33 } 34 35 int dir = data & RAIL_DIRECTION_MASK; 36 37 bool checkBelow = true; 38 switch (dir) 39 { 40 case DIR_FLAT_Z: 41 if (forward) 42 { 43 z++; 44 } 45 else 46 { 47 z--; 48 } 49 break; 50 case DIR_FLAT_X: 51 if (forward) 52 { 53 x--; 54 } 55 else 56 { 57 x++; 58 } 59 break; 60 case 2: 61 if (forward) 62 { 63 x--; 64 } 65 else 66 { 67 x++; 68 y++; 69 checkBelow = false; 70 } 71 dir = DIR_FLAT_X; 72 break; 73 case 3: 74 if (forward) 75 { 76 x--; 77 y++; 78 checkBelow = false; 79 } 80 else 81 { 82 x++; 83 } 84 dir = DIR_FLAT_X; 85 break; 86 case 4: 87 if (forward) 88 { 89 z++; 90 } 91 else 92 { 93 z--; 94 y++; 95 checkBelow = false; 96 } 97 dir = DIR_FLAT_Z; 98 break; 99 case 5: 100 if (forward) 101 { 102 z++; 103 y++; 104 checkBelow = false; 105 } 106 else 107 { 108 z--; 109 } 110 dir = DIR_FLAT_Z; 111 break; 112 } 113 114 if (isSameRailWithPower(level, x, y, z, forward, searchDepth, dir)) 115 { 116 return true; 117 } 118 if (checkBelow && isSameRailWithPower(level, x, y - 1, z, forward, searchDepth, dir)) 119 { 120 return true; 121 } 122 return false; 123} 124 125bool PoweredRailTile::isSameRailWithPower(Level *level, int x, int y, int z, bool forward, int searchDepth, int dir) 126{ 127 int tile = level->getTile(x, y, z); 128 129 if (tile == id) 130 { 131 int tileData = level->getData(x, y, z); 132 int myDir = tileData & RAIL_DIRECTION_MASK; 133 134 if (dir == DIR_FLAT_X && (myDir == DIR_FLAT_Z || myDir == 4 || myDir == 5)) 135 { 136 return false; 137 } 138 if (dir == DIR_FLAT_Z && (myDir == DIR_FLAT_X || myDir == 2 || myDir == 3)) 139 { 140 return false; 141 } 142 143 if ((tileData & RAIL_DATA_BIT) != 0) 144 { 145 if (level->hasNeighborSignal(x, y, z)) 146 { 147 return true; 148 } 149 else 150 { 151 return findPoweredRailSignal(level, x, y, z, tileData, forward, searchDepth + 1); 152 } 153 } 154 } 155 156 return false; 157} 158 159void PoweredRailTile::updateState(Level *level, int x, int y, int z, int data, int dir, int type) 160{ 161 bool signal = level->hasNeighborSignal(x, y, z); 162 signal = signal || findPoweredRailSignal(level, x, y, z, data, true, 0) || findPoweredRailSignal(level, x, y, z, data, false, 0); 163 164 bool changed = false; 165 if (signal && (data & RAIL_DATA_BIT) == 0) 166 { 167 level->setData(x, y, z, dir | RAIL_DATA_BIT, Tile::UPDATE_ALL); 168 changed = true; 169 } 170 else if (!signal && (data & RAIL_DATA_BIT) != 0) 171 { 172 level->setData(x, y, z, dir, Tile::UPDATE_ALL); 173 changed = true; 174 } 175 176 // usually the level only updates neighbors that are in the same 177 // y plane as the current tile, but sloped rails may need to 178 // update tiles above or below it as well 179 if (changed) 180 { 181 level->updateNeighborsAt(x, y - 1, z, id); 182 if (dir == 2 || dir == 3 || dir == 4 || dir == 5) 183 { 184 level->updateNeighborsAt(x, y + 1, z, id); 185 } 186 } 187}