the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1using namespace std;
2
3#include "stdafx.h"
4#include "net.minecraft.world.h"
5#include "net.minecraft.world.entity.h"
6#include "net.minecraft.world.entity.player.h"
7#include "net.minecraft.world.level.h"
8#include "net.minecraft.world.level.tile.h"
9#include "net.minecraft.world.item.h"
10#include "net.minecraft.world.h"
11#include "net.minecraft.stats.h"
12#include "TileItem.h"
13#include "facing.h"
14
15// 4J-PB - for the debug option of not removing items
16#include <xuiresource.h>
17#include <xuiapp.h>
18
19
20TileItem::TileItem(int id) : Item(id)
21{
22 this->tileId = id + 256;
23 itemIcon = NULL;
24}
25
26int TileItem::getTileId()
27{
28 return tileId;
29}
30
31int TileItem::getIconType()
32{
33 if (!Tile::tiles[tileId]->getTileItemIconName().empty())
34 {
35 return Icon::TYPE_ITEM;
36 }
37 return Icon::TYPE_TERRAIN;
38}
39
40Icon *TileItem::getIcon(int auxValue)
41{
42 if (itemIcon != NULL)
43 {
44 return itemIcon;
45 }
46 return Tile::tiles[tileId]->getTexture(Facing::UP, auxValue);
47}
48
49bool TileItem::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)
50{
51 // 4J-PB - Adding a test only version to allow tooltips to be displayed
52 int currentTile = level->getTile(x, y, z);
53 if (currentTile == Tile::topSnow_Id && (level->getData(x, y, z) & TopSnowTile::HEIGHT_MASK) < 1)
54 {
55 face = Facing::UP;
56 }
57 else if (currentTile == Tile::vine_Id || currentTile == Tile::tallgrass_Id || currentTile == Tile::deadBush_Id)
58 {
59 }
60 else
61 {
62 if (face == 0) y--;
63 if (face == 1) y++;
64 if (face == 2) z--;
65 if (face == 3) z++;
66 if (face == 4) x--;
67 if (face == 5) x++;
68 }
69
70 if (instance->count == 0) return false;
71 if (!player->mayUseItemAt(x, y, z, face, instance)) return false;
72
73
74 if (y == Level::maxBuildHeight - 1 && Tile::tiles[tileId]->material->isSolid()) return false;
75
76 int undertile = level->getTile(x,y-1,z); // For 'BodyGuard' achievement.
77
78 if (level->mayPlace(tileId, x, y, z, false, face, player, instance))
79 {
80 if(!bTestUseOnOnly)
81 {
82 Tile *tile = Tile::tiles[tileId];
83 // 4J - Adding this from 1.6
84 int itemValue = getLevelDataForAuxValue(instance->getAuxValue());
85 int dataValue = Tile::tiles[tileId]->getPlacedOnFaceDataValue(level, x, y, z, face, clickX, clickY, clickZ, itemValue);
86 if (level->setTileAndData(x, y, z, tileId, dataValue, Tile::UPDATE_ALL))
87 {
88 // 4J-JEV: Snow/Iron Golems do not have owners apparently.
89 int newTileId = level->getTile(x,y,z);
90 if ( (tileId == Tile::pumpkin_Id || tileId == Tile::litPumpkin_Id) && newTileId == 0 )
91 {
92 eINSTANCEOF golemType;
93 switch (undertile)
94 {
95 case Tile::ironBlock_Id: golemType = eTYPE_VILLAGERGOLEM; break;
96 case Tile::snow_Id: golemType = eTYPE_SNOWMAN; break;
97 default: golemType = eTYPE_NOTSET; break;
98 }
99
100 if (golemType != eTYPE_NOTSET)
101 {
102 player->awardStat(GenericStats::craftedEntity(golemType),GenericStats::param_craftedEntity(golemType));
103 }
104 }
105
106 // 4J-JEV: Hook for durango 'BlockPlaced' event.
107 player->awardStat(GenericStats::blocksPlaced(tileId),GenericStats::param_blocksPlaced(tileId,instance->getAuxValue(),1));
108
109 // 4J - Original comment
110 // ok this may look stupid, but neighbor updates can cause the
111 // placed block to become something else before these methods
112 // are called
113 if (level->getTile(x, y, z) == tileId)
114 {
115 Tile::tiles[tileId]->setPlacedBy(level, x, y, z, player, instance);
116 Tile::tiles[tileId]->finalizePlacement(level, x, y, z, dataValue);
117 }
118
119 // 4J-PB - Java 1.4 change - getStepSound replaced with getPlaceSound
120 //level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, tile->soundType->getStepSound(), (tile->soundType->getVolume() + 1) / 2, tile->soundType->getPitch() * 0.8f);
121#ifdef _DEBUG
122 int iPlaceSound=tile->soundType->getPlaceSound();
123 int iStepSound=tile->soundType->getStepSound();
124
125 // char szPlaceSoundName[256];
126 // char szStepSoundName[256];
127 // Minecraft *pMinecraft = Minecraft::GetInstance();
128 //
129 // if(iPlaceSound==-1)
130 // {
131 // strcpy(szPlaceSoundName,"NULL");
132 // }
133 // else
134 // {
135 // pMinecraft->soundEngine->GetSoundName(szPlaceSoundName,iPlaceSound);
136 // }
137 // if(iStepSound==-1)
138 // {
139 // strcpy(szStepSoundName,"NULL");
140 // }
141 // else
142 // {
143 // pMinecraft->soundEngine->GetSoundName(szStepSoundName,iStepSound);
144 // }
145
146 //app.DebugPrintf("Place Sound - %s, Step Sound - %s\n",szPlaceSoundName,szStepSoundName);
147 app.DebugPrintf("Place Sound - %d, Step Sound - %d\n",iPlaceSound,iStepSound);
148#endif
149 level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, tile->soundType->getPlaceSound(), (tile->soundType->getVolume() + 1) / 2, tile->soundType->getPitch() * 0.8f);
150#ifndef _FINAL_BUILD
151 // 4J-PB - If we have the debug option on, don't reduce the number of this item
152 if(!(app.DebugSettingsOn() && app.GetGameSettingsDebugMask()&(1L<<eDebugSetting_CraftAnything)))
153#endif
154 {
155 instance->count--;
156 }
157 }
158 }
159 return true;
160 }
161 return false;
162}
163
164
165bool TileItem::mayPlace(Level *level, int x, int y, int z, int face, shared_ptr<Player> player, shared_ptr<ItemInstance> item)
166{
167 int currentTile = level->getTile(x, y, z);
168 if (currentTile == Tile::topSnow_Id)
169 {
170 face = Facing::UP;
171 }
172 else if (currentTile != Tile::vine_Id && currentTile != Tile::tallgrass_Id && currentTile != Tile::deadBush_Id)
173 {
174 if (face == 0) y--;
175 if (face == 1) y++;
176 if (face == 2) z--;
177 if (face == 3) z++;
178 if (face == 4) x--;
179 if (face == 5) x++;
180 }
181
182 return level->mayPlace(getTileId(), x, y, z, false, face, nullptr, item);
183}
184
185// 4J Added to colourise some tile types in the hint popups
186int TileItem::getColor(int itemAuxValue, int spriteLayer)
187{
188 return Tile::tiles[tileId]->getColor();
189}
190
191unsigned int TileItem::getDescriptionId(shared_ptr<ItemInstance> instance)
192{
193 return Tile::tiles[tileId]->getDescriptionId();
194}
195
196
197unsigned int TileItem::getDescriptionId(int iData /*= -1*/)
198{
199 return Tile::tiles[tileId]->getDescriptionId(iData);
200}
201
202
203unsigned int TileItem::getUseDescriptionId(shared_ptr<ItemInstance> instance)
204{
205 return Tile::tiles[tileId]->getUseDescriptionId();
206}
207
208
209unsigned int TileItem::getUseDescriptionId()
210{
211 return Tile::tiles[tileId]->getUseDescriptionId();
212}
213
214void TileItem::registerIcons(IconRegister *iconRegister)
215{
216 wstring iconName = Tile::tiles[tileId]->getTileItemIconName();
217 if (!iconName.empty())
218 {
219 itemIcon = iconRegister->registerIcon(iconName);
220 }
221}