Thrones - Fuck states, use different blocktypes.
This commit is contained in:
parent
805f041a4a
commit
ba3de96d04
5 changed files with 125 additions and 91 deletions
21
src/java/mmm/deco/DThrone.java
Normal file
21
src/java/mmm/deco/DThrone.java
Normal 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 );
|
||||
}
|
||||
|
||||
}
|
|
@ -2,13 +2,13 @@ package mmm.deco;
|
|||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import mmm.utils.I_UBlockSeat;
|
||||
import mmm.utils.I_UColoredBlock;
|
||||
import mmm.utils.I_URecipeRegistrar;
|
||||
import mmm.utils.I_USupportBlock;
|
||||
import mmm.utils.UMaths;
|
||||
import mmm.utils.URegistry;
|
||||
import mmm.utils.USeat;
|
||||
import net.minecraft.block.Block;
|
||||
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.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyDirection;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
|
@ -50,7 +49,6 @@ public class DThroneBlock
|
|||
{
|
||||
|
||||
public static final PropertyDirection FACING;
|
||||
public static final PropertyBool IS_TOP;
|
||||
public static final PropertyEnum< EnumDyeColor > COLOR;
|
||||
|
||||
private static final AxisAlignedBB COLLISION_TOP_NORTH = UMaths.makeBlockAABB( 0 , 0 , 0 , 16 , 13 , 3 );
|
||||
|
@ -62,25 +60,32 @@ public class DThroneBlock
|
|||
|
||||
static {
|
||||
FACING = BlockHorizontal.FACING;
|
||||
IS_TOP = PropertyBool.create( "is_top" );
|
||||
COLOR = PropertyEnum.< EnumDyeColor > create( "color" , EnumDyeColor.class );
|
||||
}
|
||||
|
||||
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 );
|
||||
this.woodType = woodType;
|
||||
this.parts = throne;
|
||||
this.isTop = isTop;
|
||||
|
||||
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( ) //
|
||||
.withProperty( DThroneBlock.FACING , EnumFacing.NORTH ) //
|
||||
.withProperty( DThroneBlock.IS_TOP , false ) //
|
||||
.withProperty( DThroneBlock.COLOR , EnumDyeColor.WHITE ) );
|
||||
}
|
||||
|
||||
this.lightOpacity = 0;
|
||||
this.translucent = false;
|
||||
|
@ -123,22 +128,22 @@ public class DThroneBlock
|
|||
@Override
|
||||
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 ) ) {
|
||||
case EAST:
|
||||
return COLLISION_TOP_EAST;
|
||||
return DThroneBlock.COLLISION_TOP_EAST;
|
||||
case NORTH:
|
||||
return COLLISION_TOP_NORTH;
|
||||
return DThroneBlock.COLLISION_TOP_NORTH;
|
||||
case SOUTH:
|
||||
return COLLISION_TOP_SOUTH;
|
||||
return DThroneBlock.COLLISION_TOP_SOUTH;
|
||||
case WEST:
|
||||
return COLLISION_TOP_WEST;
|
||||
return DThroneBlock.COLLISION_TOP_WEST;
|
||||
default:
|
||||
// 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( )
|
||||
{
|
||||
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
|
||||
public IBlockState getStateFromMeta( final int meta )
|
||||
{
|
||||
final boolean isTop = ( meta & 1 ) == 1;
|
||||
IBlockState bs = this.getDefaultState( ).withProperty( DThroneBlock.IS_TOP , isTop );
|
||||
if ( isTop ) {
|
||||
bs = bs.withProperty( DThroneBlock.COLOR , EnumDyeColor.byMetadata( meta >> 1 ) );
|
||||
IBlockState bs = this.blockState.getBaseState( );
|
||||
if ( this.isTop ) {
|
||||
bs = bs.withProperty( DThroneBlock.FACING , EnumFacing.getHorizontal( meta ) );
|
||||
} else {
|
||||
bs = bs.withProperty( DThroneBlock.COLOR , EnumDyeColor.byMetadata( meta >> 1 & 1 ) ) //
|
||||
.withProperty( DThroneBlock.FACING , EnumFacing.getHorizontal( meta >> 2 ) );
|
||||
bs = bs.withProperty( DThroneBlock.COLOR , EnumDyeColor.byMetadata( meta ) );
|
||||
}
|
||||
return bs;
|
||||
}
|
||||
|
@ -173,44 +176,29 @@ public class DThroneBlock
|
|||
@Override
|
||||
public int getMetaFromState( final IBlockState state )
|
||||
{
|
||||
final boolean isTop = state.getValue( DThroneBlock.IS_TOP );
|
||||
int meta = isTop ? 1 : 0;
|
||||
if ( isTop ) {
|
||||
meta |= ( state.getValue( DThroneBlock.COLOR ).getMetadata( ) & 0x07 ) << 1;
|
||||
if ( this.isTop ) {
|
||||
return state.getValue( DThroneBlock.FACING ).getHorizontalIndex( );
|
||||
} else {
|
||||
meta |= ( state.getValue( DThroneBlock.COLOR ).getMetadata( ) & 0x01 ) << 1 //
|
||||
| state.getValue( DThroneBlock.FACING ).getHorizontalIndex( ) << 2 //
|
||||
;
|
||||
return state.getValue( DThroneBlock.COLOR ).getMetadata( );
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IBlockState getActualState( final IBlockState state , final IBlockAccess worldIn , final BlockPos pos )
|
||||
{
|
||||
final boolean isTop = state.getValue( DThroneBlock.IS_TOP );
|
||||
|
||||
final IBlockState top;
|
||||
final IBlockState bottom;
|
||||
if ( isTop ) {
|
||||
top = state;
|
||||
bottom = worldIn.getBlockState( pos.down( ) );
|
||||
if ( this.isTop ) {
|
||||
final IBlockState bottom = worldIn.getBlockState( pos.down( ) );
|
||||
if ( bottom.getBlock( ) instanceof DThroneBlock ) {
|
||||
return state.withProperty( DThroneBlock.COLOR , bottom.getValue( DThroneBlock.COLOR ) );
|
||||
}
|
||||
} else {
|
||||
top = worldIn.getBlockState( pos.up( ) );
|
||||
bottom = state;
|
||||
final IBlockState top = worldIn.getBlockState( pos.up( ) );
|
||||
if ( top.getBlock( ) instanceof DThroneBlock ) {
|
||||
return state.withProperty( DThroneBlock.FACING , top.getValue( DThroneBlock.FACING ) );
|
||||
}
|
||||
if ( top.getBlock( ) != this || bottom.getBlock( ) != this ) {
|
||||
return this.getDefaultState( );
|
||||
}
|
||||
|
||||
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 );
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
|
@ -230,17 +218,16 @@ public class DThroneBlock
|
|||
public void onBlockPlacedBy( final World worldIn , final BlockPos pos , final IBlockState state ,
|
||||
final EntityLivingBase placer , final ItemStack stack )
|
||||
{
|
||||
if ( this.isTop ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int dmg = stack.getItemDamage( );
|
||||
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( ) //
|
||||
.withProperty( DThroneBlock.FACING , placer.getHorizontalFacing( ) );
|
||||
worldIn.setBlockState( pos , nState.withProperty( DThroneBlock.COLOR , bottomColor ) , 6 );
|
||||
worldIn.setBlockState( pos , state.withProperty( DThroneBlock.COLOR , color ) , 6 );
|
||||
worldIn.setBlockState( pos.up( ) , //
|
||||
nState.withProperty( DThroneBlock.IS_TOP , true ) //
|
||||
.withProperty( DThroneBlock.COLOR , topColor ) ,
|
||||
this.parts.TOP.getDefaultState( ).withProperty( DThroneBlock.FACING , placer.getHorizontalFacing( ) ) ,
|
||||
6 );
|
||||
}
|
||||
|
||||
|
@ -249,11 +236,17 @@ public class DThroneBlock
|
|||
// BLOCK REMOVAL AND PICKING
|
||||
// *************************************************************************************************
|
||||
|
||||
public Item getItemDropped( IBlockState state , Random rand , int fortune )
|
||||
{
|
||||
return Item.getItemFromBlock( this.parts.BOTTOM );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock( final IBlockState state , final RayTraceResult target , final World world ,
|
||||
final BlockPos pos , final EntityPlayer player )
|
||||
{
|
||||
final Item item = Item.getItemFromBlock( this );
|
||||
final Item item = Item.getItemFromBlock( this.parts.BOTTOM );
|
||||
return item == null
|
||||
? null
|
||||
: new ItemStack( item , 1 , this.damageDropped( state.getActualState( world , pos ) ) );
|
||||
|
@ -280,11 +273,6 @@ public class DThroneBlock
|
|||
if ( !worldIn.isRemote && !worldIn.restoringBlockSnapshots ) {
|
||||
super.dropBlockAsItemWithChance( worldIn , pos , state , chance , fortune );
|
||||
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 )
|
||||
{
|
||||
DThroneBlock.dropping = true;
|
||||
final boolean isTop = state.getValue( DThroneBlock.IS_TOP );
|
||||
final BlockPos otherPos = isTop ? pos.down( ) : pos.up( );
|
||||
if ( world.getBlockState( otherPos ).getBlock( ) == this ) {
|
||||
final BlockPos otherPos = this.isTop ? pos.down( ) : pos.up( );
|
||||
Block otherBlock = world.getBlockState( otherPos ).getBlock( );
|
||||
if ( otherBlock instanceof DThroneBlock && ( (DThroneBlock) otherBlock ).isTop == !this.isTop ) {
|
||||
world.setBlockToAir( otherPos );
|
||||
}
|
||||
DThroneBlock.dropping = false;
|
||||
|
@ -333,7 +321,7 @@ public class DThroneBlock
|
|||
public void neighborChanged( final IBlockState state , final World worldIn , final BlockPos pos ,
|
||||
final Block blockIn )
|
||||
{
|
||||
if ( ! ( state.getValue( DThroneBlock.IS_TOP ) || DThroneBlock.dropping ) ) {
|
||||
if ( ! ( this.isTop || DThroneBlock.dropping ) ) {
|
||||
I_USupportBlock.dropIfUnsupported( state , worldIn , pos , this );
|
||||
}
|
||||
}
|
||||
|
@ -356,7 +344,7 @@ public class DThroneBlock
|
|||
final float hitX , final float hitY , final float hitZ )
|
||||
{
|
||||
BlockPos p;
|
||||
if ( state.getValue( DThroneBlock.IS_TOP ) ) {
|
||||
if ( this.isTop ) {
|
||||
p = pos.down( );
|
||||
} else {
|
||||
p = pos;
|
||||
|
@ -382,7 +370,7 @@ public class DThroneBlock
|
|||
@Override
|
||||
public void registerRecipes( )
|
||||
{
|
||||
for ( EnumDyeColor dyeColor : EnumDyeColor.values( ) ) {
|
||||
for ( final EnumDyeColor dyeColor : EnumDyeColor.values( ) ) {
|
||||
GameRegistry.addShapedRecipe( new ItemStack( this , 1 , dyeColor.getMetadata( ) ) , //
|
||||
" E " , //
|
||||
"GWG" , //
|
||||
|
|
|
@ -58,8 +58,7 @@ public class DecorativeBlocks
|
|||
URegistry.addBlock( CHAIR_ACACIA = new DChair( E_DWoodType.ACACIA ) );
|
||||
|
||||
// XXX FIXME LOL TEST!!!!
|
||||
final DThroneBlock tb = new DThroneBlock( E_DWoodType.OAK );
|
||||
URegistry.addBlock( tb );
|
||||
new DThrone( E_DWoodType.OAK );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,27 +1,14 @@
|
|||
{
|
||||
"forge_marker": 1 ,
|
||||
"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" ,
|
||||
"textures" : {
|
||||
"textures": {
|
||||
"wood": "mmm:blocks/deco/throne/oak/wood" ,
|
||||
"front" : "mmm:blocks/deco/throne/oak/front-bottom" ,
|
||||
"top" : "mmm:blocks/deco/throne/oak/bottom"
|
||||
}
|
||||
}
|
||||
} ,
|
||||
"variants" : {
|
||||
|
||||
"facing" : {
|
||||
"north" : { "y": 0 } ,
|
|
@ -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" } }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in a new issue