ItemHangingEntity .java

net.minecraft.item.ItemHangingEntity (class): members: hangingEntityClass, onItemUse. imports: EntityHanging, EntityPainting, EntityItemFrame, EnumFacing.

net.minecraft.itemclass67 linescommonextends Item2.1 KB

API Surface (1)

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

Fields & Constants (1)

hangingEntityClass

Full Source

ItemHangingEntity.java67 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item;
2
3
import net.minecraft.creativetab.CreativeTabs;
4
import net.minecraft.entity.EntityHanging;
5
import net.minecraft.entity.item.EntityItemFrame;
6
import net.minecraft.entity.item.EntityPainting;
7
import net.minecraft.entity.player.EntityPlayer;
8
import net.minecraft.util.BlockPos;
9
import net.minecraft.util.EnumFacing;
10
import net.minecraft.world.World;
11
12
public class ItemHangingEntity extends Item
13
{
14
    private final Class <? extends EntityHanging > hangingEntityClass;
15
16
    public ItemHangingEntity(Class <? extends EntityHanging > entityClass)
17
    {
18
        this.hangingEntityClass = entityClass;
19
        this.setCreativeTab(CreativeTabs.tabDecorations);
20
    }
21
22
    /**
23
     * Called when a Block is right-clicked with this Item
24
     */
25
    public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
26
    {
27
        if (side == EnumFacing.DOWN)
28
        {
29
            return false;
30
        }
31
        else if (side == EnumFacing.UP)
32
        {
33
            return false;
34
        }
35
        else
36
        {
37
            BlockPos blockpos = pos.offset(side);
38
39
            if (!playerIn.canPlayerEdit(blockpos, side, stack))
40
            {
41
                return false;
42
            }
43
            else
44
            {
45
                EntityHanging entityhanging = this.createEntity(worldIn, blockpos, side);
46
47
                if (entityhanging != null && entityhanging.onValidSurface())
48
                {
49
                    if (!worldIn.isRemote)
50
                    {
51
                        worldIn.spawnEntityInWorld(entityhanging);
52
                    }
53
54
                    --stack.stackSize;
55
                }
56
57
                return true;
58
            }
59
        }
60
    }
61
62
    private EntityHanging createEntity(World worldIn, BlockPos pos, EnumFacing clickedSide)
63
    {
64
        return (EntityHanging)(this.hangingEntityClass == EntityPainting.class ? new EntityPainting(worldIn, pos, clickedSide) : (this.hangingEntityClass == EntityItemFrame.class ? new EntityItemFrame(worldIn, pos, clickedSide) : null));
65
    }
66
}
67

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