56 lines
2.1 KiB
Java
56 lines
2.1 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.decoration.LeashFenceKnotEntity;
|
|
import net.minecraft.world.phys.AABB;
|
|
import net.minecraft.world.entity.Mob;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.tags.BlockTags;
|
|
import net.minecraft.world.InteractionResult;
|
|
|
|
public class LeadItem extends Item {
|
|
public LeadItem(final Properties a) {
|
|
super(a);
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult useOn(final UseOnContext bfw) {
|
|
final Level bjt3 = bfw.getLevel();
|
|
final BlockPos fk4 = bfw.getClickedPos();
|
|
final Block bpe5 = bjt3.getBlockState(fk4).getBlock();
|
|
if (bpe5.is(BlockTags.FENCES)) {
|
|
final Player ayg6 = bfw.getPlayer();
|
|
if (!bjt3.isClientSide && ayg6 != null) {
|
|
bindPlayerMobs(ayg6, bjt3, fk4);
|
|
}
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
return InteractionResult.PASS;
|
|
}
|
|
|
|
public static InteractionResult bindPlayerMobs(final Player ayg, final Level bjt, final BlockPos fk) {
|
|
LeashFenceKnotEntity avp4 = null;
|
|
boolean boolean5 = false;
|
|
final double double6 = 7.0;
|
|
final int integer8 = fk.getX();
|
|
final int integer9 = fk.getY();
|
|
final int integer10 = fk.getZ();
|
|
final List<Mob> list11 = bjt.<Mob>getEntitiesOfClass(Mob.class, new AABB(integer8 - 7.0, integer9 - 7.0, integer10 - 7.0, integer8 + 7.0, integer9 + 7.0, integer10 + 7.0));
|
|
for (final Mob akx13 : list11) {
|
|
if (akx13.getLeashHolder() == ayg) {
|
|
if (avp4 == null) {
|
|
avp4 = LeashFenceKnotEntity.getOrCreateKnot(bjt, fk);
|
|
}
|
|
akx13.setLeashedTo(avp4, true);
|
|
boolean5 = true;
|
|
}
|
|
}
|
|
return boolean5 ? InteractionResult.SUCCESS : InteractionResult.PASS;
|
|
}
|
|
}
|