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

126 lines
4.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;
2016-01-08 13:31:58 +01:00
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
2016-01-05 04:47:35 +01:00
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;
import net.minecraft.block.properties.PropertyInteger;
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-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
public static final TheWildPlants[] allWildPlants = TheWildPlants.values();
private static final PropertyInteger META = PropertyInteger.create("meta", 0, allWildPlants.length-1);
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-01-08 13:31:58 +01:00
BlockPos offset = PosUtil.offset(pos, 0, -1, 0);
2016-04-20 21:39:03 +02:00
return PosUtil.getMetadata(state) == TheWildPlants.RICE.ordinal() ? PosUtil.getMaterial(offset, world) == Material.WATER : PosUtil.getBlock(offset, world).canSustainPlant(world.getBlockState(offset), 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-05-02 17:12:31 +02:00
int metadata = PosUtil.getMetadata(pos, world);
2016-03-18 23:47:22 +01:00
return metadata >= allWildPlants.length ? null : new ItemStack(((BlockPlant)allWildPlants[metadata].wildVersionOf).seedItem);
2015-10-03 10:19:40 +02:00
}
@Override
2015-06-28 03:12:32 +02:00
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs tab, List list){
2015-10-02 16:48:01 +02:00
for(int j = 0; j < allWildPlants.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-03-18 15:42:06 +01:00
int metadata = PosUtil.getMetadata(state);
2016-02-01 17:49:55 +01:00
return metadata >= allWildPlants.length ? null : allWildPlants[metadata].wildVersionOf.getDrops(world, pos, allWildPlants[metadata].wildVersionOf.getStateFromMeta(7), fortune);
}
@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(){
for(int i = 0; i < allWildPlants.length; i++){
ActuallyAdditions.proxy.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), META.getName()+"="+i);
}
}
2016-02-01 17:49:55 +01:00
@Override
public EnumRarity getRarity(ItemStack stack){
return stack.getItemDamage() >= allWildPlants.length ? EnumRarity.COMMON : allWildPlants[stack.getItemDamage()].rarity;
}
@Override
protected PropertyInteger getMetaProperty(){
return META;
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){
2015-11-23 19:06:07 +01:00
return stack.getItemDamage() >= allWildPlants.length ? StringUtil.BUGGED_ITEM_NAME : this.getUnlocalizedName()+allWildPlants[stack.getItemDamage()].name;
2015-06-28 03:12:32 +02:00
}
}
}