I have made a crop called catnip and have put it into minecraft. The problem is that the MineFactory harvester won't harvest it or plant it. I can do it manually but the MFR harvester wont. I looked in the vanilla code for potatoes and my code is reasonably the same but I am wondering why it wont work. The harvester will harvest all the vanilla stuff and it is powered and has a empty chest behind it. I am just wondering why my code wont work with it.
NBTTagCompound tag = new NBTTagCompound();
tag.setString("seed", "petco:CatnipLeaves"); // 'seed' item consumed by planter
tag.setString("crop", "petco:cropCatnip"); // 'crop' block placed by the planter
FMLInterModComms.sendMessage("MineFactoryReloaded", "registerPlantable_Crop", tag);
yeah that looks great, but... what would I do about the classes it links to like Utils and TileRCrop, and what about the files that they link to like the files in your api?
Ok, I have the harvester working, and most of the planter class working, but I can't seem to make it hoe dirt or grass then plant it. I have tried heaps of different code but nothing works. Does anyone have some code that will make it hoe blocks properly?
@Override
public ReplacementBlock getPlantedBlock(World world, int x, int y, int z, ItemStack stack) {
return new ReplacementBlock(petco.catnipCrop);
}
@Override
public boolean canBePlantedHere(World world, int x, int y, int z, ItemStack stack) {
if(!world.isAirBlock(x, y, z))
return false;
Block ground = world.getBlock(x, y-1, z);
return ground.equals(Blocks.farmland);
}
@Override
public void prePlant(World world, int x, int y, int z, ItemStack stack) {
world.setBlock(x, y - 1, z, Blocks.farmland);
}
@Override
public void postPlant(World world, int x, int y, int z, ItemStack stack) {
public class HarvestableHandler implements IFactoryHarvestable {
private Block cropCatnip;
public HarvestableHandler(Block block, HarvestType normal)
{
cropCatnip = block;
}
@Override
public Block getPlant() {
return cropCatnip;
}
@Override
public HarvestType getHarvestType() {
return HarvestType.Normal;
}
@Override
public boolean breakBlock() {
return true;
}
@Override
public boolean canBeHarvested(World world, Map<String, Boolean> harvesterSettings, int x, int y, int z) {
return world.getBlockMetadata(x, y, z) >= 4;
}
@Override
public List<ItemStack> getDrops(World world, Random rand, Map<String, Boolean> harvesterSettings, int x, int y, int z) {
return cropCatnip.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
}
@Override
public void preHarvest(World world, int x, int y, int z) {
if (world.getBlockMetadata(x, y, z) > 4)
{
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
}
@Override
public void postHarvest(World world, int x, int y, int z) {
world.notifyBlocksOfNeighborChange(x, y, z, cropCatnip);
}
@Override
public ReplacementBlock getPlantedBlock(World world, int x, int y, int z, ItemStack stack) {
return new ReplacementBlock(petco.catnipCrop);
}
@Override
public boolean canBePlantedHere(World world, int x, int y, int z, ItemStack stack) {
if (!world.isAirBlock(x, y, z))
return false;
Block ground = world.getBlock(x, y-1, z);
return ground != null && (ground.equals(Blocks.dirt) || ground.equals(Blocks.grass) || ground.equals(Blocks.farmland));
}
@Override
public void prePlant(World world, int x, int y, int z, ItemStack stack)
{
Block ground = world.getBlock(x, y-1, z);
if(ground.equals(Blocks.grass) || ground.equals(Blocks.dirt))
world.setBlock(x, y-1, z, Blocks.farmland);
}
@Override
public void postPlant(World world, int x, int y, int z, ItemStack stack) {
}
}
Extract from main class
@EventHandler
public void init(FMLInitializationEvent event){
FactoryRegistry.sendMessage("registerPlantable", new PlantableHandler(catnipLeaves, catnipCrop));
FactoryRegistry.sendMessage("registerHarvestable", new HarvestableHandler(catnipCrop, HarvestType.Normal));
}
Hi,
I have made a crop called catnip and have put it into minecraft. The problem is that the MineFactory harvester won't harvest it or plant it. I can do it manually but the MFR harvester wont. I looked in the vanilla code for potatoes and my code is reasonably the same but I am wondering why it wont work. The harvester will harvest all the vanilla stuff and it is powered and has a empty chest behind it. I am just wondering why my code wont work with it.
Murdy007
BlockCatnip:
package petco.mod.crops;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
import petco.mod.core.*;
public class BlockCatnip extends BlockCrops{
@SideOnly(Side.CLIENT)
private Icon[] iconArray;
public BlockCatnip(int par1) {
super(par1);
}
@SideOnly(Side.CLIENT)
public Icon getIcon(int side, int metadata){
if(metadata < 7){
if(metadata == 6){
metadata = 5;
}
return iconArray[metadata >> 1];
}
return iconArray[3];
}
public int getSeedItem(){
return petco.itemCatnip.itemID;
}
public int getCropItem(){
return petco.itemCatnip.itemID;
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister iconRegister){
this.iconArray = new Icon[4];
for(int i = 0; i < this.iconArray.length; i++){
this.iconArray = iconRegister.registerIcon("petco" + ":" + "catnip_" + (i+1));
}
}
}
Extract from main class:
blockCatnip = new BlockCatnip(1675).setUnlocalizedName("catnip");
itemCatnip = new ItemSeedFood(16819, 3, 0.3F, blockCatnip.blockID, Block.tilledField.blockID).setUnlocalizedName("itemCatnip").setTextureName("petco:catnip").setCreativeTab(TabPetCo);
registerBlock(blockCatnip, "Catnip");
LanguageRegistry.addName(itemCatnip, "Catnip Leaves");
Are you using the mfr api? You need to define what blocks are able to be harvested with it
Art by me: MrPancakeWolfie@DeviantArt
I installed the api and added some code to blockCatnip, but it still wont harvest it or plant it. Am I using the right code???
package petco.mod.crops;
import java.lang.reflect.Method;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
import petco.mod.core.*;
import powercrystals.minefactoryreloaded.api.IFactoryHarvestable;
import powercrystals.minefactoryreloaded.api.IFactoryPlantable;
public class BlockCatnip extends BlockCrops{
public static void registerHarvestable(IFactoryHarvestable harvestable)
{
try
{
Class<?> registry = Class.forName("powercrystals.minefactoryreloaded.MFRRegistry");
if(registry != null)
{
Method reg = registry.getMethod("registerHarvestable", IFactoryHarvestable.class);
reg.invoke(registry, harvestable);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void registerPlantable(IFactoryPlantable plantable)
{
try
{
Class<?> registry = Class.forName("powercrystals.minefactoryreloaded.MFRRegistry");
if(registry != null)
{
Method reg = registry.getMethod("registerPlantable", IFactoryPlantable.class);
reg.invoke(registry, plantable);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
@SideOnly(Side.CLIENT)
private Icon[] iconArray;
public BlockCatnip(int par1) {
super(par1);
}
@SideOnly(Side.CLIENT)
public Icon getIcon(int side, int metadata){
if(metadata < 7){
if(metadata == 6){
metadata = 5;
}
return iconArray[metadata >> 1];
}
return iconArray[3];
}
public int getSeedItem(){
return petco.itemCatnip.itemID;
}
public int getCropItem(){
return petco.itemCatnip.itemID;
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister iconRegister){
this.iconArray = new Icon[4];
for(int i = 0; i < this.iconArray.length; i++){
this.iconArray = iconRegister.registerIcon("petco" + ":" + "catnip_" + (i+1));
}
}
}
tried this code:
NBTTagCompound tag = new NBTTagCompound();
tag.setString("seed", "petco:CatnipLeaves"); // 'seed' item consumed by planter
tag.setString("crop", "petco:cropCatnip"); // 'crop' block placed by the planter
FMLInterModComms.sendMessage("MineFactoryReloaded", "registerPlantable_Crop", tag);
still doesn't work. no errors though
Bump. Still haven't found how to do this. I have looked at some of the Magical crops compat with MFR but none of that works
bump. Still can't find anything. I may need some code for this one.
Take a look here. It's fairly simple.
yeah that looks great, but... what would I do about the classes it links to like Utils and TileRCrop, and what about the files that they link to like the files in your api?
Thanks, Murdy007
You uh... Read it...
Ok, I have the harvester working, and most of the planter class working, but I can't seem to make it hoe dirt or grass then plant it. I have tried heaps of different code but nothing works. Does anyone have some code that will make it hoe blocks properly?
In prePlant, just use world.setBlock(x, y - 1, z, Blocks.farmland);
Hmm...
For some reason it still doesn't want to work.
Code:
package com.petco.compat;
import com.petco.core.petco;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import powercrystals.minefactoryreloaded.api.HarvestType;
import powercrystals.minefactoryreloaded.api.IFactoryPlantable;
import powercrystals.minefactoryreloaded.api.ReplacementBlock;
public class PlantableHandler implements IFactoryPlantable{
private Item catnipLeaves;
private Block catnipCrop;
public PlantableHandler(Item catnipLeaves, Block catnipCrop)
{
this.catnipLeaves = catnipLeaves;
}
@Override
public Item getSeed() {
return catnipLeaves;
}
@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(petco.catnipCrop);
}
@Override
public boolean canBePlantedHere(World world, int x, int y, int z, ItemStack stack) {
if(!world.isAirBlock(x, y, z))
return false;
Block ground = world.getBlock(x, y-1, z);
return ground.equals(Blocks.farmland);
}
@Override
public void prePlant(World world, int x, int y, int z, ItemStack stack) {
world.setBlock(x, y - 1, z, Blocks.farmland);
}
@Override
public void postPlant(World world, int x, int y, int z, ItemStack stack) {
}
}
Does anyone know why this is happening?
Anyone?
Why not try asking the devs in their IRC channel?
ALL FIXED!
Harvest Class
package com.petco.compat;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import powercrystals.minefactoryreloaded.api.HarvestType;
import powercrystals.minefactoryreloaded.api.IFactoryHarvestable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import com.petco.core.petco;
import com.petco.crops.cropCatnip;
public class HarvestableHandler implements IFactoryHarvestable {
private Block cropCatnip;
public HarvestableHandler(Block block, HarvestType normal)
{
cropCatnip = block;
}
@Override
public Block getPlant() {
return cropCatnip;
}
@Override
public HarvestType getHarvestType() {
return HarvestType.Normal;
}
@Override
public boolean breakBlock() {
return true;
}
@Override
public boolean canBeHarvested(World world, Map<String, Boolean> harvesterSettings, int x, int y, int z) {
return world.getBlockMetadata(x, y, z) >= 4;
}
@Override
public List<ItemStack> getDrops(World world, Random rand, Map<String, Boolean> harvesterSettings, int x, int y, int z) {
return cropCatnip.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
}
@Override
public void preHarvest(World world, int x, int y, int z) {
if (world.getBlockMetadata(x, y, z) > 4)
{
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
}
@Override
public void postHarvest(World world, int x, int y, int z) {
world.notifyBlocksOfNeighborChange(x, y, z, cropCatnip);
}
}
Planter Class
package com.petco.compat;
import com.petco.core.petco;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import powercrystals.minefactoryreloaded.api.HarvestType;
import powercrystals.minefactoryreloaded.api.IFactoryPlantable;
import powercrystals.minefactoryreloaded.api.ReplacementBlock;
public class PlantableHandler implements IFactoryPlantable{
private Item catnipLeaves;
private Block catnipCrop;
public PlantableHandler(Item catnipLeaves, Block catnipCrop)
{
this.catnipLeaves = catnipLeaves;
}
@Override
public Item getSeed() {
return catnipLeaves;
}
@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(petco.catnipCrop);
}
@Override
public boolean canBePlantedHere(World world, int x, int y, int z, ItemStack stack) {
if (!world.isAirBlock(x, y, z))
return false;
Block ground = world.getBlock(x, y-1, z);
return ground != null && (ground.equals(Blocks.dirt) || ground.equals(Blocks.grass) || ground.equals(Blocks.farmland));
}
@Override
public void prePlant(World world, int x, int y, int z, ItemStack stack)
{
Block ground = world.getBlock(x, y-1, z);
if(ground.equals(Blocks.grass) || ground.equals(Blocks.dirt))
world.setBlock(x, y-1, z, Blocks.farmland);
}
@Override
public void postPlant(World world, int x, int y, int z, ItemStack stack) {
}
}
Extract from main class
@EventHandler
public void init(FMLInitializationEvent event){
FactoryRegistry.sendMessage("registerPlantable", new PlantableHandler(catnipLeaves, catnipCrop));
FactoryRegistry.sendMessage("registerHarvestable", new HarvestableHandler(catnipCrop, HarvestType.Normal));
}