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