2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("BlockWildPlant.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 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
|
|
|
|
2016-01-10 15:29:44 +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-10 15:29:44 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
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;
|
|
|
|
import net.minecraft.block.material.Material;
|
2016-01-08 15:21:05 +01:00
|
|
|
import net.minecraft.block.properties.PropertyInteger;
|
2016-01-07 23:42:42 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-06-28 03:12:32 +02:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2016-01-07 23:42:42 +01:00
|
|
|
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;
|
2016-01-07 23:42:42 +01:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-01-10 15:29:44 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-01-07 23:42:42 +01:00
|
|
|
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;
|
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public class BlockWildPlant extends BlockBushBase{
|
2015-06-28 03:12:32 +02:00
|
|
|
|
|
|
|
public static final TheWildPlants[] allWildPlants = TheWildPlants.values();
|
2016-01-08 15:21:05 +01:00
|
|
|
private static final PropertyInteger META = PropertyInteger.create("meta", 0, allWildPlants.length-1);
|
2015-06-28 03:12:32 +02:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public BlockWildPlant(String name){
|
|
|
|
super(name);
|
2015-06-28 03:12:32 +02:00
|
|
|
this.setStepSound(soundTypeGrass);
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:27:47 +01:00
|
|
|
@Override
|
|
|
|
public int damageDropped(IBlockState state){
|
|
|
|
return this.getMetaFromState(state);
|
|
|
|
}
|
|
|
|
|
2016-01-08 15:21:05 +01:00
|
|
|
@Override
|
|
|
|
protected PropertyInteger getMetaProperty(){
|
|
|
|
return META;
|
|
|
|
}
|
|
|
|
|
2015-06-28 03:12:32 +02:00
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
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);
|
|
|
|
return PosUtil.getMetadata(pos, world) == TheWildPlants.RICE.ordinal() ? PosUtil.getMaterial(offset, world) == Material.water : PosUtil.getBlock(offset, world).canSustainPlant(world, offset, EnumFacing.UP, this);
|
2015-06-28 03:12:32 +02:00
|
|
|
}
|
|
|
|
|
2015-12-16 15:26:33 +01:00
|
|
|
@Override
|
2015-12-21 22:46:23 +01:00
|
|
|
public Class<? extends ItemBlockBase> getItemBlock(){
|
|
|
|
return TheItemBlock.class;
|
2015-12-16 15:26:33 +01:00
|
|
|
}
|
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
@Override
|
2015-12-21 22:46:23 +01:00
|
|
|
public boolean shouldAddCreative(){
|
|
|
|
return false;
|
2015-12-19 10:30:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
2016-01-07 23:42:42 +01:00
|
|
|
return stack.getItemDamage() >= allWildPlants.length ? EnumRarity.COMMON : allWildPlants[stack.getItemDamage()].rarity;
|
2015-12-19 10:30:39 +01:00
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player){
|
2015-06-28 03:12:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2016-01-07 23:42:42 +01:00
|
|
|
public Item getItem(World world, BlockPos pos){
|
2016-01-08 13:31:58 +01:00
|
|
|
int metadata = PosUtil.getMetadata(pos, world);
|
|
|
|
return metadata >= allWildPlants.length ? null : ((BlockPlant)allWildPlants[metadata].wildVersionOf).seedItem;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2015-06-28 03:12:32 +02:00
|
|
|
@SuppressWarnings("all")
|
|
|
|
@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-01-10 15:29:44 +01:00
|
|
|
@Override
|
|
|
|
protected void registerRendering(){
|
|
|
|
ResourceLocation[] resLocs = new ResourceLocation[allWildPlants.length];
|
|
|
|
for(int i = 0; i < allWildPlants.length; i++){
|
|
|
|
String name = this.getBaseName()+allWildPlants[i].name;
|
|
|
|
resLocs[i] = new ResourceLocation(ModUtil.MOD_ID_LOWER, name);
|
|
|
|
ActuallyAdditions.proxy.addRenderRegister(new ItemStack(this, 1, i), new ResourceLocation(ModUtil.MOD_ID_LOWER, name));
|
|
|
|
}
|
|
|
|
ActuallyAdditions.proxy.addRenderVariant(Item.getItemFromBlock(this), resLocs);
|
|
|
|
}
|
|
|
|
|
2015-07-06 23:41:10 +02:00
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune){
|
2016-01-08 13:31:58 +01:00
|
|
|
int metadata = PosUtil.getMetadata(pos, world);
|
2016-01-07 23:42:42 +01:00
|
|
|
return metadata >= allWildPlants.length ? null : allWildPlants[metadata].wildVersionOf.getDrops(world, pos, allWildPlants[metadata].wildVersionOf.getStateFromMeta(7), fortune);
|
2015-06-28 03:12:32 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:48:56 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|