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 extinguishing/igniting campfire using dispenser with Backhand installed #72

Open
huihiuhuai opened this issue Jun 30, 2024 · 1 comment

Comments

@huihiuhuai
Copy link

https://pastebin.com/TqXR2YGN

@huihiuhuai huihiuhuai changed the title Crash when extinguishing/igniting campfire using main hand/dispenser/backhand with Backhand installed Crash when extinguishing/igniting campfire using dispenser with Backhand installed Jun 30, 2024
@connor135246
Copy link

connor135246 commented Jun 30, 2024

This is an incompatibility with Campfire Backport in case that wasn't clear. The crash occurs because I use a FakePlayer to damage the item in the dispenser, and the FakePlayer doesn't have an offhand.

This bug isn't exclusive to Campfire Backport. I've been able to cause the same crash with EnderIO's Killer Joe block (it attacks mobs automatically). There may be other blocks that have this issue.


Details:

I use a FakePlayer to do a couple things when extinguishing/igniting the campfire from a dispenser.
It looks like Backhand excludes FakePlayers from getting the offhand extended entity property:

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onEntityConstructing(EntityEvent.EntityConstructing event) {
if (!(event.entity instanceof EntityPlayer && ! (isFake(event.entity))))
return;
event.entity.registerExtendedProperties("OffhandStorage",new OffhandExtendedProperty((EntityPlayer) event.entity));
}

So when I try to damage the item, this patch tries to get the offhand item on line 81:
@Fix(insertOnExit = true)
public static void damageItem(ItemStack itemStack, int p_77972_1_, EntityLivingBase p_77972_2_)
{
if (!(p_77972_2_ instanceof EntityPlayer) || itemStack == null)
return;
EntityPlayer player = (EntityPlayer) p_77972_2_;
ItemStack offhandItem = BattlegearUtils.getOffhandItem(player);

And then there's a null pointer exception on line 79 here:
public static ItemStack getOffhandItem(EntityPlayer player) {
if (Backhand.UseInventorySlot) {
return player.inventory.getStackInSlot(Backhand.AlternateOffhandSlot);
} else {
return getOffhandEP(player).getOffhandItem();

Because this returns null:
public static OffhandExtendedProperty getOffhandEP(EntityPlayer player) {
return ((OffhandExtendedProperty)player.getExtendedProperties("OffhandStorage"));
}

So I think some null checks around getting the offhand property would be a good way to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants