Spigot 1.21.11 support
This commit is contained in:
parent
24cb2c86a5
commit
648950fb1d
6 changed files with 708 additions and 0 deletions
|
|
@ -0,0 +1,450 @@
|
|||
package org.dynmap.bukkit.helper.v121_11;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.craftbukkit.v1_21_R7.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_21_R7.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_21_R7.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.dynmap.DynmapChunk;
|
||||
import org.dynmap.Log;
|
||||
import org.dynmap.bukkit.helper.BukkitMaterial;
|
||||
import org.dynmap.bukkit.helper.BukkitVersionHelper;
|
||||
import org.dynmap.bukkit.helper.BukkitWorld;
|
||||
import org.dynmap.bukkit.helper.BukkitVersionHelperGeneric.TexturesPayload;
|
||||
import org.dynmap.renderer.DynmapBlockState;
|
||||
import org.dynmap.utils.MapChunkCache;
|
||||
import org.dynmap.utils.Polygon;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
|
||||
import net.minecraft.core.RegistryBlockID;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.nbt.NBTTagByteArray;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagDouble;
|
||||
import net.minecraft.nbt.NBTTagFloat;
|
||||
import net.minecraft.nbt.NBTTagIntArray;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.nbt.NBTTagLong;
|
||||
import net.minecraft.nbt.NBTTagShort;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.resources.MinecraftKey;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tags.TagsBlock;
|
||||
import net.minecraft.world.level.biome.BiomeBase;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.BlockFluids;
|
||||
import net.minecraft.world.level.block.entity.TileEntity;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Helper for isolation of bukkit version specific issues
|
||||
*/
|
||||
public class BukkitVersionHelperSpigot121_11 extends BukkitVersionHelper {
|
||||
|
||||
@Override
|
||||
public boolean isUnsafeAsync() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get block short name list
|
||||
*/
|
||||
@Override
|
||||
public String[] getBlockNames() {
|
||||
RegistryBlockID<IBlockData> bsids = Block.k;
|
||||
Block baseb = null;
|
||||
Iterator<IBlockData> iter = bsids.iterator();
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
while (iter.hasNext()) {
|
||||
IBlockData bs = iter.next();
|
||||
Block b = bs.b();
|
||||
// If this is new block vs last, it's the base block state
|
||||
if (b != baseb) {
|
||||
baseb = b;
|
||||
continue;
|
||||
}
|
||||
MinecraftKey id = BuiltInRegistries.e.b(b); // BuiltInRegistries.BLOCK.getKey(b)
|
||||
String bn = id.toString();
|
||||
if (bn != null) {
|
||||
names.add(bn);
|
||||
Log.info("block=" + bn);
|
||||
}
|
||||
}
|
||||
return names.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private static IRegistry<BiomeBase> reg = null;
|
||||
|
||||
private static IRegistry<BiomeBase> getBiomeReg() {
|
||||
if (reg == null) {
|
||||
reg = MinecraftServer.getServer().bc().f(Registries.aS); // MinecraftServer.registryAccess().lookupOrThrow(Registries.BIOME)
|
||||
}
|
||||
return reg;
|
||||
}
|
||||
|
||||
private Object[] biomelist;
|
||||
/**
|
||||
* Get list of defined biomebase objects
|
||||
*/
|
||||
@Override
|
||||
public Object[] getBiomeBaseList() {
|
||||
if (biomelist == null) {
|
||||
biomelist = new BiomeBase[256];
|
||||
Iterator<BiomeBase> iter = getBiomeReg().iterator();
|
||||
while (iter.hasNext()) {
|
||||
BiomeBase b = iter.next();
|
||||
int bidx = getBiomeReg().a(b); // Registry.getId
|
||||
if (bidx >= biomelist.length) {
|
||||
biomelist = Arrays.copyOf(biomelist, bidx + biomelist.length);
|
||||
}
|
||||
biomelist[bidx] = b;
|
||||
}
|
||||
}
|
||||
return biomelist;
|
||||
}
|
||||
|
||||
/** Get ID from biomebase */
|
||||
@Override
|
||||
public int getBiomeBaseID(Object bb) {
|
||||
return getBiomeReg().a((BiomeBase)bb);
|
||||
}
|
||||
|
||||
public static IdentityHashMap<IBlockData, DynmapBlockState> dataToState;
|
||||
|
||||
/**
|
||||
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
|
||||
*/
|
||||
@Override
|
||||
public void initializeBlockStates() {
|
||||
dataToState = new IdentityHashMap<IBlockData, DynmapBlockState>();
|
||||
HashMap<String, DynmapBlockState> lastBlockState = new HashMap<String, DynmapBlockState>();
|
||||
RegistryBlockID<IBlockData> bsids = Block.k;
|
||||
Block baseb = null;
|
||||
Iterator<IBlockData> iter = bsids.iterator();
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
|
||||
// Loop through block data states
|
||||
DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
|
||||
while (iter.hasNext()) {
|
||||
IBlockData bd = iter.next();
|
||||
Block b = bd.b();
|
||||
MinecraftKey id = BuiltInRegistries.e.b(b);
|
||||
String bname = id.toString();
|
||||
DynmapBlockState lastbs = lastBlockState.get(bname); // See if we have seen this one
|
||||
int idx = 0;
|
||||
if (lastbs != null) { // Yes
|
||||
idx = lastbs.getStateCount(); // Get number of states so far, since this is next
|
||||
}
|
||||
// Build state name
|
||||
String sb = "";
|
||||
String fname = bd.toString();
|
||||
int off1 = fname.indexOf('[');
|
||||
if (off1 >= 0) {
|
||||
int off2 = fname.indexOf(']');
|
||||
sb = fname.substring(off1+1, off2);
|
||||
}
|
||||
int lightAtten = bd.g(); // BlockBehaviour$BlockStateBase.getLightBlock
|
||||
//Log.info("statename=" + bname + "[" + sb + "], lightAtten=" + lightAtten);
|
||||
// Fill in base attributes
|
||||
bld.setBaseState(lastbs).setStateIndex(idx).setBlockName(bname).setStateName(sb).setAttenuatesLight(lightAtten);
|
||||
if (bd.e()) { bld.setSolid(); } // BlockBehaviour$BlockStateBase.isSolid
|
||||
if (bd.l()) { bld.setAir(); } // BlockBehaviour$BlockStateBase.isAir
|
||||
if (bd.a(TagsBlock.av)) { bld.setLog(); } // BlockBehaviour$BlockStateBase.is(BlockTags.OVERWORLD_NATURAL_LOGS)
|
||||
if (bd.a(TagsBlock.M)) { bld.setLeaves(); } // BlockBehaviour$BlockStateBase.is(BlockTags.LEAVES)
|
||||
// BlockBehaviour$BlockStateBase.getFluidState.isEmpty(), BlockBehaviour$BlockStateBase.getBlock
|
||||
if (!bd.y().c() && !(bd.b() instanceof BlockFluids)) { // Test if fluid type for block is not empty
|
||||
bld.setWaterlogged();
|
||||
//Log.info("statename=" + bname + "[" + sb + "] = waterlogged");
|
||||
}
|
||||
DynmapBlockState dbs = bld.build(); // Build state
|
||||
|
||||
dataToState.put(bd, dbs);
|
||||
lastBlockState.put(bname, (lastbs == null) ? dbs : lastbs);
|
||||
Log.verboseinfo("blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + dbs.isWaterlogged());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create chunk cache for given chunks of given world
|
||||
* @param dw - world
|
||||
* @param chunks - chunk list
|
||||
* @return cache
|
||||
*/
|
||||
@Override
|
||||
public MapChunkCache getChunkCache(BukkitWorld dw, List<DynmapChunk> chunks) {
|
||||
MapChunkCache121_11 c = new MapChunkCache121_11(gencache);
|
||||
c.setChunks(dw, chunks);
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get biome base water multiplier
|
||||
*/
|
||||
@Override
|
||||
public int getBiomeBaseWaterMult(Object bb) {
|
||||
BiomeBase biome = (BiomeBase) bb;
|
||||
return biome.i(); // Biome.getWaterColor
|
||||
}
|
||||
|
||||
/** Get temperature from biomebase */
|
||||
@Override
|
||||
public float getBiomeBaseTemperature(Object bb) {
|
||||
return ((BiomeBase)bb).f(); // Biome.getBaseTemperature
|
||||
}
|
||||
|
||||
/** Get humidity from biomebase */
|
||||
@Override
|
||||
public float getBiomeBaseHumidity(Object bb) {
|
||||
String vals = ((BiomeBase)bb).i.toString(); // Biome.climateSettings
|
||||
float humidity = 0.5F;
|
||||
int idx = vals.indexOf("downfall=");
|
||||
if (idx >= 0) {
|
||||
humidity = Float.parseFloat(vals.substring(idx+9, vals.indexOf(']', idx)));
|
||||
}
|
||||
return humidity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Polygon getWorldBorder(World world) {
|
||||
Polygon p = null;
|
||||
WorldBorder wb = world.getWorldBorder();
|
||||
if (wb != null) {
|
||||
Location c = wb.getCenter();
|
||||
double size = wb.getSize();
|
||||
if ((size > 1) && (size < 1E7)) {
|
||||
size = size / 2;
|
||||
p = new Polygon();
|
||||
p.addVertex(c.getX()-size, c.getZ()-size);
|
||||
p.addVertex(c.getX()+size, c.getZ()-size);
|
||||
p.addVertex(c.getX()+size, c.getZ()+size);
|
||||
p.addVertex(c.getX()-size, c.getZ()+size);
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
// Send title/subtitle to user
|
||||
public void sendTitleText(Player p, String title, String subtitle, int fadeInTicks, int stayTicks, int fadeOutTIcks) {
|
||||
if (p != null) {
|
||||
p.sendTitle(title, subtitle, fadeInTicks, stayTicks, fadeOutTIcks);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get material map by block ID
|
||||
*/
|
||||
@Override
|
||||
public BukkitMaterial[] getMaterialList() {
|
||||
return new BukkitMaterial[4096]; // Not used
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadChunkNoSave(World w, Chunk c, int cx, int cz) {
|
||||
Log.severe("unloadChunkNoSave not implemented");
|
||||
}
|
||||
|
||||
private String[] biomenames;
|
||||
@Override
|
||||
public String[] getBiomeNames() {
|
||||
if (biomenames == null) {
|
||||
biomenames = new String[256];
|
||||
Iterator<BiomeBase> iter = getBiomeReg().iterator();
|
||||
while (iter.hasNext()) {
|
||||
BiomeBase b = iter.next();
|
||||
int bidx = getBiomeReg().a(b);
|
||||
if (bidx >= biomenames.length) {
|
||||
biomenames = Arrays.copyOf(biomenames, bidx + biomenames.length);
|
||||
}
|
||||
biomenames[bidx] = b.toString();
|
||||
}
|
||||
}
|
||||
return biomenames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStateStringByCombinedId(int blkid, int meta) {
|
||||
Log.severe("getStateStringByCombinedId not implemented");
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
/** Get ID string from biomebase */
|
||||
public String getBiomeBaseIDString(Object bb) {
|
||||
return getBiomeReg().b((BiomeBase)bb).a(); // MinecraftKey.getPath()
|
||||
}
|
||||
@Override
|
||||
public String getBiomeBaseResourceLocsation(Object bb) {
|
||||
return getBiomeReg().b((BiomeBase)bb).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getUnloadQueue(World world) {
|
||||
Log.warning("getUnloadQueue not implemented yet");
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUnloadQueue(Object unloadqueue, int x, int z) {
|
||||
Log.warning("isInUnloadQueue not implemented yet");
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getBiomeBaseFromSnapshot(ChunkSnapshot css) {
|
||||
Log.warning("getBiomeBaseFromSnapshot not implemented yet");
|
||||
// TODO Auto-generated method stub
|
||||
return new Object[256];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInhabitedTicks(Chunk c) {
|
||||
return ((CraftChunk)c).getHandle(ChunkStatus.n).w(); // ChunkStatus.FULL ; ChunkAccess.getInhabitedTime
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<?, ?> getTileEntitiesForChunk(Chunk c) {
|
||||
return ((CraftChunk)c).getHandle(ChunkStatus.n).j; // ChunkStatus.FULL ; ChunkAccess.blockEntities
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileEntityX(Object te) {
|
||||
TileEntity tileent = (TileEntity) te;
|
||||
return tileent.aD_().u(); // BlockEntity.getBlockPos ; Vec3i.getX
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileEntityY(Object te) {
|
||||
TileEntity tileent = (TileEntity) te;
|
||||
return tileent.aD_().v(); // BlockEntity.getBlockPos ; Vec3i.getY
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileEntityZ(Object te) {
|
||||
TileEntity tileent = (TileEntity) te;
|
||||
return tileent.aD_().w(); // BlockEntity.getBlockPos ; Vec3i.getZ
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readTileEntityNBT(Object te, World w) {
|
||||
TileEntity tileent = (TileEntity) te;
|
||||
CraftWorld cw = (CraftWorld) w;
|
||||
return tileent.d(cw.getHandle().J_()); // BlockEntity.saveCustomOnly ; LevelReader.registryAccess
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getFieldValue(Object nbt, String field) {
|
||||
NBTTagCompound rec = (NBTTagCompound) nbt;
|
||||
NBTBase val = rec.a(field); // CompoundTag.get
|
||||
if(val == null) return null;
|
||||
if(val instanceof NBTTagByte) {
|
||||
return ((NBTTagByte)val).n(); // ByteTag.value
|
||||
}
|
||||
else if(val instanceof NBTTagShort) {
|
||||
return ((NBTTagShort)val).n(); // ShortTag.value
|
||||
}
|
||||
else if(val instanceof NBTTagInt) {
|
||||
return ((NBTTagInt)val).n(); // IntTag.value
|
||||
}
|
||||
else if(val instanceof NBTTagLong) {
|
||||
return ((NBTTagLong)val).n(); // LongTag.value
|
||||
}
|
||||
else if(val instanceof NBTTagFloat) {
|
||||
return ((NBTTagFloat)val).n(); // FloatTag.value
|
||||
}
|
||||
else if(val instanceof NBTTagDouble) {
|
||||
return ((NBTTagDouble)val).n(); // DoubleTag.value
|
||||
}
|
||||
else if(val instanceof NBTTagByteArray) {
|
||||
return ((NBTTagByteArray)val).e(); // ByteArrayTag.getAsByteArray
|
||||
}
|
||||
else if(val instanceof NBTTagString) {
|
||||
return ((NBTTagString)val).k(); // StringTag.value
|
||||
}
|
||||
else if(val instanceof NBTTagIntArray) {
|
||||
return ((NBTTagIntArray)val).g(); // IntArrayTag.getAsIntArray
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player[] getOnlinePlayers() {
|
||||
Collection<? extends Player> p = Bukkit.getServer().getOnlinePlayers();
|
||||
return p.toArray(new Player[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHealth(Player p) {
|
||||
return p.getHealth();
|
||||
}
|
||||
|
||||
private static final Gson gson = new GsonBuilder().create();
|
||||
|
||||
/**
|
||||
* Get skin URL for player
|
||||
* @param player
|
||||
*/
|
||||
@Override
|
||||
public String getSkinURL(Player player) {
|
||||
String url = null;
|
||||
CraftPlayer cp = (CraftPlayer)player;
|
||||
GameProfile profile = cp.getProfile();
|
||||
if (profile != null) {
|
||||
PropertyMap pm = profile.properties();
|
||||
if (pm != null) {
|
||||
Collection<Property> txt = pm.get("textures");
|
||||
Property textureProperty = Iterables.getFirst(pm.get("textures"), null);
|
||||
if (textureProperty != null) {
|
||||
String val = textureProperty.value();
|
||||
if (val != null) {
|
||||
TexturesPayload result = null;
|
||||
try {
|
||||
String json = new String(Base64.getDecoder().decode(val), StandardCharsets.UTF_8);
|
||||
result = gson.fromJson(json, TexturesPayload.class);
|
||||
} catch (JsonParseException e) {
|
||||
} catch (IllegalArgumentException x) {
|
||||
Log.warning("Malformed response from skin URL check: " + val);
|
||||
}
|
||||
if ((result != null) && (result.textures != null) && (result.textures.containsKey("SKIN"))) {
|
||||
url = result.textures.get("SKIN").url;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
// Get minY for world
|
||||
@Override
|
||||
public int getWorldMinY(World w) {
|
||||
CraftWorld cw = (CraftWorld) w;
|
||||
return cw.getMinHeight();
|
||||
}
|
||||
@Override
|
||||
public boolean useGenericCache() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package org.dynmap.bukkit.helper.v121_11;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.level.ChunkCoordIntPair;
|
||||
import net.minecraft.world.level.biome.BiomeBase;
|
||||
import net.minecraft.world.level.biome.BiomeFog;
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_21_R7.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_21_R7.CraftWorld;
|
||||
import org.dynmap.DynmapChunk;
|
||||
import org.dynmap.bukkit.helper.BukkitWorld;
|
||||
import org.dynmap.common.BiomeMap;
|
||||
import org.dynmap.common.chunk.GenericChunk;
|
||||
import org.dynmap.common.chunk.GenericChunkCache;
|
||||
import org.dynmap.common.chunk.GenericMapChunkCache;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
|
||||
*/
|
||||
public class MapChunkCache121_11 extends GenericMapChunkCache {
|
||||
private World w;
|
||||
/**
|
||||
* Construct empty cache
|
||||
*/
|
||||
public MapChunkCache121_11(GenericChunkCache cc) {
|
||||
super(cc);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Supplier<GenericChunk> getLoadedChunkAsync(DynmapChunk chunk) {
|
||||
CompletableFuture<Optional<SerializableChunkData>> chunkData = CompletableFuture.supplyAsync(() -> {
|
||||
CraftWorld cw = (CraftWorld) w;
|
||||
Chunk c = cw.getHandle().getChunkIfLoaded(chunk.x, chunk.z);
|
||||
if (c == null || !c.p) { // !LevelChunk.loaded
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(SerializableChunkData.a(cw.getHandle(), c)); // SerializableChunkData.copyOf
|
||||
}, ((CraftServer) Bukkit.getServer()).getServer());
|
||||
return () -> chunkData.join().map(SerializableChunkData::a).map(NBT.NBTCompound::new).map(this::parseChunkFromNBT).orElse(null); // SerializableChunkData::write
|
||||
}
|
||||
|
||||
protected GenericChunk getLoadedChunk(DynmapChunk chunk) {
|
||||
CraftWorld cw = (CraftWorld) w;
|
||||
if (!cw.isChunkLoaded(chunk.x, chunk.z)) return null;
|
||||
Chunk c = cw.getHandle().getChunkIfLoaded(chunk.x, chunk.z);
|
||||
if (c == null || !c.p) return null; // LevelChunk.loaded
|
||||
SerializableChunkData chunkData = SerializableChunkData.a(cw.getHandle(), c); //SerializableChunkData.copyOf
|
||||
NBTTagCompound nbt = chunkData.a(); // SerializableChunkData.write
|
||||
return nbt != null ? parseChunkFromNBT(new NBT.NBTCompound(nbt)) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Supplier<GenericChunk> loadChunkAsync(DynmapChunk chunk) {
|
||||
CraftWorld cw = (CraftWorld) w;
|
||||
CompletableFuture<Optional<NBTTagCompound>> genericChunk = cw.getHandle().p().a.d(new ChunkCoordIntPair(chunk.x, chunk.z)); // ServerLevel.getChunkSource().chunkMap.read(new ChunkCoordIntPair(chunk.x, chunk.z))
|
||||
return () -> genericChunk.join().map(NBT.NBTCompound::new).map(this::parseChunkFromNBT).orElse(null);
|
||||
}
|
||||
|
||||
protected GenericChunk loadChunk(DynmapChunk chunk) {
|
||||
CraftWorld cw = (CraftWorld) w;
|
||||
NBTTagCompound nbt = null;
|
||||
ChunkCoordIntPair cc = new ChunkCoordIntPair(chunk.x, chunk.z);
|
||||
GenericChunk gc = null;
|
||||
try { // BUGBUG - convert this all to asyn properly, since now native async
|
||||
nbt = cw.getHandle()
|
||||
.p() // ServerLevel.getChunkSource
|
||||
.a // ServerChunkCache.chunkMap
|
||||
.d(cc) // SimpleRegionStorage.read(ChunkPos)
|
||||
.join().get();
|
||||
} catch (CancellationException cx) {
|
||||
} catch (NoSuchElementException snex) {
|
||||
}
|
||||
if (nbt != null) {
|
||||
gc = parseChunkFromNBT(new NBT.NBTCompound(nbt));
|
||||
}
|
||||
return gc;
|
||||
}
|
||||
|
||||
public void setChunks(BukkitWorld dw, List<DynmapChunk> chunks) {
|
||||
this.w = dw.getWorld();
|
||||
super.setChunks(dw, chunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFoliageColor(BiomeMap bm, int[] colormap, int x, int z) {
|
||||
return bm.<BiomeBase>getBiomeObject().map(BiomeBase::h).flatMap(BiomeFog::b).orElse(colormap[bm.biomeLookup()]); // BiomeBase::getSpecialEffects, Biome::foliageColorOverride
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGrassColor(BiomeMap bm, int[] colormap, int x, int z) {
|
||||
BiomeFog fog = bm.<BiomeBase>getBiomeObject().map(BiomeBase::h).orElse(null); // BiomeBase::getSpecialEffects
|
||||
if (fog == null) return colormap[bm.biomeLookup()];
|
||||
return fog.e().a(x, z, fog.d().orElse(colormap[bm.biomeLookup()])); // BiomeFog.grassColorModifier.modifyColor ; BiomeFog.grassColorOverride
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
package org.dynmap.bukkit.helper.v121_11;
|
||||
|
||||
import org.dynmap.common.chunk.GenericBitStorage;
|
||||
import org.dynmap.common.chunk.GenericNBTCompound;
|
||||
import org.dynmap.common.chunk.GenericNBTList;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.SimpleBitStorage;
|
||||
|
||||
public class NBT {
|
||||
|
||||
public static class NBTCompound implements GenericNBTCompound {
|
||||
private final NBTTagCompound obj;
|
||||
public NBTCompound(NBTTagCompound t) {
|
||||
this.obj = t;
|
||||
}
|
||||
@Override
|
||||
public Set<String> getAllKeys() {
|
||||
return obj.e(); // CompoundTag.keySet
|
||||
}
|
||||
@Override
|
||||
public boolean contains(String s) {
|
||||
return obj.b(s); // CompoundTag.contains
|
||||
}
|
||||
@Override
|
||||
public boolean contains(String s, int i) {
|
||||
// Like contains, but with an extra constraint on type
|
||||
NBTBase base = obj.a(s); // CompoundTag.get
|
||||
if (base == null)
|
||||
return false;
|
||||
byte type = base.b(); // CompoundTag.getId
|
||||
if (type == i)
|
||||
return true;
|
||||
else if (i != TAG_ANY_NUMERIC)
|
||||
return false;
|
||||
return type == TAG_BYTE || type == TAG_SHORT || type == TAG_INT || type == TAG_LONG || type == TAG_FLOAT
|
||||
|| type == TAG_DOUBLE;
|
||||
}
|
||||
@Override
|
||||
public byte getByte(String s) {
|
||||
return obj.b(s, (byte)0); // CompoundTag.getByteOr
|
||||
}
|
||||
@Override
|
||||
public short getShort(String s) {
|
||||
return obj.b(s, (short)0); // CompoundTag.getShortOr
|
||||
}
|
||||
@Override
|
||||
public int getInt(String s) {
|
||||
return obj.b(s, 0); // CompoundTag.getIntOr
|
||||
}
|
||||
@Override
|
||||
public long getLong(String s) {
|
||||
return obj.b(s, 0L); // CompoundTag.getLongOr
|
||||
}
|
||||
@Override
|
||||
public float getFloat(String s) {
|
||||
return obj.b(s, 0.0f); // CompoundTag.getFloatOr
|
||||
}
|
||||
@Override
|
||||
public double getDouble(String s) {
|
||||
return obj.b(s, 0.0); // CompoundTag.getDoubleOr
|
||||
}
|
||||
@Override
|
||||
public String getString(String s) {
|
||||
return obj.b(s, ""); // CompoundTag.getStringOr
|
||||
}
|
||||
@Override
|
||||
public byte[] getByteArray(String s) {
|
||||
Optional<byte[]> byteArr = obj.j(s); // CompoundTag.getByteArray
|
||||
return byteArr.orElseGet(() -> new byte[0]);
|
||||
}
|
||||
@Override
|
||||
public int[] getIntArray(String s) {
|
||||
Optional<int[]> intArr = obj.k(s); // CompoundTag.getIntArray
|
||||
return intArr.orElseGet(() -> new int[0]);
|
||||
}
|
||||
@Override
|
||||
public long[] getLongArray(String s) {
|
||||
Optional<long[]> longArr = obj.l(s); // CompoundTag.getLongArray
|
||||
return longArr.orElseGet(() -> new long[0]);
|
||||
}
|
||||
@Override
|
||||
public GenericNBTCompound getCompound(String s) {
|
||||
return new NBTCompound(obj.n(s)); // CompoundTag.getCompoundOrEmpty
|
||||
}
|
||||
@Override
|
||||
public GenericNBTList getList(String s, int i) {
|
||||
// i argument used to be used to constrain list type, but nbt lists no longer have types as of 1.21.5
|
||||
return new NBTList(obj.p(s)); // CompoundTag.getListOrEmpty
|
||||
}
|
||||
@Override
|
||||
public boolean getBoolean(String s) {
|
||||
return getByte(s) != 0;
|
||||
}
|
||||
@Override
|
||||
public String getAsString(String s) {
|
||||
return obj.a(s).p_().orElseGet(() -> ""); // CompoundTag.get ; Tag.asString
|
||||
}
|
||||
@Override
|
||||
public GenericBitStorage makeBitStorage(int bits, int count, long[] data) {
|
||||
return new OurBitStorage(bits, count, data);
|
||||
}
|
||||
public String toString() {
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class NBTList implements GenericNBTList {
|
||||
private final NBTTagList obj;
|
||||
public NBTList(NBTTagList t) {
|
||||
obj = t;
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return obj.size();
|
||||
}
|
||||
@Override
|
||||
public String getString(int idx) {
|
||||
return obj.a(idx, ""); // ListTag.getStringOr
|
||||
}
|
||||
@Override
|
||||
public GenericNBTCompound getCompound(int idx) {
|
||||
return new NBTCompound(obj.b(idx)); // ListTag.getCompoundOrEmpty
|
||||
}
|
||||
public String toString() {
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class OurBitStorage implements GenericBitStorage {
|
||||
private final SimpleBitStorage bs;
|
||||
public OurBitStorage(int bits, int count, long[] data) {
|
||||
bs = new SimpleBitStorage(bits, count, data);
|
||||
}
|
||||
@Override
|
||||
public int get(int idx) {
|
||||
return bs.a(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ include ':bukkit-helper-121-4'
|
|||
include ':bukkit-helper-121-5'
|
||||
include ':bukkit-helper-121-6'
|
||||
include ':bukkit-helper-121-10'
|
||||
include ':bukkit-helper-121-11'
|
||||
include ':bukkit-helper'
|
||||
include ':dynmap-api'
|
||||
include ':DynmapCore'
|
||||
|
|
@ -84,6 +85,7 @@ project(':bukkit-helper-121-4').projectDir = "$rootDir/bukkit-helper-121-4" as F
|
|||
project(':bukkit-helper-121-5').projectDir = "$rootDir/bukkit-helper-121-5" as File
|
||||
project(':bukkit-helper-121-6').projectDir = "$rootDir/bukkit-helper-121-6" as File
|
||||
project(':bukkit-helper-121-10').projectDir = "$rootDir/bukkit-helper-121-10" as File
|
||||
project(':bukkit-helper-121-11').projectDir = "$rootDir/bukkit-helper-121-11" as File
|
||||
project(':bukkit-helper').projectDir = "$rootDir/bukkit-helper" as File
|
||||
project(':dynmap-api').projectDir = "$rootDir/dynmap-api" as File
|
||||
project(':DynmapCore').projectDir = "$rootDir/DynmapCore" as File
|
||||
|
|
|
|||
|
|
@ -106,6 +106,9 @@ dependencies {
|
|||
implementation(project(':bukkit-helper-121-10')) {
|
||||
transitive = false
|
||||
}
|
||||
implementation(project(':bukkit-helper-121-11')) {
|
||||
transitive = false
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
|
@ -152,6 +155,7 @@ shadowJar {
|
|||
include(dependency(':bukkit-helper-121-5'))
|
||||
include(dependency(':bukkit-helper-121-6'))
|
||||
include(dependency(':bukkit-helper-121-10'))
|
||||
include(dependency(':bukkit-helper-121-11'))
|
||||
}
|
||||
relocate('org.bstats', 'org.dynmap.bstats')
|
||||
destinationDirectory = file '../target'
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ public class Helper {
|
|||
else if (v.contains("(MC: 1.21.9)") || v.contains("(MC: 1.21.10)")) {
|
||||
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v121_10.BukkitVersionHelperSpigot121_10");
|
||||
}
|
||||
else if (v.contains("(MC: 1.21.11)")) {
|
||||
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v121_11.BukkitVersionHelperSpigot121_11");
|
||||
}
|
||||
else if (v.contains("(MC: 1.20)") || v.contains("(MC: 1.20.1)")) {
|
||||
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v120.BukkitVersionHelperSpigot120");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue