Common code for blocks that require supports
+ using Java 1.8 now, because fuck it. + tables now require support as well
This commit is contained in:
parent
eecce3846b
commit
414118f483
4 changed files with 65 additions and 20 deletions
|
@ -29,6 +29,9 @@ sourceSets {
|
|||
}
|
||||
}
|
||||
|
||||
srcCompat = JavaVersion.VERSION_1_8
|
||||
targetCompat = JavaVersion.VERSION_1_8
|
||||
|
||||
|
||||
minecraft {
|
||||
version = "1.9.4-12.17.0.1962"
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
40
src/java/mmm/utils/I_USupportBlock.java
Normal file
40
src/java/mmm/utils/I_USupportBlock.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
Reference in a new issue