Ender IO Zoo

Ender IO Zoo

962k Downloads

[Feature Request] Using Hoe Hook Event

GenDeathrow opened this issue ยท 6 comments

commented

This is more of a feature request to make the farming station able to hoe custom dirt/farmland. I know this was brought up once before, but I looked over your code. I think we can make it work pretty simply. I use the "UseHoeEvent" to hoe my custom dirt. I noticed that the farming station does not, and looks specifically for vanilla dirt.

Now I will admit, I haven't gone thur all your code(Its a lot). I'm sure there could be issues with using the hook(possible hoes with larger a radius). Id like to hear your response back on it. Just to see if maybe we could get it to work. I'd be willing to change things on my side as well. Example maybe using OreDic to know if the dirt is tillable or something along those lines. Or heck even a simple API.

https://github.com/SleepyTrousers/EnderIO/blob/1.10/src/main/java/crazypants/enderio/machine/farm/TileFarmStation.java#L189-L191

Just the hook that's used in the hoe item:
image

Thanks for taking the time to read.
GenDeathrow

Edit: This is for the Hatchery Mod

commented

We're already calling that to cause the damage. https://github.com/SleepyTrousers/EnderIO/blob/1.10/src/main/java/crazypants/enderio/machine/farm/TileFarmStation.java#L309

However, when looking at this, it seems we could use onItemUse() to do the actual tilling and use its EnumActionResult to decide if it did something. Looks like the side effect of some changes after 1.7.10 that makes this possible.

commented

Have a look at this, do you think this would work?

update: No it won't, but this version might...:

  public boolean tillBlock(BlockPos plantingLocation) {
    BlockPos dirtLoc = plantingLocation.down();
    Block dirtBlock = getBlock(dirtLoc);
    if (dirtBlock == Blocks.FARMLAND) {
      return true;
    } else {
      ItemStack tool = getTool(ToolType.HOE);
      if (Prep.isInvalid(tool)) {
        return false;
      }

      if (dirtBlock == Blocks.DIRT || dirtBlock == Blocks.GRASS) {
        setNotification(FarmNotification.NO_HOE);
        return false;
      }

      boolean doDamage = worldObj.rand.nextFloat() >= Config.farmToolTakeDamageChance && canDamage(tool);
      if (!doDamage) {
        tool = tool.copy();
      }

      int origDamage = tool.getItemDamage();
      EnumActionResult itemUse = tool.getItem().onItemUse(tool, farmerJoe, worldObj, dirtLoc, EnumHand.MAIN_HAND, EnumFacing.UP, 0.5f, 0.5f, 0.5f);

      if (itemUse != EnumActionResult.SUCCESS) {
        return false;
      }

      if (doDamage) {
        if (origDamage == tool.getItemDamage()) {
          tool.damageItem(1, farmerJoe);
        }

        if (Prep.isInvalid(tool) || tool.stackSize == 0 || tool.getItemDamage() >= tool.getMaxDamage()) { // TODO 1.11
          destroyTool(ToolType.HOE);
          markDirty();
        }
      }

      worldObj.playSound(dirtLoc.getX() + 0.5F, dirtLoc.getY() + 0.5F, dirtLoc.getZ() + 0.5F, SoundEvents.BLOCK_GRASS_STEP, SoundCategory.BLOCKS,
          (Blocks.FARMLAND.getSoundType().getVolume() + 1.0F) / 2.0F, Blocks.FARMLAND.getSoundType().getPitch() * 0.8F, false);
      actionPerformed(false);
      return true;
    }
  }
commented

It may, Tell ya what I will probably fork this later and mess around with it.

Edit: Here is a link to my mod in-case you get to it before me.
https://minecraft.curseforge.com/projects/hatchery?gameCategorySlug=mc-mods&projectID=251138

commented

not a problem, I probably should have left this one open...I batch closed all that was "code complete", "waiting for feedback" or just old.

The latest build has that code in, it'd be great to get feedback if it works. There still is an "is there farmland" check or two when things are planted, but this should do the tilling correctly at least.

commented

Wow I had completly forgotten about this. RL intervened sorry I wasn't more help.

commented

Its working correctly now. Thanks for taking the time to look at it. I'm sure you made hatchery users very happy.