I wanne change the world height by reflecting to modify the DimensionType(reobf: DimensionManager) under Level(reobf: World)
But the tutorials I found are too old, DimensionType is a just a field in the Level class and can easily be modified.
But on higher versions, there is no DimensionType but Holder<DimensionType> in Level class, I tried to modify it with this:
But I got strange result like this:
But the tutorials I found are too old, DimensionType is a just a field in the Level class and can easily be modified.
But on higher versions, there is no DimensionType but Holder<DimensionType> in Level class, I tried to modify it with this:
Java:
Holder<DimensionType> oldHolder = serverLevel.dimensionTypeRegistration();
Holder.Reference<DimensionType> oldReference = (Holder.Reference<DimensionType>) oldHolder;
DimensionType oldType = serverLevel.dimensionType();
DimensionType newType = new DimensionType(
oldType.fixedTime(),
oldType.hasSkyLight(),
oldType.hasCeiling(),
oldType.ultraWarm(),
oldType.natural(),
oldType.coordinateScale(),
oldType.bedWorks(),
oldType.respawnAnchorWorks(),
-128,
512 + 128,
oldType.logicalHeight(),
oldType.infiniburn(),
oldType.effectsLocation(),
oldType.ambientLight(),
oldType.monsterSettings()
);
for (Field field : Level.class.getDeclaredFields()) { // Use reflect to prevent name not same because of reobf
if (!field.getType().equals(Holder.class))
continue;
ParameterizedType type = (ParameterizedType) field.getGenericType();
Type[] types = type.getActualTypeArguments();
if (types.length != 1)
continue;
if (types[0] != DimensionType.class)
continue;
field.setAccessible(true);
try {
Holder.Reference<DimensionType> newReference = null;
for (Field typeField : Holder.Reference.class.getDeclaredFields()) {
if (typeField.getType() != HolderOwner.class)
continue;
typeField.setAccessible(true);
newReference = Holder.Reference.createStandAlone((HolderOwner<DimensionType>) typeField.get(oldReference), oldReference.key());
break;
}
if (newReference == null)
break;
for (Method method : Holder.Reference.class.getDeclaredMethods()) {
if (method.getReturnType() == Void.class || method.getReturnType() == void.class) {
if (method.getParameterCount() == 1) {
if (method.getGenericParameterTypes()[0] instanceof TypeVariable<?>) {
method.setAccessible(true);
method.invoke(newReference, newType);
break;
}
}
}
}
field.set(serverLevel, newReference);
break;
} catch (IllegalAccessException | InvocationTargetException e) {
throw new WorldException(e);
}
}
- Version Output
- This server is running Paper version git-Paper-390 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: f61ebdc)