mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Merge pull request #57 from ssblur/master
Added right-click harvest functionality to all crops.
This commit is contained in:
commit
0cc6428e45
1 changed files with 22 additions and 5 deletions
|
@ -10,23 +10,27 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.blocks.base;
|
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.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.mod.creative.CreativeTab;
|
import de.ellpeck.actuallyadditions.mod.creative.CreativeTab;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||||
import net.minecraft.block.BlockCrops;
|
import net.minecraft.block.BlockCrops;
|
||||||
import net.minecraft.block.state.IBlockState;
|
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.EnumRarity;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.EnumPlantType;
|
import net.minecraftforge.common.EnumPlantType;
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class BlockPlant extends BlockCrops{
|
public class BlockPlant extends BlockCrops{
|
||||||
|
|
||||||
public Item seedItem;
|
public Item seedItem;
|
||||||
|
@ -40,10 +44,24 @@ public class BlockPlant extends BlockCrops{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.minDropAmount = minDropAmount;
|
this.minDropAmount = minDropAmount;
|
||||||
this.addDropAmount = addDropAmount;
|
this.addDropAmount = addDropAmount;
|
||||||
|
|
||||||
this.register();
|
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(){
|
private void register(){
|
||||||
this.setUnlocalizedName(ModUtil.MOD_ID_LOWER+"."+this.getBaseName());
|
this.setUnlocalizedName(ModUtil.MOD_ID_LOWER+"."+this.getBaseName());
|
||||||
GameRegistry.registerBlock(this, this.getItemBlock(), this.getBaseName());
|
GameRegistry.registerBlock(this, this.getItemBlock(), this.getBaseName());
|
||||||
|
@ -91,7 +109,6 @@ public class BlockPlant extends BlockCrops{
|
||||||
public Item getCrop(){
|
public Item getCrop(){
|
||||||
return this.returnItem;
|
return this.returnItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item getItemDropped(IBlockState state, Random rand, int par3){
|
public Item getItemDropped(IBlockState state, Random rand, int par3){
|
||||||
return this.getMetaFromState(state) >= 7 ? this.getCrop() : this.getSeed();
|
return this.getMetaFromState(state) >= 7 ? this.getCrop() : this.getSeed();
|
||||||
|
|
Loading…
Reference in a new issue