ItemLead .java

net.minecraft.item.ItemLead (class, 72 lines): members: attachToFence, onItemUse. imports: EntityLeashKnot, BlockFence, EntityLiving, AxisAlignedBB, Block.

net.minecraft.itemclass72 linescommonextends Item2.1 KB

API Surface (2)

boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
boolean attachToFence(EntityPlayer player, World worldIn, BlockPos fence)

Full Source

ItemLead.java72 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item;
2
3
import net.minecraft.block.Block;
4
import net.minecraft.block.BlockFence;
5
import net.minecraft.creativetab.CreativeTabs;
6
import net.minecraft.entity.EntityLeashKnot;
7
import net.minecraft.entity.EntityLiving;
8
import net.minecraft.entity.player.EntityPlayer;
9
import net.minecraft.util.AxisAlignedBB;
10
import net.minecraft.util.BlockPos;
11
import net.minecraft.util.EnumFacing;
12
import net.minecraft.world.World;
13
14
public class ItemLead extends Item
15
{
16
    public ItemLead()
17
    {
18
        this.setCreativeTab(CreativeTabs.tabTools);
19
    }
20
21
    /**
22
     * Called when a Block is right-clicked with this Item
23
     */
24
    public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
25
    {
26
        Block block = worldIn.getBlockState(pos).getBlock();
27
28
        if (block instanceof BlockFence)
29
        {
30
            if (worldIn.isRemote)
31
            {
32
                return true;
33
            }
34
            else
35
            {
36
                attachToFence(playerIn, worldIn, pos);
37
                return true;
38
            }
39
        }
40
        else
41
        {
42
            return false;
43
        }
44
    }
45
46
    public static boolean attachToFence(EntityPlayer player, World worldIn, BlockPos fence)
47
    {
48
        EntityLeashKnot entityleashknot = EntityLeashKnot.getKnotForPosition(worldIn, fence);
49
        boolean flag = false;
50
        double d0 = 7.0D;
51
        int i = fence.getX();
52
        int j = fence.getY();
53
        int k = fence.getZ();
54
55
        for (EntityLiving entityliving : worldIn.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB((double)i - d0, (double)j - d0, (double)k - d0, (double)i + d0, (double)j + d0, (double)k + d0)))
56
        {
57
            if (entityliving.getLeashed() && entityliving.getLeashedToEntity() == player)
58
            {
59
                if (entityleashknot == null)
60
                {
61
                    entityleashknot = EntityLeashKnot.createKnot(worldIn, fence);
62
                }
63
64
                entityliving.setLeashedToEntity(entityleashknot, true);
65
                flag = true;
66
            }
67
        }
68
69
        return flag;
70
    }
71
}
72

Deobfuscated MCP 1.8.9 source of ItemLead from Marcelektro/MavenMCP-1.8.9 (net/minecraft/item/ItemLead.java), stored verbatim.