the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 61 lines 1.9 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.h" 3#include "net.minecraft.world.entity.player.h" 4#include "net.minecraft.world.level.h" 5#include "net.minecraft.world.level.tile.h" 6#include "net.minecraft.world.item.h" 7#include "Facing.h" 8#include "GenericStats.h" 9#include "BedItem.h" 10 11BedItem::BedItem(int id) : Item( id ) 12{ 13} 14 15bool BedItem::useOn(shared_ptr<ItemInstance> itemInstance, shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly) 16{ 17 if (level->isClientSide) return true; 18 19 if (face != Facing::UP) 20 { 21 return false; 22 } 23 24 // place on top of tile 25 y = y + 1; 26 27 BedTile *tile = (BedTile *) Tile::bed; 28 29 int dir = ( Mth::floor(player->yRot * 4 / (360) + 0.5f) ) & 3; 30 int xra = 0; 31 int zra = 0; 32 33 if (dir == Direction::SOUTH) zra = 1; 34 if (dir == Direction::WEST) xra = -1; 35 if (dir == Direction::NORTH) zra = -1; 36 if (dir == Direction::EAST) xra = 1; 37 38 if (!player->mayUseItemAt(x, y, z, face, itemInstance) || !player->mayUseItemAt(x + xra, y, z + zra, face, itemInstance)) return false; 39 40 if (level->isEmptyTile(x, y, z) && level->isEmptyTile(x + xra, y, z + zra) && level->isTopSolidBlocking(x, y - 1, z) && level->isTopSolidBlocking(x + xra, y - 1, z + zra)) 41 { 42 // 4J-PB - Adding a test only version to allow tooltips to be displayed 43 if(!bTestUseOnOnly) 44 { 45 level->setTileAndData(x, y, z, tile->id, dir, Tile::UPDATE_ALL); 46 // double-check that the bed was successfully placed 47 if (level->getTile(x, y, z) == tile->id) 48 { 49 // 4J-JEV: Hook for durango 'BlockPlaced' event. 50 player->awardStat(GenericStats::blocksPlaced(tile->id), GenericStats::param_blocksPlaced(tile->id,itemInstance->getAuxValue(),1)); 51 52 level->setTileAndData(x + xra, y, z + zra, tile->id, dir + BedTile::HEAD_PIECE_DATA, Tile::UPDATE_ALL); 53 } 54 55 itemInstance->count--; 56 } 57 return true; 58 } 59 60 return false; 61}