AppleCore

AppleCore

56M Downloads

Crash When Eating Cake

ChloeDawn opened this issue ยท 6 comments

commented

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

commented

Two things:

  • AppleCore implements an 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).
  • More importantly, I'm not sure why you'd need to do registry replacement at all to do what your mod does. The following works fine, and it seems to do everything your registry replacement does (unless I'm missing something):
@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));
	}
}
commented

Ah, yes, you're totally right. Fixed in 0515815, 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.

commented

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.

commented

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)).

commented

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

commented

Should be fixed in AppleCore v3.1.1. You can safely revert ChloeDawn/PersistentCake@ddb991d if you want.