ItemEnderEye .java

net.minecraft.item.ItemEnderEye (class): members: onItemRightClick, onItemUse. strings: "Stronghold", "random.bow". imports: BlockEndPortalFrame, StatList.

net.minecraft.itemclass178 linescommonextends Item6.9 KB

API Surface (2)

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

String literals (2)

"Stronghold"
"random.bow"

Full Source

ItemEnderEye.java178 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item;
2
3
import net.minecraft.block.BlockEndPortalFrame;
4
import net.minecraft.block.state.IBlockState;
5
import net.minecraft.creativetab.CreativeTabs;
6
import net.minecraft.entity.item.EntityEnderEye;
7
import net.minecraft.entity.player.EntityPlayer;
8
import net.minecraft.init.Blocks;
9
import net.minecraft.stats.StatList;
10
import net.minecraft.util.BlockPos;
11
import net.minecraft.util.EnumFacing;
12
import net.minecraft.util.EnumParticleTypes;
13
import net.minecraft.util.MovingObjectPosition;
14
import net.minecraft.world.World;
15
16
public class ItemEnderEye extends Item
17
{
18
    public ItemEnderEye()
19
    {
20
        this.setCreativeTab(CreativeTabs.tabMisc);
21
    }
22
23
    /**
24
     * Called when a Block is right-clicked with this Item
25
     */
26
    public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
27
    {
28
        IBlockState iblockstate = worldIn.getBlockState(pos);
29
30
        if (playerIn.canPlayerEdit(pos.offset(side), side, stack) && iblockstate.getBlock() == Blocks.end_portal_frame && !((Boolean)iblockstate.getValue(BlockEndPortalFrame.EYE)).booleanValue())
31
        {
32
            if (worldIn.isRemote)
33
            {
34
                return true;
35
            }
36
            else
37
            {
38
                worldIn.setBlockState(pos, iblockstate.withProperty(BlockEndPortalFrame.EYE, Boolean.valueOf(true)), 2);
39
                worldIn.updateComparatorOutputLevel(pos, Blocks.end_portal_frame);
40
                --stack.stackSize;
41
42
                for (int i = 0; i < 16; ++i)
43
                {
44
                    double d0 = (double)((float)pos.getX() + (5.0F + itemRand.nextFloat() * 6.0F) / 16.0F);
45
                    double d1 = (double)((float)pos.getY() + 0.8125F);
46
                    double d2 = (double)((float)pos.getZ() + (5.0F + itemRand.nextFloat() * 6.0F) / 16.0F);
47
                    double d3 = 0.0D;
48
                    double d4 = 0.0D;
49
                    double d5 = 0.0D;
50
                    worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, d3, d4, d5, new int[0]);
51
                }
52
53
                EnumFacing enumfacing = (EnumFacing)iblockstate.getValue(BlockEndPortalFrame.FACING);
54
                int l = 0;
55
                int j = 0;
56
                boolean flag1 = false;
57
                boolean flag = true;
58
                EnumFacing enumfacing1 = enumfacing.rotateY();
59
60
                for (int k = -2; k <= 2; ++k)
61
                {
62
                    BlockPos blockpos1 = pos.offset(enumfacing1, k);
63
                    IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
64
65
                    if (iblockstate1.getBlock() == Blocks.end_portal_frame)
66
                    {
67
                        if (!((Boolean)iblockstate1.getValue(BlockEndPortalFrame.EYE)).booleanValue())
68
                        {
69
                            flag = false;
70
                            break;
71
                        }
72
73
                        j = k;
74
75
                        if (!flag1)
76
                        {
77
                            l = k;
78
                            flag1 = true;
79
                        }
80
                    }
81
                }
82
83
                if (flag && j == l + 2)
84
                {
85
                    BlockPos blockpos = pos.offset(enumfacing, 4);
86
87
                    for (int i1 = l; i1 <= j; ++i1)
88
                    {
89
                        BlockPos blockpos2 = blockpos.offset(enumfacing1, i1);
90
                        IBlockState iblockstate3 = worldIn.getBlockState(blockpos2);
91
92
                        if (iblockstate3.getBlock() != Blocks.end_portal_frame || !((Boolean)iblockstate3.getValue(BlockEndPortalFrame.EYE)).booleanValue())
93
                        {
94
                            flag = false;
95
                            break;
96
                        }
97
                    }
98
99
                    for (int j1 = l - 1; j1 <= j + 1; j1 += 4)
100
                    {
101
                        blockpos = pos.offset(enumfacing1, j1);
102
103
                        for (int l1 = 1; l1 <= 3; ++l1)
104
                        {
105
                            BlockPos blockpos3 = blockpos.offset(enumfacing, l1);
106
                            IBlockState iblockstate2 = worldIn.getBlockState(blockpos3);
107
108
                            if (iblockstate2.getBlock() != Blocks.end_portal_frame || !((Boolean)iblockstate2.getValue(BlockEndPortalFrame.EYE)).booleanValue())
109
                            {
110
                                flag = false;
111
                                break;
112
                            }
113
                        }
114
                    }
115
116
                    if (flag)
117
                    {
118
                        for (int k1 = l; k1 <= j; ++k1)
119
                        {
120
                            blockpos = pos.offset(enumfacing1, k1);
121
122
                            for (int i2 = 1; i2 <= 3; ++i2)
123
                            {
124
                                BlockPos blockpos4 = blockpos.offset(enumfacing, i2);
125
                                worldIn.setBlockState(blockpos4, Blocks.end_portal.getDefaultState(), 2);
126
                            }
127
                        }
128
                    }
129
                }
130
131
                return true;
132
            }
133
        }
134
        else
135
        {
136
            return false;
137
        }
138
    }
139
140
    /**
141
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
142
     */
143
    public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
144
    {
145
        MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, false);
146
147
        if (movingobjectposition != null && movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && worldIn.getBlockState(movingobjectposition.getBlockPos()).getBlock() == Blocks.end_portal_frame)
148
        {
149
            return itemStackIn;
150
        }
151
        else
152
        {
153
            if (!worldIn.isRemote)
154
            {
155
                BlockPos blockpos = worldIn.getStrongholdPos("Stronghold", new BlockPos(playerIn));
156
157
                if (blockpos != null)
158
                {
159
                    EntityEnderEye entityendereye = new EntityEnderEye(worldIn, playerIn.posX, playerIn.posY, playerIn.posZ);
160
                    entityendereye.moveTowards(blockpos);
161
                    worldIn.spawnEntityInWorld(entityendereye);
162
                    worldIn.playSoundAtEntity(playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
163
                    worldIn.playAuxSFXAtEntity((EntityPlayer)null, 1002, new BlockPos(playerIn), 0);
164
165
                    if (!playerIn.capabilities.isCreativeMode)
166
                    {
167
                        --itemStackIn.stackSize;
168
                    }
169
170
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
171
                }
172
            }
173
174
            return itemStackIn;
175
        }
176
    }
177
}
178

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