public BlockWoodSlab(WoodMaterial wd) { super(Material.WOOD); this.setSoundType(SoundType.WOOD); this.wood = wd; this.blockHardness = wood.getPlankBlockHardness(); this.blockResistance = wood.getBlastResistance(); this.setHarvestLevel("axe", wood.getRequiredHarvestLevel()); Blocks.FIRE.setFireInfo(this, 5, 20); IBlockState iblockstate = this.blockState.getBaseState(); if (!this.isDouble()) { iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM); } this.setDefaultState(iblockstate.withProperty(VARIANT, BlockWoodSlab.Variant.DEFAULT)); this.useNeighborBrightness = !this.isDouble(); }
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) { BlockPos blockpos = pos; IProperty iproperty = this.singleSlab.getVariantProperty(); Object object = this.singleSlab.getVariant(stack); IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this.singleSlab) { boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP; if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == iblockstate.getValue(iproperty)) { return true; } } pos = pos.offset(side); IBlockState iblockstate1 = worldIn.getBlockState(pos); return iblockstate1.getBlock() == this.singleSlab && object == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos, side, player, stack); }
public BlockRubberSlab() { super(Material.WOOD, MapColor.WOOD); IBlockState iblockstate = this.blockState.getBaseState(); if (!this.isDouble()) { iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM); setRegistryName(new ResourceLocation(TRConstants.MOD_ID, "rubber_slab")); } else { setRegistryName(new ResourceLocation(TRConstants.MOD_ID, "rubber_double_slab")); } setCreativeTab(TechRebornCreativeTab.TECHREBORN); setUnlocalizedName(getRegistryName().toString()); setHarvestLevel("axe", 0); setHardness(2.0F); setResistance(15); setSoundType(SoundType.WOOD); TechReborn.blockModelsToRegister.add(this); this.setDefaultState(iblockstate.withProperty(VARIANT, BlockRubberSlab.Variant.DEFAULT)); }
@Test @SuppressWarnings("unchecked") public void test_getSubtype() throws Exception { ContentBlockSlab content = new ContentBlockSlab(); content.subtypes = new int[] {0, 1, 2, 3, 4, 5, 6, 7}; content.id = "test_getSubtype"; Block block = content.createBlock(); CSBlock<ContentBlockSlab> csblock = (CSBlock<ContentBlockSlab>) block; for (int subtype = 0; subtype < 8; subtype++) { for (BlockSlab.EnumBlockHalf facing : BlockSlabWithSubtypes.HALF.getAllowedValues()) { IBlockState state = block.getDefaultState() .withProperty(BlockSlabWithSubtypes.HALF, facing) .withProperty(BlockHelper.getSubtypeProperty(content.subtypes), EnumSubtype.values()[subtype]); assertEquals(subtype, csblock.getSubtype(state)); } } }
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) { BlockPos blockpos = pos; IProperty<?> iproperty = this.singleSlab.getVariantProperty(); Comparable<?> comparable = this.singleSlab.getTypeForItem(stack); IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this.singleSlab) { boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP; if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && comparable == iblockstate.getValue(iproperty)) { return true; } } pos = pos.offset(side); IBlockState iblockstate1 = worldIn.getBlockState(pos); return iblockstate1.getBlock() == this.singleSlab && comparable == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos, side, player, stack); }
@SideOnly(Side.CLIENT) public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) { BlockPos blockpos = pos; IProperty<?> iproperty = this.singleSlab.getVariantProperty(); Comparable<?> comparable = this.singleSlab.getTypeForItem(stack); IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this.singleSlab) { boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP; if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && comparable == iblockstate.getValue(iproperty)) { return true; } } pos = pos.offset(side); IBlockState iblockstate1 = worldIn.getBlockState(pos); return iblockstate1.getBlock() == this.singleSlab && comparable == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos, side, player, stack); }
public static void placeHut(final World world, BlockPos startpos, int[][][] data, IBlockState[] states, Random rand) { for (int pass = 0; pass <= 1; pass++) { for (int y = 0; y < data.length; y++) { for (int x = 0; x < 6; x++) { for (int z = 0; z < 6; z++) { BlockPos pos = startpos.add(x + 5, -y + 5, z + 5); if (data[y][z][x] != -1) { IBlockState state = states[data[y][z][x]]; if (state == null || (pass == 0 && (state.getBlock() instanceof BlockCarpet || state.getBlock() instanceof BlockSapling))) { world.setBlockToAir(pos); } else if (state.getBlock() instanceof BlockFalling) { while (world.getBlockState(pos).getBlock().isReplaceable(world, pos) && !world.isAirBlock(new BlockPos(pos.getX(), 0, pos.getZ()))) { world.setBlockState(pos, state); world.immediateBlockTick(pos, state, rand); } } else if (!(state.getBlock() instanceof BlockSlab) || (world.getBlockState(pos).getBlock().isReplaceable(world, pos) && world.getBlockState(pos).getMaterial() != Material.WATER)) { world.setBlockState(pos, state); } } } } } } }
@Override public int getMetaFromState(IBlockState state) { if (!this.isDouble()) { if (state.getValue(HALF) == BlockSlab.EnumBlockHalf.BOTTOM) { return 0; } else if (state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP) { return 1; } } return 0; }
@SideOnly(Side.CLIENT) public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) { BlockPos blockpos = pos; IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this.singleSlab) { boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP; if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag)) { return true; } } pos = pos.offset(side); IBlockState iblockstate1 = worldIn.getBlockState(pos); return iblockstate1.getBlock() == this.singleSlab ? true : super.canPlaceBlockOnSide(worldIn, blockpos, side, player, stack); }
public BlockGlassSlab() { super(Material.GLASS); this.setSoundType(SoundType.GLASS); IBlockState iblockstate = this.blockState.getBaseState(); this.setHardness(0.5F); if (!this.isDouble()) { iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM); ModRegistry.setBlockName(this, "block_half_glass_slab"); this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); } else { ModRegistry.setBlockName(this, "block_glass_slab"); } iblockstate = iblockstate.withProperty(VARIANT_PROPERTY, false); this.setDefaultState(iblockstate); this.useNeighborBrightness = !this.isDouble(); }
public BlockGraniteSlab() { super(Material.ROCK); this.setSoundType(SoundType.STONE); IBlockState iblockstate = this.blockState.getBaseState(); this.setHardness(0.5F); if (!this.isDouble()) { iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM); ModRegistry.setBlockName(this, "block_half_granite_slab"); this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); } else { ModRegistry.setBlockName(this, "block_granite_slab"); } iblockstate = iblockstate.withProperty(VARIANT_PROPERTY, false); this.setDefaultState(iblockstate); this.useNeighborBrightness = !this.isDouble(); }
public BlockDioriteSlab() { super(Material.ROCK); this.setSoundType(SoundType.STONE); IBlockState iblockstate = this.blockState.getBaseState(); this.setHardness(0.5F); if (!this.isDouble()) { iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM); ModRegistry.setBlockName(this, "block_half_diorite_slab"); this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); } else { ModRegistry.setBlockName(this, "block_diorite_slab"); } iblockstate = iblockstate.withProperty(VARIANT_PROPERTY, false); this.setDefaultState(iblockstate); this.useNeighborBrightness = !this.isDouble(); }
public BlockAndesiteSlab() { super(Material.ROCK); this.setSoundType(SoundType.STONE); IBlockState iblockstate = this.blockState.getBaseState(); this.setHardness(0.5F); if (!this.isDouble()) { iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM); ModRegistry.setBlockName(this, "block_half_andesite_slab"); this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS); } else { ModRegistry.setBlockName(this, "block_andesite_slab"); } iblockstate = iblockstate.withProperty(VARIANT_PROPERTY, false); this.setDefaultState(iblockstate); this.useNeighborBrightness = !this.isDouble(); }
@Override @SideOnly(Side.CLIENT) public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) { if (block instanceof AlchemyBlockSlab && !((BlockSlab) block).isDouble()) { BlockSlab singleSlab = (BlockSlab) block; BlockPos blockpos = pos; IProperty<?> iproperty = singleSlab.getVariantProperty(); Comparable<?> comparable = singleSlab.getTypeForItem(stack); IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == singleSlab) { boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP; if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && comparable == iblockstate.getValue(iproperty)) return true; } pos = pos.offset(side); IBlockState iblockstate1 = worldIn.getBlockState(pos); return iblockstate1.getBlock() == singleSlab && comparable == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos, side, player, stack); } else return super.canPlaceBlockOnSide(worldIn, pos, side, player, stack); }
private boolean tryPlace(EntityPlayer player, ItemStack stack, World worldIn, BlockPos pos, Object itemSlabType) { if (block instanceof AlchemyBlockSlab && !((BlockSlab) block).isDouble()) { BlockSlab singleSlab = (BlockSlab) block; IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == singleSlab) { Comparable<?> comparable = iblockstate.getValue(singleSlab.getVariantProperty()); if (comparable == itemSlabType) { IBlockState iblockstate1 = makeSlabState(singleSlab.getVariantProperty(), comparable); AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, pos); if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, iblockstate1, 11)) { SoundType soundtype = singleSlab.getSoundType(iblockstate1, worldIn, pos, player); worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); stack.setCount(stack.getCount() - 1); } return true; } } } return false; }
@Override @SideOnly(Side.CLIENT) public boolean canPlaceBlockOnSide(World worldIn, BlockPos p_179222_2_, EnumFacing p_179222_3_, EntityPlayer p_179222_4_, ItemStack p_179222_5_) { BlockPos blockpos1 = p_179222_2_; Object object = this.slab.getVariant(p_179222_5_); IBlockState iblockstate = worldIn.getBlockState(p_179222_2_); if (iblockstate.getBlock() == this.slab) { boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP; if ((p_179222_3_ == EnumFacing.UP && !flag || p_179222_3_ == EnumFacing.DOWN && flag)) { return true; } } p_179222_2_ = p_179222_2_.offset(p_179222_3_); IBlockState iblockstate1 = worldIn.getBlockState(p_179222_2_); return iblockstate1.getBlock() == this.slab || super.canPlaceBlockOnSide(worldIn, blockpos1, p_179222_3_, p_179222_4_, p_179222_5_); }
public static int getMixedBrightnessForBlockWithColor(IBlockAccess blockAccess, int x, int y, int z) { int l; Block block = blockAccess.getBlock(x, y, z); if (blockAccess instanceof World) l = CLWorldHelper.getLightBrightnessForSkyBlocksWithColor((World) blockAccess, x, y, z, block.getLightValue(blockAccess, x, y, z)); else l = CLChunkCacheHelper.getLightBrightnessForSkyBlocksWithColor((ChunkCache) blockAccess, x, y, z, block.getLightValue(blockAccess, x, y, z)); if (l == 0 && block instanceof BlockSlab) { --y; block = blockAccess.getBlock(x, y, z); if (blockAccess instanceof World) return CLWorldHelper.getLightBrightnessForSkyBlocksWithColor((World) blockAccess, x, y, z, block.getLightValue(blockAccess, x, y, z)); else return CLChunkCacheHelper.getLightBrightnessForSkyBlocksWithColor((ChunkCache) blockAccess, x, y, z, block.getLightValue(blockAccess, x, y, z)); } else { return l; } }
@Override @SideOnly(Side.CLIENT) public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack){ BlockPos blockpos1 = pos; IProperty<?> iproperty = singleSlab.getVariantProperty(); Object object = singleSlab.getTypeForItem(stack); IBlockState iblockstate = worldIn.getBlockState(pos); if(iblockstate.getBlock() == singleSlab){ boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP; if((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == iblockstate.getValue(iproperty)) return true; } pos = pos.offset(side); IBlockState iblockstate1 = worldIn.getBlockState(pos); return iblockstate1.getBlock() == singleSlab && object == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos1, side, player, stack); }
@Override @SideOnly(Side.CLIENT) public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack){ BlockPos blockpos1 = pos; IProperty iproperty = singleSlab.getVariantProperty(); Object object = singleSlab.getVariant(stack); IBlockState iblockstate = worldIn.getBlockState(pos); if(iblockstate.getBlock() == singleSlab){ boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP; if((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == iblockstate.getValue(iproperty)) return true; } pos = pos.offset(side); IBlockState iblockstate1 = worldIn.getBlockState(pos); return iblockstate1.getBlock() == singleSlab && object == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos1, side, player, stack); }
public CPCherrySlab() { super(Material.WOOD); IBlockState iblockstate = this.blockState.getBaseState(); if (!this.isDouble()) { iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM); } this.setDefaultState(iblockstate.withProperty(VARIANT, BlockPurpurSlab.Variant.DEFAULT)); this.setHardness(2.0F); this.setResistance(5.0F); this.setSoundType(SoundType.WOOD); this.setCreativeTab(CherryPig.tabCherryPig); }
/** * Returns whether block is a cover. */ public static boolean isCover(ItemStack itemStack) { if (itemStack.getItem() instanceof ItemBlock && !isOverlay(itemStack)) { Block block = toBlock(itemStack); return block.renderAsNormalBlock() || block instanceof BlockSlab || block instanceof BlockPane || block instanceof BlockBreakable || FeatureRegistry.coverExceptions.contains(itemStack.getDisplayName()) || FeatureRegistry.coverExceptions.contains(ChatHandler.getDefaultTranslation(itemStack)); } return false; }
@Override @SideOnly(Side.CLIENT) public List<IBlockState> mapBlockRender(@Nonnull IBlockStateWrapper state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, BlockRenderLayer blockLayer, @Nonnull QuadCollector quadCollector) { for (BlockSlab.EnumBlockHalf half : BlockSlab.EnumBlockHalf.values()) { if (isDouble() || half == state.getValue(HALF)) { boolean isTop = half == BlockSlab.EnumBlockHalf.TOP; IBlockState paintSource = isTop ? getPaintSource2(state, world, pos) : getPaintSource(state, world, pos); if (blockLayer == null || PaintUtil.canRenderInLayer(paintSource, blockLayer)) { quadCollector.addFriendlybakedModel(blockLayer, PaintRegistry.getModel(IBakedModel.class, isTop ? "slab_hi" : "slab_lo", paintSource, null), paintSource, MathHelper.getPositionRandom(pos)); } } } return null; }
@Override @SideOnly(Side.CLIENT) public boolean canPlaceBlockOnSide(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull EnumFacing side, @Nonnull EntityPlayer player, @Nonnull ItemStack stack) { BlockPos blockpos = pos; IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this.singleSlab) { boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP; if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag)) { return true; } } pos = pos.offset(side); IBlockState iblockstate1 = worldIn.getBlockState(pos); return iblockstate1.getBlock() == this.singleSlab ? true : super.canPlaceBlockOnSide(worldIn, blockpos, side, player, stack); }
@Override public @Nonnull EnumActionResult onItemUse(@Nonnull EntityPlayer playerIn, @Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull EnumHand hand, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack stack = playerIn.getHeldItem(hand); if (!playerIn.canPlayerEdit(pos.offset(side), side, stack)) { return EnumActionResult.FAIL; } else { IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this.singleSlab) { BlockSlab.EnumBlockHalf blockslab$enumblockhalf = iblockstate.getValue(BlockSlab.HALF); if ((side == EnumFacing.UP && blockslab$enumblockhalf == BlockSlab.EnumBlockHalf.BOTTOM || side == EnumFacing.DOWN && blockslab$enumblockhalf == BlockSlab.EnumBlockHalf.TOP)) { tryPlace(stack, worldIn, pos); return EnumActionResult.SUCCESS; } } return this.tryPlace(stack, worldIn, pos.offset(side)) ? EnumActionResult.SUCCESS : super.onItemUse(playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ); } }