diff --git a/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java b/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java new file mode 100644 index 000000000..119b4d3e0 --- /dev/null +++ b/src/main/java/forestry/farming/logic/CropBasicAgriCraft.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.farming.logic; + +import java.util.ArrayList; +import java.util.Collection; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import forestry.core.config.Defaults; +import forestry.core.proxy.Proxies; +import forestry.core.vect.Vect; + +public class CropBasicAgriCraft extends Crop { + + protected final Block block; + protected final int meta; + + public CropBasicAgriCraft(World world, Block block, int meta, Vect position) { + super(world, position); + this.block = block; + this.meta = meta; + } + + @Override + protected boolean isCrop(Vect pos) { + return getBlock(pos) == block && getBlockMeta(pos) == meta; + } + + @Override + protected Collection harvestBlock(Vect pos) { + ArrayList harvest = block.getDrops(world, pos.x, pos.y, pos.z, meta, 0); + if (harvest.size() > 1) { + harvest.remove(1); //AgriCraft returns cropsticks in 0, seeds in 1 in getDrops, removing since harvesting doesn't return them. + } + harvest.remove(0); + Proxies.common.addBlockDestroyEffects(world, pos.x, pos.y, pos.z, block, 0); + world.setBlockMetadataWithNotify(pos.x, pos.y, pos.z, 0, Defaults.FLAG_BLOCK_SYNCH); + return harvest; + } + + @Override + public String toString() { + return String.format("CropBasicAgriCraft [ position: [ %s ]; block: %s; meta: %s ]", position.toString(), block.getUnlocalizedName(), meta); + } +} diff --git a/src/main/java/forestry/farming/logic/FarmableBasicAgricraft.java b/src/main/java/forestry/farming/logic/FarmableBasicAgricraft.java new file mode 100644 index 000000000..2c31b7234 --- /dev/null +++ b/src/main/java/forestry/farming/logic/FarmableBasicAgricraft.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.farming.logic; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; +import forestry.core.config.Defaults; +import forestry.core.utils.StackUtils; +import forestry.core.vect.Vect; + +public class FarmableBasicAgricraft implements IFarmable { + + private final Block block; + private final int matureMeta; + + public FarmableBasicAgricraft(Block block, int matureMeta) { + this.block = block; + this.matureMeta = matureMeta; + } + + @Override + public boolean isSaplingAt(World world, int x, int y, int z) { + return world.getBlock(x, y, z) == block; + } + + @Override + public ICrop getCropAt(World world, int x, int y, int z) { + if (world.getBlock(x, y, z) != block) { + return null; + } + if (world.getBlockMetadata(x, y, z) != matureMeta) { + return null; + } + return new CropBasicAgriCraft(world, block, matureMeta, new Vect(x, y, z)); + } + + @Override + public boolean isGermling(ItemStack itemstack) { + return StackUtils.equals(block, itemstack); + } + + @Override + public boolean isWindfall(ItemStack itemstack) { + return false; + } + + @Override + public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, int x, int y, int z) { + return world.setBlock(x, y, z, block, 0, Defaults.FLAG_BLOCK_SYNCH); + } + +} diff --git a/src/main/java/forestry/plugins/PluginAgriCraft.java b/src/main/java/forestry/plugins/PluginAgriCraft.java new file mode 100644 index 000000000..3e25ece44 --- /dev/null +++ b/src/main/java/forestry/plugins/PluginAgriCraft.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.plugins; + +import net.minecraft.block.Block; + +import cpw.mods.fml.common.registry.GameRegistry; + +import forestry.api.farming.Farmables; +import forestry.core.config.Defaults; +import forestry.core.proxy.Proxies; +import forestry.farming.logic.FarmableBasicAgricraft; + +@Plugin(pluginID = "AgriCraft", name = "AgriCraft", author = "Nirek", url = Defaults.URL, unlocalizedDescription = "for.plugin.agricraft.description") +public class PluginAgriCraft extends ForestryPlugin { + + private static final String AgriCraft = "AgriCraft"; + + @Override + public boolean isAvailable() { + return Proxies.common.isModLoaded(AgriCraft); + } + + @Override + public String getFailMessage() { + return "AgriCraft"; + } + + @Override + protected void registerRecipes() { + + Block cropBlock = GameRegistry.findBlock(AgriCraft, "crops"); + if (cropBlock != null) { + Farmables.farmables.get("farmOrchard").add(new FarmableBasicAgricraft(cropBlock, 7)); + } + } + +} + diff --git a/src/main/java/forestry/plugins/PluginManager.java b/src/main/java/forestry/plugins/PluginManager.java index dccf579c4..a573e4c9b 100644 --- a/src/main/java/forestry/plugins/PluginManager.java +++ b/src/main/java/forestry/plugins/PluginManager.java @@ -85,6 +85,7 @@ public class PluginManager { BUILDCRAFT_TRANSPORT(new PluginBuildCraftTransport()), PROPOLIS_PIPE(new PluginPropolisPipe()), + AGRICRAFT(new PluginAgriCraft()), BIOMESOPLENTY(new PluginBiomesOPlenty()), CHISEL(new PluginChisel()), EXTRAUTILITIES(new PluginExtraUtilities()),