aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/LeashItem.cpp
diff options
context:
space:
mode:
authordaoge <3523206925@qq.com>2026-03-03 03:04:10 +0800
committerGitHub <noreply@github.com>2026-03-03 03:04:10 +0800
commitb3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch)
tree267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/LeashItem.cpp
parent84c31a2331f7a0ec85b9d438992e244f60e5020f (diff)
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict * feat: TU19 (Dec 2014) Features & Content (#32) * December 2014 files * Working release build * Fix compilation issues * Add sound to Windows64Media * Add DLC content and force Tutorial DLC * Revert "Add DLC content and force Tutorial DLC" This reverts commit 97a43994725008e35fceb984d5549df9c8cea470. * Disable broken light packing * Disable breakpoint during DLC texture map load Allows DLC loading but the DLC textures are still broken * Fix post build not working * ... * fix vs2022 build * fix cmake build --------- Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/LeashItem.cpp')
-rw-r--r--Minecraft.World/LeashItem.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/Minecraft.World/LeashItem.cpp b/Minecraft.World/LeashItem.cpp
new file mode 100644
index 00000000..d8d7b3fc
--- /dev/null
+++ b/Minecraft.World/LeashItem.cpp
@@ -0,0 +1,74 @@
+#include "stdafx.h"
+#include "net.minecraft.world.level.tile.h"
+#include "net.minecraft.world.level.h"
+#include "net.minecraft.world.entity.h"
+#include "net.minecraft.world.phys.h"
+#include "LeashItem.h"
+
+LeashItem::LeashItem(int id) : Item(id)
+{
+}
+
+bool LeashItem::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)
+{
+ int tile = level->getTile(x, y, z);
+ if (Tile::tiles[tile] != NULL && Tile::tiles[tile]->getRenderShape() == Tile::SHAPE_FENCE)
+ {
+ if (bTestUseOnOnly) return bindPlayerMobsTest(player, level, x,y,z);
+
+ if (level->isClientSide)
+ {
+ return true;
+ }
+
+ bindPlayerMobs(player, level, x, y, z);
+ return true;
+ }
+ return false;
+}
+
+bool LeashItem::bindPlayerMobs(shared_ptr<Player> player, Level *level, int x, int y, int z)
+{
+ // check if there is a knot at the given coordinate
+ shared_ptr<LeashFenceKnotEntity> activeKnot = LeashFenceKnotEntity::findKnotAt(level, x, y, z);
+
+ // look for entities that can be attached to the fence
+ bool foundMobs = false;
+ double range = 7;
+ vector<shared_ptr<Entity> > *mobs = level->getEntitiesOfClass(typeid(Mob), AABB::newTemp(x - range, y - range, z - range, x + range, y + range, z + range));
+ if (mobs != NULL)
+ {
+ for(AUTO_VAR(it,mobs->begin()); it != mobs->end(); ++it)
+ {
+ shared_ptr<Mob> mob = dynamic_pointer_cast<Mob>(*it);
+ if (mob->isLeashed() && mob->getLeashHolder() == player)
+ {
+ if (activeKnot == NULL)
+ {
+ activeKnot = LeashFenceKnotEntity::createAndAddKnot(level, x, y, z);
+ }
+ mob->setLeashedTo(activeKnot, true);
+ foundMobs = true;
+ }
+ }
+ }
+ return foundMobs;
+}
+
+// 4J-JEV: Similar to bindPlayerMobs, but doesn't actually bind mobs,
+bool LeashItem::bindPlayerMobsTest(shared_ptr<Player> player, Level *level, int x, int y, int z)
+{
+ // look for entities that can be attached to the fence
+ double range = 7;
+ vector<shared_ptr<Entity> > *mobs = level->getEntitiesOfClass(typeid(Mob), AABB::newTemp(x - range, y - range, z - range, x + range, y + range, z + range));
+
+ if (mobs != NULL)
+ {
+ for(AUTO_VAR(it,mobs->begin()); it != mobs->end(); ++it)
+ {
+ shared_ptr<Mob> mob = dynamic_pointer_cast<Mob>(*it);
+ if (mob->isLeashed() && mob->getLeashHolder() == player) return true;
+ }
+ }
+ return false;
+} \ No newline at end of file