the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 153 lines 4.6 kB view raw
1#include "stdafx.h" 2#include "BrewingStandTile.h" 3#include "BrewingStandTileEntity.h" 4#include "net.minecraft.world.level.h" 5#include "net.minecraft.world.item.h" 6#include "net.minecraft.world.entity.item.h" 7#include "net.minecraft.world.h" 8#include "net.minecraft.world.inventory.h" 9 10BrewingStandTile::BrewingStandTile(int id) : BaseEntityTile(id, Material::metal, isSolidRender()) 11{ 12 random = new Random(); 13 iconBase = NULL; 14} 15 16BrewingStandTile::~BrewingStandTile() 17{ 18 delete random; 19} 20 21bool BrewingStandTile::isSolidRender(bool isServerLevel) 22{ 23 return false; 24} 25 26int BrewingStandTile::getRenderShape() 27{ 28 return SHAPE_BREWING_STAND; 29} 30 31shared_ptr<TileEntity> BrewingStandTile::newTileEntity(Level *level) 32{ 33 return shared_ptr<TileEntity>(new BrewingStandTileEntity()); 34} 35 36bool BrewingStandTile::isCubeShaped() 37{ 38 return false; 39} 40 41void BrewingStandTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source) 42{ 43 setShape(7.0f / 16.0f, 0, 7.0f / 16.0f, 9.0f / 16.0f, 14.0f / 16.0f, 9.0f / 16.0f); 44 BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source); 45 updateDefaultShape(); 46 BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source); 47} 48 49void BrewingStandTile::updateDefaultShape() 50{ 51 setShape(0, 0, 0, 1, 2.0f / 16.0f, 1); 52} 53 54bool BrewingStandTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly/*=false*/) // 4J added soundOnly param 55{ 56 if(soundOnly) return false; 57 58 if (level->isClientSide) 59 { 60 return true; 61 } 62 shared_ptr<BrewingStandTileEntity> brewingStand = dynamic_pointer_cast<BrewingStandTileEntity>(level->getTileEntity(x, y, z)); 63 if (brewingStand != NULL) player->openBrewingStand(brewingStand); 64 65 return true; 66} 67 68void BrewingStandTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance) 69{ 70 if (itemInstance->hasCustomHoverName()) 71 { 72 dynamic_pointer_cast<BrewingStandTileEntity>( level->getTileEntity(x, y, z))->setCustomName(itemInstance->getHoverName()); 73 } 74} 75 76void BrewingStandTile::animateTick(Level *level, int xt, int yt, int zt, Random *random) 77{ 78 double x = xt + 0.4f + random->nextFloat() * 0.2f; 79 double y = yt + 0.7f + random->nextFloat() * 0.3f; 80 double z = zt + 0.4f + random->nextFloat() * 0.2f; 81 82 83 level->addParticle(eParticleType_smoke, x, y, z, 0, 0, 0); 84} 85 86void BrewingStandTile::onRemove(Level *level, int x, int y, int z, int id, int data) 87{ 88 shared_ptr<TileEntity> tileEntity = level->getTileEntity(x, y, z); 89 if (tileEntity != NULL && ( dynamic_pointer_cast<BrewingStandTileEntity>(tileEntity) != NULL) ) 90 { 91 shared_ptr<BrewingStandTileEntity> container = dynamic_pointer_cast<BrewingStandTileEntity>(tileEntity); 92 for (int i = 0; i < container->getContainerSize(); i++) 93 { 94 shared_ptr<ItemInstance> item = container->getItem(i); 95 if (item != NULL) 96 { 97 float xo = random->nextFloat() * 0.8f + 0.1f; 98 float yo = random->nextFloat() * 0.8f + 0.1f; 99 float zo = random->nextFloat() * 0.8f + 0.1f; 100 101 while (item->count > 0) 102 { 103 int count = random->nextInt(21) + 10; 104 if (count > item->count) count = item->count; 105 item->count -= count; 106 107 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())))); 108 float pow = 0.05f; 109 itemEntity->xd = (float) random->nextGaussian() * pow; 110 itemEntity->yd = (float) random->nextGaussian() * pow + 0.2f; 111 itemEntity->zd = (float) random->nextGaussian() * pow; 112 if (item->hasTag()) 113 { 114 itemEntity->getItem()->setTag((CompoundTag *) item->getTag()->copy()); 115 } 116 level->addEntity(itemEntity); 117 } 118 } 119 } 120 } 121 BaseEntityTile::onRemove(level, x, y, z, id, data); 122} 123 124int BrewingStandTile::getResource(int data, Random *random, int playerBonusLevel) 125{ 126 return Item::brewingStand_Id; 127} 128 129int BrewingStandTile::cloneTileId(Level *level, int x, int y, int z) 130{ 131 return Item::brewingStand_Id; 132} 133 134bool BrewingStandTile::hasAnalogOutputSignal() 135{ 136 return true; 137} 138 139int BrewingStandTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir) 140{ 141 return AbstractContainerMenu::getRedstoneSignalFromContainer(dynamic_pointer_cast<Container>(level->getTileEntity(x, y, z))); 142} 143 144void BrewingStandTile::registerIcons(IconRegister *iconRegister) 145{ 146 BaseEntityTile::registerIcons(iconRegister); 147 iconBase = iconRegister->registerIcon(getIconName() + L"_base"); 148} 149 150Icon *BrewingStandTile::getBaseTexture() 151{ 152 return iconBase; 153}