the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 211 lines 6.0 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.h" 3#include "net.minecraft.world.entity.item.h" 4#include "net.minecraft.world.item.h" 5#include "net.minecraft.world.inventory.h" 6#include "net.minecraft.world.level.h" 7#include "net.minecraft.world.level.tile.entity.h" 8#include "net.minecraft.world.h" 9#include "HopperTile.h" 10 11const wstring HopperTile::TEXTURE_OUTSIDE = L"hopper_outside"; 12const wstring HopperTile::TEXTURE_INSIDE = L"hopper_inside"; 13 14HopperTile::HopperTile(int id) : BaseEntityTile(id, Material::metal, isSolidRender() ) 15{ 16 setShape(0, 0, 0, 1, 1, 1); 17} 18 19void HopperTile::updateShape(LevelSource *level, int x, int y, int z, int forceData , shared_ptr<TileEntity> forceEntity) 20{ 21 setShape(0, 0, 0, 1, 1, 1); 22} 23 24void HopperTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source) 25{ 26 setShape(0, 0, 0, 1, 10.0f / 16.0f, 1); 27 BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source); 28 float thickness = 2.0f / 16.0f; 29 setShape(0, 0, 0, thickness, 1, 1); 30 BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source); 31 setShape(0, 0, 0, 1, 1, thickness); 32 BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source); 33 setShape(1 - thickness, 0, 0, 1, 1, 1); 34 BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source); 35 setShape(0, 0, 1 - thickness, 1, 1, 1); 36 BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source); 37 38 setShape(0, 0, 0, 1, 1, 1); 39} 40 41int HopperTile::getPlacedOnFaceDataValue(Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, int itemValue) 42{ 43 int attached = Facing::OPPOSITE_FACING[face]; 44 if (attached == Facing::UP) attached = Facing::DOWN; 45 return attached; 46} 47 48shared_ptr<TileEntity> HopperTile::newTileEntity(Level *level) 49{ 50 return shared_ptr<HopperTileEntity>( new HopperTileEntity() ); 51} 52 53void HopperTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance) 54{ 55 BaseEntityTile::setPlacedBy(level, x, y, z, by, itemInstance); 56 57 if (itemInstance->hasCustomHoverName()) 58 { 59 shared_ptr<HopperTileEntity> hopper = getHopper(level, x, y, z); 60 hopper->setCustomName(itemInstance->getHoverName()); 61 } 62} 63 64void HopperTile::onPlace(Level *level, int x, int y, int z) 65{ 66 BaseEntityTile::onPlace(level, x, y, z); 67 checkPoweredState(level, x, y, z); 68} 69 70bool HopperTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly) 71{ 72 if (level->isClientSide) 73 { 74 return true; 75 } 76 shared_ptr<HopperTileEntity> hopper = getHopper(level, x, y, z); 77 if (hopper != NULL) player->openHopper(hopper); 78 return true; 79} 80 81void HopperTile::neighborChanged(Level *level, int x, int y, int z, int type) 82{ 83 checkPoweredState(level, x, y, z); 84} 85 86void HopperTile::checkPoweredState(Level *level, int x, int y, int z) 87{ 88 int data = level->getData(x, y, z); 89 int attachedFace = getAttachedFace(data); 90 bool shouldBeOn = !level->hasNeighborSignal(x, y, z); 91 bool isOn = isTurnedOn(data); 92 93 if (shouldBeOn != isOn) 94 { 95 level->setData(x, y, z, attachedFace | (shouldBeOn ? 0 : MASK_TOGGLE), UPDATE_NONE); 96 } 97} 98 99void HopperTile::onRemove(Level *level, int x, int y, int z, int id, int data) 100{ 101 shared_ptr<Container> container = dynamic_pointer_cast<HopperTileEntity>( level->getTileEntity(x, y, z) ); 102 if (container != NULL) 103 { 104 for (int i = 0; i < container->getContainerSize(); i++) 105 { 106 shared_ptr<ItemInstance> item = container->getItem(i); 107 if (item != NULL) 108 { 109 float xo = random.nextFloat() * 0.8f + 0.1f; 110 float yo = random.nextFloat() * 0.8f + 0.1f; 111 float zo = random.nextFloat() * 0.8f + 0.1f; 112 113 while (item->count > 0) 114 { 115 int count = random.nextInt(21) + 10; 116 if (count > item->count) count = item->count; 117 item->count -= count; 118 119 shared_ptr<ItemEntity> itemEntity = shared_ptr<ItemEntity>( new ItemEntity(level, x + xo, y + yo, z + zo, shared_ptr<ItemInstance>( new ItemInstance(item->id, count, item->getAuxValue())))); 120 121 if (item->hasTag()) 122 { 123 itemEntity->getItem()->setTag((CompoundTag *) item->getTag()->copy()); 124 } 125 126 float pow = 0.05f; 127 itemEntity->xd = (float) random.nextGaussian() * pow; 128 itemEntity->yd = (float) random.nextGaussian() * pow + 0.2f; 129 itemEntity->zd = (float) random.nextGaussian() * pow; 130 level->addEntity(itemEntity); 131 } 132 } 133 } 134 level->updateNeighbourForOutputSignal(x, y, z, id); 135 } 136 137 BaseEntityTile::onRemove(level, x, y, z, id, data); 138} 139 140int HopperTile::getRenderShape() 141{ 142 return SHAPE_HOPPER; 143} 144 145bool HopperTile::isCubeShaped() 146{ 147 return false; 148} 149 150bool HopperTile::isSolidRender(bool isServerLevel /*= false*/) 151{ 152 return false; 153} 154 155bool HopperTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face) 156{ 157 return true; 158} 159 160Icon *HopperTile::getTexture(int face, int data) 161{ 162 if (face == Facing::UP) 163 { 164 return hopperTopIcon; 165 } 166 return hopperIcon; 167} 168 169int HopperTile::getAttachedFace(int data) 170{ 171 return data & MASK_ATTACHED; 172} 173 174bool HopperTile::isTurnedOn(int data) 175{ 176 return (data & MASK_TOGGLE) != MASK_TOGGLE; 177} 178 179bool HopperTile::hasAnalogOutputSignal() 180{ 181 return true; 182} 183 184int HopperTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir) 185{ 186 return AbstractContainerMenu::getRedstoneSignalFromContainer(getHopper(level, x, y, z)); 187} 188 189void HopperTile::registerIcons(IconRegister *iconRegister) 190{ 191 hopperIcon = iconRegister->registerIcon(TEXTURE_OUTSIDE); 192 hopperTopIcon = iconRegister->registerIcon(L"hopper_top"); 193 hopperInnerIcon = iconRegister->registerIcon(TEXTURE_INSIDE); 194} 195 196Icon *HopperTile::getTexture(const wstring &name) 197{ 198 if (name.compare(TEXTURE_OUTSIDE) == 0) return Tile::hopper->hopperIcon; 199 if (name.compare(TEXTURE_INSIDE) == 0) return Tile::hopper->hopperInnerIcon; 200 return NULL; 201} 202 203wstring HopperTile::getTileItemIconName() 204{ 205 return L"hopper"; 206} 207 208shared_ptr<HopperTileEntity> HopperTile::getHopper(LevelSource *level, int x, int y, int z) 209{ 210 return dynamic_pointer_cast<HopperTileEntity>( level->getTileEntity(x, y, z) ); 211}