the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 73 lines 2.5 kB view raw
1using namespace std; 2 3#include "stdafx.h" 4#include "net.minecraft.world.h" 5#include "net.minecraft.world.entity.player.h" 6#include "net.minecraft.world.level.h" 7#include "net.minecraft.world.level.tile.h" 8#include "net.minecraft.world.phys.h" 9#include "net.minecraft.world.item.h" 10#include "Facing.h" 11#include "Material.h" 12#include "GenericStats.h" 13#include "DoorItem.h" 14 15DoorItem::DoorItem(int id, Material *material) : Item(id) 16{ 17 this->material = material; 18 maxStackSize = 1; 19} 20 21bool DoorItem::useOn(shared_ptr<ItemInstance> instance, shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly) 22{ 23 if (face != Facing::UP) return false; 24 y++; 25 26 Tile *tile; 27 28 if (material == Material::wood) tile = Tile::door_wood; 29 else tile = Tile::door_iron; 30 31 if (!player->mayUseItemAt(x, y, z, face, instance) || !player->mayUseItemAt(x, y + 1, z, face, instance)) return false; 32 if (!tile->mayPlace(level, x, y, z)) return false; 33 34 // 4J-PB - Adding a test only version to allow tooltips to be displayed 35 if(bTestUseOnOnly) return true; 36 37 // 4J-JEV: Hook for durango 'BlockPlaced' event. 38 player->awardStat(GenericStats::blocksPlaced(tile->id),GenericStats::param_blocksPlaced(tile->id,instance->getAuxValue(),1)); 39 40 int dir = Mth::floor(((player->yRot + 180) * 4) / 360 - 0.5) & 3; 41 place(level, x, y, z, dir, tile); 42 43 instance->count--; 44 return true; 45} 46 47void DoorItem::place(Level *level, int x, int y, int z, int dir, Tile *tile) 48{ 49 50 int xra = 0; 51 int zra = 0; 52 if (dir == 0) zra = +1; 53 if (dir == 1) xra = -1; 54 if (dir == 2) zra = -1; 55 if (dir == 3) xra = +1; 56 57 58 int solidLeft = (level->isSolidBlockingTile(x - xra, y, z - zra) ? 1 : 0) + (level->isSolidBlockingTile(x - xra, y + 1, z - zra) ? 1 : 0); 59 int solidRight = (level->isSolidBlockingTile(x + xra, y, z + zra) ? 1 : 0) + (level->isSolidBlockingTile(x + xra, y + 1, z + zra) ? 1 : 0); 60 61 bool doorLeft = (level->getTile(x - xra, y, z - zra) == tile->id) || (level->getTile(x - xra, y + 1, z - zra) == tile->id); 62 bool doorRight = (level->getTile(x + xra, y, z + zra) == tile->id) || (level->getTile(x + xra, y + 1, z + zra) == tile->id); 63 64 bool flip = false; 65 if (doorLeft && !doorRight) flip = true; 66 else if (solidRight > solidLeft) flip = true; 67 68 level->setTileAndData(x, y, z, tile->id, dir, Tile::UPDATE_CLIENTS); 69 level->setTileAndData(x, y + 1, z, tile->id, 8 | (flip ? 1 : 0), Tile::UPDATE_CLIENTS); 70 level->updateNeighborsAt(x, y, z, tile->id); 71 level->updateNeighborsAt(x, y + 1, z, tile->id); 72} 73