ItemArmorStand .java

net.minecraft.item.ItemArmorStand (class): members: onItemUse. strings: "EntityTag". imports: Rotations, EntityArmorStand, AxisAlignedBB, CreativeTabs.

net.minecraft.itemclass107 linescommonextends Item4.4 KB

API Surface (1)

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

String literals (1)

"EntityTag"

Full Source

ItemArmorStand.java107 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item;
2
3
import java.util.List;
4
import java.util.Random;
5
import net.minecraft.creativetab.CreativeTabs;
6
import net.minecraft.entity.Entity;
7
import net.minecraft.entity.item.EntityArmorStand;
8
import net.minecraft.entity.player.EntityPlayer;
9
import net.minecraft.nbt.NBTTagCompound;
10
import net.minecraft.util.AxisAlignedBB;
11
import net.minecraft.util.BlockPos;
12
import net.minecraft.util.EnumFacing;
13
import net.minecraft.util.MathHelper;
14
import net.minecraft.util.Rotations;
15
import net.minecraft.world.World;
16
17
public class ItemArmorStand extends Item
18
{
19
    public ItemArmorStand()
20
    {
21
        this.setCreativeTab(CreativeTabs.tabDecorations);
22
    }
23
24
    /**
25
     * Called when a Block is right-clicked with this Item
26
     */
27
    public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
28
    {
29
        if (side == EnumFacing.DOWN)
30
        {
31
            return false;
32
        }
33
        else
34
        {
35
            boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
36
            BlockPos blockpos = flag ? pos : pos.offset(side);
37
38
            if (!playerIn.canPlayerEdit(blockpos, side, stack))
39
            {
40
                return false;
41
            }
42
            else
43
            {
44
                BlockPos blockpos1 = blockpos.up();
45
                boolean flag1 = !worldIn.isAirBlock(blockpos) && !worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
46
                flag1 = flag1 | (!worldIn.isAirBlock(blockpos1) && !worldIn.getBlockState(blockpos1).getBlock().isReplaceable(worldIn, blockpos1));
47
48
                if (flag1)
49
                {
50
                    return false;
51
                }
52
                else
53
                {
54
                    double d0 = (double)blockpos.getX();
55
                    double d1 = (double)blockpos.getY();
56
                    double d2 = (double)blockpos.getZ();
57
                    List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity((Entity)null, AxisAlignedBB.fromBounds(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D));
58
59
                    if (list.size() > 0)
60
                    {
61
                        return false;
62
                    }
63
                    else
64
                    {
65
                        if (!worldIn.isRemote)
66
                        {
67
                            worldIn.setBlockToAir(blockpos);
68
                            worldIn.setBlockToAir(blockpos1);
69
                            EntityArmorStand entityarmorstand = new EntityArmorStand(worldIn, d0 + 0.5D, d1, d2 + 0.5D);
70
                            float f = (float)MathHelper.floor_float((MathHelper.wrapAngleTo180_float(playerIn.rotationYaw - 180.0F) + 22.5F) / 45.0F) * 45.0F;
71
                            entityarmorstand.setLocationAndAngles(d0 + 0.5D, d1, d2 + 0.5D, f, 0.0F);
72
                            this.applyRandomRotations(entityarmorstand, worldIn.rand);
73
                            NBTTagCompound nbttagcompound = stack.getTagCompound();
74
75
                            if (nbttagcompound != null && nbttagcompound.hasKey("EntityTag", 10))
76
                            {
77
                                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
78
                                entityarmorstand.writeToNBTOptional(nbttagcompound1);
79
                                nbttagcompound1.merge(nbttagcompound.getCompoundTag("EntityTag"));
80
                                entityarmorstand.readFromNBT(nbttagcompound1);
81
                            }
82
83
                            worldIn.spawnEntityInWorld(entityarmorstand);
84
                        }
85
86
                        --stack.stackSize;
87
                        return true;
88
                    }
89
                }
90
            }
91
        }
92
    }
93
94
    private void applyRandomRotations(EntityArmorStand armorStand, Random rand)
95
    {
96
        Rotations rotations = armorStand.getHeadRotation();
97
        float f = rand.nextFloat() * 5.0F;
98
        float f1 = rand.nextFloat() * 20.0F - 10.0F;
99
        Rotations rotations1 = new Rotations(rotations.getX() + f, rotations.getY() + f1, rotations.getZ());
100
        armorStand.setHeadRotation(rotations1);
101
        rotations = armorStand.getBodyRotation();
102
        f = rand.nextFloat() * 10.0F - 5.0F;
103
        rotations1 = new Rotations(rotations.getX(), rotations.getY() + f, rotations.getZ());
104
        armorStand.setBodyRotation(rotations1);
105
    }
106
}
107

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