the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 176 lines 4.6 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.item.h" 3#include "net.minecraft.world.level.h" 4#include "net.minecraft.world.level.tile.h" 5#include "net.minecraft.world.h" 6#include "net.minecraft.h" 7#include "CocoaTile.h" 8 9const wstring CocoaTile::TEXTURE_AGES[] = { L"cocoa_0", L"cocoa_1", L"cocoa_2"}; 10 11CocoaTile::CocoaTile(int id) : DirectionalTile(id, Material::plant, isSolidRender() ) 12{ 13 setTicking(true); 14} 15 16Icon *CocoaTile::getTexture(int face, int data) 17{ 18 return icons[2]; 19} 20 21Icon *CocoaTile::getTextureForAge(int age) 22{ 23 if (age < 0 || age >= COCOA_TEXTURES_LENGTH) 24 { 25 age = COCOA_TEXTURES_LENGTH - 1; 26 } 27 return icons[age]; 28} 29 30void CocoaTile::tick(Level *level, int x, int y, int z, Random *random) 31{ 32 if (!canSurvive(level, x, y, z)) 33 { 34 this->spawnResources(level, x, y, z, level->getData(x, y, z), 0); 35 level->setTileAndData(x, y, z, 0, 0, UPDATE_CLIENTS); 36 } 37 else if (level->random->nextInt(5) == 0) 38 { 39 int data = level->getData(x, y, z); 40 int age = getAge(data); 41 if (age < 2) 42 { 43 age++; 44 level->setData(x, y, z, (age << 2) | (getDirection(data)), Tile::UPDATE_CLIENTS); 45 } 46 } 47} 48 49bool CocoaTile::canSurvive(Level *level, int x, int y, int z) 50{ 51 int dir = getDirection(level->getData(x, y, z)); 52 53 x += Direction::STEP_X[dir]; 54 z += Direction::STEP_Z[dir]; 55 int attachedTo = level->getTile(x, y, z); 56 57 return attachedTo == Tile::treeTrunk_Id && TreeTile::getWoodType(level->getData(x, y, z)) == TreeTile::JUNGLE_TRUNK; 58} 59 60int CocoaTile::getRenderShape() 61{ 62 return SHAPE_COCOA; 63} 64 65bool CocoaTile::isCubeShaped() 66{ 67 return false; 68} 69 70bool CocoaTile::isSolidRender(bool isServerLevel) 71{ 72 return false; 73} 74 75AABB *CocoaTile::getAABB(Level *level, int x, int y, int z) 76{ 77 updateShape(level, x, y, z); 78 return DirectionalTile::getAABB(level, x, y, z); 79} 80 81AABB *CocoaTile::getTileAABB(Level *level, int x, int y, int z) 82{ 83 updateShape(level, x, y, z); 84 return DirectionalTile::getTileAABB(level, x, y, z); 85} 86 87void CocoaTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) 88{ 89 int data = level->getData(x, y, z); 90 int dir = getDirection(data); 91 int age = getAge(data); 92 93 int width = 4 + age * 2; 94 int height = 5 + age * 2; 95 96 float hWidth = width / 2.0f; 97 98 switch (dir) 99 { 100 case Direction::SOUTH: 101 setShape((8.0f - hWidth) / 16.0f, (12.0f - height) / 16.0f, (15.0f - width) / 16.0f, (8.0f + hWidth) / 16.0f, (12.0f) / 16.0f, (15.0f) / 16.0f); 102 break; 103 case Direction::NORTH: 104 setShape((8.0f - hWidth) / 16.0f, (12.0f - height) / 16.0f, (1.0f) / 16.0f, (8.0f + hWidth) / 16.0f, (12.0f) / 16.0f, (1.0f + width) / 16.0f); 105 break; 106 case Direction::WEST: 107 setShape((1.0f) / 16.0f, (12.0f - height) / 16.0f, (8.0f - hWidth) / 16.0f, (1.0f + width) / 16.0f, (12.0f) / 16.0f, (8.0f + hWidth) / 16.0f); 108 break; 109 case Direction::EAST: 110 setShape((15.0f - width) / 16.0f, (12.0f - height) / 16.0f, (8.0f - hWidth) / 16.0f, (15.0f) / 16.0f, (12.0f) / 16.0f, (8.0f + hWidth) / 16.0f); 111 break; 112 } 113} 114 115void CocoaTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance) 116{ 117 int dir = (((Mth::floor(by->yRot * 4 / (360) + 0.5)) & 3) + 0) % 4; 118 level->setData(x, y, z, dir, Tile::UPDATE_CLIENTS); 119} 120 121int CocoaTile::getPlacedOnFaceDataValue(Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, int itemValue) 122{ 123 if (face == Facing::UP || face == Facing::DOWN) 124 { 125 face = Facing::NORTH; 126 } 127 return Direction::DIRECTION_OPPOSITE[Direction::FACING_DIRECTION[face]]; 128} 129 130void CocoaTile::neighborChanged(Level *level, int x, int y, int z, int type) 131{ 132 if (!canSurvive(level, x, y, z)) 133 { 134 this->spawnResources(level, x, y, z, level->getData(x, y, z), 0); 135 level->setTileAndData(x, y, z, 0, 0, UPDATE_CLIENTS); 136 } 137} 138 139int CocoaTile::getAge(int data) 140{ 141 return (data & DirectionalTile::DIRECTION_INV_MASK) >> 2; 142} 143 144void CocoaTile::spawnResources(Level *level, int x, int y, int z, int data, float odds, int playerBonusLevel) 145{ 146 int age = getAge(data); 147 int count = 1; 148 if (age >= 2) 149 { 150 count = 3; 151 } 152 for (int i = 0; i < count; i++) 153 { 154 popResource(level, x, y, z, shared_ptr<ItemInstance>( new ItemInstance(Item::dye_powder, 1, DyePowderItem::BROWN) )); 155 } 156} 157 158int CocoaTile::cloneTileId(Level *level, int x, int y, int z) 159{ 160 return Item::dye_powder_Id; 161} 162 163int CocoaTile::cloneTileData(Level *level, int x, int y, int z) 164{ 165 return DyePowderItem::BROWN; 166} 167 168void CocoaTile::registerIcons(IconRegister *iconRegister) 169{ 170 icons = new Icon*[COCOA_TEXTURES_LENGTH]; 171 172 for (int i = 0; i < COCOA_TEXTURES_LENGTH; i++) 173 { 174 icons[i] = iconRegister->registerIcon(TEXTURE_AGES[i]); 175 } 176}