Fixes #2433: Readded decorative slabs.
This commit is contained in:
@@ -26,6 +26,7 @@ import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
@@ -72,6 +73,8 @@ class BlockDefinitionBuilder implements IBlockBuilder
|
||||
|
||||
private CreativeTabs creativeTab = CreativeTab.instance;
|
||||
|
||||
private boolean disableItem = false;
|
||||
|
||||
private Function<Block, ItemBlock> itemFactory;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
@@ -163,6 +166,13 @@ class BlockDefinitionBuilder implements IBlockBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockBuilder disableItem()
|
||||
{
|
||||
this.disableItem = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private void customizeForClient( BlockRenderingCustomizer callback )
|
||||
{
|
||||
@@ -183,12 +193,17 @@ class BlockDefinitionBuilder implements IBlockBuilder
|
||||
block.setRegistryName( AppEng.MOD_ID, registryName );
|
||||
|
||||
ItemBlock item = constructItemFromBlock( block );
|
||||
item.setRegistryName( AppEng.MOD_ID, registryName );
|
||||
if ( item != null ) {
|
||||
item.setRegistryName( AppEng.MOD_ID, registryName );
|
||||
}
|
||||
|
||||
// Register the item and block with the game
|
||||
factory.addPreInit( side -> {
|
||||
GameRegistry.register( block );
|
||||
GameRegistry.register( item );
|
||||
if ( item != null )
|
||||
{
|
||||
GameRegistry.register( item );
|
||||
}
|
||||
} );
|
||||
|
||||
block.setCreativeTab( creativeTab );
|
||||
@@ -211,7 +226,10 @@ class BlockDefinitionBuilder implements IBlockBuilder
|
||||
blockRendering.apply( factory, block, null );
|
||||
}
|
||||
|
||||
itemRendering.apply( factory, item );
|
||||
if( item != null )
|
||||
{
|
||||
itemRendering.apply( factory, item );
|
||||
}
|
||||
}
|
||||
|
||||
if( block instanceof AEBaseTileBlock )
|
||||
@@ -233,8 +251,14 @@ class BlockDefinitionBuilder implements IBlockBuilder
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ItemBlock constructItemFromBlock( Block block )
|
||||
{
|
||||
if( disableItem )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if( itemFactory != null )
|
||||
{
|
||||
return itemFactory.apply( block );
|
||||
|
||||
@@ -45,6 +45,11 @@ public interface IBlockBuilder
|
||||
|
||||
IBlockBuilder rendering( BlockRenderingCustomizer callback );
|
||||
|
||||
/**
|
||||
* Don't register an item for this block.
|
||||
*/
|
||||
IBlockBuilder disableItem();
|
||||
|
||||
/**
|
||||
* Forces this block's item to uses a custom model, instead of using the default block state as the item model.
|
||||
* The model has the same name as the registry name.
|
||||
|
||||
@@ -19,8 +19,14 @@
|
||||
package appeng.core.api.definitions;
|
||||
|
||||
|
||||
import com.google.common.base.Verify;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemSlab;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -29,6 +35,7 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.definitions.IBlocks;
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.api.definitions.ITileDefinition;
|
||||
import appeng.block.AEBaseItemBlockChargeable;
|
||||
import appeng.block.crafting.BlockCraftingMonitor;
|
||||
@@ -91,11 +98,13 @@ import appeng.client.render.model.GlassModel;
|
||||
import appeng.client.render.spatial.SpatialPylonRendering;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.features.BlockDefinition;
|
||||
import appeng.core.features.registries.PartModels;
|
||||
import appeng.debug.BlockChunkloader;
|
||||
import appeng.debug.BlockCubeGenerator;
|
||||
import appeng.debug.BlockItemGen;
|
||||
import appeng.debug.BlockPhantomNode;
|
||||
import appeng.decorative.slab.BlockSlabCommon;
|
||||
import appeng.decorative.solid.BlockChargedQuartzOre;
|
||||
import appeng.decorative.solid.BlockChiseledQuartz;
|
||||
import appeng.decorative.solid.BlockFluix;
|
||||
@@ -175,16 +184,15 @@ public final class ApiBlocks implements IBlocks
|
||||
private final IBlockDefinition quartzStairs;
|
||||
private final IBlockDefinition chiseledQuartzStairs;
|
||||
private final IBlockDefinition quartzPillarStairs;
|
||||
/*
|
||||
* private final IBlockDefinition skyStoneSlab;
|
||||
* private final IBlockDefinition skyStoneBlockSlab;
|
||||
* private final IBlockDefinition skyStoneBrickSlab;
|
||||
* private final IBlockDefinition skyStoneSmallBrickSlab;
|
||||
* private final IBlockDefinition fluixSlab;
|
||||
* private final IBlockDefinition quartzSlab;
|
||||
* private final IBlockDefinition chiseledQuartzSlab;
|
||||
* private final IBlockDefinition quartzPillarSlab;
|
||||
*/
|
||||
|
||||
private final IBlockDefinition skyStoneSlab;
|
||||
private final IBlockDefinition smoothSkyStoneSlab;
|
||||
private final IBlockDefinition skyStoneBrickSlab;
|
||||
private final IBlockDefinition skyStoneSmallBrickSlab;
|
||||
private final IBlockDefinition fluixSlab;
|
||||
private final IBlockDefinition quartzSlab;
|
||||
private final IBlockDefinition chiseledQuartzSlab;
|
||||
private final IBlockDefinition quartzPillarSlab;
|
||||
|
||||
private final IBlockDefinition itemGen;
|
||||
private final IBlockDefinition chunkLoader;
|
||||
@@ -395,25 +403,14 @@ public final class ApiBlocks implements IBlocks
|
||||
} )
|
||||
.build();
|
||||
|
||||
// TODO Re-Add Slabs...
|
||||
/*
|
||||
* this.skyStoneSlab = constructor.registerBlockDefinition( new AEBaseSlabBlock( skyStone_stone,
|
||||
* EnumSet.of(AEFeature.DecorativeQuartzBlocks), false, "SkyStoneSlabBlock" ) );
|
||||
* this.skyStoneBlockSlab = constructor.registerBlockDefinition( new AEBaseSlabBlock( skyStone_block,
|
||||
* EnumSet.of(AEFeature.DecorativeQuartzBlocks), false, "SkyStoneBlockSlabBlock" ) );
|
||||
* this.skyStoneBrickSlab = constructor.registerBlockDefinition( new AEBaseSlabBlock( skyStone_brick,
|
||||
* EnumSet.of(AEFeature.DecorativeQuartzBlocks), false, "SkyStoneBrickSlabBlock" ) );
|
||||
* this.skyStoneSmallBrickSlab = constructor.registerBlockDefinition( new AEBaseSlabBlock( skyStone_smallbrick,
|
||||
* EnumSet.of(AEFeature.DecorativeQuartzBlocks), false, "SkyStoneSmallBrickSlabBlock" ) );
|
||||
* this.fluixSlab = constructor.registerBlockDefinition( new AEBaseSlabBlock( fluixBlock,
|
||||
* EnumSet.of(AEFeature.DecorativeQuartzBlocks), false, "FluixSlabBlock" ) );
|
||||
* this.quartzSlab = constructor.registerBlockDefinition( new AEBaseSlabBlock( quartzBlock,
|
||||
* EnumSet.of(AEFeature.DecorativeQuartzBlocks), false, "QuartzSlabBlock" ) );
|
||||
* this.chiseledQuartzSlab = constructor.registerBlockDefinition( new AEBaseSlabBlock( chiseledQuartzBlock,
|
||||
* EnumSet.of(AEFeature.DecorativeQuartzBlocks), false, "ChiseledQuartzSlabBlock" ) );
|
||||
* this.quartzPillarSlab = constructor.registerBlockDefinition( new AEBaseSlabBlock( quartzPillar,
|
||||
* EnumSet.of(AEFeature.DecorativeQuartzBlocks), false, "QuartzPillarSlabBlock" ) )
|
||||
*/
|
||||
this.skyStoneSlab = makeSlab( "sky_stone_slab", "sky_stone_double_slab", registry, this.skyStoneBlock() );
|
||||
this.smoothSkyStoneSlab = makeSlab( "smooth_sky_stone_slab", "smooth_sky_stone_double_slab", registry, this.smoothSkyStoneBlock() );
|
||||
this.skyStoneBrickSlab = makeSlab( "sky_stone_brick_slab", "sky_stone_brick_double_slab", registry, this.skyStoneBrick() );
|
||||
this.skyStoneSmallBrickSlab = makeSlab( "sky_stone_small_brick_slab", "sky_stone_small_brick_double_slab", registry, this.skyStoneSmallBrick() );
|
||||
this.fluixSlab = makeSlab( "fluix_slab", "fluix_double_slab", registry, this.fluixBlock() );
|
||||
this.quartzSlab = makeSlab( "quartz_slab", "quartz_double_slab", registry, this.quartzBlock() );
|
||||
this.chiseledQuartzSlab = makeSlab( "chiseled_quartz_slab", "chiseled_quartz_double_slab", registry, this.chiseledQuartzBlock() );
|
||||
this.quartzPillarSlab = makeSlab( "quartz_pillar_slab", "quartz_pillar_double_slab", registry, this.quartzPillar() );
|
||||
|
||||
this.itemGen = registry.block( "debug_item_gen", BlockItemGen::new )
|
||||
.features( AEFeature.UnsupportedDeveloperTools, AEFeature.Creative )
|
||||
@@ -433,6 +430,48 @@ public final class ApiBlocks implements IBlocks
|
||||
.build();
|
||||
}
|
||||
|
||||
private static IBlockDefinition makeSlab( String slabId, String doubleSlabId, FeatureFactory registry, IBlockDefinition blockDef )
|
||||
{
|
||||
if( !blockDef.maybeBlock().isPresent() )
|
||||
{
|
||||
return new BlockDefinition( slabId, null, null );
|
||||
}
|
||||
|
||||
Block block = blockDef.maybeBlock().get();
|
||||
|
||||
IBlockDefinition slabDef = registry.block( slabId, () -> new BlockSlabCommon.Half( block ) )
|
||||
.features( AEFeature.DecorativeQuartzBlocks )
|
||||
.disableItem()
|
||||
.build();
|
||||
|
||||
if( !slabDef.maybeBlock().isPresent() )
|
||||
{
|
||||
return new BlockDefinition( slabId, null, null );
|
||||
}
|
||||
|
||||
BlockSlab slabBlock = (BlockSlab) slabDef.maybeBlock().get();
|
||||
|
||||
// Reigster the double slab variant as well
|
||||
IBlockDefinition doubleSlabDef = registry.block( doubleSlabId, () -> new BlockSlabCommon.Double( slabBlock, block ) )
|
||||
.features( AEFeature.DecorativeQuartzBlocks )
|
||||
.disableItem()
|
||||
.build();
|
||||
|
||||
Verify.verify( doubleSlabDef.maybeBlock().isPresent() );
|
||||
|
||||
BlockSlab doubleSlabBlock = (BlockSlab) doubleSlabDef.maybeBlock().get();
|
||||
|
||||
// Make the slab item
|
||||
IItemDefinition itemDef = registry.item( slabId, () -> new ItemSlab( slabBlock, slabBlock, doubleSlabBlock ) )
|
||||
.features( AEFeature.DecorativeQuartzBlocks )
|
||||
.build();
|
||||
|
||||
Verify.verify( itemDef.maybeItem().isPresent() );
|
||||
|
||||
// Return a new composite block definition that combines the single slab block with the slab item
|
||||
return new BlockDefinition( slabId, slabBlock, (ItemBlock) itemDef.maybeItem().get() );
|
||||
}
|
||||
|
||||
private static IBlockDefinition makeStairs( String registryName, FeatureFactory registry, IBlockDefinition block )
|
||||
{
|
||||
return registry.block( registryName, () -> new BlockStairCommon( block.maybeBlock().get(), block.identifier() ) )
|
||||
@@ -600,48 +639,53 @@ public final class ApiBlocks implements IBlocks
|
||||
return this.quartzPillarStairs;
|
||||
}
|
||||
|
||||
/*
|
||||
* @Override
|
||||
* public IBlockDefinition skyStoneSlab()
|
||||
* {
|
||||
* return this.skyStoneSlab;
|
||||
* }
|
||||
* @Override
|
||||
* public IBlockDefinition skyStoneBlockSlab()
|
||||
* {
|
||||
* return this.skyStoneBlockSlab;
|
||||
* }
|
||||
* @Override
|
||||
* public IBlockDefinition skyStoneBrickSlab()
|
||||
* {
|
||||
* return this.skyStoneBrickSlab;
|
||||
* }
|
||||
* @Override
|
||||
* public IBlockDefinition skyStoneSmallBrickSlab()
|
||||
* {
|
||||
* return this.skyStoneSmallBrickSlab;
|
||||
* }
|
||||
* @Override
|
||||
* public IBlockDefinition fluixSlab()
|
||||
* {
|
||||
* return this.fluixSlab;
|
||||
* }
|
||||
* @Override
|
||||
* public IBlockDefinition quartzSlab()
|
||||
* {
|
||||
* return this.quartzSlab;
|
||||
* }
|
||||
* @Override
|
||||
* public IBlockDefinition chiseledQuartzSlab()
|
||||
* {
|
||||
* return this.chiseledQuartzSlab;
|
||||
* }
|
||||
* @Override
|
||||
* public IBlockDefinition quartzPillarSlab()
|
||||
* {
|
||||
* return this.quartzPillarSlab;
|
||||
* }
|
||||
*/
|
||||
@Override
|
||||
public IBlockDefinition skyStoneSlab()
|
||||
{
|
||||
return this.skyStoneSlab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition smoothSkyStoneSlab()
|
||||
{
|
||||
return this.smoothSkyStoneSlab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition skyStoneBrickSlab()
|
||||
{
|
||||
return this.skyStoneBrickSlab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition skyStoneSmallBrickSlab()
|
||||
{
|
||||
return this.skyStoneSmallBrickSlab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition fluixSlab()
|
||||
{
|
||||
return this.fluixSlab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition quartzSlab()
|
||||
{
|
||||
return this.quartzSlab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition chiseledQuartzSlab()
|
||||
{
|
||||
return this.chiseledQuartzSlab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition quartzPillarSlab()
|
||||
{
|
||||
return this.quartzPillarSlab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileDefinition grindstone()
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package appeng.decorative.slab;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
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.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
public abstract class BlockSlabCommon extends BlockSlab
|
||||
{
|
||||
|
||||
static final PropertyEnum<BlockSlabCommon.Variant> VARIANT = PropertyEnum.create( "variant", Variant.class );
|
||||
|
||||
private BlockSlabCommon( Block block )
|
||||
{
|
||||
super( block.getMaterial( block.getDefaultState() ) );
|
||||
this.setHardness( block.getBlockHardness( block.getDefaultState(), null, null ) );
|
||||
this.setResistance( block.getExplosionResistance( null ) * 5.0F / 3.0F );
|
||||
|
||||
IBlockState iblockstate = this.blockState.getBaseState();
|
||||
|
||||
if( !this.isDouble() )
|
||||
{
|
||||
iblockstate = iblockstate.withProperty( HALF, BlockSlab.EnumBlockHalf.BOTTOM );
|
||||
}
|
||||
|
||||
this.setDefaultState( iblockstate.withProperty( VARIANT, Variant.DEFAULT ) );
|
||||
this.setCreativeTab( CreativeTabs.BUILDING_BLOCKS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given metadata into a BlockState for this Block
|
||||
*/
|
||||
public IBlockState getStateFromMeta( int meta )
|
||||
{
|
||||
IBlockState iblockstate = this.getDefaultState().withProperty( VARIANT, Variant.DEFAULT );
|
||||
|
||||
if( !this.isDouble() )
|
||||
{
|
||||
iblockstate = iblockstate.withProperty( HALF, ( meta & 8 ) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP );
|
||||
}
|
||||
|
||||
return iblockstate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the BlockState into the correct metadata value
|
||||
*/
|
||||
public int getMetaFromState( IBlockState state )
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if( !this.isDouble() && state.getValue( HALF ) == BlockSlab.EnumBlockHalf.TOP )
|
||||
{
|
||||
i |= 8;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
protected BlockStateContainer createBlockState()
|
||||
{
|
||||
return this.isDouble() ? new BlockStateContainer( this, VARIANT ) : new BlockStateContainer( this, HALF, VARIANT );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Item getItemDropped( IBlockState state, Random rand, int fortune )
|
||||
{
|
||||
return Item.getItemFromBlock( this );
|
||||
}
|
||||
|
||||
public ItemStack getItem( World worldIn, BlockPos pos, IBlockState state )
|
||||
{
|
||||
return new ItemStack( this, 1, 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName( int meta )
|
||||
{
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProperty<?> getVariantProperty()
|
||||
{
|
||||
return VARIANT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparable<?> getTypeForItem( ItemStack stack )
|
||||
{
|
||||
return Variant.DEFAULT;
|
||||
}
|
||||
|
||||
public static class Double extends BlockSlabCommon
|
||||
{
|
||||
|
||||
private final Block halfSlabBlock;
|
||||
|
||||
public Double( Block halfSlabBlock, Block block )
|
||||
{
|
||||
super( block );
|
||||
this.halfSlabBlock = halfSlabBlock;
|
||||
}
|
||||
|
||||
public boolean isDouble()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Item getItemDropped( IBlockState state, Random rand, int fortune )
|
||||
{
|
||||
return Item.getItemFromBlock( halfSlabBlock );
|
||||
}
|
||||
|
||||
public ItemStack getItem( World worldIn, BlockPos pos, IBlockState state )
|
||||
{
|
||||
return new ItemStack( halfSlabBlock, 1, 0 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Half extends BlockSlabCommon
|
||||
{
|
||||
|
||||
public Half( Block block )
|
||||
{
|
||||
super( block );
|
||||
}
|
||||
|
||||
public boolean isDouble()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Variant implements IStringSerializable
|
||||
{
|
||||
DEFAULT;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user