source-code/src/main/java/net/minecraft/block/BlockLadder.java
eaglercraft 573420e1b8 u24
2024-03-02 22:18:18 -08:00

161 lines
No EOL
5.9 KiB
Java
Executable file

package net.minecraft.block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
/**+
* This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code.
*
* Minecraft 1.8.8 bytecode is (c) 2015 Mojang AB. "Do not distribute!"
* Mod Coder Pack v9.18 deobfuscation configs are (c) Copyright by the MCP Team
*
* EaglercraftX 1.8 patch files (c) 2022-2024 lax1dude, ayunami2000. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
public class BlockLadder extends Block {
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
protected BlockLadder() {
super(Material.circuits);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
this.setCreativeTab(CreativeTabs.tabDecorations);
}
public AxisAlignedBB getCollisionBoundingBox(World world, BlockPos blockpos, IBlockState iblockstate) {
this.setBlockBoundsBasedOnState(world, blockpos);
return super.getCollisionBoundingBox(world, blockpos, iblockstate);
}
public AxisAlignedBB getSelectedBoundingBox(World world, BlockPos blockpos) {
this.setBlockBoundsBasedOnState(world, blockpos);
return super.getSelectedBoundingBox(world, blockpos);
}
public void setBlockBoundsBasedOnState(IBlockAccess iblockaccess, BlockPos blockpos) {
IBlockState iblockstate = iblockaccess.getBlockState(blockpos);
if (iblockstate.getBlock() == this) {
float f = 0.125F;
switch ((EnumFacing) iblockstate.getValue(FACING)) {
case NORTH:
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
break;
case SOUTH:
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
break;
case WEST:
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case EAST:
default:
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}
}
}
/**+
* Used to determine ambient occlusion and culling when
* rebuilding chunks for render
*/
public boolean isOpaqueCube() {
return false;
}
public boolean isFullCube() {
return false;
}
public boolean canPlaceBlockAt(World world, BlockPos blockpos) {
return world.getBlockState(blockpos.west()).getBlock().isNormalCube() ? true
: (world.getBlockState(blockpos.east()).getBlock().isNormalCube() ? true
: (world.getBlockState(blockpos.north()).getBlock().isNormalCube() ? true
: world.getBlockState(blockpos.south()).getBlock().isNormalCube()));
}
/**+
* Called by ItemBlocks just before a block is actually set in
* the world, to allow for adjustments to the IBlockstate
*/
public IBlockState onBlockPlaced(World world, BlockPos blockpos, EnumFacing enumfacing, float var4, float var5,
float var6, int var7, EntityLivingBase var8) {
if (enumfacing.getAxis().isHorizontal() && this.canBlockStay(world, blockpos, enumfacing)) {
return this.getDefaultState().withProperty(FACING, enumfacing);
} else {
EnumFacing[] facings = EnumFacing.Plane.HORIZONTAL.facingsArray;
for (int i = 0; i < facings.length; ++i) {
EnumFacing enumfacing1 = facings[i];
if (this.canBlockStay(world, blockpos, enumfacing1)) {
return this.getDefaultState().withProperty(FACING, enumfacing1);
}
}
return this.getDefaultState();
}
}
/**+
* Called when a neighboring block changes.
*/
public void onNeighborBlockChange(World world, BlockPos blockpos, IBlockState iblockstate, Block block) {
EnumFacing enumfacing = (EnumFacing) iblockstate.getValue(FACING);
if (!this.canBlockStay(world, blockpos, enumfacing)) {
this.dropBlockAsItem(world, blockpos, iblockstate, 0);
world.setBlockToAir(blockpos);
}
super.onNeighborBlockChange(world, blockpos, iblockstate, block);
}
protected boolean canBlockStay(World worldIn, BlockPos pos, EnumFacing facing) {
return worldIn.getBlockState(pos.offset(facing.getOpposite())).getBlock().isNormalCube();
}
public EnumWorldBlockLayer getBlockLayer() {
return EnumWorldBlockLayer.CUTOUT;
}
/**+
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int i) {
EnumFacing enumfacing = EnumFacing.getFront(i);
if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
enumfacing = EnumFacing.NORTH;
}
return this.getDefaultState().withProperty(FACING, enumfacing);
}
/**+
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState iblockstate) {
return ((EnumFacing) iblockstate.getValue(FACING)).getIndex();
}
protected BlockState createBlockState() {
return new BlockState(this, new IProperty[] { FACING });
}
}