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
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD> 2015 Ellpeck
|
|
|
|
|
*/
|
|
|
|
|
|
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.INameableItem;
|
|
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
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.ItemBlock;
|
|
|
|
|
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;
|
|
|
|
|
|
2015-06-28 03:12:32 +02:00
|
|
|
|
public class BlockPlant extends BlockCrops implements INameableItem{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
|
|
private IIcon[] textures;
|
|
|
|
|
private String name;
|
|
|
|
|
public Item seedItem;
|
2015-06-21 02:28:49 +02:00
|
|
|
|
public Item returnItem;
|
|
|
|
|
public int returnMeta;
|
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;
|
|
|
|
|
this.textures = new IIcon[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
|
2015-06-21 02:28:49 +02:00
|
|
|
|
public int quantityDropped(int meta, int fortune, Random random){
|
2015-06-28 03:12:32 +02:00
|
|
|
|
return meta >= 7 ? random.nextInt(addDropAmount)+minDropAmount : super.quantityDropped(meta, fortune, random);
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public IIcon getIcon(int side, int meta){
|
|
|
|
|
if(meta < 7){
|
|
|
|
|
if (meta == 6) meta = 5;
|
|
|
|
|
return this.textures[meta >> 1];
|
|
|
|
|
}
|
|
|
|
|
else return this.textures[this.textures.length-1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Item func_149866_i(){
|
|
|
|
|
return this.seedItem;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 02:28:49 +02:00
|
|
|
|
@Override
|
|
|
|
|
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
|
|
|
|
|
public Item func_149865_P(){
|
2015-06-21 02:28:49 +02:00
|
|
|
|
return this.returnItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int damageDropped(int meta){
|
|
|
|
|
return this.returnMeta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getDamageValue(World world, int x, int y, int z){
|
|
|
|
|
return 0;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public void registerBlockIcons(IIconRegister iconReg){
|
|
|
|
|
for (int i = 0; i < this.textures.length; i++){
|
|
|
|
|
textures[i] = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName() + "Stage" + (i+1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName(){
|
|
|
|
|
return this.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class TheItemBlock extends ItemBlock{
|
|
|
|
|
|
|
|
|
|
private Block theBlock;
|
|
|
|
|
|
|
|
|
|
public TheItemBlock(Block block){
|
|
|
|
|
super(block);
|
|
|
|
|
this.theBlock = block;
|
|
|
|
|
this.setHasSubtypes(false);
|
|
|
|
|
this.setMaxDamage(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
|
return EnumRarity.uncommon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getUnlocalizedName(ItemStack stack){
|
|
|
|
|
return this.getUnlocalizedName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getMetadata(int damage){
|
|
|
|
|
return damage;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|