the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 192 lines 4.8 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.player.h" 3#include "net.minecraft.world.item.h" 4#include "net.minecraft.world.level.h" 5#include "net.minecraft.world.level.tile.h" 6#include "FlowerPotTile.h" 7 8FlowerPotTile::FlowerPotTile(int id) : Tile(id, Material::decoration, isSolidRender() ) 9{ 10 updateDefaultShape(); 11 sendTileData(); 12} 13 14void FlowerPotTile::updateDefaultShape() 15{ 16 float size = 6.0f / 16.0f; 17 float half = size / 2; 18 setShape(0.5f - half, 0, 0.5f - half, 0.5f + half, size, 0.5f + half); 19} 20 21bool FlowerPotTile::isSolidRender(bool isServerLevel) 22{ 23 return false; 24} 25 26int FlowerPotTile::getRenderShape() 27{ 28 return SHAPE_FLOWER_POT; 29} 30 31bool FlowerPotTile::isCubeShaped() 32{ 33 return false; 34} 35 36bool FlowerPotTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly) 37{ 38 shared_ptr<ItemInstance> item = player->inventory->getSelected(); 39 if (item == NULL) return false; 40 if (level->getData(x, y, z) != 0) return false; 41 int type = getTypeFromItem(item); 42 43 if (type > 0) 44 { 45 level->setData(x, y, z, type, Tile::UPDATE_CLIENTS); 46 47 if (!player->abilities.instabuild) 48 { 49 if (--item->count <= 0) 50 { 51 player->inventory->setItem(player->inventory->selected, nullptr); 52 } 53 } 54 55 return true; 56 } 57 58 return false; 59} 60 61int FlowerPotTile::cloneTileId(Level *level, int x, int y, int z) 62{ 63 shared_ptr<ItemInstance> item = getItemFromType(level->getData(x, y, z)); 64 65 if (item == NULL) 66 { 67 return Item::flowerPot_Id; 68 } 69 else 70 { 71 return item->id; 72 } 73} 74 75int FlowerPotTile::cloneTileData(Level *level, int x, int y, int z) 76{ 77 shared_ptr<ItemInstance> item = getItemFromType(level->getData(x, y, z)); 78 79 if (item == NULL) 80 { 81 return Item::flowerPot_Id; 82 } 83 else 84 { 85 return item->getAuxValue(); 86 } 87} 88 89bool FlowerPotTile::useOwnCloneData() 90{ 91 return true; 92} 93 94bool FlowerPotTile::mayPlace(Level *level, int x, int y, int z) 95{ 96 return Tile::mayPlace(level, x, y, z) && level->isTopSolidBlocking(x, y - 1, z); 97} 98 99void FlowerPotTile::neighborChanged(Level *level, int x, int y, int z, int type) 100{ 101 if (!level->isTopSolidBlocking(x, y - 1, z)) 102 { 103 spawnResources(level, x, y, z, level->getData(x, y, z), 0); 104 105 level->removeTile(x, y, z); 106 } 107} 108 109void FlowerPotTile::spawnResources(Level *level, int x, int y, int z, int data, float odds, int playerBonusLevel) 110{ 111 Tile::spawnResources(level, x, y, z, data, odds, playerBonusLevel); 112 113 if (data > 0) 114 { 115 shared_ptr<ItemInstance> item = getItemFromType(data); 116 if (item != NULL) popResource(level, x, y, z, item); 117 } 118} 119 120int FlowerPotTile::getResource(int data, Random *random, int playerBonusLevel) 121{ 122 return Item::flowerPot_Id; 123} 124 125shared_ptr<ItemInstance> FlowerPotTile::getItemFromType(int type) 126{ 127 switch (type) 128 { 129 case TYPE_FLOWER_RED: 130 return shared_ptr<ItemInstance>( new ItemInstance(Tile::rose) ); 131 case TYPE_FLOWER_YELLOW: 132 return shared_ptr<ItemInstance>( new ItemInstance(Tile::flower) ); 133 case TYPE_CACTUS: 134 return shared_ptr<ItemInstance>( new ItemInstance(Tile::cactus) ); 135 case TYPE_MUSHROOM_BROWN: 136 return shared_ptr<ItemInstance>( new ItemInstance(Tile::mushroom_brown) ); 137 case TYPE_MUSHROOM_RED: 138 return shared_ptr<ItemInstance>( new ItemInstance(Tile::mushroom_red) ); 139 case TYPE_DEAD_BUSH: 140 return shared_ptr<ItemInstance>( new ItemInstance(Tile::deadBush) ); 141 case TYPE_SAPLING_DEFAULT: 142 return shared_ptr<ItemInstance>( new ItemInstance(Tile::sapling, 1, Sapling::TYPE_DEFAULT) ); 143 case TYPE_SAPLING_BIRCH: 144 return shared_ptr<ItemInstance>( new ItemInstance(Tile::sapling, 1, Sapling::TYPE_BIRCH) ); 145 case TYPE_SAPLING_EVERGREEN: 146 return shared_ptr<ItemInstance>( new ItemInstance(Tile::sapling, 1, Sapling::TYPE_EVERGREEN) ); 147 case TYPE_SAPLING_JUNGLE: 148 return shared_ptr<ItemInstance>( new ItemInstance(Tile::sapling, 1, Sapling::TYPE_JUNGLE) ); 149 case TYPE_FERN: 150 return shared_ptr<ItemInstance>( new ItemInstance(Tile::tallgrass, 1, TallGrass::FERN) ); 151 } 152 153 return nullptr; 154} 155 156int FlowerPotTile::getTypeFromItem(shared_ptr<ItemInstance> item) 157{ 158 int id = item->getItem()->id; 159 160 if (id == Tile::rose_Id) return TYPE_FLOWER_RED; 161 if (id == Tile::flower_Id) return TYPE_FLOWER_YELLOW; 162 if (id == Tile::cactus_Id) return TYPE_CACTUS; 163 if (id == Tile::mushroom_brown_Id) return TYPE_MUSHROOM_BROWN; 164 if (id == Tile::mushroom_red_Id) return TYPE_MUSHROOM_RED; 165 if (id == Tile::deadBush_Id) return TYPE_DEAD_BUSH; 166 167 if (id == Tile::sapling_Id) 168 { 169 switch (item->getAuxValue()) 170 { 171 case Sapling::TYPE_DEFAULT: 172 return TYPE_SAPLING_DEFAULT; 173 case Sapling::TYPE_BIRCH: 174 return TYPE_SAPLING_BIRCH; 175 case Sapling::TYPE_EVERGREEN: 176 return TYPE_SAPLING_EVERGREEN; 177 case Sapling::TYPE_JUNGLE: 178 return TYPE_SAPLING_JUNGLE; 179 } 180 } 181 182 if (id == Tile::tallgrass_Id) 183 { 184 switch (item->getAuxValue()) 185 { 186 case TallGrass::FERN: 187 return TYPE_FERN; 188 } 189 } 190 191 return 0; 192}