Files
MinecraftConsoles/Minecraft.World/LeashItem.cpp
daoge b3feddfef3 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 97a4399472.

* 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>
2026-03-03 03:04:10 +08:00

74 lines
2.3 KiB
C++

#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;
}