diff --git a/src/java/mmm/plants/PNetherCoral.java b/src/java/mmm/plants/PNetherCoral.java index 3a502c6..130037e 100644 --- a/src/java/mmm/plants/PNetherCoral.java +++ b/src/java/mmm/plants/PNetherCoral.java @@ -1,11 +1,14 @@ package mmm.plants; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import mmm.core.CRegistry; import mmm.core.api.I_FloraRegistrar; import mmm.core.api.world.I_FloraParameters; +import mmm.utils.UBlockItemWithVariants; import mmm.world.WLocation; import mmm.world.gen.WGFloraParameters; import net.minecraft.block.BlockBush; @@ -14,8 +17,18 @@ 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.entity.player.EntityPlayer; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.util.IStringSerializable; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; +import net.minecraftforge.common.IShearable; @@ -40,6 +53,16 @@ public class PNetherCoral } + public static String[] getNames( ) + { + final String[] names = new String[ E_Color.VALUES.length ]; + for ( int i = 0 ; i < E_Color.VALUES.length ; i++ ) { + names[ i ] = E_Color.VALUES[ i ].getName( ); + } + return names; + } + + @Override public String getName( ) { @@ -57,6 +80,7 @@ public class PNetherCoral public class Plant extends BlockBush + implements IShearable { public Plant( ) @@ -64,7 +88,7 @@ public class PNetherCoral CRegistry.setIdentifiers( this , "plant" , "block" , "nether_coral" ); this.setTickRandomly( true ); - this.setCreativeTab( (CreativeTabs) null ); + this.setCreativeTab( CreativeTabs.DECORATIONS ); this.setHardness( 0f ); this.setSoundType( SoundType.PLANT ); this.lightValue = 13; @@ -102,15 +126,84 @@ public class PNetherCoral return state.getBlock( ) == Blocks.NETHERRACK || state.getBlock( ) == Blocks.SOUL_SAND; } + + @Override + public EnumPlantType getPlantType( final IBlockAccess world , final BlockPos pos ) + { + return EnumPlantType.Nether; + } + + + @Override + public void getSubBlocks( final Item itemIn , final CreativeTabs tab , final List< ItemStack > list ) + { + for ( final E_Color color : E_Color.VALUES ) { + list.add( new ItemStack( itemIn , 1 , color.toMetadata( ) ) ); + } + } + + + @Override + public void onBlockHarvested( final World worldIn , final BlockPos pos , final IBlockState state , + final EntityPlayer player ) + { + if ( !player.isCreative( ) ) { + final ItemStack heldItemMainhand = player.getHeldItemMainhand( ); + if ( heldItemMainhand == null || heldItemMainhand.getItem( ) != Items.SHEARS ) { + player.setFire( 5 ); + } + } + super.onBlockHarvested( worldIn , pos , state , player ); + } + + + @Override + public boolean isShearable( final ItemStack item , final IBlockAccess world , final BlockPos pos ) + { + return true; + } + + + @Override + public List< ItemStack > onSheared( final ItemStack item , final IBlockAccess world , final BlockPos pos , + final int fortune ) + { + final List< ItemStack > ret = new ArrayList< ItemStack >( ); + ret.add( new ItemStack( PNetherCoral.this.ITEM , 1 , + world.getBlockState( pos ).getValue( PNetherCoral.COLOR ).toMetadata( ) ) ); + return ret; + } + + + @Override + public List< ItemStack > getDrops( final IBlockAccess world , final BlockPos pos , final IBlockState state , + final int fortune ) + { + return Collections.emptyList( ); + } + + + @Override + public ItemStack getPickBlock( final IBlockState state , final RayTraceResult target , final World world , + final BlockPos pos , final EntityPlayer player ) + { + return new ItemStack( PNetherCoral.this.ITEM , 1 , state.getValue( PNetherCoral.COLOR ).toMetadata( ) ); + } + } public final Plant PLANT; + public final UBlockItemWithVariants ITEM; public PNetherCoral( ) { CRegistry.addRegistrar( this ); - CRegistry.addBlock( this.PLANT = new Plant( ) , null ); + this.PLANT = new Plant( ); + this.ITEM = new UBlockItemWithVariants( this.PLANT , "plant" , "block" , "nether_coral" ) // + .setVariants( E_Color.getNames( ) ) // + .register( ); + CRegistry.addBlock( this.PLANT , this.ITEM ); } diff --git a/src/java/mmm/utils/UBlockItemWithVariants.java b/src/java/mmm/utils/UBlockItemWithVariants.java index 271a737..46afd45 100644 --- a/src/java/mmm/utils/UBlockItemWithVariants.java +++ b/src/java/mmm/utils/UBlockItemWithVariants.java @@ -84,8 +84,7 @@ public class UBlockItemWithVariants @Override public String getUnlocalizedName( final ItemStack stack ) { - return super.getUnlocalizedName( ) + "." - + EnumDyeColor.byMetadata( stack.getMetadata( ) ).getUnlocalizedName( ); + return super.getUnlocalizedName( ) + "." + this.variants[ stack.getMetadata( ) ]; } diff --git a/src/resources/assets/mmm/lang/en_US.lang b/src/resources/assets/mmm/lang/en_US.lang index a1b9ec1..a1324a1 100644 --- a/src/resources/assets/mmm/lang/en_US.lang +++ b/src/resources/assets/mmm/lang/en_US.lang @@ -11,6 +11,10 @@ gui.mmm.tech.base.am.disabled=Deactivated item.mmm.plant.fruit.tomato.name=Tomato item.mmm.plant.seeds.tomato.name=Tomato Seeds tile.mmm.plant.block.wild_tomato.name=Wild Tomato Plant +tile.mmm.plant.block.nether_coral.red.name=Red Nether Coral +tile.mmm.plant.block.nether_coral.yellow.name=Yellow Nether Coral +tile.mmm.plant.block.nether_coral.orange.name=Orange Nether Coral +tile.mmm.plant.block.nether_coral.blue.name=Blue Nether Coral tile.mmm.materials.rock.limestone.name=Limestone diff --git a/src/resources/assets/mmm/models/item/plant/block/nether_coral/blue.json b/src/resources/assets/mmm/models/item/plant/block/nether_coral/blue.json new file mode 100644 index 0000000..f10e651 --- /dev/null +++ b/src/resources/assets/mmm/models/item/plant/block/nether_coral/blue.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "mmm:blocks/plant/nether_coral/blue" + } +} \ No newline at end of file diff --git a/src/resources/assets/mmm/models/item/plant/block/nether_coral/orange.json b/src/resources/assets/mmm/models/item/plant/block/nether_coral/orange.json new file mode 100644 index 0000000..d9cf71f --- /dev/null +++ b/src/resources/assets/mmm/models/item/plant/block/nether_coral/orange.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "mmm:blocks/plant/nether_coral/orange" + } +} \ No newline at end of file diff --git a/src/resources/assets/mmm/models/item/plant/block/nether_coral/red.json b/src/resources/assets/mmm/models/item/plant/block/nether_coral/red.json new file mode 100644 index 0000000..9c03946 --- /dev/null +++ b/src/resources/assets/mmm/models/item/plant/block/nether_coral/red.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "mmm:blocks/plant/nether_coral/red" + } +} \ No newline at end of file diff --git a/src/resources/assets/mmm/models/item/plant/block/nether_coral/yellow.json b/src/resources/assets/mmm/models/item/plant/block/nether_coral/yellow.json new file mode 100644 index 0000000..85885be --- /dev/null +++ b/src/resources/assets/mmm/models/item/plant/block/nether_coral/yellow.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "mmm:blocks/plant/nether_coral/yellow" + } +} \ No newline at end of file