| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import java.util.Random;
|
| 5 | import net.minecraft.block.material.Material;
|
| 6 | import net.minecraft.block.properties.IProperty;
|
| 7 | import net.minecraft.block.properties.PropertyEnum;
|
| 8 | import net.minecraft.block.state.IBlockState;
|
| 9 | import net.minecraft.entity.Entity;
|
| 10 | import net.minecraft.entity.EntityLivingBase;
|
| 11 | import net.minecraft.init.Blocks;
|
| 12 | import net.minecraft.item.ItemStack;
|
| 13 | import net.minecraft.util.AxisAlignedBB;
|
| 14 | import net.minecraft.util.BlockPos;
|
| 15 | import net.minecraft.util.EnumFacing;
|
| 16 | import net.minecraft.util.IStringSerializable;
|
| 17 | import net.minecraft.world.IBlockAccess;
|
| 18 | import net.minecraft.world.World;
|
| 19 |
|
| 20 | public abstract class BlockSlab extends Block
|
| 21 | {
|
| 22 | public static final PropertyEnum<BlockSlab.EnumBlockHalf> HALF = PropertyEnum.<BlockSlab.EnumBlockHalf>create("half", BlockSlab.EnumBlockHalf.class);
|
| 23 |
|
| 24 | public BlockSlab(Material materialIn)
|
| 25 | {
|
| 26 | super(materialIn);
|
| 27 |
|
| 28 | if (this.isDouble())
|
| 29 | {
|
| 30 | this.fullBlock = true;
|
| 31 | }
|
| 32 | else
|
| 33 | {
|
| 34 | this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
|
| 35 | }
|
| 36 |
|
| 37 | this.setLightOpacity(255);
|
| 38 | }
|
| 39 |
|
| 40 | protected boolean canSilkHarvest()
|
| 41 | {
|
| 42 | return false;
|
| 43 | }
|
| 44 |
|
| 45 | public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
|
| 46 | {
|
| 47 | if (this.isDouble())
|
| 48 | {
|
| 49 | this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
| 50 | }
|
| 51 | else
|
| 52 | {
|
| 53 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 54 |
|
| 55 | if (iblockstate.getBlock() == this)
|
| 56 | {
|
| 57 | if (iblockstate.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
|
| 58 | {
|
| 59 | this.setBlockBounds(0.0F, 0.5F, 0.0F, 1.0F, 1.0F, 1.0F);
|
| 60 | }
|
| 61 | else
|
| 62 | {
|
| 63 | this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
|
| 64 | }
|
| 65 | }
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | /**
|
| 70 | * Sets the block's bounds for rendering it as an item
|
| 71 | */
|
| 72 | public void setBlockBoundsForItemRender()
|
| 73 | {
|
| 74 | if (this.isDouble())
|
| 75 | {
|
| 76 | this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
|
| 77 | }
|
| 78 | else
|
| 79 | {
|
| 80 | this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
|
| 81 | }
|
| 82 | }
|
| 83 |
|
| 84 | /**
|
| 85 | * Add all collision boxes of this Block to the list that intersect with the given mask.
|
| 86 | */
|
| 87 | public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity)
|
| 88 | {
|
| 89 | this.setBlockBoundsBasedOnState(worldIn, pos);
|
| 90 | super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
|
| 91 | }
|
| 92 |
|
| 93 | /**
|
| 94 | * Used to determine ambient occlusion and culling when rebuilding chunks for render
|
| 95 | */
|
| 96 | public boolean isOpaqueCube()
|
| 97 | {
|
| 98 | return this.isDouble();
|
| 99 | }
|
| 100 |
|
| 101 | /**
|
| 102 | * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
|
| 103 | * IBlockstate
|
| 104 | */
|
| 105 | public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
| 106 | {
|
| 107 | IBlockState iblockstate = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
|
| 108 | return this.isDouble() ? iblockstate : (facing != EnumFacing.DOWN && (facing == EnumFacing.UP || (double)hitY <= 0.5D) ? iblockstate : iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.TOP));
|
| 109 | }
|
| 110 |
|
| 111 | /**
|
| 112 | * Returns the quantity of items to drop on block destruction.
|
| 113 | */
|
| 114 | public int quantityDropped(Random random)
|
| 115 | {
|
| 116 | return this.isDouble() ? 2 : 1;
|
| 117 | }
|
| 118 |
|
| 119 | public boolean isFullCube()
|
| 120 | {
|
| 121 | return this.isDouble();
|
| 122 | }
|
| 123 |
|
| 124 | public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
|
| 125 | {
|
| 126 | if (this.isDouble())
|
| 127 | {
|
| 128 | return super.shouldSideBeRendered(worldIn, pos, side);
|
| 129 | }
|
| 130 | else if (side != EnumFacing.UP && side != EnumFacing.DOWN && !super.shouldSideBeRendered(worldIn, pos, side))
|
| 131 | {
|
| 132 | return false;
|
| 133 | }
|
| 134 | else
|
| 135 | {
|
| 136 | BlockPos blockpos = pos.offset(side.getOpposite());
|
| 137 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 138 | IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
|
| 139 | boolean flag = isSlab(iblockstate.getBlock()) && iblockstate.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP;
|
| 140 | boolean flag1 = isSlab(iblockstate1.getBlock()) && iblockstate1.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP;
|
| 141 | return flag1 ? (side == EnumFacing.DOWN ? true : (side == EnumFacing.UP && super.shouldSideBeRendered(worldIn, pos, side) ? true : !isSlab(iblockstate.getBlock()) || !flag)) : (side == EnumFacing.UP ? true : (side == EnumFacing.DOWN && super.shouldSideBeRendered(worldIn, pos, side) ? true : !isSlab(iblockstate.getBlock()) || flag));
|
| 142 | }
|
| 143 | }
|
| 144 |
|
| 145 | protected static boolean isSlab(Block blockIn)
|
| 146 | {
|
| 147 | return blockIn == Blocks.stone_slab || blockIn == Blocks.wooden_slab || blockIn == Blocks.stone_slab2;
|
| 148 | }
|
| 149 |
|
| 150 | /**
|
| 151 | * Returns the slab block name with the type associated with it
|
| 152 | */
|
| 153 | public abstract String getUnlocalizedName(int meta);
|
| 154 |
|
| 155 | /**
|
| 156 | * Gets the meta to use for the Pick Block ItemStack result
|
| 157 | */
|
| 158 | public int getDamageValue(World worldIn, BlockPos pos)
|
| 159 | {
|
| 160 | return super.getDamageValue(worldIn, pos) & 7;
|
| 161 | }
|
| 162 |
|
| 163 | public abstract boolean isDouble();
|
| 164 |
|
| 165 | public abstract IProperty<?> getVariantProperty();
|
| 166 |
|
| 167 | public abstract Object getVariant(ItemStack stack);
|
| 168 |
|
| 169 | public static enum EnumBlockHalf implements IStringSerializable
|
| 170 | {
|
| 171 | TOP("top"),
|
| 172 | BOTTOM("bottom");
|
| 173 |
|
| 174 | private final String name;
|
| 175 |
|
| 176 | private EnumBlockHalf(String name)
|
| 177 | {
|
| 178 | this.name = name;
|
| 179 | }
|
| 180 |
|
| 181 | public String toString()
|
| 182 | {
|
| 183 | return this.name;
|
| 184 | }
|
| 185 |
|
| 186 | public String getName()
|
| 187 | {
|
| 188 | return this.name;
|
| 189 | }
|
| 190 | }
|
| 191 | }
|
| 192 |
|