Added right-click harvest functionality to all crops.

This commit is contained in:
Patrick Emery 2016-01-15 21:39:38 -05:00
parent 7a69411948
commit 62a4b04e6f

View file

@ -10,23 +10,27 @@
package de.ellpeck.actuallyadditions.mod.blocks.base;
import java.util.List;
import java.util.Random;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.creative.CreativeTab;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.fml.common.registry.GameRegistry;
import java.util.Random;
public class BlockPlant extends BlockCrops{
public Item seedItem;
@ -40,10 +44,24 @@ public class BlockPlant extends BlockCrops{
this.name = name;
this.minDropAmount = minDropAmount;
this.addDropAmount = addDropAmount;
this.register();
}
public boolean onBlockActivated(World w, BlockPos p, IBlockState s, EntityPlayer ep, EnumFacing f, float hitX, float hitY, float hitZ){
if(getMetaFromState(s)>=7){
if(w.isRemote)return true;
List<ItemStack> isa = getDrops(w, p, s, 0);
for(ItemStack i:isa){
if(i!=null&&i.getItem()==this.getSeed()){
i.stackSize--;
}
EntityItem ei = new EntityItem(w, p.getX()+.5,p.getY()+.5,p.getZ()+.5,i);
w.spawnEntityInWorld(ei);
}
w.setBlockState(p, getStateFromMeta(0));
return true;
}
return false;
}
private void register(){
this.setUnlocalizedName(ModUtil.MOD_ID_LOWER+"."+this.getBaseName());
GameRegistry.registerBlock(this, this.getItemBlock(), this.getBaseName());
@ -91,7 +109,6 @@ public class BlockPlant extends BlockCrops{
public Item getCrop(){
return this.returnItem;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int par3){
return this.getMetaFromState(state) >= 7 ? this.getCrop() : this.getSeed();