Temporaly removed schematic-related code

This commit is contained in:
Nanit 2022-01-28 16:09:17 +02:00
parent 970d5cfcd2
commit 9670aeecbe
12 changed files with 0 additions and 638 deletions

View File

@ -42,9 +42,6 @@ public final class LimboConfig {
private int maxPlayers;
private PingData pingData;
private boolean useSchematic;
private Path schematicPath;
private String dimensionType;
private Location spawnPosition;
private int gameMode;
@ -82,7 +79,6 @@ public final class LimboConfig {
address = conf.node("bind").get(SocketAddress.class);
maxPlayers = conf.node("maxPlayers").getInt();
pingData = conf.node("ping").get(PingData.class);
//useSchematic = conf.node("world", "enable").getBoolean(false);
dimensionType = conf.node("dimension").getString();
spawnPosition = conf.node("spawnPosition").get(Location.class);
gameMode = conf.node("gameMode").getInt();
@ -91,9 +87,6 @@ public final class LimboConfig {
useBossBar = conf.node("bossBar", "enable").getBoolean();
useTitle = conf.node("title", "enable").getBoolean();
/*if (useSchematic)
schematicPath = Paths.get(conf.node("world", "path").getString("./spawn.schem"));*/
if(useBrandName)
brandName = conf.node("brandName", "content").getString();
@ -154,14 +147,6 @@ public final class LimboConfig {
return pingData;
}
public boolean isUseSchematic() {
return useSchematic;
}
public Path getSchematicPath() {
return schematicPath;
}
public String getDimensionType() {
return dimensionType;
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world;
public class BlockData {
private final String state;
private final int id;
private final byte data;
public BlockData(String state, int id, byte data) {
this.state = state;
this.id = id;
this.data = data;
}
public BlockData(String state) {
this(state, 0, (byte) 0);
}
public BlockData(int id, byte data) {
this(null, id, data);
}
public String getState() {
return state;
}
public int getId() {
return id;
}
public byte getData() {
return data;
}
}

View File

@ -1,45 +0,0 @@
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world;
import net.kyori.adventure.nbt.CompoundBinaryTag;
public class BlockEntity {
private final Location pos;
private final String id;
private final CompoundBinaryTag data;
public BlockEntity(Location pos, String id, CompoundBinaryTag data) {
this.pos = pos;
this.id = id;
this.data = data;
}
public Location getPos() {
return pos;
}
public String getId() {
return id;
}
public CompoundBinaryTag getData() {
return data;
}
}

View File

@ -1,68 +0,0 @@
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world;
import ru.nanit.limbo.protocol.registry.Version;
import java.util.HashMap;
import java.util.Map;
public final class BlockMappings {
private final Map<String, String> idToState = new HashMap<>();
private final Map<String, String> stateToId = new HashMap<>();
public BlockData convert(int id, byte data, Version version) {
if (version.less(Version.V1_13))
return new BlockData(id, data);
String state = idToState.get(toId(id, data));
return state != null ? new BlockData(state) : null;
}
public BlockData convert(String state, Version version) {
if (state == null) return null;
if (version.moreOrEqual(Version.V1_13)) {
return new BlockData(state);
}
String id = stateToId.get(state);
if (id != null) {
String[] arr = id.split(":");
int blockId = Integer.parseInt(arr[0]);
byte data = Byte.parseByte(arr[1]);
return new BlockData(blockId, data);
}
return null;
}
public void register(int id, byte data, String state) {
String strId = toId(id, data);
idToState.put(strId, state);
stateToId.put(state, strId);
}
private String toId(int id, byte data) {
return id + ":" + data;
}
}

View File

@ -1,73 +0,0 @@
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world.schematic;
import ru.nanit.limbo.world.BlockEntity;
import ru.nanit.limbo.world.BlockMappings;
import java.util.List;
public abstract class AbstractSchematic implements Schematic {
protected final BlockMappings mappings;
private int width;
private int height;
private int length;
private List<BlockEntity> blockEntities;
public AbstractSchematic(BlockMappings mappings) {
this.mappings = mappings;
}
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
@Override
public int getLength() {
return length;
}
@Override
public List<BlockEntity> getBlockEntities() {
return blockEntities;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setLength(int length) {
this.length = length;
}
public void setBlockEntities(List<BlockEntity> blockEntities) {
this.blockEntities = blockEntities;
}
}

View File

@ -1,39 +0,0 @@
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world.schematic;
import ru.nanit.limbo.protocol.registry.Version;
import ru.nanit.limbo.world.BlockData;
import ru.nanit.limbo.world.BlockEntity;
import ru.nanit.limbo.world.Location;
import java.util.List;
public interface Schematic {
int getWidth();
int getHeight();
int getLength();
List<BlockEntity> getBlockEntities();
BlockData getBlock(Location loc, Version version);
}

View File

@ -1,139 +0,0 @@
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world.schematic;
import net.kyori.adventure.nbt.BinaryTag;
import net.kyori.adventure.nbt.BinaryTagIO;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import ru.nanit.limbo.world.BlockEntity;
import ru.nanit.limbo.world.BlockMappings;
import ru.nanit.limbo.world.Location;
import ru.nanit.limbo.world.schematic.versions.LegacySchematic;
import ru.nanit.limbo.world.schematic.versions.SpongeSchematic;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class SchematicLoader {
private final BlockMappings mappings;
public SchematicLoader(BlockMappings mappings) {
this.mappings = mappings;
}
public Schematic load(Path file) throws IOException {
return load(Files.newInputStream(file));
}
public Schematic load(InputStream stream) throws IOException {
CompoundBinaryTag nbt = BinaryTagIO.unlimitedReader().read(stream, BinaryTagIO.Compression.GZIP);
if (nbt.keySet().contains("BlockData")) {
return loadSponge(nbt);
} else {
return loadLegacy(nbt);
}
}
// Specification: https://github.com/SpongePowered/Schematic-Specification/blob/master/versions/schematic-2.md
private Schematic loadSponge(CompoundBinaryTag nbt) {
SpongeSchematic schematic = new SpongeSchematic(mappings);
schematic.setDataVersion(nbt.getInt("DataVersion"));
schematic.setWidth(nbt.getShort("Width"));
schematic.setHeight(nbt.getShort("Height"));
schematic.setLength(nbt.getShort("Length"));
schematic.setPaletteMax(nbt.getInt("PaletteMax"));
Map<Integer, String> palette = new HashMap<>();
CompoundBinaryTag paletteNbt = nbt.getCompound("Palette");
for (String key : paletteNbt.keySet()) {
palette.put(paletteNbt.getInt(key), key);
}
schematic.setPalette(palette);
schematic.setBlockData(nbt.getByteArray("BlockData"));
List<BlockEntity> blockEntities = new LinkedList<>();
for (BinaryTag tag : nbt.getList("BlockEntities")) {
if (tag instanceof CompoundBinaryTag) {
CompoundBinaryTag data = (CompoundBinaryTag) tag;
int[] posArr = data.getIntArray("Pos");
Location pos = Location.pos(posArr[0], posArr[1], posArr[2]);
String id = data.getString("Id");
CompoundBinaryTag extra = data.getCompound("Extra");
blockEntities.add(new BlockEntity(pos, id, extra));
}
}
schematic.setBlockEntities(blockEntities);
return schematic;
}
private Schematic loadLegacy(CompoundBinaryTag nbt) {
LegacySchematic schematic = new LegacySchematic(mappings);
schematic.setWidth(nbt.getShort("Width"));
schematic.setHeight(nbt.getShort("Height"));
schematic.setLength(nbt.getShort("Length"));
schematic.setMaterials(LegacySchematic.Materials.from(nbt.getString("Materials")));
schematic.setBlocks(nbt.getByteArray("Blocks"));
schematic.setAddBlocks(nbt.getByteArray("AddBlocks"));
schematic.setData(nbt.getByteArray("Data"));
List<BlockEntity> blockEntities = new LinkedList<>();
for (BinaryTag tag : nbt.getList("TileEntities")) {
if (tag instanceof CompoundBinaryTag) {
CompoundBinaryTag data = (CompoundBinaryTag) tag;
String id = data.getString("id");
int x = data.getInt("x");
int y = data.getInt("y");
int z = data.getInt("z");
data.remove("id");
data.remove("x");
data.remove("y");
data.remove("z");
blockEntities.add(new BlockEntity(Location.pos(x, y, z), id, data));
}
}
schematic.setBlockEntities(blockEntities);
return schematic;
}
}

View File

@ -1,94 +0,0 @@
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world.schematic.versions;
import ru.nanit.limbo.protocol.registry.Version;
import ru.nanit.limbo.world.BlockData;
import ru.nanit.limbo.world.BlockMappings;
import ru.nanit.limbo.world.Location;
import ru.nanit.limbo.world.schematic.AbstractSchematic;
/**
* Legacy schematic format (1.12-)
*/
public class LegacySchematic extends AbstractSchematic {
private Materials materials;
private byte[] blocks;
private byte[] addBlocks;
private byte[] data;
public LegacySchematic(BlockMappings mappings) {
super(mappings);
}
@Override
public BlockData getBlock(Location loc, Version version) {
int index = (loc.getBlockY() * getLength() + loc.getBlockZ()) * getWidth() + loc.getBlockX();
byte id = this.blocks[index];
byte data = this.data[index];
return mappings.convert(id, data, version);
}
public void setMaterials(Materials materials) {
this.materials = materials;
}
public void setBlocks(byte[] blocks) {
this.blocks = blocks;
}
public void setAddBlocks(byte[] addBlocks) {
this.addBlocks = addBlocks;
}
public void setData(byte[] data) {
this.data = data;
}
@Override
public String toString() {
return "Schematic{" +
"width=" + getWidth() +
", height=" + getHeight() +
", length=" + getLength() +
", materials=" + materials +
", blocks length=" + blocks.length +
", addBlocks length=" + addBlocks.length +
", data length=" + data.length +
", blockEntities=" + getBlockEntities() +
'}';
}
public enum Materials {
CLASSIC,
ALPHA,
POCKET;
public static Materials from(String value) {
switch (value.toLowerCase()) {
case "classic": return CLASSIC;
case "alpha": return ALPHA;
case "pocket": return POCKET;
default: throw new IllegalArgumentException("Invalid materials type");
}
}
}
}

View File

@ -1,79 +0,0 @@
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.nanit.limbo.world.schematic.versions;
import ru.nanit.limbo.protocol.registry.Version;
import ru.nanit.limbo.world.BlockData;
import ru.nanit.limbo.world.BlockMappings;
import ru.nanit.limbo.world.Location;
import ru.nanit.limbo.world.schematic.AbstractSchematic;
import java.util.Map;
/**
* Modern schematic format (Sponge second specification)
*/
public class SpongeSchematic extends AbstractSchematic {
private int dataVersion;
private int paletteMax;
private Map<Integer, String> palette;
private byte[] blockData;
public SpongeSchematic(BlockMappings mappings) {
super(mappings);
}
@Override
public BlockData getBlock(Location loc, Version version) {
int index = loc.getBlockX() + loc.getBlockZ() * getWidth() + loc.getBlockY() * getWidth() * getLength();
int id = blockData[index];
String state = palette.get(id);
return mappings.convert(state, version);
}
public void setDataVersion(int dataVersion) {
this.dataVersion = dataVersion;
}
public void setPaletteMax(int paletteMax) {
this.paletteMax = paletteMax;
}
public void setPalette(Map<Integer, String> palette) {
this.palette = palette;
}
public void setBlockData(byte[] blockData) {
this.blockData = blockData;
}
@Override
public String toString() {
return "SpongeSchematic{" +
"dataVersion=" + dataVersion +
", width=" + getWidth() +
", height=" + getHeight() +
", length=" + getLength() +
", paletteMax=" + paletteMax +
", palette=" + palette +
", blockData bytes=" + blockData.length +
", blockEntities=" + getBlockEntities() +
'}';
}
}

View File

@ -1,35 +0,0 @@
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import org.junit.jupiter.api.Test;
import ru.nanit.limbo.world.BlockMappings;
import ru.nanit.limbo.world.schematic.SchematicLoader;
import java.io.IOException;
import java.io.InputStream;
public class SchematicTest {
@Test
public void testLoading() throws IOException {
BlockMappings mappings = new BlockMappings();
SchematicLoader loader = new SchematicLoader(mappings);
InputStream stream = getClass().getResourceAsStream("spawn.schem");
System.out.println(loader.load(stream));
}
}

Binary file not shown.

Binary file not shown.