Something went wrong. Try again.
the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
Something went wrong. Try again.
4.0 kB · 169 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170#include "stdafx.h"#include "net.minecraft.world.level.h"#include "net.minecraft.world.level.tile.h"#include "net.minecraft.world.level.levelgen.feature.h"#include "net.minecraft.world.h"
#include "Sapling.h"
int Sapling::SAPLING_NAMES[SAPLING_NAMES_SIZE] = { IDS_TILE_SAPLING_OAK, IDS_TILE_SAPLING_SPRUCE, IDS_TILE_SAPLING_BIRCH, IDS_TILE_SAPLING_JUNGLE};
const wstring Sapling::TEXTURE_NAMES[] = {L"sapling", L"sapling_spruce", L"sapling_birch", L"sapling_jungle"};
Sapling::Sapling(int id) : Bush( id ){ this->updateDefaultShape(); icons = NULL;}
// 4J Added overridevoid Sapling::updateDefaultShape(){ float ss = 0.4f; this->setShape(0.5f - ss, 0, 0.5f - ss, 0.5f + ss, ss * 2, 0.5f + ss);}
void Sapling::tick(Level *level, int x, int y, int z, Random *random){ if (level->isClientSide) return;
Bush::tick(level, x, y, z, random);
if (level->getRawBrightness(x, y + 1, z) >= Level::MAX_BRIGHTNESS - 6) { if (random->nextInt(7) == 0) { advanceTree(level, x, y, z, random); } }}
Icon *Sapling::getTexture(int face, int data){ data = data & TYPE_MASK; return icons[data];}
void Sapling::advanceTree(Level *level, int x, int y, int z, Random *random){ int data = level->getData(x, y, z); if ((data & AGE_BIT) == 0) { level->setData(x, y, z, data | AGE_BIT, Tile::UPDATE_NONE); } else { growTree(level, x, y, z, random); }}
void Sapling::growTree(Level *level, int x, int y, int z, Random *random){ int data = level->getData(x, y, z) & TYPE_MASK;
Feature *f = NULL;
int ox = 0, oz = 0; bool multiblock = false;
if (data == TYPE_EVERGREEN) { f = new SpruceFeature(true); } else if (data == TYPE_BIRCH) { f = new BirchFeature(true); } else if (data == TYPE_JUNGLE) { // check for mega tree for (ox = 0; ox >= -1; ox--) { for (oz = 0; oz >= -1; oz--) { if (isSapling(level, x + ox, y, z + oz, TYPE_JUNGLE) && isSapling(level, x + ox + 1, y, z + oz, TYPE_JUNGLE) && isSapling(level, x + ox, y, z + oz + 1, TYPE_JUNGLE) && isSapling(level, x + ox + 1, y, z + oz + 1, TYPE_JUNGLE)) { f = new MegaTreeFeature(true, 10 + random->nextInt(20), TreeTile::JUNGLE_TRUNK, LeafTile::JUNGLE_LEAF); multiblock = true; break; } } if (f != NULL) { break; } } if (f == NULL) { ox = oz = 0; f = new TreeFeature(true, 4 + random->nextInt(7), TreeTile::JUNGLE_TRUNK, LeafTile::JUNGLE_LEAF, false); } } else { f = new TreeFeature(true); if (random->nextInt(10) == 0) { delete f; f = new BasicTree(true); } } if (multiblock) { level->setTileAndData(x + ox, y, z + oz, 0, 0, Tile::UPDATE_NONE); level->setTileAndData(x + ox + 1, y, z + oz, 0, 0, Tile::UPDATE_NONE); level->setTileAndData(x + ox, y, z + oz + 1, 0, 0, Tile::UPDATE_NONE); level->setTileAndData(x + ox + 1, y, z + oz + 1, 0, 0, Tile::UPDATE_NONE); } else { level->setTileAndData(x, y, z, 0, 0, Tile::UPDATE_NONE); } if (!f->place(level, random, x + ox, y, z + oz)) { if (multiblock) { level->setTileAndData(x + ox, y, z + oz, id, data, Tile::UPDATE_NONE); level->setTileAndData(x + ox + 1, y, z + oz, id, data, Tile::UPDATE_NONE); level->setTileAndData(x + ox, y, z + oz + 1, id, data, Tile::UPDATE_NONE); level->setTileAndData(x + ox + 1, y, z + oz + 1, id, data, Tile::UPDATE_NONE); } else { level->setTileAndData(x, y, z, id, data, Tile::UPDATE_NONE); } } if( f != NULL ) delete f;}
unsigned int Sapling::getDescriptionId(int iData /*= -1*/){ if(iData < 0 ) iData = 0; return Sapling::SAPLING_NAMES[iData];}
int Sapling::getSpawnResourcesAuxValue(int data){ return data & TYPE_MASK;}
bool Sapling::isSapling(Level *level, int x, int y, int z, int type){ return (level->getTile(x, y, z) == id) && ((level->getData(x, y, z) & TYPE_MASK) == type);}
void Sapling::registerIcons(IconRegister *iconRegister){ icons = new Icon*[SAPLING_NAMES_SIZE];
for (int i = 0; i < SAPLING_NAMES_SIZE; i++) { icons[i] = iconRegister->registerIcon(TEXTURE_NAMES[i]); }}