EntityLeashKnot .java

net.minecraft.entity.EntityLeashKnot (class): members: getKnotForPosition, createKnot, updateFacingWithBoundingBox, writeToNBTOptional, onValidSurface.

net.minecraft.entityclass173 linescommonextends EntityHanging5.1 KB

API Surface (14)

void entityInit()
void updateFacingWithBoundingBox(EnumFacing facingDirectionIn)
int getWidthPixels()
int getHeightPixels()
float getEyeHeight()
boolean isInRangeToRenderDist(double distance)
void onBroken(Entity brokenEntity)
boolean writeToNBTOptional(NBTTagCompound tagCompund)
void writeEntityToNBT(NBTTagCompound tagCompound)
void readEntityFromNBT(NBTTagCompound tagCompund)
boolean interactFirst(EntityPlayer playerIn)
boolean onValidSurface()
EntityLeashKnot createKnot(World worldIn, BlockPos fence)
EntityLeashKnot getKnotForPosition(World worldIn, BlockPos pos)

Full Source

EntityLeashKnot.java173 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity;
2
3
import net.minecraft.block.BlockFence;
4
import net.minecraft.entity.player.EntityPlayer;
5
import net.minecraft.init.Items;
6
import net.minecraft.item.ItemStack;
7
import net.minecraft.nbt.NBTTagCompound;
8
import net.minecraft.util.AxisAlignedBB;
9
import net.minecraft.util.BlockPos;
10
import net.minecraft.util.EnumFacing;
11
import net.minecraft.world.World;
12
13
public class EntityLeashKnot extends EntityHanging
14
{
15
    public EntityLeashKnot(World worldIn)
16
    {
17
        super(worldIn);
18
    }
19
20
    public EntityLeashKnot(World worldIn, BlockPos hangingPositionIn)
21
    {
22
        super(worldIn, hangingPositionIn);
23
        this.setPosition((double)hangingPositionIn.getX() + 0.5D, (double)hangingPositionIn.getY() + 0.5D, (double)hangingPositionIn.getZ() + 0.5D);
24
        float f = 0.125F;
25
        float f1 = 0.1875F;
26
        float f2 = 0.25F;
27
        this.setEntityBoundingBox(new AxisAlignedBB(this.posX - 0.1875D, this.posY - 0.25D + 0.125D, this.posZ - 0.1875D, this.posX + 0.1875D, this.posY + 0.25D + 0.125D, this.posZ + 0.1875D));
28
    }
29
30
    protected void entityInit()
31
    {
32
        super.entityInit();
33
    }
34
35
    /**
36
     * Updates facing and bounding box based on it
37
     */
38
    public void updateFacingWithBoundingBox(EnumFacing facingDirectionIn)
39
    {
40
    }
41
42
    public int getWidthPixels()
43
    {
44
        return 9;
45
    }
46
47
    public int getHeightPixels()
48
    {
49
        return 9;
50
    }
51
52
    public float getEyeHeight()
53
    {
54
        return -0.0625F;
55
    }
56
57
    /**
58
     * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
59
     * length * 64 * renderDistanceWeight Args: distance
60
     */
61
    public boolean isInRangeToRenderDist(double distance)
62
    {
63
        return distance < 1024.0D;
64
    }
65
66
    /**
67
     * Called when this entity is broken. Entity parameter may be null.
68
     */
69
    public void onBroken(Entity brokenEntity)
70
    {
71
    }
72
73
    /**
74
     * Either write this entity to the NBT tag given and return true, or return false without doing anything. If this
75
     * returns false the entity is not saved on disk. Ridden entities return false here as they are saved with their
76
     * rider.
77
     */
78
    public boolean writeToNBTOptional(NBTTagCompound tagCompund)
79
    {
80
        return false;
81
    }
82
83
    /**
84
     * (abstract) Protected helper method to write subclass entity data to NBT.
85
     */
86
    public void writeEntityToNBT(NBTTagCompound tagCompound)
87
    {
88
    }
89
90
    /**
91
     * (abstract) Protected helper method to read subclass entity data from NBT.
92
     */
93
    public void readEntityFromNBT(NBTTagCompound tagCompund)
94
    {
95
    }
96
97
    /**
98
     * First layer of player interaction
99
     */
100
    public boolean interactFirst(EntityPlayer playerIn)
101
    {
102
        ItemStack itemstack = playerIn.getHeldItem();
103
        boolean flag = false;
104
105
        if (itemstack != null && itemstack.getItem() == Items.lead && !this.worldObj.isRemote)
106
        {
107
            double d0 = 7.0D;
108
109
            for (EntityLiving entityliving : this.worldObj.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB(this.posX - d0, this.posY - d0, this.posZ - d0, this.posX + d0, this.posY + d0, this.posZ + d0)))
110
            {
111
                if (entityliving.getLeashed() && entityliving.getLeashedToEntity() == playerIn)
112
                {
113
                    entityliving.setLeashedToEntity(this, true);
114
                    flag = true;
115
                }
116
            }
117
        }
118
119
        if (!this.worldObj.isRemote && !flag)
120
        {
121
            this.setDead();
122
123
            if (playerIn.capabilities.isCreativeMode)
124
            {
125
                double d1 = 7.0D;
126
127
                for (EntityLiving entityliving1 : this.worldObj.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB(this.posX - d1, this.posY - d1, this.posZ - d1, this.posX + d1, this.posY + d1, this.posZ + d1)))
128
                {
129
                    if (entityliving1.getLeashed() && entityliving1.getLeashedToEntity() == this)
130
                    {
131
                        entityliving1.clearLeashed(true, false);
132
                    }
133
                }
134
            }
135
        }
136
137
        return true;
138
    }
139
140
    /**
141
     * checks to make sure painting can be placed there
142
     */
143
    public boolean onValidSurface()
144
    {
145
        return this.worldObj.getBlockState(this.hangingPosition).getBlock() instanceof BlockFence;
146
    }
147
148
    public static EntityLeashKnot createKnot(World worldIn, BlockPos fence)
149
    {
150
        EntityLeashKnot entityleashknot = new EntityLeashKnot(worldIn, fence);
151
        entityleashknot.forceSpawn = true;
152
        worldIn.spawnEntityInWorld(entityleashknot);
153
        return entityleashknot;
154
    }
155
156
    public static EntityLeashKnot getKnotForPosition(World worldIn, BlockPos pos)
157
    {
158
        int i = pos.getX();
159
        int j = pos.getY();
160
        int k = pos.getZ();
161
162
        for (EntityLeashKnot entityleashknot : worldIn.getEntitiesWithinAABB(EntityLeashKnot.class, new AxisAlignedBB((double)i - 1.0D, (double)j - 1.0D, (double)k - 1.0D, (double)i + 1.0D, (double)j + 1.0D, (double)k + 1.0D)))
163
        {
164
            if (entityleashknot.getHangingPosition().equals(pos))
165
            {
166
                return entityleashknot;
167
            }
168
        }
169
170
        return null;
171
    }
172
}
173

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