Jump to content

Localize Name Problem in Creative Tab (1.10.2)


Dustpuppy

Recommended Posts

Hi,

i have a book for my mod. Class looks like this

package thewizardmod.books;

import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBook;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;

public class BookWizardsGuide extends ItemBook
{
  public BookWizardsGuide()
  {
    this.setCreativeTab(CreativeTabs.MISC); 
  }

  @Override
	public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
	  Minecraft.getMinecraft().displayGuiScreen(new GuiWizardsGuide());
		return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand);
	}
}

 

I register it this way

package thewizardmod.books;

import thewizardmod.books.BookWizardsGuide;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class StartupCommon
{
	  public static BookWizardsGuide book;

  public static void preInitCommon()
  {
	    book = (BookWizardsGuide)(new BookWizardsGuide().setUnlocalizedName("wizard_guide_twm"));
	    book.setRegistryName("wizard_guide_registry_name_twm");
	    GameRegistry.register(book);
  
  }

  public static void initCommon()
  {
  }

  public static void postInitCommon()
  {
  }
}

 

My Creative Tab looks like this

package thewizardmod.creative_tab;

import java.util.List;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import thewizardmod.books.StartupCommon;

public class BooksTab extends CreativeTabs {
  public BooksTab(String label) {
    super(label);
  }

  @Override
  @SideOnly(Side.CLIENT)
  public Item getTabIconItem() {
    return StartupCommon.book;
  }

  @Override
  @SideOnly(Side.CLIENT)
  public void displayAllRelevantItems(List<ItemStack> itemsToShowOnTab)
  {
    for (Item item : Item.REGISTRY) {
      if (item != null) {
        if (item.getUnlocalizedName().contains("_twm")) {
          item.getSubItems(item, this, itemsToShowOnTab);  // add all sub items to the list
        }
      }
    }
    
  }

}

 

The Language file


# Books
item.wizard_guide_twm=Wizards Guide

 

Where the hack comes the .name from, that apears at the back of the name i set in the language file?

HUElNtR.png

 

It's only happening since i've made a new tab for books. When i had the book in the main tab of the mod, it was ok.

 

Edited by Dustpuppy
Link to comment
Share on other sites

3 hours ago, Dustpuppy said:

@Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
  Minecraft.getMinecraft().displayGuiScreen(new GuiWizardsGuide());
  return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand);
}

 

For reference, Minecraft.getMinecraft is client-side-onlyl and onItemRightClick is common code. This will crash the dedicated server.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

That won't work, the crash occurs when your class is loaded before any code is executed. The JVM has no way of knowing that that line will never be anything but false and so it has to prepare to load the Minecraft class. In order to do so it needs to check "can I load this class if that line is ever executed?" and it fails to find the Minecraft class on the dedicated server, then crashes informing the user as such with a ClassNotFoundException.

 

http://mcforge.readthedocs.io/en/latest/concepts/sides/

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

5 minutes ago, Dustpuppy said:

Thanks for telling me. I catched it with

      if(!worldIn.isRemote)

 

You need to read a bit more about sides: http://mcforge.readthedocs.io/en/latest/concepts/sides/

 

Basically there is some code that runs on both sides, and in that case you can use the code you just mentioned.

 

But there is other code that isn't even loaded on a side, so the Java virtual machine will crash if it tries to interpret it. Note that just having a reference to that code in your code can crash even if that code won't ever run on that side.

 

Modders get fooled though because when running in single player mode both sides load in a single JVM. So the JVM can actually see the code loaded on the other side. But later if you run it on a dedicated server it will crash.

 

I highly recommend that you test all your mods with a server run configuration in Eclipse to find these errors. Using the client run configuration only will hide them.

 

I also have some explanation of sided code (and the use of proxies to manage some of it) here: http://mcforge.readthedocs.io/en/latest/concepts/sides/

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.