BlockBanner .java

net.minecraft.block.BlockBanner (class): members: BlockBannerStanding, BlockBannerHanging, ROTATION, canSpawnInBlock, getSelectedBoundingBox, harvestBlock.

net.minecraft.blockclass257 linescommonextends BlockContainer8.2 KB

API Surface (22)

String getLocalizedName()
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
boolean isFullCube()
boolean isPassable(IBlockAccess worldIn, BlockPos pos)
boolean isOpaqueCube()
boolean canSpawnInBlock()
TileEntity createNewTileEntity(World worldIn, int meta)
Item getItemDropped(IBlockState state, Random rand, int fortune)
Item getItem(World worldIn, BlockPos pos)
void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (2)

FACING
ROTATION

String literals (4)

"facing"
"rotation"
"item.banner.white.name"
"BlockEntityTag"

Full Source

BlockBanner.java257 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.Random;
4
import net.minecraft.block.material.Material;
5
import net.minecraft.block.properties.IProperty;
6
import net.minecraft.block.properties.PropertyDirection;
7
import net.minecraft.block.properties.PropertyInteger;
8
import net.minecraft.block.state.BlockState;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.entity.player.EntityPlayer;
11
import net.minecraft.init.Items;
12
import net.minecraft.item.Item;
13
import net.minecraft.item.ItemStack;
14
import net.minecraft.nbt.NBTTagCompound;
15
import net.minecraft.tileentity.TileEntity;
16
import net.minecraft.tileentity.TileEntityBanner;
17
import net.minecraft.util.AxisAlignedBB;
18
import net.minecraft.util.BlockPos;
19
import net.minecraft.util.EnumFacing;
20
import net.minecraft.util.StatCollector;
21
import net.minecraft.world.IBlockAccess;
22
import net.minecraft.world.World;
23
24
public class BlockBanner extends BlockContainer
25
{
26
    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
27
    public static final PropertyInteger ROTATION = PropertyInteger.create("rotation", 0, 15);
28
29
    protected BlockBanner()
30
    {
31
        super(Material.wood);
32
        float f = 0.25F;
33
        float f1 = 1.0F;
34
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
35
    }
36
37
    /**
38
     * Gets the localized name of this block. Used for the statistics page.
39
     */
40
    public String getLocalizedName()
41
    {
42
        return StatCollector.translateToLocal("item.banner.white.name");
43
    }
44
45
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
46
    {
47
        return null;
48
    }
49
50
    public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos)
51
    {
52
        this.setBlockBoundsBasedOnState(worldIn, pos);
53
        return super.getSelectedBoundingBox(worldIn, pos);
54
    }
55
56
    public boolean isFullCube()
57
    {
58
        return false;
59
    }
60
61
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
62
    {
63
        return true;
64
    }
65
66
    /**
67
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
68
     */
69
    public boolean isOpaqueCube()
70
    {
71
        return false;
72
    }
73
74
    /**
75
     * Return true if an entity can be spawned inside the block (used to get the player's bed spawn location)
76
     */
77
    public boolean canSpawnInBlock()
78
    {
79
        return true;
80
    }
81
82
    /**
83
     * Returns a new instance of a block's tile entity class. Called on placing the block.
84
     */
85
    public TileEntity createNewTileEntity(World worldIn, int meta)
86
    {
87
        return new TileEntityBanner();
88
    }
89
90
    /**
91
     * Get the Item that this Block should drop when harvested.
92
     */
93
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
94
    {
95
        return Items.banner;
96
    }
97
98
    public Item getItem(World worldIn, BlockPos pos)
99
    {
100
        return Items.banner;
101
    }
102
103
    /**
104
     * Spawns this Block's drops into the World as EntityItems.
105
     */
106
    public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
107
    {
108
        TileEntity tileentity = worldIn.getTileEntity(pos);
109
110
        if (tileentity instanceof TileEntityBanner)
111
        {
112
            ItemStack itemstack = new ItemStack(Items.banner, 1, ((TileEntityBanner)tileentity).getBaseColor());
113
            NBTTagCompound nbttagcompound = new NBTTagCompound();
114
            tileentity.writeToNBT(nbttagcompound);
115
            nbttagcompound.removeTag("x");
116
            nbttagcompound.removeTag("y");
117
            nbttagcompound.removeTag("z");
118
            nbttagcompound.removeTag("id");
119
            itemstack.setTagInfo("BlockEntityTag", nbttagcompound);
120
            spawnAsEntity(worldIn, pos, itemstack);
121
        }
122
        else
123
        {
124
            super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
125
        }
126
    }
127
128
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
129
    {
130
        return !this.hasInvalidNeighbor(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos);
131
    }
132
133
    public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
134
    {
135
        if (te instanceof TileEntityBanner)
136
        {
137
            TileEntityBanner tileentitybanner = (TileEntityBanner)te;
138
            ItemStack itemstack = new ItemStack(Items.banner, 1, ((TileEntityBanner)te).getBaseColor());
139
            NBTTagCompound nbttagcompound = new NBTTagCompound();
140
            TileEntityBanner.setBaseColorAndPatterns(nbttagcompound, tileentitybanner.getBaseColor(), tileentitybanner.getPatterns());
141
            itemstack.setTagInfo("BlockEntityTag", nbttagcompound);
142
            spawnAsEntity(worldIn, pos, itemstack);
143
        }
144
        else
145
        {
146
            super.harvestBlock(worldIn, player, pos, state, (TileEntity)null);
147
        }
148
    }
149
150
    public static class BlockBannerHanging extends BlockBanner
151
    {
152
        public BlockBannerHanging()
153
        {
154
            this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
155
        }
156
157
        public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
158
        {
159
            EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
160
            float f = 0.0F;
161
            float f1 = 0.78125F;
162
            float f2 = 0.0F;
163
            float f3 = 1.0F;
164
            float f4 = 0.125F;
165
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
166
167
            switch (enumfacing)
168
            {
169
                case NORTH:
170
                default:
171
                    this.setBlockBounds(f2, f, 1.0F - f4, f3, f1, 1.0F);
172
                    break;
173
174
                case SOUTH:
175
                    this.setBlockBounds(f2, f, 0.0F, f3, f1, f4);
176
                    break;
177
178
                case WEST:
179
                    this.setBlockBounds(1.0F - f4, f, f2, 1.0F, f1, f3);
180
                    break;
181
182
                case EAST:
183
                    this.setBlockBounds(0.0F, f, f2, f4, f1, f3);
184
            }
185
        }
186
187
        public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
188
        {
189
            EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
190
191
            if (!worldIn.getBlockState(pos.offset(enumfacing.getOpposite())).getBlock().getMaterial().isSolid())
192
            {
193
                this.dropBlockAsItem(worldIn, pos, state, 0);
194
                worldIn.setBlockToAir(pos);
195
            }
196
197
            super.onNeighborBlockChange(worldIn, pos, state, neighborBlock);
198
        }
199
200
        public IBlockState getStateFromMeta(int meta)
201
        {
202
            EnumFacing enumfacing = EnumFacing.getFront(meta);
203
204
            if (enumfacing.getAxis() == EnumFacing.Axis.Y)
205
            {
206
                enumfacing = EnumFacing.NORTH;
207
            }
208
209
            return this.getDefaultState().withProperty(FACING, enumfacing);
210
        }
211
212
        public int getMetaFromState(IBlockState state)
213
        {
214
            return ((EnumFacing)state.getValue(FACING)).getIndex();
215
        }
216
217
        protected BlockState createBlockState()
218
        {
219
            return new BlockState(this, new IProperty[] {FACING});
220
        }
221
    }
222
223
    public static class BlockBannerStanding extends BlockBanner
224
    {
225
        public BlockBannerStanding()
226
        {
227
            this.setDefaultState(this.blockState.getBaseState().withProperty(ROTATION, Integer.valueOf(0)));
228
        }
229
230
        public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
231
        {
232
            if (!worldIn.getBlockState(pos.down()).getBlock().getMaterial().isSolid())
233
            {
234
                this.dropBlockAsItem(worldIn, pos, state, 0);
235
                worldIn.setBlockToAir(pos);
236
            }
237
238
            super.onNeighborBlockChange(worldIn, pos, state, neighborBlock);
239
        }
240
241
        public IBlockState getStateFromMeta(int meta)
242
        {
243
            return this.getDefaultState().withProperty(ROTATION, Integer.valueOf(meta));
244
        }
245
246
        public int getMetaFromState(IBlockState state)
247
        {
248
            return ((Integer)state.getValue(ROTATION)).intValue();
249
        }
250
251
        protected BlockState createBlockState()
252
        {
253
            return new BlockState(this, new IProperty[] {ROTATION});
254
        }
255
    }
256
}
257

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