Thrones - Fuck states, use different blocktypes.

This commit is contained in:
Emmanuel BENOîT 2016-07-05 15:54:39 +02:00
parent 805f041a4a
commit ba3de96d04
5 changed files with 125 additions and 91 deletions

View file

@ -0,0 +1,21 @@
package mmm.deco;
import mmm.utils.URegistry;
public class DThrone
{
public final DThroneBlock TOP;
public final DThroneBlock BOTTOM;
public DThrone( E_DWoodType woodType )
{
URegistry.addBlock( this.BOTTOM = new DThroneBlock( this , woodType , false ) );
URegistry.addBlock( this.TOP = new DThroneBlock( this , woodType , true ) , null );
}
}

View file

@ -2,13 +2,13 @@ package mmm.deco;
import java.util.List; import java.util.List;
import java.util.Random;
import mmm.utils.I_UBlockSeat; import mmm.utils.I_UBlockSeat;
import mmm.utils.I_UColoredBlock; import mmm.utils.I_UColoredBlock;
import mmm.utils.I_URecipeRegistrar; import mmm.utils.I_URecipeRegistrar;
import mmm.utils.I_USupportBlock; import mmm.utils.I_USupportBlock;
import mmm.utils.UMaths; import mmm.utils.UMaths;
import mmm.utils.URegistry;
import mmm.utils.USeat; import mmm.utils.USeat;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal; import net.minecraft.block.BlockHorizontal;
@ -16,7 +16,6 @@ import net.minecraft.block.SoundType;
import net.minecraft.block.material.EnumPushReaction; import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
@ -50,7 +49,6 @@ public class DThroneBlock
{ {
public static final PropertyDirection FACING; public static final PropertyDirection FACING;
public static final PropertyBool IS_TOP;
public static final PropertyEnum< EnumDyeColor > COLOR; public static final PropertyEnum< EnumDyeColor > COLOR;
private static final AxisAlignedBB COLLISION_TOP_NORTH = UMaths.makeBlockAABB( 0 , 0 , 0 , 16 , 13 , 3 ); private static final AxisAlignedBB COLLISION_TOP_NORTH = UMaths.makeBlockAABB( 0 , 0 , 0 , 16 , 13 , 3 );
@ -62,25 +60,32 @@ public class DThroneBlock
static { static {
FACING = BlockHorizontal.FACING; FACING = BlockHorizontal.FACING;
IS_TOP = PropertyBool.create( "is_top" );
COLOR = PropertyEnum.< EnumDyeColor > create( "color" , EnumDyeColor.class ); COLOR = PropertyEnum.< EnumDyeColor > create( "color" , EnumDyeColor.class );
} }
public final E_DWoodType woodType; public final E_DWoodType woodType;
public final DThrone parts;
public final boolean isTop;
public DThroneBlock( final E_DWoodType woodType ) public DThroneBlock( final DThrone throne , final E_DWoodType woodType , final boolean isTop )
{ {
super( Material.WOOD ); super( Material.WOOD );
this.woodType = woodType; this.woodType = woodType;
this.parts = throne;
this.isTop = isTop;
this.setCreativeTab( CreativeTabs.DECORATIONS ); this.setCreativeTab( CreativeTabs.DECORATIONS );
URegistry.setIdentifiers( this , "deco" , "throne" , woodType.suffix ); this.setRegistryName( "mmm:deco/throne/" + woodType.suffix + "/" + ( isTop ? "top" : "bottom" ) );
this.setUnlocalizedName( "mmm.deco.throne." + woodType.suffix );
if ( this.isTop ) {
this.setDefaultState( this.blockState.getBaseState( ) //
.withProperty( DThroneBlock.FACING , EnumFacing.NORTH ) );
} else {
this.setDefaultState( this.blockState.getBaseState( ) // this.setDefaultState( this.blockState.getBaseState( ) //
.withProperty( DThroneBlock.FACING , EnumFacing.NORTH ) //
.withProperty( DThroneBlock.IS_TOP , false ) //
.withProperty( DThroneBlock.COLOR , EnumDyeColor.WHITE ) ); .withProperty( DThroneBlock.COLOR , EnumDyeColor.WHITE ) );
}
this.lightOpacity = 0; this.lightOpacity = 0;
this.translucent = false; this.translucent = false;
@ -123,22 +128,22 @@ public class DThroneBlock
@Override @Override
public AxisAlignedBB getBoundingBox( final IBlockState state , final IBlockAccess source , final BlockPos pos ) public AxisAlignedBB getBoundingBox( final IBlockState state , final IBlockAccess source , final BlockPos pos )
{ {
if ( state.getValue( IS_TOP )) { if ( this.isTop ) {
switch ( state.getValue( DChair.FACING ) ) { switch ( state.getValue( DChair.FACING ) ) {
case EAST: case EAST:
return COLLISION_TOP_EAST; return DThroneBlock.COLLISION_TOP_EAST;
case NORTH: case NORTH:
return COLLISION_TOP_NORTH; return DThroneBlock.COLLISION_TOP_NORTH;
case SOUTH: case SOUTH:
return COLLISION_TOP_SOUTH; return DThroneBlock.COLLISION_TOP_SOUTH;
case WEST: case WEST:
return COLLISION_TOP_WEST; return DThroneBlock.COLLISION_TOP_WEST;
default: default:
// TODO log problem // TODO log problem
return FULL_BLOCK_AABB; return Block.FULL_BLOCK_AABB;
} }
} }
return FULL_BLOCK_AABB; return Block.FULL_BLOCK_AABB;
} }
@ -150,7 +155,7 @@ public class DThroneBlock
protected BlockStateContainer createBlockState( ) protected BlockStateContainer createBlockState( )
{ {
return new BlockStateContainer( this , new IProperty[] { return new BlockStateContainer( this , new IProperty[] {
DThroneBlock.FACING , DThroneBlock.IS_TOP , DThroneBlock.COLOR DThroneBlock.FACING , DThroneBlock.COLOR
} ); } );
} }
@ -158,13 +163,11 @@ public class DThroneBlock
@Override @Override
public IBlockState getStateFromMeta( final int meta ) public IBlockState getStateFromMeta( final int meta )
{ {
final boolean isTop = ( meta & 1 ) == 1; IBlockState bs = this.blockState.getBaseState( );
IBlockState bs = this.getDefaultState( ).withProperty( DThroneBlock.IS_TOP , isTop ); if ( this.isTop ) {
if ( isTop ) { bs = bs.withProperty( DThroneBlock.FACING , EnumFacing.getHorizontal( meta ) );
bs = bs.withProperty( DThroneBlock.COLOR , EnumDyeColor.byMetadata( meta >> 1 ) );
} else { } else {
bs = bs.withProperty( DThroneBlock.COLOR , EnumDyeColor.byMetadata( meta >> 1 & 1 ) ) // bs = bs.withProperty( DThroneBlock.COLOR , EnumDyeColor.byMetadata( meta ) );
.withProperty( DThroneBlock.FACING , EnumFacing.getHorizontal( meta >> 2 ) );
} }
return bs; return bs;
} }
@ -173,44 +176,29 @@ public class DThroneBlock
@Override @Override
public int getMetaFromState( final IBlockState state ) public int getMetaFromState( final IBlockState state )
{ {
final boolean isTop = state.getValue( DThroneBlock.IS_TOP ); if ( this.isTop ) {
int meta = isTop ? 1 : 0; return state.getValue( DThroneBlock.FACING ).getHorizontalIndex( );
if ( isTop ) {
meta |= ( state.getValue( DThroneBlock.COLOR ).getMetadata( ) & 0x07 ) << 1;
} else { } else {
meta |= ( state.getValue( DThroneBlock.COLOR ).getMetadata( ) & 0x01 ) << 1 // return state.getValue( DThroneBlock.COLOR ).getMetadata( );
| state.getValue( DThroneBlock.FACING ).getHorizontalIndex( ) << 2 //
;
} }
return meta;
} }
@Override @Override
public IBlockState getActualState( final IBlockState state , final IBlockAccess worldIn , final BlockPos pos ) public IBlockState getActualState( final IBlockState state , final IBlockAccess worldIn , final BlockPos pos )
{ {
final boolean isTop = state.getValue( DThroneBlock.IS_TOP ); if ( this.isTop ) {
final IBlockState bottom = worldIn.getBlockState( pos.down( ) );
final IBlockState top; if ( bottom.getBlock( ) instanceof DThroneBlock ) {
final IBlockState bottom; return state.withProperty( DThroneBlock.COLOR , bottom.getValue( DThroneBlock.COLOR ) );
if ( isTop ) { }
top = state;
bottom = worldIn.getBlockState( pos.down( ) );
} else { } else {
top = worldIn.getBlockState( pos.up( ) ); final IBlockState top = worldIn.getBlockState( pos.up( ) );
bottom = state; if ( top.getBlock( ) instanceof DThroneBlock ) {
return state.withProperty( DThroneBlock.FACING , top.getValue( DThroneBlock.FACING ) );
} }
if ( top.getBlock( ) != this || bottom.getBlock( ) != this ) {
return this.getDefaultState( );
} }
return state;
final EnumDyeColor cTop = top.getValue( DThroneBlock.COLOR );
final EnumDyeColor cBottom = bottom.getValue( DThroneBlock.COLOR );
final EnumDyeColor color = EnumDyeColor.byMetadata( cBottom.getMetadata( ) << 3 | cTop.getMetadata( ) );
final EnumFacing facing = bottom.getValue( DThroneBlock.FACING );
return state.withProperty( DThroneBlock.FACING , facing )//
.withProperty( DThroneBlock.COLOR , color );
} }
@ -230,17 +218,16 @@ public class DThroneBlock
public void onBlockPlacedBy( final World worldIn , final BlockPos pos , final IBlockState state , public void onBlockPlacedBy( final World worldIn , final BlockPos pos , final IBlockState state ,
final EntityLivingBase placer , final ItemStack stack ) final EntityLivingBase placer , final ItemStack stack )
{ {
if ( this.isTop ) {
return;
}
final int dmg = stack.getItemDamage( ); final int dmg = stack.getItemDamage( );
final EnumDyeColor color = EnumDyeColor.byMetadata( dmg ); final EnumDyeColor color = EnumDyeColor.byMetadata( dmg );
final EnumDyeColor topColor = EnumDyeColor.byMetadata( color.getMetadata( ) & 7 );
final EnumDyeColor bottomColor = EnumDyeColor.byMetadata( color.getMetadata( ) >> 3 );
final IBlockState nState = this.getDefaultState( ) // worldIn.setBlockState( pos , state.withProperty( DThroneBlock.COLOR , color ) , 6 );
.withProperty( DThroneBlock.FACING , placer.getHorizontalFacing( ) );
worldIn.setBlockState( pos , nState.withProperty( DThroneBlock.COLOR , bottomColor ) , 6 );
worldIn.setBlockState( pos.up( ) , // worldIn.setBlockState( pos.up( ) , //
nState.withProperty( DThroneBlock.IS_TOP , true ) // this.parts.TOP.getDefaultState( ).withProperty( DThroneBlock.FACING , placer.getHorizontalFacing( ) ) ,
.withProperty( DThroneBlock.COLOR , topColor ) ,
6 ); 6 );
} }
@ -249,11 +236,17 @@ public class DThroneBlock
// BLOCK REMOVAL AND PICKING // BLOCK REMOVAL AND PICKING
// ************************************************************************************************* // *************************************************************************************************
public Item getItemDropped( IBlockState state , Random rand , int fortune )
{
return Item.getItemFromBlock( this.parts.BOTTOM );
}
@Override @Override
public ItemStack getPickBlock( final IBlockState state , final RayTraceResult target , final World world , public ItemStack getPickBlock( final IBlockState state , final RayTraceResult target , final World world ,
final BlockPos pos , final EntityPlayer player ) final BlockPos pos , final EntityPlayer player )
{ {
final Item item = Item.getItemFromBlock( this ); final Item item = Item.getItemFromBlock( this.parts.BOTTOM );
return item == null return item == null
? null ? null
: new ItemStack( item , 1 , this.damageDropped( state.getActualState( world , pos ) ) ); : new ItemStack( item , 1 , this.damageDropped( state.getActualState( world , pos ) ) );
@ -280,11 +273,6 @@ public class DThroneBlock
if ( !worldIn.isRemote && !worldIn.restoringBlockSnapshots ) { if ( !worldIn.isRemote && !worldIn.restoringBlockSnapshots ) {
super.dropBlockAsItemWithChance( worldIn , pos , state , chance , fortune ); super.dropBlockAsItemWithChance( worldIn , pos , state , chance , fortune );
this.removeOtherBlock( state , worldIn , pos ); this.removeOtherBlock( state , worldIn , pos );
try {
throw new RuntimeException( "fart fart fart " + pos );
} catch ( final RuntimeException e ) {
e.printStackTrace( );
}
} }
} }
@ -301,9 +289,9 @@ public class DThroneBlock
private void removeOtherBlock( final IBlockState state , final World world , final BlockPos pos ) private void removeOtherBlock( final IBlockState state , final World world , final BlockPos pos )
{ {
DThroneBlock.dropping = true; DThroneBlock.dropping = true;
final boolean isTop = state.getValue( DThroneBlock.IS_TOP ); final BlockPos otherPos = this.isTop ? pos.down( ) : pos.up( );
final BlockPos otherPos = isTop ? pos.down( ) : pos.up( ); Block otherBlock = world.getBlockState( otherPos ).getBlock( );
if ( world.getBlockState( otherPos ).getBlock( ) == this ) { if ( otherBlock instanceof DThroneBlock && ( (DThroneBlock) otherBlock ).isTop == !this.isTop ) {
world.setBlockToAir( otherPos ); world.setBlockToAir( otherPos );
} }
DThroneBlock.dropping = false; DThroneBlock.dropping = false;
@ -333,7 +321,7 @@ public class DThroneBlock
public void neighborChanged( final IBlockState state , final World worldIn , final BlockPos pos , public void neighborChanged( final IBlockState state , final World worldIn , final BlockPos pos ,
final Block blockIn ) final Block blockIn )
{ {
if ( ! ( state.getValue( DThroneBlock.IS_TOP ) || DThroneBlock.dropping ) ) { if ( ! ( this.isTop || DThroneBlock.dropping ) ) {
I_USupportBlock.dropIfUnsupported( state , worldIn , pos , this ); I_USupportBlock.dropIfUnsupported( state , worldIn , pos , this );
} }
} }
@ -356,7 +344,7 @@ public class DThroneBlock
final float hitX , final float hitY , final float hitZ ) final float hitX , final float hitY , final float hitZ )
{ {
BlockPos p; BlockPos p;
if ( state.getValue( DThroneBlock.IS_TOP ) ) { if ( this.isTop ) {
p = pos.down( ); p = pos.down( );
} else { } else {
p = pos; p = pos;
@ -382,7 +370,7 @@ public class DThroneBlock
@Override @Override
public void registerRecipes( ) public void registerRecipes( )
{ {
for ( EnumDyeColor dyeColor : EnumDyeColor.values( ) ) { for ( final EnumDyeColor dyeColor : EnumDyeColor.values( ) ) {
GameRegistry.addShapedRecipe( new ItemStack( this , 1 , dyeColor.getMetadata( ) ) , // GameRegistry.addShapedRecipe( new ItemStack( this , 1 , dyeColor.getMetadata( ) ) , //
" E " , // " E " , //
"GWG" , // "GWG" , //

View file

@ -58,8 +58,7 @@ public class DecorativeBlocks
URegistry.addBlock( CHAIR_ACACIA = new DChair( E_DWoodType.ACACIA ) ); URegistry.addBlock( CHAIR_ACACIA = new DChair( E_DWoodType.ACACIA ) );
// XXX FIXME LOL TEST!!!! // XXX FIXME LOL TEST!!!!
final DThroneBlock tb = new DThroneBlock( E_DWoodType.OAK ); new DThrone( E_DWoodType.OAK );
URegistry.addBlock( tb );
} }

View file

@ -1,27 +1,14 @@
{ {
"forge_marker": 1 , "forge_marker": 1 ,
"defaults" : { "defaults" : {
"textures": {
"wood": "mmm:blocks/deco/throne/oak/wood"
}
} ,
"variants" : {
"is_top" : {
"true" : {
"model": "mmm:deco/throne/top" ,
"textures" : {
"front" : "mmm:blocks/deco/throne/oak/front-top"
}
} ,
"false" : {
"model": "mmm:deco/throne/bottom" , "model": "mmm:deco/throne/bottom" ,
"textures": { "textures": {
"wood": "mmm:blocks/deco/throne/oak/wood" ,
"front" : "mmm:blocks/deco/throne/oak/front-bottom" , "front" : "mmm:blocks/deco/throne/oak/front-bottom" ,
"top" : "mmm:blocks/deco/throne/oak/bottom" "top" : "mmm:blocks/deco/throne/oak/bottom"
} }
}
} , } ,
"variants" : {
"facing" : { "facing" : {
"north" : { "y": 0 } , "north" : { "y": 0 } ,

View file

@ -0,0 +1,39 @@
{
"forge_marker": 1 ,
"defaults" : {
"model": "mmm:deco/throne/top" ,
"textures": {
"wood": "mmm:blocks/deco/throne/oak/wood" ,
"front" : "mmm:blocks/deco/throne/oak/front-top"
}
} ,
"variants" : {
"facing" : {
"north" : { "y": 0 } ,
"east" : { "y": 90 } ,
"south" : { "y": 180 } ,
"west" : { "y": 270 }
} ,
"color" : {
"black" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_black" } } ,
"blue" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_blue" } } ,
"brown" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_brown" } } ,
"cyan" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_cyan" } } ,
"gray" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_gray" } } ,
"green" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_green" } } ,
"light_blue" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_light_blue" } } ,
"lime" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_lime" } } ,
"magenta" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_magenta" } } ,
"orange" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_orange" } } ,
"pink" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_pink" } } ,
"purple" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_purple" } } ,
"red" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_red" } } ,
"silver" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_silver" } } ,
"white" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_white" } } ,
"yellow" : { "textures" : { "wool" : "minecraft:blocks/wool_colored_yellow" } }
}
}
}