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

132 lines
4.7 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
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 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;
2018-06-23 18:37:41 +02:00
import net.minecraft.block.BlockCrops;
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.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;
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();
public 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();
return state.getValue(TYPE) == TheWildPlants.RICE ? offsetState.getMaterial() == 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
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player){
BlockPlant wild = (BlockPlant) state.getValue(TYPE).wildVersionOf;
return new ItemStack(wild.seedItem);
2015-10-03 10:19:40 +02:00
}
@Override
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list){
2016-06-17 23:50:38 +02:00
for(int j = 0; j < ALL_WILD_PLANTS.length; j++){
2017-06-17 00:48:49 +02:00
list.add(new ItemStack(this, 1, j));
2015-06-28 03:12:32 +02:00
}
}
2016-02-01 17:49:55 +01:00
@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune){
2018-06-23 18:37:41 +02:00
state.getValue(TYPE).wildVersionOf.getDrops(drops, world, pos, state.getValue(TYPE).wildVersionOf.getDefaultState().withProperty(BlockCrops.AGE, 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
public void registerRendering(){
2016-06-17 23:50:38 +02:00
for(int i = 0; i < ALL_WILD_PLANTS.length; i++){
2018-05-10 11:38:58 +02: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
2018-08-04 04:22:20 +02:00
public String getTranslationKey(ItemStack stack){
return stack.getItemDamage() >= ALL_WILD_PLANTS.length ? StringUtil.BUGGED_ITEM_NAME : this.getTranslationKey()+"_"+ALL_WILD_PLANTS[stack.getItemDamage()].name;
2015-06-28 03:12:32 +02:00
}
}
}