Jump to content

Recommended Posts

Posted

For my mod, I would like large biomes to be the default when people create a new world with my mod. How would you recommend going about this? Do I have to create my own WorldProvider, etc.? I'm open to that, because there's a chance I'll eventually want to do other stuff with it. But for now I'm kinda hoping there's a simpler way.

Posted

I got it to work by using an InitGuiEvent to check for GuiCreateWorld, then using reflection to modify the selectedIndex field of GuiCreateWorld to manually set it to WorldType.LARGE_BIOMES.getId(). This still allows the user to go into More World Options and change the world type if they want, but by default it will automatically be set to the Large Biomes type.

 

Spoiler

	@SubscribeEvent
	public void initGui(InitGuiEvent.Post event)
	{
		if (event.getGui() instanceof GuiCreateWorld)
		{
			try
			{
                Field f = GuiCreateWorld.class.getDeclaredField("selectedIndex");
	            f.setAccessible(true);
	            f.set(event.getGui(), WorldType.LARGE_BIOMES.getId());
			}
			catch (IllegalAccessException x)
			{
				x.printStackTrace();
			}
			catch (NoSuchFieldException e)
			{
				e.printStackTrace();
			}
		}
	}

 

 

If anyone has a good idea of another way to do it, I'm all ears.

 

As a side note, when trying to set up the reflection, I was baffled by ReflectionHelper#setPrivateValue. I ended up doing it "manually" so to speak, without using ReflectionHelper. But I was initially trying to use ReflectionHelper#setPrivateValue like this:

 

                ReflectionHelper.setPrivateValue(GuiCreateWorld.class, event.getGui(), 2, "selectedIndex");

 

Where 2 is an int that's the value I wanted to set the field selectedIndex to. But Eclipse keeps giving me this error:

 

The method setPrivateValue(Class<? super T>, T, E, int) in the type ReflectionHelper is not applicable for the arguments (Class<GuiCreateWorld>, GuiScreen, int, String).

 

I'm actually trying to use the other setPrivateValue, whose final parameter is a vararg of String, rather than an int. I suspect I'm not passing a correct argument for E value, and it's causing Eclipse to think I want the other method, but I'm not sure. I tried reading up on generic type parameters but didn't see anything that clearly pointed to me doing it wrong. What am I not understanding here?

Posted (edited)

I'm not great at generics, but doesn't <? super T? mean that it needs to be a super class of T. I don't think GuiCreateWorld is a superclass of GuiScreen. But if you've already tested that the event.getGui() is instanceof GuiCreateWorld then maybe you can cast it to GuiCreateWorld to satisfy the generic?

Edited by jabelar

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

Posted
31 minutes ago, jabelar said:

but doesn't <? super T> mean that it needs to be a super class of T

T is a superclass of T. It's basically just preventing you from putting in Foo.class and passing in an object of Type Bar, which doesn't extend Foo.

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.

Posted
4 minutes ago, Draco18s said:

T is a superclass of T. It's basically just preventing you from putting in Foo.class and passing in an object of Type Bar, which doesn't extend Foo.

Yes, I know T is a superclass of T. But in his example above his "T" is GuiScreen and his ? is GuiCreateWorld. So isn't he trying to put in a type Bar that doesn't extend Foo?

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

Posted (edited)

event.getGui() is returning a GuiScreen that may be GuiCreateWorld (as GuiCreateWorld extends GuiScreen). If it is of the correct type, that's the screen you want to modify, so you get it, pass it to reflection helper, and voila. If the method doesn't like it that's what casts are for.

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.

Posted
1 hour ago, Draco18s said:

event.getGui() is returning a GuiScreen that may be GuiCreateWorld (as GuiCreateWorld extends GuiScreen). If it is of the correct type, that's the screen you want to modify, so you get it, pass it to reflection helper, and voila. If the method doesn't like it that's what casts are for.

Yes, that's exactly what I said. He is only guaranteed to get a GuiScreen from getGui(), so I told him to use instanceof to confirm it is a GuiCreateWorld and told him to cast it to make the method accept it.

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

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.

Announcements



×
×
  • Create New...

Important Information

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