the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 96 lines 2.7 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.level.redstone.h" 4#include "net.minecraft.world.level.tile.entity.h" 5#include "CommandBlock.h" 6 7CommandBlock::CommandBlock(int id) : BaseEntityTile(id, Material::metal, isSolidRender() ) 8{ 9} 10 11shared_ptr<TileEntity> CommandBlock::newTileEntity(Level *level) 12{ 13 return shared_ptr<CommandBlockEntity>( new CommandBlockEntity() ); 14} 15 16void CommandBlock::neighborChanged(Level *level, int x, int y, int z, int type) 17{ 18 if (!level->isClientSide) 19 { 20 21 bool signal = level->hasNeighborSignal(x, y, z); 22 int data = level->getData(x, y, z); 23 bool isTriggered = (data & TRIGGER_BIT) != 0; 24 25 if (signal && !isTriggered) 26 { 27 level->setData(x, y, z, data | TRIGGER_BIT, Tile::UPDATE_NONE); 28 level->addToTickNextTick(x, y, z, id, getTickDelay(level)); 29 } 30 else if (!signal && isTriggered) 31 { 32 level->setData(x, y, z, data & ~TRIGGER_BIT, Tile::UPDATE_NONE); 33 } 34 } 35} 36 37void CommandBlock::tick(Level *level, int x, int y, int z, Random *random) 38{ 39 shared_ptr<TileEntity> tileEntity = level->getTileEntity(x, y, z); 40 41 if (tileEntity != NULL && dynamic_pointer_cast<CommandBlockEntity>( tileEntity ) != NULL) 42 { 43 shared_ptr<CommandBlockEntity> commandBlock = dynamic_pointer_cast<CommandBlockEntity>( tileEntity ); 44 commandBlock->setSuccessCount(commandBlock->performCommand(level)); 45 level->updateNeighbourForOutputSignal(x, y, z, id); 46 } 47} 48 49int CommandBlock::getTickDelay(Level *level) 50{ 51 return 1; 52} 53 54bool CommandBlock::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly) 55{ 56 shared_ptr<CommandBlockEntity> amce = dynamic_pointer_cast<CommandBlockEntity>( level->getTileEntity(x, y, z) ); 57 58 if (amce != NULL) 59 { 60 player->openTextEdit(amce); 61 } 62 63 return true; 64} 65 66bool CommandBlock::hasAnalogOutputSignal() 67{ 68 return true; 69} 70 71int CommandBlock::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir) 72{ 73 shared_ptr<TileEntity> tileEntity = level->getTileEntity(x, y, z); 74 75 if (tileEntity != NULL && dynamic_pointer_cast<CommandBlockEntity>( tileEntity ) != NULL) 76 { 77 return dynamic_pointer_cast<CommandBlockEntity>( tileEntity )->getSuccessCount(); 78 } 79 80 return Redstone::SIGNAL_NONE; 81} 82 83void CommandBlock::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance) 84{ 85 shared_ptr<CommandBlockEntity> cblock = dynamic_pointer_cast<CommandBlockEntity>( level->getTileEntity(x, y, z) ); 86 87 if (itemInstance->hasCustomHoverName()) 88 { 89 cblock->setName(itemInstance->getHoverName()); 90 } 91} 92 93int CommandBlock::getResourceCount(Random *random) 94{ 95 return 0; 96}