Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save WizardlyBump17/e4df668d7dafaf592141e9047bf75903 to your computer and use it in GitHub Desktop.
Save WizardlyBump17/e4df668d7dafaf592141e9047bf75903 to your computer and use it in GitHub Desktop.
change world height (client only)
@Override
public void onPacketSending(PacketEvent event) {
ClientboundLoginPacket packet = (ClientboundLoginPacket) event.getPacket().getHandle();
Holder.Reference<DimensionType> dimensionType = (Holder.Reference<DimensionType>) clone((Holder.Reference<?>) packet.dimensionType(), clone(packet.dimensionType().value()));
event.setPacket(new PacketContainer(
PacketType.fromClass(packet.getClass()),
new ClientboundLoginPacket(
packet.playerId(),
packet.hardcore(),
packet.gameType(),
packet.previousGameType(),
packet.levels(),
packet.registryHolder(),
dimensionType,
packet.dimension(),
packet.seed(),
packet.maxPlayers(),
packet.chunkRadius(),
packet.simulationDistance(),
packet.reducedDebugInfo(),
packet.showDeathScreen(),
packet.isDebug(),
packet.isFlat()
)
));
Bukkit.getScheduler().runTaskLater(plugin, () -> {
Player player = Bukkit.getPlayer("WizardlyBump17");
Location location = player.getLocation();
player.sendBlockChange(new Location(player.getWorld(), location.getX(), 330, location.getZ()), Material.STONE.createBlockData());
}, 100);
}
public static DimensionType clone(DimensionType original) {
System.out.println(original.height() + " " + original.logicalHeight());
return DimensionType.create(
getField(DimensionType.class, original, "w"), //fixedTime
original.hasSkyLight(),
original.hasCeiling(),
original.ultraWarm(),
original.natural(),
original.coordinateScale(),
original.createDragonFight(),
original.piglinSafe(),
original.bedWorks(),
original.respawnAnchorWorks(),
original.hasRaids(),
-64, //original.minY()
384 + 16, //original.height() big values the client takes more to pass the "Loading terrain...". I tested it with 512
384 + 16, //original.logicalHeight()
original.infiniburn(),
original.effectsLocation(),
original.brightness(0)
);
}
public static Holder.Reference<?> clone(Holder.Reference<?> original, Object value) {
Holder.Reference<?> newHolder = Holder.Reference.createStandAlone(getField(Holder.Reference.class, original, "a"), original.key()); //registry
setField(Holder.Reference.class, newHolder, "b", getField(Holder.Reference.class, original, "b")); //tags
setField(Holder.Reference.class, newHolder, "e", value); //value
return newHolder;
}
public static <T> T getField(Class<?> clazz, Object instance, String fieldName) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
return (T) field.get(instance);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
public static void setField(Class<?> clazz, Object instance, String fieldName, Object value) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(instance, value);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment