the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 141 lines 3.8 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.entity.player.h" 4#include "net.minecraft.world.level.tile.h" 5#include "net.minecraft.world.level.tile.entity.h" 6#include "net.minecraft.h" 7#include "net.minecraft.world.h" 8#include "SkullItem.h" 9 10const unsigned int SkullItem::NAMES[SKULL_COUNT] = {IDS_ITEM_SKULL_SKELETON, IDS_ITEM_SKULL_WITHER, IDS_ITEM_SKULL_ZOMBIE, IDS_ITEM_SKULL_CHARACTER, IDS_ITEM_SKULL_CREEPER}; 11 12wstring SkullItem::ICON_NAMES[SKULL_COUNT] = {L"skeleton", L"wither", L"zombie", L"char", L"creeper"}; 13 14SkullItem::SkullItem(int id) : Item(id) 15{ 16 //setItemCategory(CreativeModeTab.TAB_DECORATIONS); 17 setMaxDamage(0); 18 setStackedByData(true); 19} 20 21bool SkullItem::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) //float clickX, float clickY, float clickZ) 22{ 23 if (face == 0) return false; 24 if (!level->getMaterial(x, y, z)->isSolid()) return false; 25 26 if (face == 1) y++; 27 28 if (face == 2) z--; 29 if (face == 3) z++; 30 if (face == 4) x--; 31 if (face == 5) x++; 32 33 //if (!player->mayUseItemAt(x, y, z, face, instance)) return false; 34 if (!player->mayUseItemAt(x, y, z, face, instance)) return false; 35 36 if (!Tile::skull->mayPlace(level, x, y, z)) return false; 37 38 if(!bTestUseOnOnly) 39 { 40 level->setTileAndData(x, y, z, Tile::skull_Id, face, Tile::UPDATE_CLIENTS); 41 42 int rot = 0; 43 if (face == Facing::UP) 44 { 45 rot = Mth::floor(((player->yRot) * 16) / 360 + 0.5) & 15; 46 } 47 48 shared_ptr<TileEntity> skullTE = level->getTileEntity(x, y, z); 49 shared_ptr<SkullTileEntity> skull = dynamic_pointer_cast<SkullTileEntity>(skullTE); 50 51 if (skull != NULL) 52 { 53 wstring extra = L""; 54 if (instance->hasTag() && instance->getTag()->contains(L"SkullOwner")) 55 { 56 extra = instance->getTag()->getString(L"SkullOwner"); 57 } 58 skull->setSkullType(instance->getAuxValue(), extra); 59 skull->setRotation(rot); 60 ((SkullTile *) Tile::skull)->checkMobSpawn(level, x, y, z, skull); 61 } 62 63 instance->count--; 64 } 65 return true; 66} 67 68bool SkullItem::mayPlace(Level *level, int x, int y, int z, int face, shared_ptr<Player> player, shared_ptr<ItemInstance> item) 69{ 70 int currentTile = level->getTile(x, y, z); 71 if (currentTile == Tile::topSnow_Id) 72 { 73 face = Facing::UP; 74 } 75 else if (currentTile != Tile::vine_Id && currentTile != Tile::tallgrass_Id && currentTile != Tile::deadBush_Id) 76 { 77 if (face == 0) y--; 78 if (face == 1) y++; 79 if (face == 2) z--; 80 if (face == 3) z++; 81 if (face == 4) x--; 82 if (face == 5) x++; 83 } 84 85 return level->mayPlace(Tile::skull_Id, x, y, z, false, face, nullptr, item); 86} 87 88Icon *SkullItem::getIcon(int itemAuxValue) 89{ 90 if (itemAuxValue < 0 || itemAuxValue >= SKULL_COUNT) 91 { 92 itemAuxValue = 0; 93 } 94 return icons[itemAuxValue]; 95} 96 97int SkullItem::getLevelDataForAuxValue(int auxValue) 98{ 99 return auxValue; 100} 101 102unsigned int SkullItem::getDescriptionId(int iData) 103{ 104 if (iData < 0 || iData >= SKULL_COUNT) 105 { 106 iData = 0; 107 } 108 return NAMES[iData]; 109} 110 111unsigned int SkullItem::getDescriptionId(shared_ptr<ItemInstance> instance) 112{ 113 int auxValue = instance->getAuxValue(); 114 if (auxValue < 0 || auxValue >= SKULL_COUNT) 115 { 116 auxValue = 0; 117 } 118 return NAMES[auxValue]; 119} 120 121wstring SkullItem::getHoverName(shared_ptr<ItemInstance> itemInstance) 122{ 123#if 0 124 if (itemInstance->getAuxValue() == SkullTileEntity::TYPE_CHAR && itemInstance->hasTag() && itemInstance->getTag()->contains(L"SkullOwner")) 125 { 126 return I18n.get("item.skull.player.name", itemInstance->getTag()->getString(L"SkullOwner")); 127 } 128 else 129#endif 130 { 131 return Item::getHoverName(itemInstance); 132 } 133} 134 135void SkullItem::registerIcons(IconRegister *iconRegister) 136{ 137 for (int i = 0; i < SKULL_COUNT; i++) 138 { 139 icons[i] = iconRegister->registerIcon(getIconName() + L"_" + ICON_NAMES[i]); 140 } 141}