Crash when opening the menu on 1.8.9
HowardZHY opened this issue · 15 comments
If you open the giver without an item, it will crash the game, it happens with <1.10 versions, which are discontinued
public static String getGiveCode(ItemStack itemStack) {
boolean a = itemStack.getTagCompound() != null && !itemStack.getTagCompound().hasNoTags();
boolean b = itemStack.getMetadata() == 0 && !a;
if (itemStack.stackSize > 1)
return itemStack == null ? ""
: Item.itemRegistry.getNameForObject(itemStack.getItem()).toString()
+ ((itemStack.stackSize == 1 || itemStack.stackSize == 0) && b ? ""
: " " + itemStack.stackSize
+ (b ? ""
: " " + itemStack.getMetadata()
+ (a ? " " + itemStack.getTagCompound().toString() : "")));
if (itemStack.stackSize == 0)
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText("[ACT] Tried to edit null item"));
return null;
}
In 1.10 version and before air = null, in 1.11 version and after air = ItemStack(Items.AIR), the ACT2 code is based on the second model, so to fix it, someone would need to check for null for every usage of an itemstack.
If someone wants to do a PR I can merge it and upload the result, but I won't work on this (the 1.8 was released when I was in high school and I have a M.Sc., maybe it's time to update...)
at least I've fixed a crash with TMI by replace equals to ==
public void getSubItems(CreativeTabs tab, NonNullList items) {
if (tab /.equals/ == (ACTMod.ADVANCED_CREATIVE_TAB))
items.addAll(subItems);
}
Feel free to do a PR if you want...
Also it's better to not use ==
with non primitive values in Java, if you want to do equals on a and b, you can:
- if a can be null and not b do
b.equals(a)
- if a and b can be null do
Objects.equals(a, b)
There's no existing 1.8.9 branch anymore...
and here's the crash when try to edit hand(null item)
crash-2023-01-16_23.38.32-client.txt
if (!(mc.thePlayer.inventory.getCurrentItem() == null))
idk can this fix the sec crash
yea the sec crash fixed by
int slot = mc.thePlayer.inventory.currentItem;
if (mc.thePlayer.inventory.getCurrentItem() == null)
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText("[ACT] Tried to edit null item!"));
if (mc.thePlayer.inventory.getCurrentItem() != null)
mc.displayGuiScreen(new GuiItemStackModifier(this, mc.thePlayer.getHeldItem().copy(),
is -> ItemUtils.give(mc, is, 36 + slot)));
}, () -> {
public static String getGiveCode(ItemStack itemStack) {
if (mc.thePlayer.inventory.getCurrentItem() == null)
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText("[ACT] Tried to give null item !"));
boolean a;
boolean b;
if (mc.thePlayer.inventory.getCurrentItem() != null) {
a = itemStack.getTagCompound() != null && !itemStack.getTagCompound().hasNoTags();
b = itemStack.getMetadata() == 0 && !a;
return itemStack == null ? ""
: Item.itemRegistry.getNameForObject(itemStack.getItem()).toString()
+ ((itemStack.stackSize == 1 || itemStack.stackSize == 0) && b ? ""
: " " + itemStack.stackSize
+ (b ? ""
: " " + itemStack.getMetadata()
+ (a ? " " + itemStack.getTagCompound().toString() : "")));
}
return null;
}
damn this crashes when loading, what thing should I return at last
oh damn I'm dumb
I should add if && mc.thePlayer.inventory.getCurrentItem() != null in GuiGiver's init.
All these 2 crashes should be fixed.