2015-05-20 22:39:43 +02:00
|
|
|
package ellpeck.actuallyadditions.items;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
import ellpeck.actuallyadditions.blocks.BlockPlant;
|
|
|
|
import ellpeck.actuallyadditions.util.INameableItem;
|
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.Item;
|
2015-05-22 17:48:50 +02:00
|
|
|
import net.minecraft.item.ItemSeeds;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.EnumPlantType;
|
|
|
|
import net.minecraftforge.common.util.BlockSnapshot;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import net.minecraftforge.event.ForgeEventFactory;
|
2015-05-22 17:48:50 +02:00
|
|
|
import powercrystals.minefactoryreloaded.api.IFactoryPlantable;
|
|
|
|
import powercrystals.minefactoryreloaded.api.ReplacementBlock;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-05-22 17:48:50 +02:00
|
|
|
public class ItemSeed extends ItemSeeds implements INameableItem, IFactoryPlantable{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
public Block plant;
|
|
|
|
public Block soilBlock;
|
|
|
|
public EnumPlantType type;
|
|
|
|
public String name;
|
|
|
|
|
|
|
|
public ItemSeed(String name, Block plant, Block soilBlock, EnumPlantType type, ItemStack returnItem){
|
2015-05-22 17:48:50 +02:00
|
|
|
super(plant, soilBlock);
|
2015-05-20 22:39:43 +02:00
|
|
|
this.name = name;
|
|
|
|
this.plant = plant;
|
|
|
|
this.soilBlock = soilBlock;
|
|
|
|
this.type = type;
|
|
|
|
((BlockPlant)this.plant).seedItem = this;
|
|
|
|
((BlockPlant)this.plant).returnItem = returnItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int hitSide, float hitX, float hitY, float hitZ){
|
|
|
|
if(this.type == EnumPlantType.Water || hitSide != 1) return false;
|
|
|
|
else if(player.canPlayerEdit(x, y, z, hitSide, stack) && player.canPlayerEdit(x, y + 1, z, hitSide, stack)){
|
|
|
|
if(((BlockPlant)this.plant).canPlaceBlockOn(world.getBlock(x, y, z)) && world.isAirBlock(x, y + 1, z)){
|
|
|
|
world.setBlock(x, y + 1, z, this.plant);
|
|
|
|
stack.stackSize--;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
|
|
|
|
if(this.type == EnumPlantType.Water){
|
|
|
|
MovingObjectPosition pos = this.getMovingObjectPositionFromPlayer(world, player, true);
|
|
|
|
if(pos != null){
|
|
|
|
if(pos.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK){
|
|
|
|
int i = pos.blockX;
|
|
|
|
int j = pos.blockY;
|
|
|
|
int k = pos.blockZ;
|
|
|
|
|
2015-05-22 17:48:50 +02:00
|
|
|
if(player.canPlayerEdit(i, j, k, pos.sideHit, stack)){
|
2015-05-20 22:39:43 +02:00
|
|
|
if(world.getBlock(i, j, k).getMaterial() == Material.water && world.getBlockMetadata(i, j, k) == 0 && world.isAirBlock(i, j + 1, k)){
|
|
|
|
BlockSnapshot snap = BlockSnapshot.getBlockSnapshot(world, i, j+1, k);
|
|
|
|
world.setBlock(i, j + 1, k, this.plant);
|
|
|
|
if(ForgeEventFactory.onPlayerBlockPlace(player, snap, ForgeDirection.UP).isCanceled()){
|
|
|
|
snap.restore(true, false);
|
|
|
|
return super.onItemRightClick(stack, world, player);
|
|
|
|
}
|
|
|
|
stack.stackSize--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onItemRightClick(stack, world, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return EnumRarity.rare;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IIcon getIcon(ItemStack stack, int pass){
|
|
|
|
return this.itemIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerIcons(IIconRegister iconReg){
|
|
|
|
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z){
|
|
|
|
return this.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Block getPlant(IBlockAccess world, int x, int y, int z){
|
|
|
|
return this.plant;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPlantMetadata(IBlockAccess world, int x, int y, int z){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName(){
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getOredictName(){
|
|
|
|
return this.getName();
|
|
|
|
}
|
2015-05-22 17:48:50 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Item getSeed(){
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canBePlanted(ItemStack stack, boolean forFermenting){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ReplacementBlock getPlantedBlock(World world, int x, int y, int z, ItemStack stack){
|
|
|
|
return new ReplacementBlock(this.plant);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canBePlantedHere(World world, int x, int y, int z, ItemStack stack){
|
|
|
|
return world.getBlock(x, y, z).isReplaceable(world, x, y, z) && ((BlockPlant)this.plant).canPlaceBlockOn(world.getBlock(x, y-1, z));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void prePlant(World world, int x, int y, int z, ItemStack stack){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postPlant(World world, int x, int y, int z, ItemStack stack){
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|