Add some null safety

In my survival playthrough, I got a crash when
a tool with AOE broke mid-operation.
This should fix it
This commit is contained in:
abel1502 2025-05-21 00:56:30 +03:00
parent df1ee57563
commit 527459b92c
No known key found for this signature in database
GPG Key ID: 076926596A536338

View File

@ -297,6 +297,10 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
EntityPlayerMP player = (EntityPlayerMP) playerEntity; EntityPlayerMP player = (EntityPlayerMP) playerEntity;
ItemStack stack = player.getHeldItem(); ItemStack stack = player.getHeldItem();
if (stack == null) {
return;
}
Block block = world.getBlock(x, y, z); Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z); int meta = world.getBlockMetadata(x, y, z);
@ -485,7 +489,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
public Configuration getConfiguration(ItemStack stack) { public Configuration getConfiguration(ItemStack stack) {
Configuration config = new Configuration(); Configuration config = new Configuration();
if(!stack.hasTagCompound() || !stack.stackTagCompound.hasKey("ability") || !stack.stackTagCompound.hasKey("abilityPresets")) { if(stack == null || !stack.hasTagCompound() || !stack.stackTagCompound.hasKey("ability") || !stack.stackTagCompound.hasKey("abilityPresets")) {
config.reset(availableAbilities); config.reset(availableAbilities);
return config; return config;
} }
@ -496,8 +500,13 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
} }
public void setConfiguration(ItemStack stack, Configuration config) { public void setConfiguration(ItemStack stack, Configuration config) {
if(!stack.hasTagCompound()) if (stack == null) {
return;
}
if (!stack.hasTagCompound()) {
stack.stackTagCompound = new NBTTagCompound(); stack.stackTagCompound = new NBTTagCompound();
}
config.writeToNBT(stack.stackTagCompound); config.writeToNBT(stack.stackTagCompound);
} }