From 414118f483444fcebfb71db5af61c157d63c6f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Tue, 14 Jun 2016 17:36:26 +0200 Subject: [PATCH] Common code for blocks that require supports + using Java 1.8 now, because fuck it. + tables now require support as well --- build.gradle | 3 ++ src/java/mmm/deco/DBlockChair.java | 22 ++------------ src/java/mmm/deco/DBlockTable.java | 20 ++++++++++++- src/java/mmm/utils/I_USupportBlock.java | 40 +++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 20 deletions(-) create mode 100644 src/java/mmm/utils/I_USupportBlock.java diff --git a/build.gradle b/build.gradle index b98fafc..ec7edb5 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,9 @@ sourceSets { } } +srcCompat = JavaVersion.VERSION_1_8 +targetCompat = JavaVersion.VERSION_1_8 + minecraft { version = "1.9.4-12.17.0.1962" diff --git a/src/java/mmm/deco/DBlockChair.java b/src/java/mmm/deco/DBlockChair.java index 3169084..13b516e 100644 --- a/src/java/mmm/deco/DBlockChair.java +++ b/src/java/mmm/deco/DBlockChair.java @@ -5,6 +5,7 @@ import java.util.List; import mmm.utils.I_UBlockSeat; import mmm.utils.I_URecipeRegistrar; +import mmm.utils.I_USupportBlock; import mmm.utils.UMaths; import mmm.utils.URegistry; import mmm.utils.USeat; @@ -21,7 +22,6 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockRenderLayer; @@ -218,29 +218,13 @@ public class DBlockChair public void neighborChanged( final IBlockState state , final World worldIn , final BlockPos pos , final Block blockIn ) { - if ( !this.checkSupportBlock( worldIn , pos ) ) { - this.dropBlockAsItem( worldIn , pos , state , 0 ); - worldIn.setBlockToAir( pos ); - } + I_USupportBlock.dropIfUnsupported( state , worldIn , pos , this ); } @Override public boolean canPlaceBlockAt( final World worldIn , final BlockPos pos ) { - return super.canPlaceBlockAt( worldIn , pos ) && this.checkSupportBlock( worldIn , pos ); - } - - - private boolean checkSupportBlock( final IBlockAccess worldIn , final BlockPos pos ) - { - final BlockPos down = pos.down( ); - final IBlockState downState = worldIn.getBlockState( down ); - if ( downState.isSideSolid( worldIn , down , EnumFacing.UP ) ) { - return true; - } - - final Block downBlock = downState.getBlock( ); - return downBlock == Blocks.GLASS || downBlock == Blocks.STAINED_GLASS; + return super.canPlaceBlockAt( worldIn , pos ) && I_USupportBlock.check( worldIn , pos ); } } diff --git a/src/java/mmm/deco/DBlockTable.java b/src/java/mmm/deco/DBlockTable.java index 9ee20c2..1ffdc1c 100644 --- a/src/java/mmm/deco/DBlockTable.java +++ b/src/java/mmm/deco/DBlockTable.java @@ -4,6 +4,7 @@ package mmm.deco; import java.util.List; import mmm.utils.I_URecipeRegistrar; +import mmm.utils.I_USupportBlock; import mmm.utils.UMaths; import mmm.utils.URegistry; import net.minecraft.block.Block; @@ -266,8 +267,25 @@ public class DBlockTable @Override - public boolean isSideSolid( IBlockState base_state , IBlockAccess world , BlockPos pos , EnumFacing side ) + public boolean isSideSolid( final IBlockState base_state , final IBlockAccess world , final BlockPos pos , + final EnumFacing side ) { return side == EnumFacing.UP; } + + + @Override + public void neighborChanged( final IBlockState state , final World worldIn , final BlockPos pos , + final Block blockIn ) + { + I_USupportBlock.dropIfUnsupported( state , worldIn , pos , this ); + } + + + @Override + public boolean canPlaceBlockAt( final World worldIn , final BlockPos pos ) + { + return super.canPlaceBlockAt( worldIn , pos ) && I_USupportBlock.check( worldIn , pos ); + } + } diff --git a/src/java/mmm/utils/I_USupportBlock.java b/src/java/mmm/utils/I_USupportBlock.java new file mode 100644 index 0000000..000cbd8 --- /dev/null +++ b/src/java/mmm/utils/I_USupportBlock.java @@ -0,0 +1,40 @@ +package mmm.utils; + + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + + + +public interface I_USupportBlock +{ + + public static boolean check( final IBlockAccess worldIn , final BlockPos pos ) + { + final BlockPos down = pos.down( ); + final IBlockState downState = worldIn.getBlockState( down ); + if ( downState.isSideSolid( worldIn , down , EnumFacing.UP ) ) { + return true; + } + + final Block downBlock = downState.getBlock( ); + return downBlock == Blocks.GLASS || downBlock == Blocks.STAINED_GLASS || downBlock instanceof I_USupportBlock; + } + + + public static boolean dropIfUnsupported( final IBlockState state , final World worldIn , final BlockPos pos , + final Block block ) + { + final boolean rv = !I_USupportBlock.check( worldIn , pos ); + if ( rv ) { + block.dropBlockAsItem( worldIn , pos , state , 0 ); + worldIn.setBlockToAir( pos ); + } + return rv; + } +}