forked from SteamWar/SteamWar
Add chunk reset logic for Minecraft 1.21 in CraftbukkitWrapper21 to support advanced chunk management.
This commit is contained in:
+24
@@ -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<BlockPos> 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user