Something went wrong. Try again.
the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
Something went wrong. Try again.
6.8 kB · 249 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249#include "stdafx.h"#include "net.minecraft.world.level.h"#include "net.minecraft.world.level.redstone.h"#include "NotGateTile.h"#include "SoundTypes.h"#include "net.minecraft.world.h"
unordered_map<Level *, deque<NotGateTile::Toggle> *> NotGateTile::recentToggles = unordered_map<Level *, deque<NotGateTile::Toggle> *>();
// 4J - added, to tie in with other changes brought forward from 1.3.2 to associate toggles with a level. In addition to what the java// version does, we are also removing any references to levels that we are storing when they hit their dtor.void NotGateTile::removeLevelReferences(Level *level){ if( recentToggles.find(level) != recentToggles.end() ) { delete recentToggles[level]; recentToggles.erase(level); }}
bool NotGateTile::isToggledTooFrequently(Level *level, int x, int y, int z, bool add){ // 4J - brought forward changes to associate toggles with a level from 1.3.2 if( recentToggles.find(level) == recentToggles.end() ) { recentToggles[level] = new deque<Toggle>; } if (add) recentToggles[level]->push_back(Toggle(x, y, z, level->getGameTime())); int count = 0;
AUTO_VAR(itEnd, recentToggles[level]->end()); for (AUTO_VAR(it, recentToggles[level]->begin()); it != itEnd; it++) { if (it->x == x && it->y == y && it->z == z) { count++; if (count >= MAX_RECENT_TOGGLES) { return true; } } } return false;}
NotGateTile::NotGateTile(int id, bool on) : TorchTile(id){ this->on = on; this->setTicking(true);}
int NotGateTile::getTickDelay(Level *level){ return 2;}
void NotGateTile::onPlace(Level *level, int x, int y, int z){ if (level->getData(x, y, z) == 0) TorchTile::onPlace(level, x, y, z); if (on) { level->updateNeighborsAt(x, y - 1, z, id); level->updateNeighborsAt(x, y + 1, z, id); level->updateNeighborsAt(x - 1, y, z, id); level->updateNeighborsAt(x + 1, y, z, id); level->updateNeighborsAt(x, y, z - 1, id); level->updateNeighborsAt(x, y, z + 1, id); }}
void NotGateTile::onRemove(Level *level, int x, int y, int z, int id, int data){ if (on) { level->updateNeighborsAt(x, y - 1, z, this->id); level->updateNeighborsAt(x, y + 1, z, this->id); level->updateNeighborsAt(x - 1, y, z, this->id); level->updateNeighborsAt(x + 1, y, z, this->id); level->updateNeighborsAt(x, y, z - 1, this->id); level->updateNeighborsAt(x, y, z + 1, this->id); }}
int NotGateTile::getSignal(LevelSource *level, int x, int y, int z, int face){ if (!on) return Redstone::SIGNAL_NONE;
int dir = level->getData(x, y, z);
if (dir == 5 && face == 1) return Redstone::SIGNAL_NONE; if (dir == 3 && face == 3) return Redstone::SIGNAL_NONE; if (dir == 4 && face == 2) return Redstone::SIGNAL_NONE; if (dir == 1 && face == 5) return Redstone::SIGNAL_NONE; if (dir == 2 && face == 4) return Redstone::SIGNAL_NONE;
return Redstone::SIGNAL_MAX;}
bool NotGateTile::hasNeighborSignal(Level *level, int x, int y, int z){ int dir = level->getData(x, y, z);
if (dir == 5 && level->hasSignal(x, y - 1, z, 0)) return true; if (dir == 3 && level->hasSignal(x, y, z - 1, 2)) return true; if (dir == 4 && level->hasSignal(x, y, z + 1, 3)) return true; if (dir == 1 && level->hasSignal(x - 1, y, z, 4)) return true; if (dir == 2 && level->hasSignal(x + 1, y, z, 5)) return true; return false;}
void NotGateTile::tick(Level *level, int x, int y, int z, Random *random){ bool neighborSignal = hasNeighborSignal(level, x, y, z);
// 4J - brought forward changes from 1.3.2 to associate toggles with level if( recentToggles.find(level) != recentToggles.end() ) { deque<Toggle> *toggles = recentToggles[level]; while (!toggles->empty() && level->getGameTime() - toggles->front().when > RECENT_TOGGLE_TIMER) { toggles->pop_front(); } }
if (on) { if (neighborSignal) { level->setTileAndData(x, y, z, Tile::redstoneTorch_off_Id, level->getData(x, y, z), Tile::UPDATE_ALL);
if (isToggledTooFrequently(level, x, y, z, true)) { app.DebugPrintf("Torch at (%d,%d,%d) has toggled too many times\n",x,y,z);
level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, eSoundType_RANDOM_FIZZ, 0.5f, 2.6f + (level->random->nextFloat() - level->random->nextFloat()) * 0.8f); for (int i = 0; i < 5; i++) { double xx = x + random->nextDouble() * 0.6 + 0.2; double yy = y + random->nextDouble() * 0.6 + 0.2; double zz = z + random->nextDouble() * 0.6 + 0.2;
level->addParticle(eParticleType_smoke, xx, yy, zz, 0, 0, 0); } } } } else { if (!neighborSignal) { if (!isToggledTooFrequently(level, x, y, z, false)) { level->setTileAndData(x, y, z, Tile::redstoneTorch_on_Id, level->getData(x, y, z), Tile::UPDATE_ALL); } else { app.DebugPrintf("Torch at (%d,%d,%d) has toggled too many times\n",x,y,z); } } }}
void NotGateTile::neighborChanged(Level *level, int x, int y, int z, int type){ if (checkDoPop(level, x, y, z, type)) { return; }
bool neighborSignal = hasNeighborSignal(level, x, y, z); if ((on && neighborSignal) || (!on && !neighborSignal)) { level->addToTickNextTick(x, y, z, id, getTickDelay(level)); }}
int NotGateTile::getDirectSignal(LevelSource *level, int x, int y, int z, int face){ if (face == 0) { return getSignal(level, x, y, z, face); } return Redstone::SIGNAL_NONE;}
int NotGateTile::getResource(int data, Random *random, int playerBonusLevel){ return Tile::redstoneTorch_on_Id;}
bool NotGateTile::isSignalSource(){ return true;}
void NotGateTile::animateTick(Level *level, int xt, int yt, int zt, Random *random){ if (!on) return; int dir = level->getData(xt, yt, zt); double x = xt + 0.5f + (random->nextFloat() - 0.5f) * 0.2; double y = yt + 0.7f + (random->nextFloat() - 0.5f) * 0.2; double z = zt + 0.5f + (random->nextFloat() - 0.5f) * 0.2; double h = 0.22f; double r = 0.27f; if (dir == 1) { level->addParticle(eParticleType_reddust, x - r, y + h, z, 0, 0, 0); } else if(dir == 2) { level->addParticle(eParticleType_reddust, x + r, y + h, z, 0, 0, 0); } else if (dir == 3) { level->addParticle(eParticleType_reddust, x, y + h, z - r, 0, 0, 0); } else if (dir == 4) { level->addParticle(eParticleType_reddust, x, y + h, z + r, 0, 0, 0); } else { level->addParticle(eParticleType_reddust, x, y, z, 0, 0, 0); }
}
int NotGateTile::cloneTileId(Level *level, int x, int y, int z){ return Tile::redstoneTorch_on_Id;}
void NotGateTile::levelTimeChanged(Level *level, __int64 delta, __int64 newTime){ deque<Toggle> *toggles = recentToggles[level];
if (toggles != NULL) { for (AUTO_VAR(it,toggles->begin()); it != toggles->end(); ++it) { (*it).when += delta; } }}
bool NotGateTile::isMatching(int id){ return id == Tile::redstoneTorch_off_Id || id == Tile::redstoneTorch_on_Id;}