Advanced Creative Tab (Forge)

Advanced Creative Tab (Forge)

58.1k Downloads

Crash when opening the menu on 1.8.9

HowardZHY opened this issue · 15 comments

commented

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

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

damn nope

commented

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

commented

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

commented

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

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

commented

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

commented
		if (!(mc.thePlayer.inventory.getCurrentItem() == null))	

idk can this fix the sec crash

commented

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

commented
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

commented

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

commented

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.

commented

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