ate47 / AdvancedCreativeTab

Minecraft creative client mod to edit/give items
https://www.curseforge.com/minecraft/mc-mods/advanced-extended-creative-mode
GNU Lesser General Public License v3.0
4 stars 3 forks source link

Crash when opening the menu on 1.8.9 #18

Closed HowardZHY closed 1 year ago

HowardZHY commented 2 years ago

crash-2022-05-18_22.31.44-client.txt crash-2022-05-18_22.35.12-client.txt

ate47 commented 2 years ago

If you open the giver without an item, it will crash the game, it happens with <1.10 versions, which are discontinued

HowardZHY commented 2 years ago

:( could u try to fix it?

At 2022-05-20 01:32:01, "Antoine Willerval" @.***> wrote:

If you open the giver without an item, it will crash the game, it happens with <1.10 versions, which are discontinued

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

HowardZHY commented 1 year ago
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;
}
HowardZHY commented 1 year ago

damn nope

ate47 commented 1 year ago

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

HowardZHY commented 1 year ago

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

ate47 commented 1 year ago

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:

HowardZHY commented 1 year ago

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

HowardZHY commented 1 year ago

A temp solution is disable giver key. (it's useless with TMI)

HowardZHY commented 1 year ago
        if (!(mc.thePlayer.inventory.getCurrentItem() == null)) 

idk can this fix the sec crash

HowardZHY commented 1 year ago

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))); }, () -> {

HowardZHY commented 1 year ago
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

HowardZHY commented 1 year ago

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.

HowardZHY commented 1 year ago

You should create a 1.8.9 branch to let me PR in...

HowardZHY commented 1 year ago

Please make create a new 1.8.9 branch, then I can fork and PR in, and then I can make Chinese translation jsons.