ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/blocks/BlockPlant.java

115 lines
3.2 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("BlockPlant.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
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2015-11-02 20:55:19 +01:00
* © 2015 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2015-05-20 22:39:43 +02:00
package ellpeck.actuallyadditions.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.util.IActAddItemOrBlock;
2015-05-20 22:39:43 +02:00
import ellpeck.actuallyadditions.util.ModUtil;
import net.minecraft.block.BlockCrops;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
2015-06-28 21:28:58 +02:00
import net.minecraft.world.IBlockAccess;
2015-05-20 22:39:43 +02:00
import net.minecraft.world.World;
2015-06-28 21:28:58 +02:00
import net.minecraftforge.common.EnumPlantType;
2015-05-20 22:39:43 +02:00
import java.util.Random;
public class BlockPlant extends BlockCrops implements IActAddItemOrBlock{
2015-05-20 22:39:43 +02:00
public Item seedItem;
2015-06-21 02:28:49 +02:00
public Item returnItem;
public int returnMeta;
2015-10-28 14:46:04 +01:00
@SideOnly(Side.CLIENT)
2015-10-03 10:16:18 +02:00
private IIcon[] textures;
2015-10-28 14:46:04 +01:00
private int stages;
2015-10-03 10:16:18 +02:00
private String name;
2015-06-06 01:25:53 +02:00
private int minDropAmount;
private int addDropAmount;
2015-05-20 22:39:43 +02:00
2015-06-06 01:25:53 +02:00
public BlockPlant(String name, int stages, int minDropAmount, int addDropAmount){
2015-05-20 22:39:43 +02:00
this.name = name;
2015-10-28 14:46:04 +01:00
this.stages = stages;
2015-06-06 01:25:53 +02:00
this.minDropAmount = minDropAmount;
this.addDropAmount = addDropAmount;
2015-05-20 22:39:43 +02:00
}
2015-06-28 21:28:58 +02:00
@Override
public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z){
return EnumPlantType.Crop;
}
2015-05-20 22:39:43 +02:00
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta){
if(meta < 7){
2015-10-03 10:16:18 +02:00
if(meta == 6){
meta = 5;
}
2015-05-20 22:39:43 +02:00
return this.textures[meta >> 1];
}
2015-10-02 16:48:01 +02:00
else{
return this.textures[this.textures.length-1];
}
2015-05-20 22:39:43 +02:00
}
@Override
public Item func_149866_i(){
return this.seedItem;
}
@Override
public Item func_149865_P(){
2015-06-21 02:28:49 +02:00
return this.returnItem;
}
@Override
2015-10-03 10:19:40 +02:00
public Item getItemDropped(int meta, Random rand, int par3){
return meta >= 7 ? this.func_149865_P() : this.func_149866_i();
2015-05-20 22:39:43 +02:00
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconReg){
2015-10-28 14:46:04 +01:00
this.textures = new IIcon[this.stages];
2015-10-02 16:48:01 +02:00
for(int i = 0; i < this.textures.length; i++){
textures[i] = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()+"Stage"+(i+1));
2015-05-20 22:39:43 +02:00
}
}
@Override
public String getName(){
return this.name;
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.rare;
}
2015-10-03 10:19:40 +02:00
@Override
public int damageDropped(int meta){
return this.returnMeta;
}
@Override
public int getDamageValue(World world, int x, int y, int z){
return 0;
}
@Override
public int quantityDropped(int meta, int fortune, Random random){
return meta >= 7 ? random.nextInt(addDropAmount)+minDropAmount : super.quantityDropped(meta, fortune, random);
}
2015-05-20 22:39:43 +02:00
}