Jump to content

[Solved] (1.15.2) Can't overwrite vanilla GenerationSettings


DarkLions

Recommended Posts

(I apologize for bad english)

Hello,

I have tried to overwrite the vanilla GenerationSettings using Java.Reflection.

Settings override class: (This code will run, if the LoadCompleteEvent fire)

	public static void overrideSettings()
	{
		
		try 
		{

			Class<?> GenClass = Class.forName("net.minecraft.world.gen.GenerationSettings");
			Field defaultBlockField = GenClass.getDeclaredField("defaultBlock");
			
			GenerationSettings gen = (GenerationSettings) GenClass.newInstance();

			defaultBlockField.setAccessible(true);

			Field modifiers = Field.class.getDeclaredField("modifiers");

			modifiers.setAccessible(true);

			modifiers.setInt(defaultBlockField,  defaultBlockField.getModifiers() & ~Modifier.FINAL);

			defaultBlockField.set(gen, Blocks.DIAMOND_BLOCK.getDefaultState());

			StickOfDebug.s = new String(defaultBlockField.get(gen).toString());
		}
		catch(Exception e)
		{
			StickOfDebug.s = new String(e.toString());
		}
		
	}

 

The Field with the "defaultBlock" have been successfully overwritten and the field give me the diamond_block and I don't get any exception.

But when I generate a new world, the defaultBlock is still stone_block.

If I using the my Debug_Stick, the GenerationSettings still give me the stone_block value back.

The debug stick class:

public class StickOfDebug extends Item
{
	public static String s = "";
	public StickOfDebug(Properties properties) 
	{
		super(properties);
	}
	
	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) 
	{
		ItemStack itemstack = playerIn.getHeldItem(handIn);
		if(worldIn.isRemote)
		{
			return ActionResult.resultPass(itemstack);
		}
		else
		{

			playerIn.sendMessage(new StringTextComponent(s));
			try 
			{
				Class<?> genClass = Class.forName("net.minecraft.world.gen.GenerationSettings");
				GenerationSettings gen = (GenerationSettings) genClass.newInstance();
				Field field = genClass.getDeclaredField("defaultBlock");
				field.setAccessible(true);
				playerIn.sendMessage(new StringTextComponent(field.get(gen).toString()));
			} 
			catch (Exception e) 
			{
				e.printStackTrace();
			}
			return ActionResult.resultSuccess(itemstack);
		}
	}

}

 

I would appreciate if someone could help me.

Edited by DarkLions
This question is solved for me.
Link to comment
Share on other sites

Well, your code (if it worked at all) will only work in the development environment. Because that string is not the actual name of the compiled vanilla class (any reason you aren't using Class GenClass = GenerationSettings.class?) or the field name when compiled. There's a reason Forge supplies an ObfuscationReflectionHelper class.

 

As for why its not changing, I don't know. When and where are you calling that code?

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

 

Thanks for your reply.

The code is seperated from the main class and it will called if the "FMLLoadCompleteEvent" is fired. I have tried (Class GenClass = GenerationSettings.class) seem also not working.

So have tried to implement the ObfuscationReflectionHelper, but I get the same issue. It isn't changing anything.

I'm not sure, if it is because I call a newInstance for the object.

 

the code in his own class:

(only changed the class.getDeclaredField to ObfuscationReflection)

package com.darklions.testmod.world.gen;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import com.darklions.testmod.objects.items.StickOfDebug;

import net.minecraft.block.Blocks;
import net.minecraft.world.gen.GenerationSettings;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;

public class VanillaGenSettingsOverride 
{
	public static void overrideSettings()
	{
		
		try 
		{
			Class<?> GenClass = GenerationSettings.class;

			//used this method instead of GenClass.getDeclaredField
			Field defaultBlockField = ObfuscationReflectionHelper.findField(GenClass, "defaultBlock");
			
			GenerationSettings gen = (GenerationSettings) GenClass.newInstance();
			
			Field modifiers = Field.class.getDeclaredField("modifiers");
			
			modifiers.setAccessible(true);
			modifiers.setInt(defaultBlockField, defaultBlockField.getModifiers() & ~Modifier.FINAL);
			
			defaultBlockField.set(gen, Blocks.DIAMOND_BLOCK.getDefaultState());
			//this give me the diamond_block value
			StickOfDebug.s = new String(defaultBlockField.get(gen).toString());
		}
		catch(Exception e)
		{
			StickOfDebug.s = new String(e.toString());
		}
		
	}

	
}
	@SubscribeEvent
	public static void loadCompleteEvent(FMLLoadCompleteEvent event)
	{
		CustomOreGen.setupOverWorldOreGeneration();
		CustomOreGen.setupEndOreGeneration();
		CustomOreGen.setupNetherOreGeneration();
		CustomWorldCarverGen.setupEndCarverGeneration();
		
		VanillaGenSettingsOverride.overrideSettings();
	}

And this is in the main class.

Link to comment
Share on other sites

My guess would be that when you go into generate a new world, the values are being set by something else, overwriting your change.

Go look at the field, what sets its value, and what calls the code that sets its value.

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

So I have found out what the problem was. The Overworlddimension has overwrite the defaultBlock value. Because the value is in the constructor defined, I can‘t change it directly. or is impossible to change. 

The best is I just create a custom Dimension and settings. 
 

Thank you for your support :D

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://cdjh.short.gy/slotsc Selamat datang di Senangcasino88 salah satu situs slot gacor gampang menang hari ini di Indonesia yang sangat menjajikan. Slot gacor adalah adalah suatu istilah yang digunakan untuk menjelaskan sebuah permainan slot gampang menang di situs slot online. Situs slot gacor Senangcasino88 ini bisa menjadi populer walaupun terbilang baru karena RTP slot online yang disajikan begitu tinggi. Seiring dengan perkembangan zaman situs slot gacor terbaru ini juga sudah update dari segi teknologi yang menggunakan HTML5, inilah yang membuat grafis permainan terlihat begitu modern, audio lebih jernih, dan user interface yang smooth. Tidak dipungkiri grafis yang kami memiliki sudah menarik banyak sekali pendatang baru yang ingin merasakan terbawa dalam suasana tema permainan mesin slot. Kehadiran slot gacor menjadi angin segar bagi para pecinta judi online, memberikan alternatif permainan yang seru dan menguntungkan. Tak heran jika popularitas slot gacor terus meningkat, menarik minat para pemain baru untuk mencoba peruntungan mereka di situs slot gacor hari ini Senangcasino88.
    • Selamat datang di Rajadomino salah satu situs slot gacor gampang menang hari ini di Indonesia yang sangat menjajikan. Slot gacor adalah adalah suatu istilah yang digunakan untuk menjelaskan sebuah permainan slot gampang menang di situs slot online. Situs slot gacor Rajadomino ini bisa menjadi populer walaupun terbilang baru karena RTP slot online yang disajikan begitu tinggi. Seiring dengan perkembangan zaman situs slot gacor terbaru ini juga sudah update dari segi teknologi yang menggunakan HTML5, inilah yang membuat grafis permainan terlihat begitu modern, audio lebih jernih, dan user interface yang smooth. Tidak dipungkiri grafis yang kami memiliki sudah menarik banyak sekali pendatang baru yang ingin merasakan terbawa dalam suasana tema permainan mesin slot. Kehadiran slot gacor menjadi angin segar bagi para pecinta judi online, memberikan alternatif permainan yang seru dan menguntungkan. Tak heran jika popularitas slot gacor terus meningkat, menarik minat para pemain baru untuk mencoba peruntungan mereka di situs slot gacor hari ini Rajadomino.
    • Selamat datang di IDRkasino salah satu situs slot gacor gampang menang hari ini di Indonesia yang sangat menjajikan. Slot gacor adalah adalah suatu istilah yang digunakan untuk menjelaskan sebuah permainan slot gampang menang di situs slot online. Situs slot gacor IDRkasino ini bisa menjadi populer walaupun terbilang baru karena RTP slot online yang disajikan begitu tinggi. Seiring dengan perkembangan zaman situs slot gacor terbaru ini juga sudah update dari segi teknologi yang menggunakan HTML5, inilah yang membuat grafis permainan terlihat begitu modern, audio lebih jernih, dan user interface yang smooth. Tidak dipungkiri grafis yang kami memiliki sudah menarik banyak sekali pendatang baru yang ingin merasakan terbawa dalam suasana tema permainan mesin slot. Kehadiran slot gacor menjadi angin segar bagi para pecinta judi online, memberikan alternatif permainan yang seru dan menguntungkan. Tak heran jika popularitas slot gacor terus meningkat, menarik minat para pemain baru untuk mencoba peruntungan mereka di situs slot gacor hari ini IDRkasino.
    • Selamat datang di Rajabonanza88 salah satu situs slot gacor gampang menang hari ini di Indonesia yang sangat menjajikan. Slot gacor adalah adalah suatu istilah yang digunakan untuk menjelaskan sebuah permainan slot gampang menang di situs slot online. Situs slot gacor Rajabonanza88 ini bisa menjadi populer walaupun terbilang baru karena RTP slot online yang disajikan begitu tinggi. Seiring dengan perkembangan zaman situs slot gacor terbaru ini juga sudah update dari segi teknologi yang menggunakan HTML5, inilah yang membuat grafis permainan terlihat begitu modern, audio lebih jernih, dan user interface yang smooth. Tidak dipungkiri grafis yang kami memiliki sudah menarik banyak sekali pendatang baru yang ingin merasakan terbawa dalam suasana tema permainan mesin slot. Kehadiran slot gacor menjadi angin segar bagi para pecinta judi online, memberikan alternatif permainan yang seru dan menguntungkan. Tak heran jika popularitas slot gacor terus meningkat, menarik minat para pemain baru untuk mencoba peruntungan mereka di situs slot gacor hari ini Rajabonanza88.
    • A code: public class CommonProxy {     public void registerItemRenderer() {         Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(                 ModItems.YOUR_ITEM,                 0,                 new ModelResourceLocation(ModItems.YOUR_ITEM.getRegistryName(), "inventory")         );         Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(                 ModItems.YOUR_ITEM,                 0,                 new ModelResourceLocation(ModItems.YOUR_ITEM.getRegistryName(), "inventory"),                 new CustomItemRenderer(Minecraft.getMinecraft().getTextureManager(), Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager(), Minecraft.getMinecraft().getItemColors())         );     } }   In YOUR_ITEM you must specify item. If not working try this: public class ModInit {     @Mod.EventHandler     public void init(FMLInitializationEvent event) {         CommonProxy commonProxy = new CommonProxy();         commonProxy.registerItemRenderer();     } }
  • Topics

×
×
  • Create New...

Important Information

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