BlockFence .java

net.minecraft.block.BlockFence (class, 199 lines): members: canConnectTo, NORTH, SOUTH, EAST, WEST, isPassable, addCollisionBoxesToList, getActualState.

net.minecraft.blockclass199 linescommonextends Block6.1 KB

API Surface (11)

void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity)
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
boolean isOpaqueCube()
boolean isFullCube()
boolean isPassable(IBlockAccess worldIn, BlockPos pos)
boolean canConnectTo(IBlockAccess worldIn, BlockPos pos)
boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
int getMetaFromState(IBlockState state)
IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
BlockState createBlockState()

Fields & Constants (4)

NORTH
EAST
SOUTH
WEST

String literals (4)

"north"
"east"
"south"
"west"

Full Source

BlockFence.java199 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import java.util.List;
4
import net.minecraft.block.material.MapColor;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.block.properties.IProperty;
7
import net.minecraft.block.properties.PropertyBool;
8
import net.minecraft.block.state.BlockState;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.creativetab.CreativeTabs;
11
import net.minecraft.entity.Entity;
12
import net.minecraft.entity.player.EntityPlayer;
13
import net.minecraft.init.Blocks;
14
import net.minecraft.item.ItemLead;
15
import net.minecraft.util.AxisAlignedBB;
16
import net.minecraft.util.BlockPos;
17
import net.minecraft.util.EnumFacing;
18
import net.minecraft.world.IBlockAccess;
19
import net.minecraft.world.World;
20
21
public class BlockFence extends Block
22
{
23
    /** Whether this fence connects in the northern direction */
24
    public static final PropertyBool NORTH = PropertyBool.create("north");
25
26
    /** Whether this fence connects in the eastern direction */
27
    public static final PropertyBool EAST = PropertyBool.create("east");
28
29
    /** Whether this fence connects in the southern direction */
30
    public static final PropertyBool SOUTH = PropertyBool.create("south");
31
32
    /** Whether this fence connects in the western direction */
33
    public static final PropertyBool WEST = PropertyBool.create("west");
34
35
    public BlockFence(Material materialIn)
36
    {
37
        this(materialIn, materialIn.getMaterialMapColor());
38
    }
39
40
    public BlockFence(Material p_i46395_1_, MapColor p_i46395_2_)
41
    {
42
        super(p_i46395_1_, p_i46395_2_);
43
        this.setDefaultState(this.blockState.getBaseState().withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)));
44
        this.setCreativeTab(CreativeTabs.tabDecorations);
45
    }
46
47
    /**
48
     * Add all collision boxes of this Block to the list that intersect with the given mask.
49
     */
50
    public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity)
51
    {
52
        boolean flag = this.canConnectTo(worldIn, pos.north());
53
        boolean flag1 = this.canConnectTo(worldIn, pos.south());
54
        boolean flag2 = this.canConnectTo(worldIn, pos.west());
55
        boolean flag3 = this.canConnectTo(worldIn, pos.east());
56
        float f = 0.375F;
57
        float f1 = 0.625F;
58
        float f2 = 0.375F;
59
        float f3 = 0.625F;
60
61
        if (flag)
62
        {
63
            f2 = 0.0F;
64
        }
65
66
        if (flag1)
67
        {
68
            f3 = 1.0F;
69
        }
70
71
        if (flag || flag1)
72
        {
73
            this.setBlockBounds(f, 0.0F, f2, f1, 1.5F, f3);
74
            super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
75
        }
76
77
        f2 = 0.375F;
78
        f3 = 0.625F;
79
80
        if (flag2)
81
        {
82
            f = 0.0F;
83
        }
84
85
        if (flag3)
86
        {
87
            f1 = 1.0F;
88
        }
89
90
        if (flag2 || flag3 || !flag && !flag1)
91
        {
92
            this.setBlockBounds(f, 0.0F, f2, f1, 1.5F, f3);
93
            super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
94
        }
95
96
        if (flag)
97
        {
98
            f2 = 0.0F;
99
        }
100
101
        if (flag1)
102
        {
103
            f3 = 1.0F;
104
        }
105
106
        this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3);
107
    }
108
109
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
110
    {
111
        boolean flag = this.canConnectTo(worldIn, pos.north());
112
        boolean flag1 = this.canConnectTo(worldIn, pos.south());
113
        boolean flag2 = this.canConnectTo(worldIn, pos.west());
114
        boolean flag3 = this.canConnectTo(worldIn, pos.east());
115
        float f = 0.375F;
116
        float f1 = 0.625F;
117
        float f2 = 0.375F;
118
        float f3 = 0.625F;
119
120
        if (flag)
121
        {
122
            f2 = 0.0F;
123
        }
124
125
        if (flag1)
126
        {
127
            f3 = 1.0F;
128
        }
129
130
        if (flag2)
131
        {
132
            f = 0.0F;
133
        }
134
135
        if (flag3)
136
        {
137
            f1 = 1.0F;
138
        }
139
140
        this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3);
141
    }
142
143
    /**
144
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
145
     */
146
    public boolean isOpaqueCube()
147
    {
148
        return false;
149
    }
150
151
    public boolean isFullCube()
152
    {
153
        return false;
154
    }
155
156
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
157
    {
158
        return false;
159
    }
160
161
    public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos)
162
    {
163
        Block block = worldIn.getBlockState(pos).getBlock();
164
        return block == Blocks.barrier ? false : ((!(block instanceof BlockFence) || block.blockMaterial != this.blockMaterial) && !(block instanceof BlockFenceGate) ? (block.blockMaterial.isOpaque() && block.isFullCube() ? block.blockMaterial != Material.gourd : false) : true);
165
    }
166
167
    public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
168
    {
169
        return true;
170
    }
171
172
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
173
    {
174
        return worldIn.isRemote ? true : ItemLead.attachToFence(playerIn, worldIn, pos);
175
    }
176
177
    /**
178
     * Convert the BlockState into the correct metadata value
179
     */
180
    public int getMetaFromState(IBlockState state)
181
    {
182
        return 0;
183
    }
184
185
    /**
186
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
187
     * metadata, such as fence connections.
188
     */
189
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
190
    {
191
        return state.withProperty(NORTH, Boolean.valueOf(this.canConnectTo(worldIn, pos.north()))).withProperty(EAST, Boolean.valueOf(this.canConnectTo(worldIn, pos.east()))).withProperty(SOUTH, Boolean.valueOf(this.canConnectTo(worldIn, pos.south()))).withProperty(WEST, Boolean.valueOf(this.canConnectTo(worldIn, pos.west())));
192
    }
193
194
    protected BlockState createBlockState()
195
    {
196
        return new BlockState(this, new IProperty[] {NORTH, EAST, WEST, SOUTH});
197
    }
198
}
199

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