ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockWildPlant.java

139 lines
5 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("BlockWildPlant.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.blocks;
2015-06-28 03:12:32 +02:00
2016-01-08 13:31:58 +01:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBushBase;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockPlant;
import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheWildPlants;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
2015-06-28 03:12:32 +02:00
import net.minecraft.block.Block;
2016-03-18 23:47:22 +01:00
import net.minecraft.block.SoundType;
2015-06-28 03:12:32 +02:00
import net.minecraft.block.material.Material;
2016-11-21 16:23:48 +01:00
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
2015-06-28 03:12:32 +02:00
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
2015-06-28 03:12:32 +02:00
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
2016-11-19 21:11:17 +01:00
import net.minecraft.util.NonNullList;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
2015-06-28 03:12:32 +02:00
import net.minecraft.world.World;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-06-28 03:12:32 +02:00
import java.util.List;
public class BlockWildPlant extends BlockBushBase{
2015-06-28 03:12:32 +02:00
2016-06-17 23:50:38 +02:00
public static final TheWildPlants[] ALL_WILD_PLANTS = TheWildPlants.values();
2016-11-21 16:23:48 +01:00
private static final PropertyEnum<TheWildPlants> TYPE = PropertyEnum.create("type", TheWildPlants.class);
2015-06-28 03:12:32 +02:00
public BlockWildPlant(String name){
super(name);
2016-04-20 21:39:03 +02:00
this.setSoundType(SoundType.PLANT);
2015-06-28 03:12:32 +02:00
}
@Override
public boolean canBlockStay(World world, BlockPos pos, IBlockState state){
2016-07-04 20:15:41 +02:00
BlockPos offset = pos.down();
IBlockState offsetState = world.getBlockState(offset);
Block offsetBlock = offsetState.getBlock();
2016-08-02 19:08:06 +02:00
return this.getMetaFromState(state) == TheWildPlants.RICE.ordinal() ? offsetBlock.getMaterial(offsetState) == Material.WATER : offsetBlock.canSustainPlant(offsetState, world, offset, EnumFacing.UP, this);
2015-06-28 03:12:32 +02:00
}
2015-10-03 10:19:40 +02:00
@Override
@SideOnly(Side.CLIENT)
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player){
2016-07-04 20:15:41 +02:00
int metadata = this.getMetaFromState(state);
2016-06-17 23:50:38 +02:00
return metadata >= ALL_WILD_PLANTS.length ? null : new ItemStack(((BlockPlant)ALL_WILD_PLANTS[metadata].wildVersionOf).seedItem);
2015-10-03 10:19:40 +02:00
}
@Override
2015-06-28 03:12:32 +02:00
@SideOnly(Side.CLIENT)
2016-11-19 21:11:17 +01:00
public void getSubBlocks(Item item, CreativeTabs tab, NonNullList list){
2016-06-17 23:50:38 +02:00
for(int j = 0; j < ALL_WILD_PLANTS.length; j++){
2015-06-28 03:12:32 +02:00
list.add(new ItemStack(item, 1, j));
}
}
2016-02-01 17:49:55 +01:00
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune){
2016-07-04 20:15:41 +02:00
int metadata = this.getMetaFromState(state);
2016-06-17 23:50:38 +02:00
return metadata >= ALL_WILD_PLANTS.length ? null : ALL_WILD_PLANTS[metadata].wildVersionOf.getDrops(world, pos, ALL_WILD_PLANTS[metadata].wildVersionOf.getStateFromMeta(7), fortune);
2016-02-01 17:49:55 +01:00
}
@Override
public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player){
2016-02-01 17:49:55 +01:00
return false;
}
@Override
2016-04-20 21:39:03 +02:00
protected ItemBlockBase getItemBlock(){
return new TheItemBlock(this);
}
@Override
public boolean shouldAddCreative(){
return false;
}
@Override
protected void registerRendering(){
2016-06-17 23:50:38 +02:00
for(int i = 0; i < ALL_WILD_PLANTS.length; i++){
2016-11-21 16:23:48 +01:00
ActuallyAdditions.proxy.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), TYPE.getName()+"="+ALL_WILD_PLANTS[i].name);
}
}
2016-02-01 17:49:55 +01:00
@Override
2016-11-21 16:23:48 +01:00
public IBlockState getStateFromMeta(int meta){
return this.getDefaultState().withProperty(TYPE, TheWildPlants.values()[meta]);
}
@Override
public int getMetaFromState(IBlockState state){
return state.getValue(TYPE).ordinal();
2016-02-01 17:49:55 +01:00
}
@Override
2016-11-21 16:23:48 +01:00
protected BlockStateContainer createBlockState(){
return new BlockStateContainer(this, TYPE);
}
@Override
public EnumRarity getRarity(ItemStack stack){
return stack.getItemDamage() >= ALL_WILD_PLANTS.length ? EnumRarity.COMMON : ALL_WILD_PLANTS[stack.getItemDamage()].rarity;
2015-06-28 03:12:32 +02:00
}
public static class TheItemBlock extends ItemBlockBase{
2015-06-28 03:12:32 +02:00
public TheItemBlock(Block block){
super(block);
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
2015-06-28 03:12:32 +02:00
@Override
2015-10-23 16:54:33 +02:00
public String getUnlocalizedName(ItemStack stack){
2016-11-21 16:23:48 +01:00
return stack.getItemDamage() >= ALL_WILD_PLANTS.length ? StringUtil.BUGGED_ITEM_NAME : this.getUnlocalizedName()+"_"+ALL_WILD_PLANTS[stack.getItemDamage()].name;
2015-06-28 03:12:32 +02:00
}
}
}