From 50780ad9bd1f2a23a5d65dae5a0eab217d882efe Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 3 Aug 2025 16:39:25 +0200 Subject: [PATCH] Add chunk reset logic for Minecraft 1.21 in `CraftbukkitWrapper21` to support advanced chunk management. --- .../utils/CraftbukkitWrapper21.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/FightSystem/FightSystem_21/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper21.java b/FightSystem/FightSystem_21/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper21.java index 68f35171..312dce88 100644 --- a/FightSystem/FightSystem_21/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper21.java +++ b/FightSystem/FightSystem_21/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper21.java @@ -20,9 +20,17 @@ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.Config; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; import org.bukkit.GameRule; +import org.bukkit.World; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Entity; +import java.util.HashSet; +import java.util.Set; + public class CraftbukkitWrapper21 extends CraftbukkitWrapper18 { @Override @@ -34,4 +42,20 @@ public class CraftbukkitWrapper21 extends CraftbukkitWrapper18 { public void setupGamerule() { Config.world.setGameRule(GameRule.LOCATOR_BAR, false); } + + private LevelChunk getChunk(World world, int x, int z) { + return ((CraftWorld) world).getHandle().getChunk(x, z); + } + + @Override + public void resetChunk(World world, World backup, int x, int z) { + LevelChunk worldChunk = getChunk(world, x, z); + LevelChunk backupChunk = getChunk(backup, x, z); + LevelChunkSection[] sections = worldChunk.getSections(); + System.arraycopy(backupChunk.getSections(), 0, sections, 0, sections.length); + Set blocks = new HashSet<>(worldChunk.blockEntities.keySet()); + blocks.stream().filter(key -> !backupChunk.blockEntities.containsKey(key)).forEach(worldChunk::removeBlockEntity); + worldChunk.heightmaps.clear(); + worldChunk.heightmaps.putAll(backupChunk.heightmaps); + } }