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.item.h"
4#include "net.minecraft.world.level.h"
5#include "net.minecraft.world.phys.h"
6#include "LeashFenceKnotEntity.h"
7
8void LeashFenceKnotEntity::_init()
9{
10 defineSynchedData();
11}
12
13LeashFenceKnotEntity::LeashFenceKnotEntity(Level *level) : HangingEntity(level)
14{
15 _init();
16}
17
18LeashFenceKnotEntity::LeashFenceKnotEntity(Level *level, int xTile, int yTile, int zTile) : HangingEntity(level, xTile, yTile, zTile, 0)
19{
20 _init();
21 setPos(xTile + .5, yTile + .5, zTile + .5);
22}
23
24void LeashFenceKnotEntity::defineSynchedData()
25{
26 HangingEntity::defineSynchedData();
27}
28
29void LeashFenceKnotEntity::setDir(int dir)
30{
31 // override to do nothing, knots don't have directions
32}
33
34int LeashFenceKnotEntity::getWidth()
35{
36 return 9;
37}
38
39int LeashFenceKnotEntity::getHeight()
40{
41 return 9;
42}
43
44bool LeashFenceKnotEntity::shouldRenderAtSqrDistance(double distance)
45{
46 return distance < 32 * 32;
47}
48
49void LeashFenceKnotEntity::dropItem(shared_ptr<Entity> causedBy)
50{
51
52}
53
54bool LeashFenceKnotEntity::save(CompoundTag *entityTag)
55{
56 // knots are not saved, they are recreated by the entities that are tied
57 return false;
58}
59
60void LeashFenceKnotEntity::addAdditonalSaveData(CompoundTag *tag)
61{
62}
63
64void LeashFenceKnotEntity::readAdditionalSaveData(CompoundTag *tag)
65{
66}
67
68bool LeashFenceKnotEntity::interact(shared_ptr<Player> player)
69{
70 shared_ptr<ItemInstance> item = player->getCarriedItem();
71
72 bool attachedMob = false;
73 if (item != NULL && item->id == Item::lead_Id)
74 {
75 if (!level->isClientSide)
76 {
77 // look for entities that can be attached to the fence
78 double range = 7;
79 vector<shared_ptr<Entity> > *mobs = level->getEntitiesOfClass(typeid(Mob), AABB::newTemp(x - range, y - range, z - range, x + range, y + range, z + range));
80 if (mobs != NULL)
81 {
82 for(AUTO_VAR(it, mobs->begin()); it != mobs->end(); ++it)
83 {
84 shared_ptr<Mob> mob = dynamic_pointer_cast<Mob>( *it );
85 if (mob->isLeashed() && mob->getLeashHolder() == player)
86 {
87 mob->setLeashedTo(shared_from_this(), true);
88 attachedMob = true;
89 }
90 }
91 delete mobs;
92 }
93 }
94 }
95 if (!level->isClientSide && !attachedMob)
96 {
97 remove();
98
99 if (player->abilities.instabuild)
100 {
101 // if the player is in creative mode, attempt to remove all leashed mobs without dropping additional items
102 double range = 7;
103 vector<shared_ptr<Entity> > *mobs = level->getEntitiesOfClass(typeid(Mob), AABB::newTemp(x - range, y - range, z - range, x + range, y + range, z + range));
104 if (mobs != NULL)
105 {
106 for(AUTO_VAR(it, mobs->begin()); it != mobs->end(); ++it)
107 {
108 shared_ptr<Mob> mob = dynamic_pointer_cast<Mob>( *it );
109 if (mob->isLeashed() && mob->getLeashHolder() == shared_from_this())
110 {
111 mob->dropLeash(true, false);
112 }
113 }
114 delete mobs;
115 }
116 }
117 }
118 return true;
119}
120
121bool LeashFenceKnotEntity::survives()
122{
123 // knots are placed on top of fence tiles
124 int tile = level->getTile(xTile, yTile, zTile);
125 if (Tile::tiles[tile] != NULL && Tile::tiles[tile]->getRenderShape() == Tile::SHAPE_FENCE)
126 {
127 return true;
128 }
129 return false;
130}
131
132shared_ptr<LeashFenceKnotEntity> LeashFenceKnotEntity::createAndAddKnot(Level *level, int x, int y, int z)
133{
134 shared_ptr<LeashFenceKnotEntity> knot = shared_ptr<LeashFenceKnotEntity>( new LeashFenceKnotEntity(level, x, y, z) );
135 knot->forcedLoading = true;
136 level->addEntity(knot);
137 return knot;
138}
139
140shared_ptr<LeashFenceKnotEntity> LeashFenceKnotEntity::findKnotAt(Level *level, int x, int y, int z)
141{
142 vector<shared_ptr<Entity> > *knots = level->getEntitiesOfClass(typeid(LeashFenceKnotEntity), AABB::newTemp(x - 1.0, y - 1.0, z - 1.0, x + 1.0, y + 1.0, z + 1.0));
143 if (knots != NULL)
144 {
145 for(AUTO_VAR(it, knots->begin()); it != knots->end(); ++it)
146 {
147 shared_ptr<LeashFenceKnotEntity> knot = dynamic_pointer_cast<LeashFenceKnotEntity>( *it );
148 if (knot->xTile == x && knot->yTile == y && knot->zTile == z)
149 {
150 delete knots;
151 return knot;
152 }
153 }
154 delete knots;
155 }
156 return nullptr;
157}