Closed ChloeDawn closed 6 years ago
Two things:
IEdibleBlock interface
on BlockCake at runtime, so that's what's missing. So, you could potentially solve this by @Optional
-ly implementing that interface in PersistentCakeBlock
and then redirect the implementation to super
/BlockCake
(unsure if this would be easy).@SubscribeEvent
public void onGetHarvestDrops(BlockEvent.HarvestDropsEvent event)
{
if (event.getState().getBlock() == Blocks.CAKE && event.getState().getValue(BlockCake.BITES) == 0)
{
event.getDrops().add(new ItemStack(Items.CAKE));
}
}
That single event hook would not account for all occasions where a cake block is broken in the world. I had been using events at one point, as seen here: PersistentCake.java#L25-L56. It was much cleaner and more reliable to replace the cake instance; which I also handle for Harvestcraft cakes, as you can see in the other packages of the current branch. I will add an Optional interface for IEdibleBlock to my replacement, thanks for the info.
Ah, ok, block breaking is a pretty crazy tangle of unexpected behaviors 😢 . I've run into similar edge-cases when trying to use HarvestDropsEvent.
Let me know if you run into any issues trying to use IEdibleBlock.
EDIT: Also worth noting that in your case, the onBlockActivated
and onEatenCompatibility
methods shown in the linked example above are irrelevant. getFoodValues
and setEdibleAtMaxHunger
is all you need to implement (and, if possible, it'd be best if you could just implement them as something like ((IEdibleBlock)super).getFoodValues(itemStack)
).
Poking around, the root issue is you will be holding a hard reference to the cake block ItemFoodProxy.java#L21 which is incompatible with registry replacements.
EDIT:
Secondly, I realise my class isn't the issue at all. I extend BlockCake, which would implement the interface at runtime. This is 100% an issue with your internal references not being compatible with registry replacements. ;-;
Thirdly, discussing things inside an issue is frustrating lol, do you have Discord? There is a modded Minecraft discord (r/ftb) here. Ping @DiscordPolice
to ask for Mod Developer role, which gives access to #developers
Ah, yes, you're totally right. Fixed in https://github.com/squeek502/AppleCore/commit/0515815840cea82a9040b634d61b8f5b16e3966f, and confirmed that it works without any interface compat. Will release new 1.12.x versions with the fix soon.
Just for the sake of completeness, an alternative (less complete) 'fix' would be to have your mod add your block to AppleCore's edible block registry by doing: AppleCoreAPI.registry.registerEdibleBlock(your_registered_cake_block, Items.CAKE)
. Up to you if want to add that to be compatible with AppleCore versions before the above fix.
EDIT: Actually didn't realize you had merged the applecore branch into master. Checking if the version without the interface compat works now.
EDIT#2: Confirmed to work without PersistentCakeBlock
implementing IEdibleBlock
.
Should be fixed in AppleCore v3.1.1. You can safely revert https://github.com/SleeplessDevelopment/PersistentCake/commit/ddb991d6709233b405690d18e37a62984a46b906 if you want.
Game crashes when trying to right-click/eat a cake block.
Mod version: 1.12.2-3.1.0 Crash report: pastebin.com/Ng1CYAXE
It may be worth noting I apply a registry replacement for the cake block, which might be the issue? I'm not sure. If that is the case, let me know what needs changing here to prevent issues with your mod.
Replacement instance: net.insomniakitten.cake.PersistentCakeBlock