Nether coral item

Can be obtained using shears. Not using shears will destroy the coral
and set the player on fire
This commit is contained in:
Emmanuel BENOîT 2016-07-21 14:11:12 +02:00
parent 5b31453cec
commit 2ebda1f1a3
7 changed files with 124 additions and 4 deletions

View file

@ -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 );
}

View file

@ -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( ) ];
}

View file

@ -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

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "mmm:blocks/plant/nether_coral/blue"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "mmm:blocks/plant/nether_coral/orange"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "mmm:blocks/plant/nether_coral/red"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "mmm:blocks/plant/nether_coral/yellow"
}
}