Dynamic Trees

Dynamic Trees

25M Downloads

DT getActiveHand compatibility

TakunSho opened this issue ยท 7 comments

commented

Minecraft: 1.12.2
Forge: 2705 and 2757
DT: 0.7.8
PinklySheep: 4.0b6

When chopping down a DT Oak tree, I CTD. This happens on both single and multiplayer. Note: on the server only the client crashes, the server still runs and doesn't have any errors. After relaunching, the BWM and DT drops are there, but if there are supposed to be PS drops they do not. I've already submitted this issue on PS's end here as well.

The object in hand does not matter, I've tried bare handed, stone axe, and accidentally bonemeal. This occurs in both creative and survival

Having investigated this, Wabbit0101 has identified that this issue is occurring due to a mismatch in the way DT and PS check for the item in hand.
DT uses the call ItemStack heldItem = player.getHeldItemMainhand();
Whereas PS uses Player::getActiveHand instead (which allows for either mainhand or offhand use.
When this occurs, Minecraft crashes due to Player::getActiveHand being NULL (since DT doesn't set it).

This would be awesome if we could get an update to resolve this issue. I imagine that most likely any derived compat modules would also need to be updated to this as well (BoP, Thaumcraft, Heat and Climate). Though I run into the other issue I posted with BoP, and am not using Thaumcraft due to a (now resolved) compatibility issue between Metal Chests and Thaumcraft.

commented

@ferreusveritas For the record, did the update on curse today include this fix? Or do I have to build the commit?

commented

I released moments before you posted. So you'll need to build or wait a few days.

commented

The fix isn't right. I'm getting a crash now. I had to change it back to the way it was.
I'm afraid I don't understand why using player.getHeldItemMainhand is a problem. It's never been a problem before and I struggling to wrap my head around this issue.

commented

Is it perhaps supposed to just be player.getActiveHand rather than player.getHeldItem(player.getActiveHand)?

Also, I take you are testing with an axe? because it appears to me (I'm a newbie at coding though) that the null check is only for the axe and not for say, your bare hand. Like, maybe it needs an elseif check for if it is not an axe. (again a newbie at programming, I barely know how to read the language. I'm like a foreigner that has the concept of the language but not the experience and immersion in it yet).

commented

I did add a check for a null item anyway so the latest dev might work for you. At least it shouldn't crash.

commented

I'll test it as soon as I get my workspace setup, been having problems getting things setup.

commented

This has been resolved in PinklySheep. This issue is too weird for me. Block::removedByPlayer(...) is called by PlayerControllerMP::onPlayerDestroyBlock(...) and the player parameter can sometimes have a null for it's active hand, which shouldn't be possible since that object originates from Minecraft itself and should be fully valid. I could set the player's active hand when it's null but should I do that? There's no reason for me to get the held item from an offhand because as far as I understand it the tool isn't supposed to work that way anyway. I was unable to chop a tree with an axe or any other tool in the off hand no matter what I tried. There may be modded axes that allow off hand use but in the end this doesn't seem like my problem. It seems like it could potentially be a forge problem.