Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash When Eating Cake #113

Closed
ChloeDawn opened this issue Feb 11, 2018 · 6 comments
Closed

Crash When Eating Cake #113

ChloeDawn opened this issue Feb 11, 2018 · 6 comments
Labels

Comments

@ChloeDawn
Copy link

ChloeDawn commented Feb 11, 2018

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

@squeek502
Copy link
Owner

squeek502 commented Feb 12, 2018

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));
	}
}

@ChloeDawn
Copy link
Author

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.

@squeek502
Copy link
Owner

squeek502 commented Feb 13, 2018

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

ChloeDawn pushed a commit to ChloeDawn/PersistentCake that referenced this issue Feb 13, 2018
@ChloeDawn
Copy link
Author

ChloeDawn commented Feb 13, 2018

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

squeek502 added a commit that referenced this issue Feb 13, 2018
Fixes #113, solves incompatibility with Persistent Cake mod
@squeek502
Copy link
Owner

squeek502 commented Feb 13, 2018

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.

@squeek502
Copy link
Owner

squeek502 commented Feb 13, 2018

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

ChloeDawn added a commit to ChloeDawn/PersistentCake that referenced this issue Apr 28, 2020
ChloeDawn added a commit to ChloeDawn/PersistentCake that referenced this issue Apr 28, 2020
ChloeDawn added a commit to ChloeDawn/PersistentCake that referenced this issue Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants