After you get the block below the entity, first check if the block above that is farmland, and if so, use that block instead.
Alternatively, get the blockpos one block below the entity's position with a small positive Y offset.
I'd put an IDE breakpoint on the line of code that's being unexpectedly hit (this.entityWorld.playEvent....) and find out what the blockstate actually is there (and verify that the blockpos is what you expect it to be, i.e. the block the entity is standing on).
Hi, I am trying to make my custom AI task for pigs that works similiary to the EntityAIEatGrass task of sheeps so I am just copying code from there. But I don't want to copy code I don't understand so what does
this.entityWorld.setEntityState(this.grassEaterEntity, (byte)10);
do? What is the opcode 10?
As far as I can tell, its a lot better than previous series (like Loremaster). But I'd be interested in knowing what it is that he does wrong or otherwise poorly explains (I skimmed through the first couple looking to see if I could find any obvious problems).
As seems always the case, the OP has solved their own problem moments after posting it due to finding something they originally overlooked.
When looking one more time in net.minecraftforge.event I found that net.minecraftforge.event.BlockEvent held a class HarvestDropsEvent that does exactly what I wanted to.
By pushing a(n?) @SubscribeEvent on(HarvestDropsEvent) to MinecraftForge.EVENT_BUS I was able to hook an event that if the block that checks for dropping happens to be an instanceof BlockMonsterSpawner to add an ItemStack(mobCage, 1) to the drop queue.
I hope that in the future people searching for how to do Custom Vanilla Block Drops in Forge can find this thread or do what I have done and find it themself so they can continue on and make great (or at least working) mods.
My Listening class for those interested to accomplish this task:
https://gist.github.com/CAD97/0f67b8f95804a0bd2d90