the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 169 lines 6.7 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.animal.h" 3#include "net.minecraft.world.level.h" 4#include "net.minecraft.h" 5#include "net.minecraft.world.h" 6#include "PumpkinTile.h" 7#include "Mob.h" 8#include "SnowMan.h" 9#include "MobCategory.h" 10 11const wstring PumpkinTile::TEXTURE_FACE = L"pumpkin_face"; 12const wstring PumpkinTile::TEXTURE_LANTERN = L"pumpkin_jack"; 13 14PumpkinTile::PumpkinTile(int id, bool lit) : DirectionalTile(id, Material::vegetable, isSolidRender() ) 15{ 16 iconTop = NULL; 17 iconFace = NULL; 18 setTicking(true); 19 this->lit = lit; 20} 21 22Icon *PumpkinTile::getTexture(int face, int data) 23{ 24 if (face == Facing::UP) return iconTop; 25 if (face == Facing::DOWN) return iconTop; 26 27 if (data == DIR_NORTH && face == Facing::NORTH) return iconFace; 28 if (data == DIR_EAST && face == Facing::EAST) return iconFace; 29 if (data == DIR_SOUTH && face == Facing::SOUTH) return iconFace; 30 if (data == DIR_WEST && face == Facing::WEST) return iconFace; 31 32 else return icon; 33} 34 35void PumpkinTile::onPlace(Level *level, int x, int y, int z) 36{ 37 Tile::onPlace(level, x, y, z); 38 if (level->getTile(x, y - 1, z) == Tile::snow_Id && level->getTile(x, y - 2, z) == Tile::snow_Id) 39 { 40 if (!level->isClientSide) 41 { 42 // 4J - added limit of number of snowmen that can be spawned 43 if( level->canCreateMore( eTYPE_SNOWMAN, Level::eSpawnType_Egg) ) 44 { 45 level->setTileAndData(x, y, z, 0, 0, Tile::UPDATE_CLIENTS); 46 level->setTileAndData(x, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS); 47 level->setTileAndData(x, y - 2, z, 0, 0, Tile::UPDATE_CLIENTS); 48 shared_ptr<SnowMan> snowMan = shared_ptr<SnowMan>(new SnowMan(level)); 49 snowMan->moveTo(x + 0.5, y - 1.95, z + 0.5, 0, 0); 50 level->addEntity(snowMan); 51 52 level->tileUpdated(x, y, z, 0); 53 level->tileUpdated(x, y - 1, z, 0); 54 level->tileUpdated(x, y - 2, z, 0); 55 } 56 else 57 { 58 // If we can't spawn it, at least give the resources back 59 Tile::spawnResources(level, x, y, z, level->getData(x, y, z), 0); 60 Tile::tiles[Tile::snow_Id]->spawnResources(level, x, y - 1, z, level->getData(x, y - 1, z), 0); 61 Tile::tiles[Tile::snow_Id]->spawnResources(level, x, y - 2, z, level->getData(x, y - 2, z), 0); 62 level->setTileAndData(x, y, z, 0, 0, Tile::UPDATE_CLIENTS); 63 level->setTileAndData(x, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS); 64 level->setTileAndData(x, y - 2, z, 0, 0, Tile::UPDATE_CLIENTS); 65 } 66 } 67 for (int i = 0; i < 120; i++) 68 { 69 level->addParticle(eParticleType_snowshovel, x + level->random->nextDouble(), y - 2 + level->random->nextDouble() * 2.5, z + level->random->nextDouble(), 0, 0, 0); 70 } 71 } 72 else if (level->getTile(x, y - 1, z) == Tile::ironBlock_Id && level->getTile(x, y - 2, z) == Tile::ironBlock_Id) 73 { 74 bool xArms = level->getTile(x - 1, y - 1, z) == Tile::ironBlock_Id && level->getTile(x + 1, y - 1, z) == Tile::ironBlock_Id; 75 bool zArms = level->getTile(x, y - 1, z - 1) == Tile::ironBlock_Id && level->getTile(x, y - 1, z + 1) == Tile::ironBlock_Id; 76 if (xArms || zArms) 77 { 78 if (!level->isClientSide) 79 { 80 // 4J - added limit of number of golems that can be spawned 81 if( level->canCreateMore( eTYPE_VILLAGERGOLEM, Level::eSpawnType_Egg) ) 82 { 83 level->setTileAndData(x, y, z, 0, 0, Tile::UPDATE_CLIENTS); 84 level->setTileAndData(x, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS); 85 level->setTileAndData(x, y - 2, z, 0, 0, Tile::UPDATE_CLIENTS); 86 if (xArms) 87 { 88 level->setTileAndData(x - 1, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS); 89 level->setTileAndData(x + 1, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS); 90 } 91 else 92 { 93 level->setTileAndData(x, y - 1, z - 1, 0, 0, Tile::UPDATE_CLIENTS); 94 level->setTileAndData(x, y - 1, z + 1, 0, 0, Tile::UPDATE_CLIENTS); 95 } 96 97 shared_ptr<VillagerGolem> villagerGolem = shared_ptr<VillagerGolem>(new VillagerGolem(level)); 98 villagerGolem->setPlayerCreated(true); 99 villagerGolem->moveTo(x + 0.5, y - 1.95, z + 0.5, 0, 0); 100 level->addEntity(villagerGolem); 101 102 for (int i = 0; i < 120; i++) 103 { 104 level->addParticle(eParticleType_snowballpoof, x + level->random->nextDouble(), y - 2 + level->random->nextDouble() * 3.9, z + level->random->nextDouble(), 0, 0, 0); 105 } 106 107 level->tileUpdated(x, y, z, 0); 108 level->tileUpdated(x, y - 1, z, 0); 109 level->tileUpdated(x, y - 2, z, 0); 110 if (xArms) 111 { 112 level->tileUpdated(x - 1, y - 1, z, 0); 113 level->tileUpdated(x + 1, y - 1, z, 0); 114 } 115 else 116 { 117 level->tileUpdated(x, y - 1, z - 1, 0); 118 level->tileUpdated(x, y - 1, z + 1, 0); 119 } 120 } 121 else 122 { 123 // If we can't spawn it, at least give the resources back 124 Tile::spawnResources(level, x, y, z, level->getData(x, y, z), 0); 125 Tile::tiles[Tile::ironBlock_Id]->spawnResources(level, x, y - 1, z, level->getData(x, y - 1, z), 0); 126 Tile::tiles[Tile::ironBlock_Id]->spawnResources(level, x, y - 2, z, level->getData(x, y - 2, z), 0); 127 level->setTileAndData(x, y, z, 0, 0, Tile::UPDATE_CLIENTS); 128 level->setTileAndData(x, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS); 129 level->setTileAndData(x, y - 2, z, 0, 0, Tile::UPDATE_CLIENTS); 130 131 if(xArms) 132 { 133 Tile::tiles[Tile::ironBlock_Id]->spawnResources(level, x - 1, y - 1, z, level->getData(x - 1, y - 1, z), 0); 134 Tile::tiles[Tile::ironBlock_Id]->spawnResources(level, x + 1, y - 1, z, level->getData(x + 1, y - 1, z), 0); 135 level->setTileAndData(x - 1, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS); 136 level->setTileAndData(x + 1, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS); 137 } 138 else 139 { 140 Tile::tiles[Tile::ironBlock_Id]->spawnResources(level, x, y - 1, z - 1, level->getData(x, y - 1, z - 1), 0); 141 Tile::tiles[Tile::ironBlock_Id]->spawnResources(level, x, y - 1, z + 1, level->getData(x, y - 1, z + 1), 0); 142 level->setTileAndData(x, y - 1, z - 1, 0, 0, Tile::UPDATE_CLIENTS); 143 level->setTileAndData(x, y - 1, z + 1, 0, 0, Tile::UPDATE_CLIENTS); 144 } 145 } 146 } 147 } 148 } 149} 150 151bool PumpkinTile::mayPlace(Level *level, int x, int y, int z) 152{ 153 int t = level->getTile(x, y, z); 154 return (t == 0 || Tile::tiles[t]->material->isReplaceable()) && level->isTopSolidBlocking(x, y - 1, z); 155 156} 157 158void PumpkinTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance) 159{ 160 int dir = Mth::floor(by->yRot * 4 / (360) + 2.5) & 3; 161 level->setData(x, y, z, dir, Tile::UPDATE_CLIENTS); 162} 163 164void PumpkinTile::registerIcons(IconRegister *iconRegister) 165{ 166 iconFace = iconRegister->registerIcon(getIconName() + L"_face_" + (lit ? L"on" : L"off")); 167 iconTop = iconRegister->registerIcon(getIconName() + L"_top"); 168 icon = iconRegister->registerIcon(getIconName() + L"_side"); 169}