the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.entity.player.h"
3#include "net.minecraft.world.entity.item.h"
4#include "net.minecraft.world.level.h"
5#include "net.minecraft.world.level.tile.h"
6#include "net.minecraft.world.h"
7#include "net.minecraft.h"
8#include "AnvilTile.h"
9
10const unsigned int AnvilTile::ANVIL_NAMES[ANVIL_NAMES_LENGTH] = { IDS_TILE_ANVIL_INTACT,
11 IDS_TILE_ANVIL_SLIGHTLYDAMAGED,
12 IDS_TILE_ANVIL_VERYDAMAGED,
13 };
14
15
16wstring AnvilTile::TEXTURE_DAMAGE_NAMES[ANVIL_NAMES_LENGTH] = {
17 L"anvil_top", L"anvil_top_damaged_1", L"anvil_top_damaged_2"
18};
19
20AnvilTile::AnvilTile(int id) : HeavyTile(id, Material::heavyMetal, isSolidRender() )
21{
22 part = PART_BASE;
23 setLightBlock(0);
24 icons = NULL;
25}
26
27bool AnvilTile::isCubeShaped()
28{
29 return false;
30}
31
32bool AnvilTile::isSolidRender(bool isServerLevel)
33{
34 return false;
35}
36
37Icon *AnvilTile::getTexture(int face, int data)
38{
39 if (part == PART_TOP && face == Facing::UP)
40 {
41 int damage = (data >> 2) % ANVIL_NAMES_LENGTH;
42 return icons[damage];
43 }
44 return icon;
45}
46
47void AnvilTile::registerIcons(IconRegister *iconRegister)
48{
49 icon = iconRegister->registerIcon(L"anvil_base");
50 icons = new Icon*[ANVIL_NAMES_LENGTH];
51
52 for (int i = 0; i < ANVIL_NAMES_LENGTH; i++)
53 {
54 icons[i] = iconRegister->registerIcon(TEXTURE_DAMAGE_NAMES[i]);
55 }
56}
57
58void AnvilTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance)
59{
60 int dir = (Mth::floor(by->yRot * 4 / (360) + 0.5)) & 3;
61 int dmg = level->getData(x, y, z) >> 2;
62
63 dir = ++dir % 4;
64 if (dir == 0) level->setData(x, y, z, Direction::NORTH | (dmg << 2), Tile::UPDATE_CLIENTS);
65 if (dir == 1) level->setData(x, y, z, Direction::EAST | (dmg << 2), Tile::UPDATE_CLIENTS);
66 if (dir == 2) level->setData(x, y, z, Direction::SOUTH | (dmg << 2), Tile::UPDATE_CLIENTS);
67 if (dir == 3) level->setData(x, y, z, Direction::WEST | (dmg << 2), Tile::UPDATE_CLIENTS);
68}
69
70bool AnvilTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly)
71{
72 if (level->isClientSide)
73 {
74 return true;
75 }
76 player->startRepairing(x, y, z);
77 return true;
78}
79
80int AnvilTile::getRenderShape()
81{
82 return SHAPE_ANVIL;
83}
84
85int AnvilTile::getSpawnResourcesAuxValue(int data)
86{
87 return data >> 2;
88}
89
90void AnvilTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity)
91{
92 int dir = level->getData(x, y, z) & 3;
93
94 if (dir == Direction::EAST || dir == Direction::WEST)
95 {
96 setShape(0, 0, 2 / 16.0f, 1, 1, 1 - 2 / 16.0f);
97 }
98 else
99 {
100 setShape(2 / 16.0f, 0, 0, 1 - 2 / 16.0f, 1, 1);
101 }
102}
103
104void AnvilTile::falling(shared_ptr<FallingTile> entity)
105{
106 entity->setHurtsEntities(true);
107}
108
109void AnvilTile::onLand(Level *level, int xt, int yt, int zt, int data)
110{
111 level->levelEvent(LevelEvent::SOUND_ANVIL_LAND, xt, yt, zt, 0);
112}
113
114bool AnvilTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face)
115{
116 return true;
117}