Extra slabs (granite, diorite, andesite)

Needs custom texture though.
This commit is contained in:
Emmanuel BENOîT 2016-06-15 11:36:12 +02:00
parent 457a6f33e4
commit 1de7ead35c
27 changed files with 470 additions and 19 deletions

View file

@ -2,6 +2,7 @@ package mmm;
import mmm.deco.DecorativeBlocks;
import mmm.utils.UAccessors;
import mmm.utils.URegistry;
import mmm.utils.USeat;
import net.minecraftforge.fml.common.Mod;
@ -32,6 +33,8 @@ public class Mmm
public void preInit( final FMLPreInitializationEvent event )
{
UAccessors.preInit( );
DecorativeBlocks.preInit( );
URegistry.registerRecipes( );
}

View file

@ -0,0 +1,58 @@
package mmm.deco;
import mmm.utils.I_URecipeRegistrar;
import mmm.utils.URegistry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStone;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemSlab;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class DExtraSlab
implements I_URecipeRegistrar
{
public static DExtraSlab fromStone( final BlockStone.EnumType type )
{
final IBlockState bs = Blocks.STONE.getDefaultState( ).withProperty( BlockStone.VARIANT , type );
final String name = type.getName( ).replace( "smooth_" , "" );
return new DExtraSlab( bs , name );
}
public final DExtraSlabHalf HALF;
public final DExtraSlabDouble DOUBLE;
public final ItemSlab ITEM;
public DExtraSlab( final IBlockState modelState , final String name )
{
this.HALF = new DExtraSlabHalf( modelState , name );
this.DOUBLE = new DExtraSlabDouble( this.HALF , name );
this.ITEM = new ItemSlab( this.HALF , this.HALF , this.DOUBLE );
URegistry.setIdentifiers( this.ITEM , "deco" , "slabs" , name );
}
public DExtraSlab register( )
{
URegistry.addBlock( this.HALF , this.ITEM );
URegistry.addBlock( this.DOUBLE , null );
URegistry.addRecipeRegistrar( this );
return this;
}
@Override
public void registerRecipes( )
{
final Block block = this.HALF.modelBlock;
final IBlockState state = this.HALF.modelState;
GameRegistry.addShapedRecipe( new ItemStack( this.HALF ) , //
"BBB" , //
'B' , new ItemStack( block , 6 , block.getMetaFromState( state ) ) );
}
}

View file

@ -0,0 +1,124 @@
package mmm.deco;
import mmm.utils.UAccessors;
import mmm.utils.URegistry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
public abstract class DExtraSlabBlock
extends BlockSlab
{
public static enum E_Variant
implements IStringSerializable {
DEFAULT;
@Override
public String getName( )
{
return "default";
}
}
public static final PropertyEnum< DExtraSlabBlock.E_Variant > VARIANT //
= PropertyEnum.< DExtraSlabBlock.E_Variant > create( "variant" , DExtraSlabBlock.E_Variant.class );
public final IBlockState modelState;
public final Block modelBlock;
public DExtraSlabBlock( final IBlockState modelState , final String name )
{
super( modelState.getMaterial( ) );
this.modelState = modelState;
this.modelBlock = modelState.getBlock( );
this.setSoundType( this.modelBlock.getSoundType( ) );
try {
this.setHardness( UAccessors.getBlockHardness( this.modelBlock ) );
this.setResistance( UAccessors.getBlockResistance( this.modelBlock ) + 0.5f );
} catch ( final Throwable e ) {
if ( e instanceof RuntimeException ) {
throw (RuntimeException) e;
}
throw new RuntimeException( e );
}
this.setCreativeTab( CreativeTabs.BUILDING_BLOCKS );
IBlockState state = this.blockState.getBaseState( );
if ( !this.isDouble( ) ) {
state = state.withProperty( BlockSlab.HALF , BlockSlab.EnumBlockHalf.BOTTOM );
}
this.setDefaultState( state.withProperty( DExtraSlabBlock.VARIANT , E_Variant.DEFAULT ) );
URegistry.setIdentifiers( this , "deco" , "slabs" , name );
}
@Override
public IBlockState getStateFromMeta( final int meta )
{
IBlockState iblockstate = this.getDefaultState( ).withProperty( DExtraSlabBlock.VARIANT , E_Variant.DEFAULT );
if ( !this.isDouble( ) ) {
iblockstate = iblockstate.withProperty( BlockSlab.HALF ,
( meta & 1 ) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP );
}
return iblockstate;
}
@Override
public int getMetaFromState( final IBlockState state )
{
int i = 0;
if ( !this.isDouble( ) && state.getValue( BlockSlab.HALF ) == BlockSlab.EnumBlockHalf.TOP ) {
i |= 1;
}
return i;
}
@Override
protected BlockStateContainer createBlockState( )
{
return this.isDouble( ) //
? new BlockStateContainer( this , new IProperty[] {
DExtraSlabBlock.VARIANT
} ) //
: new BlockStateContainer( this , new IProperty[] {
BlockSlab.HALF , DExtraSlabBlock.VARIANT
} );
}
@Override
public String getUnlocalizedName( final int meta )
{
return super.getUnlocalizedName( );
}
@Override
public IProperty< ? > getVariantProperty( )
{
return DExtraSlabBlock.VARIANT;
}
@Override
public Comparable< ? > getTypeForItem( final ItemStack stack )
{
return E_Variant.DEFAULT;
}
}

View file

@ -0,0 +1,48 @@
package mmm.deco;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class DExtraSlabDouble
extends DExtraSlabBlock
{
public final DExtraSlabHalf singleSlab;
public DExtraSlabDouble( final DExtraSlabHalf single , final String name )
{
super( single.modelState , name + "_double" );
this.singleSlab = single;
}
@Override
@Nullable
public Item getItemDropped( final IBlockState state , final Random rand , final int fortune )
{
return Item.getItemFromBlock( this.singleSlab );
}
@Override
public ItemStack getItem( final World worldIn , final BlockPos pos , final IBlockState state )
{
return new ItemStack( this.singleSlab );
}
@Override
public boolean isDouble( )
{
return true;
}
}

View file

@ -0,0 +1,21 @@
package mmm.deco;
import net.minecraft.block.state.IBlockState;
public class DExtraSlabHalf
extends DExtraSlabBlock
{
public DExtraSlabHalf( final IBlockState modelState , final String name )
{
super( modelState , name );
}
@Override
public boolean isDouble( )
{
return false;
}
}

View file

@ -17,9 +17,9 @@ public class DExtraStairs
extends BlockStairs
implements I_URecipeRegistrar
{
public static DExtraStairs makeStoneStairs( BlockStone.EnumType type )
public static DExtraStairs fromStone( final BlockStone.EnumType type )
{
IBlockState bs = Blocks.STONE.getDefaultState( ).withProperty( BlockStone.VARIANT , type );
final IBlockState bs = Blocks.STONE.getDefaultState( ).withProperty( BlockStone.VARIANT , type );
return new DExtraStairs( bs , type.getName( ).replace( "smooth_" , "" ) );
}
@ -27,7 +27,7 @@ public class DExtraStairs
public final Block modelBlock;
public DExtraStairs( final IBlockState modelState , String name )
public DExtraStairs( final IBlockState modelState , final String name )
{
super( modelState );
this.modelState = modelState;
@ -43,7 +43,7 @@ public class DExtraStairs
"B " , //
"BB " , //
"BBB" , //
'B' , new ItemStack( this.modelBlock , 1 , this.modelBlock.getMetaFromState( this.modelState ) ) );
'B' , new ItemStack( this.modelBlock , 4 , this.modelBlock.getMetaFromState( this.modelState ) ) );
}
}

View file

@ -12,6 +12,10 @@ public class DecorativeBlocks
public static final DExtraStairs STAIRS_DIORITE;
public static final DExtraStairs STAIRS_ANDESITE;
public static final DExtraSlab SLAB_GRANITE;
public static final DExtraSlab SLAB_DIORITE;
public static final DExtraSlab SLAB_ANDESITE;
public static final DBlockTable TABLE_OAK;
public static final DBlockTable TABLE_BIRCH;
public static final DBlockTable TABLE_SPRUCE;
@ -27,9 +31,17 @@ public class DecorativeBlocks
public static final DBlockChair CHAIR_ACACIA;
static {
URegistry.addBlock( STAIRS_GRANITE = DExtraStairs.makeStoneStairs( BlockStone.EnumType.GRANITE_SMOOTH ) );
URegistry.addBlock( STAIRS_DIORITE = DExtraStairs.makeStoneStairs( BlockStone.EnumType.DIORITE_SMOOTH ) );
URegistry.addBlock( STAIRS_ANDESITE = DExtraStairs.makeStoneStairs( BlockStone.EnumType.ANDESITE_SMOOTH ) );
final BlockStone.EnumType granite = BlockStone.EnumType.GRANITE_SMOOTH;
final BlockStone.EnumType diorite = BlockStone.EnumType.DIORITE_SMOOTH;
final BlockStone.EnumType andesite = BlockStone.EnumType.ANDESITE_SMOOTH;
URegistry.addBlock( STAIRS_GRANITE = DExtraStairs.fromStone( granite ) );
URegistry.addBlock( STAIRS_DIORITE = DExtraStairs.fromStone( diorite ) );
URegistry.addBlock( STAIRS_ANDESITE = DExtraStairs.fromStone( andesite ) );
SLAB_GRANITE = DExtraSlab.fromStone( granite ).register( );
SLAB_DIORITE = DExtraSlab.fromStone( diorite ).register( );
SLAB_ANDESITE = DExtraSlab.fromStone( andesite ).register( );
URegistry.addBlock( TABLE_OAK = new DBlockTable( E_DWoodType.OAK ) );
URegistry.addBlock( TABLE_BIRCH = new DBlockTable( E_DWoodType.BIRCH ) );

View file

@ -0,0 +1,66 @@
package mmm.utils;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import net.minecraft.block.Block;
import net.minecraft.launchwrapper.Launch;
/** Accessors for various Minecraft fields */
public class UAccessors
{
private static final boolean isDeobfuscated;
private static MethodHandle createGetter( Class< ? > cls , String fnForge , String fnSearge )
{
String fn = isDeobfuscated ? fnForge : fnSearge;
Field f;
try {
f = cls.getDeclaredField( fn );
} catch ( NoSuchFieldException e ) {
throw new RuntimeException( "could not find field " + fnForge + " / " + fnSearge //
+ " in class " + cls.getCanonicalName( ) , e );
}
f.setAccessible( true );
try {
return MethodHandles.lookup( ).unreflectGetter( f );
} catch ( IllegalAccessException e ) {
throw new RuntimeException( "error while creating getter for " + fnForge + " / " + fnSearge //
+ " in class " + cls.getCanonicalName( ) , e );
}
}
private static final MethodHandle fg_Block_blockHardness;
private static final MethodHandle fg_Block_blockResistance;
static {
isDeobfuscated = (Boolean) Launch.blackboard.get( "fml.deobfuscatedEnvironment" );
fg_Block_blockHardness = createGetter( Block.class , "blockHardness" , "field_149782_v" );
fg_Block_blockResistance = createGetter( Block.class , "blockResistance" , "field_149781_w" );
}
public static void preInit( )
{
// EMPTY
}
public static float getBlockHardness( Block block )
throws Throwable
{
return (float) fg_Block_blockHardness.invokeExact( block );
}
public static float getBlockResistance( Block block )
throws Throwable
{
return (float) fg_Block_blockResistance.invokeExact( block );
}
}

View file

@ -0,0 +1,6 @@
{
"variants": {
"half=bottom,variant=default": { "model": "mmm:deco/slabs/andesite/bottom" },
"half=top,variant=default": { "model": "mmm:deco/slabs/andesite/top" }
}
}

View file

@ -0,0 +1,5 @@
{
"variants": {
"variant=default": { "model": "mmm:deco/slabs/andesite/double" }
}
}

View file

@ -0,0 +1,6 @@
{
"variants": {
"half=bottom,variant=default": { "model": "mmm:deco/slabs/diorite/bottom" },
"half=top,variant=default": { "model": "mmm:deco/slabs/diorite/top" }
}
}

View file

@ -0,0 +1,5 @@
{
"variants": {
"variant=default": { "model": "mmm:deco/slabs/diorite/double" }
}
}

View file

@ -0,0 +1,6 @@
{
"variants": {
"half=bottom,variant=default": { "model": "mmm:deco/slabs/granite/bottom" },
"half=top,variant=default": { "model": "mmm:deco/slabs/granite/top" }
}
}

View file

@ -0,0 +1,5 @@
{
"variants": {
"variant=default": { "model": "mmm:deco/slabs/granite/double" }
}
}

View file

@ -1,13 +1,21 @@
tile.mmm.deco.table.oak.name=Oak table
tile.mmm.deco.table.birch.name=Birch table
tile.mmm.deco.table.spruce.name=Spruce table
tile.mmm.deco.table.acacia.name=Acacia table
tile.mmm.deco.table.jungle.name=Jungle wood table
tile.mmm.deco.table.dark_oak.name=Dark oak table
tile.mmm.deco.stairs.granite.name=Granite Stairs
tile.mmm.deco.stairs.diorite.name=Diorite Stairs
tile.mmm.deco.stairs.andesite.name=Andesite Stairs
tile.mmm.deco.chair.oak.name=Oak chair
tile.mmm.deco.chair.birch.name=Birch chair
tile.mmm.deco.chair.spruce.name=Spruce chair
tile.mmm.deco.chair.acacia.name=Acacia chair
tile.mmm.deco.chair.jungle.name=Jungle wood chair
tile.mmm.deco.chair.dark_oak.name=Dark oak chair
tile.mmm.deco.slabs.granite.name=Granite Slab
tile.mmm.deco.slabs.diorite.name=Diorite Slab
tile.mmm.deco.slabs.andesite.name=Andesite Slab
tile.mmm.deco.table.oak.name=Oak Table
tile.mmm.deco.table.birch.name=Birch Table
tile.mmm.deco.table.spruce.name=Spruce Table
tile.mmm.deco.table.acacia.name=Acacia Table
tile.mmm.deco.table.jungle.name=Jungle Wood Table
tile.mmm.deco.table.dark_oak.name=Dark Oak Table
tile.mmm.deco.chair.oak.name=Oak Chair
tile.mmm.deco.chair.birch.name=Birch Chair
tile.mmm.deco.chair.spruce.name=Spruce Chair
tile.mmm.deco.chair.acacia.name=Acacia Chair
tile.mmm.deco.chair.jungle.name=Jungle Wood Chair
tile.mmm.deco.chair.dark_oak.name=Dark Oak Chair

View file

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/half_slab",
"textures": {
"bottom": "minecraft:blocks/stone_andesite_smooth",
"top": "minecraft:blocks/stone_andesite_smooth",
"side": "minecraft:blocks/stone_andesite_smooth"
}
}

View file

@ -0,0 +1,7 @@
{
"parent": "minecraft:block/cube_column",
"textures": {
"end": "minecraft:blocks/stone_andesite_smooth",
"side": "minecraft:blocks/stone_andesite_smooth"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/upper_slab",
"textures": {
"bottom": "minecraft:blocks/stone_andesite_smooth",
"top": "minecraft:blocks/stone_andesite_smooth",
"side": "minecraft:blocks/stone_andesite_smooth"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/half_slab",
"textures": {
"bottom": "minecraft:blocks/stone_diorite_smooth",
"top": "minecraft:blocks/stone_diorite_smooth",
"side": "minecraft:blocks/stone_diorite_smooth"
}
}

View file

@ -0,0 +1,7 @@
{
"parent": "minecraft:block/cube_column",
"textures": {
"end": "minecraft:blocks/stone_diorite_smooth",
"side": "minecraft:blocks/stone_diorite_smooth"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/upper_slab",
"textures": {
"bottom": "minecraft:blocks/stone_diorite_smooth",
"top": "minecraft:blocks/stone_diorite_smooth",
"side": "minecraft:blocks/stone_diorite_smooth"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/half_slab",
"textures": {
"bottom": "minecraft:blocks/stone_granite_smooth",
"top": "minecraft:blocks/stone_granite_smooth",
"side": "minecraft:blocks/stone_granite_smooth"
}
}

View file

@ -0,0 +1,7 @@
{
"parent": "minecraft:block/cube_column",
"textures": {
"end": "minecraft:blocks/stone_granite_smooth",
"side": "minecraft:blocks/stone_granite_smooth"
}
}

View file

@ -0,0 +1,8 @@
{
"parent": "minecraft:block/upper_slab",
"textures": {
"bottom": "minecraft:blocks/stone_granite_smooth",
"top": "minecraft:blocks/stone_granite_smooth",
"side": "minecraft:blocks/stone_granite_smooth"
}
}

View file

@ -0,0 +1,3 @@
{
"parent": "mmm:block/deco/slabs/andesite/bottom"
}

View file

@ -0,0 +1,3 @@
{
"parent": "mmm:block/deco/slabs/diorite/bottom"
}

View file

@ -0,0 +1,3 @@
{
"parent": "mmm:block/deco/slabs/granite/bottom"
}