BlockFenceGate .java

net.minecraft.block.BlockFenceGate (class): members: IN_WALL, OPEN, POWERED, isPassable, shouldSideBeRendered, getActualState, canPlaceBlockAt, isFullCube.

net.minecraft.blockclass198 linescommonextends BlockDirectional7.8 KB

API Surface (14)

IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
boolean canPlaceBlockAt(World worldIn, BlockPos pos)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
boolean isOpaqueCube()
boolean isFullCube()
boolean isPassable(IBlockAccess worldIn, BlockPos pos)
IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()

Fields & Constants (3)

OPEN
POWERED
IN_WALL

String literals (3)

"open"
"powered"
"in_wall"

Full Source

BlockFenceGate.java198 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import net.minecraft.block.material.Material;
4
import net.minecraft.block.properties.IProperty;
5
import net.minecraft.block.properties.PropertyBool;
6
import net.minecraft.block.state.BlockState;
7
import net.minecraft.block.state.IBlockState;
8
import net.minecraft.creativetab.CreativeTabs;
9
import net.minecraft.entity.EntityLivingBase;
10
import net.minecraft.entity.player.EntityPlayer;
11
import net.minecraft.init.Blocks;
12
import net.minecraft.util.AxisAlignedBB;
13
import net.minecraft.util.BlockPos;
14
import net.minecraft.util.EnumFacing;
15
import net.minecraft.world.IBlockAccess;
16
import net.minecraft.world.World;
17
18
public class BlockFenceGate extends BlockDirectional
19
{
20
    public static final PropertyBool OPEN = PropertyBool.create("open");
21
    public static final PropertyBool POWERED = PropertyBool.create("powered");
22
    public static final PropertyBool IN_WALL = PropertyBool.create("in_wall");
23
24
    public BlockFenceGate(BlockPlanks.EnumType p_i46394_1_)
25
    {
26
        super(Material.wood, p_i46394_1_.getMapColor());
27
        this.setDefaultState(this.blockState.getBaseState().withProperty(OPEN, Boolean.valueOf(false)).withProperty(POWERED, Boolean.valueOf(false)).withProperty(IN_WALL, Boolean.valueOf(false)));
28
        this.setCreativeTab(CreativeTabs.tabRedstone);
29
    }
30
31
    /**
32
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
33
     * metadata, such as fence connections.
34
     */
35
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
36
    {
37
        EnumFacing.Axis enumfacing$axis = ((EnumFacing)state.getValue(FACING)).getAxis();
38
39
        if (enumfacing$axis == EnumFacing.Axis.Z && (worldIn.getBlockState(pos.west()).getBlock() == Blocks.cobblestone_wall || worldIn.getBlockState(pos.east()).getBlock() == Blocks.cobblestone_wall) || enumfacing$axis == EnumFacing.Axis.X && (worldIn.getBlockState(pos.north()).getBlock() == Blocks.cobblestone_wall || worldIn.getBlockState(pos.south()).getBlock() == Blocks.cobblestone_wall))
40
        {
41
            state = state.withProperty(IN_WALL, Boolean.valueOf(true));
42
        }
43
44
        return state;
45
    }
46
47
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
48
    {
49
        return worldIn.getBlockState(pos.down()).getBlock().getMaterial().isSolid() ? super.canPlaceBlockAt(worldIn, pos) : false;
50
    }
51
52
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
53
    {
54
        if (((Boolean)state.getValue(OPEN)).booleanValue())
55
        {
56
            return null;
57
        }
58
        else
59
        {
60
            EnumFacing.Axis enumfacing$axis = ((EnumFacing)state.getValue(FACING)).getAxis();
61
            return enumfacing$axis == EnumFacing.Axis.Z ? new AxisAlignedBB((double)pos.getX(), (double)pos.getY(), (double)((float)pos.getZ() + 0.375F), (double)(pos.getX() + 1), (double)((float)pos.getY() + 1.5F), (double)((float)pos.getZ() + 0.625F)) : new AxisAlignedBB((double)((float)pos.getX() + 0.375F), (double)pos.getY(), (double)pos.getZ(), (double)((float)pos.getX() + 0.625F), (double)((float)pos.getY() + 1.5F), (double)(pos.getZ() + 1));
62
        }
63
    }
64
65
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
66
    {
67
        EnumFacing.Axis enumfacing$axis = ((EnumFacing)worldIn.getBlockState(pos).getValue(FACING)).getAxis();
68
69
        if (enumfacing$axis == EnumFacing.Axis.Z)
70
        {
71
            this.setBlockBounds(0.0F, 0.0F, 0.375F, 1.0F, 1.0F, 0.625F);
72
        }
73
        else
74
        {
75
            this.setBlockBounds(0.375F, 0.0F, 0.0F, 0.625F, 1.0F, 1.0F);
76
        }
77
    }
78
79
    /**
80
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
81
     */
82
    public boolean isOpaqueCube()
83
    {
84
        return false;
85
    }
86
87
    public boolean isFullCube()
88
    {
89
        return false;
90
    }
91
92
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
93
    {
94
        return ((Boolean)worldIn.getBlockState(pos).getValue(OPEN)).booleanValue();
95
    }
96
97
    /**
98
     * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
99
     * IBlockstate
100
     */
101
    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
102
    {
103
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing()).withProperty(OPEN, Boolean.valueOf(false)).withProperty(POWERED, Boolean.valueOf(false)).withProperty(IN_WALL, Boolean.valueOf(false));
104
    }
105
106
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
107
    {
108
        if (((Boolean)state.getValue(OPEN)).booleanValue())
109
        {
110
            state = state.withProperty(OPEN, Boolean.valueOf(false));
111
            worldIn.setBlockState(pos, state, 2);
112
        }
113
        else
114
        {
115
            EnumFacing enumfacing = EnumFacing.fromAngle((double)playerIn.rotationYaw);
116
117
            if (state.getValue(FACING) == enumfacing.getOpposite())
118
            {
119
                state = state.withProperty(FACING, enumfacing);
120
            }
121
122
            state = state.withProperty(OPEN, Boolean.valueOf(true));
123
            worldIn.setBlockState(pos, state, 2);
124
        }
125
126
        worldIn.playAuxSFXAtEntity(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? 1003 : 1006, pos, 0);
127
        return true;
128
    }
129
130
    /**
131
     * Called when a neighboring block changes.
132
     */
133
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
134
    {
135
        if (!worldIn.isRemote)
136
        {
137
            boolean flag = worldIn.isBlockPowered(pos);
138
139
            if (flag || neighborBlock.canProvidePower())
140
            {
141
                if (flag && !((Boolean)state.getValue(OPEN)).booleanValue() && !((Boolean)state.getValue(POWERED)).booleanValue())
142
                {
143
                    worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(true)).withProperty(POWERED, Boolean.valueOf(true)), 2);
144
                    worldIn.playAuxSFXAtEntity((EntityPlayer)null, 1003, pos, 0);
145
                }
146
                else if (!flag && ((Boolean)state.getValue(OPEN)).booleanValue() && ((Boolean)state.getValue(POWERED)).booleanValue())
147
                {
148
                    worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(false)).withProperty(POWERED, Boolean.valueOf(false)), 2);
149
                    worldIn.playAuxSFXAtEntity((EntityPlayer)null, 1006, pos, 0);
150
                }
151
                else if (flag != ((Boolean)state.getValue(POWERED)).booleanValue())
152
                {
153
                    worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag)), 2);
154
                }
155
            }
156
        }
157
    }
158
159
    public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
160
    {
161
        return true;
162
    }
163
164
    /**
165
     * Convert the given metadata into a BlockState for this Block
166
     */
167
    public IBlockState getStateFromMeta(int meta)
168
    {
169
        return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)).withProperty(OPEN, Boolean.valueOf((meta & 4) != 0)).withProperty(POWERED, Boolean.valueOf((meta & 8) != 0));
170
    }
171
172
    /**
173
     * Convert the BlockState into the correct metadata value
174
     */
175
    public int getMetaFromState(IBlockState state)
176
    {
177
        int i = 0;
178
        i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
179
180
        if (((Boolean)state.getValue(POWERED)).booleanValue())
181
        {
182
            i |= 8;
183
        }
184
185
        if (((Boolean)state.getValue(OPEN)).booleanValue())
186
        {
187
            i |= 4;
188
        }
189
190
        return i;
191
    }
192
193
    protected BlockState createBlockState()
194
    {
195
        return new BlockState(this, new IProperty[] {FACING, OPEN, POWERED, IN_WALL});
196
    }
197
}
198

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