mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Remove hunk writers & old nbt
This commit is contained in:
parent
7b6405fba7
commit
401ed0a7a5
@ -21,14 +21,13 @@ package com.volmit.iris.util.hunk;
|
|||||||
import com.volmit.iris.engine.object.basic.IrisPosition;
|
import com.volmit.iris.engine.object.basic.IrisPosition;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.function.*;
|
import com.volmit.iris.util.function.*;
|
||||||
import com.volmit.iris.util.hunk.io.HunkIOAdapter;
|
|
||||||
import com.volmit.iris.util.hunk.storage.*;
|
import com.volmit.iris.util.hunk.storage.*;
|
||||||
import com.volmit.iris.util.hunk.view.*;
|
import com.volmit.iris.util.hunk.view.*;
|
||||||
import com.volmit.iris.util.interpolation.InterpolationMethod;
|
import com.volmit.iris.util.interpolation.InterpolationMethod;
|
||||||
import com.volmit.iris.util.interpolation.InterpolationMethod3D;
|
import com.volmit.iris.util.interpolation.InterpolationMethod3D;
|
||||||
import com.volmit.iris.util.interpolation.IrisInterpolation;
|
import com.volmit.iris.util.interpolation.IrisInterpolation;
|
||||||
import com.volmit.iris.util.math.BlockPosition;
|
import com.volmit.iris.util.math.BlockPosition;
|
||||||
import com.volmit.iris.util.oldnbt.ByteArrayTag;
|
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.stream.interpolation.Interpolated;
|
import com.volmit.iris.util.stream.interpolation.Interpolated;
|
||||||
@ -229,18 +228,6 @@ public interface Hunk<T> {
|
|||||||
return count.get();
|
return count.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
default void write(OutputStream s, HunkIOAdapter<T> h) throws IOException {
|
|
||||||
h.write(this, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
default ByteArrayTag writeByteArrayTag(HunkIOAdapter<T> h, String name) throws IOException {
|
|
||||||
return h.writeByteArrayTag(this, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
default void write(File s, HunkIOAdapter<T> h) throws IOException {
|
|
||||||
h.write(this, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
default boolean isAtomic() {
|
default boolean isAtomic() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.hunk.io;
|
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.util.function.Function3;
|
|
||||||
import com.volmit.iris.util.hunk.Hunk;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
public abstract class BasicHunkIOAdapter<T> implements HunkIOAdapter<T> {
|
|
||||||
@Override
|
|
||||||
public void write(Hunk<T> t, OutputStream out) throws IOException {
|
|
||||||
DataOutputStream dos = new DataOutputStream(out);
|
|
||||||
dos.writeShort(t.getWidth() + Short.MIN_VALUE);
|
|
||||||
dos.writeShort(t.getHeight() + Short.MIN_VALUE);
|
|
||||||
dos.writeShort(t.getDepth() + Short.MIN_VALUE);
|
|
||||||
dos.writeInt(t.getNonNullEntries() + Integer.MIN_VALUE);
|
|
||||||
|
|
||||||
AtomicBoolean failure = new AtomicBoolean(false);
|
|
||||||
t.iterate(0, (x, y, z, w) -> {
|
|
||||||
if (w != null) {
|
|
||||||
try {
|
|
||||||
dos.writeShort(x + Short.MIN_VALUE);
|
|
||||||
dos.writeShort(y + Short.MIN_VALUE);
|
|
||||||
dos.writeShort(z + Short.MIN_VALUE);
|
|
||||||
write(w, dos);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
failure.set(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dos.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, InputStream in) throws IOException {
|
|
||||||
DataInputStream din = new DataInputStream(in);
|
|
||||||
int w = din.readShort() - Short.MIN_VALUE;
|
|
||||||
int h = din.readShort() - Short.MIN_VALUE;
|
|
||||||
int d = din.readShort() - Short.MIN_VALUE;
|
|
||||||
int e = din.readInt() - Integer.MIN_VALUE;
|
|
||||||
Hunk<T> t = factory.apply(w, h, d);
|
|
||||||
|
|
||||||
for (int i = 0; i < e; i++) {
|
|
||||||
int x = din.readShort() - Short.MIN_VALUE;
|
|
||||||
int y = din.readShort() - Short.MIN_VALUE;
|
|
||||||
int z = din.readShort() - Short.MIN_VALUE;
|
|
||||||
T v = read(din);
|
|
||||||
|
|
||||||
if (v == null) {
|
|
||||||
throw new IOException("NULL VALUE AT " + x + " " + y + " " + z);
|
|
||||||
}
|
|
||||||
|
|
||||||
t.setRaw(x, y, z, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
in.close();
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.hunk.io;
|
|
||||||
|
|
||||||
import com.volmit.iris.util.data.IOAdapter;
|
|
||||||
import com.volmit.iris.util.function.Function3;
|
|
||||||
import com.volmit.iris.util.hunk.Hunk;
|
|
||||||
import com.volmit.iris.util.io.CustomOutputStream;
|
|
||||||
import com.volmit.iris.util.oldnbt.ByteArrayTag;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
public interface HunkIOAdapter<T> extends IOAdapter<T> {
|
|
||||||
void write(Hunk<T> t, OutputStream out) throws IOException;
|
|
||||||
|
|
||||||
Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, InputStream in) throws IOException;
|
|
||||||
|
|
||||||
default void write(Hunk<T> t, File f) throws IOException {
|
|
||||||
f.getParentFile().mkdirs();
|
|
||||||
FileOutputStream fos = new FileOutputStream(f);
|
|
||||||
GZIPOutputStream gzo = new CustomOutputStream(fos, 6);
|
|
||||||
write(t, gzo);
|
|
||||||
}
|
|
||||||
|
|
||||||
default Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, File f) throws IOException {
|
|
||||||
return read(factory, new GZIPInputStream(new FileInputStream(f)));
|
|
||||||
}
|
|
||||||
|
|
||||||
default Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, ByteArrayTag f) throws IOException {
|
|
||||||
return read(factory, new ByteArrayInputStream(f.getValue()));
|
|
||||||
}
|
|
||||||
|
|
||||||
default ByteArrayTag writeByteArrayTag(Hunk<T> tHunk, String name) throws IOException {
|
|
||||||
ByteArrayOutputStream boas = new ByteArrayOutputStream();
|
|
||||||
write(tHunk, boas);
|
|
||||||
return new ByteArrayTag(name, boas.toByteArray());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.hunk.io;
|
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.util.collection.KMap;
|
|
||||||
import com.volmit.iris.util.oldnbt.CompoundTag;
|
|
||||||
import com.volmit.iris.util.oldnbt.NBTInputStream;
|
|
||||||
import com.volmit.iris.util.oldnbt.NBTOutputStream;
|
|
||||||
import com.volmit.iris.util.oldnbt.Tag;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@SuppressWarnings("SynchronizeOnNonFinalField")
|
|
||||||
public class HunkRegion {
|
|
||||||
private final File folder;
|
|
||||||
private CompoundTag compound;
|
|
||||||
private final int x;
|
|
||||||
private final int z;
|
|
||||||
|
|
||||||
public HunkRegion(File folder, int x, int z, CompoundTag compound) {
|
|
||||||
this.compound = fix(compound);
|
|
||||||
this.folder = folder;
|
|
||||||
this.x = x;
|
|
||||||
this.z = z;
|
|
||||||
folder.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
public HunkRegion(File folder, int x, int z) {
|
|
||||||
this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>()));
|
|
||||||
File f = getFile();
|
|
||||||
|
|
||||||
if (f.exists()) {
|
|
||||||
try {
|
|
||||||
NBTInputStream in = new NBTInputStream(new FileInputStream(f));
|
|
||||||
compound = fix((CompoundTag) in.readTag());
|
|
||||||
in.close();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompoundTag getCompound() {
|
|
||||||
return compound;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CompoundTag fix(CompoundTag readTag) {
|
|
||||||
Map<String, Tag> v = readTag.getValue();
|
|
||||||
|
|
||||||
if (!(v instanceof KMap)) {
|
|
||||||
return new CompoundTag(readTag.getName(), new KMap<>(v));
|
|
||||||
}
|
|
||||||
|
|
||||||
return readTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getFile() {
|
|
||||||
return new File(folder, x + "." + z + ".dat");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() throws IOException {
|
|
||||||
synchronized (compound) {
|
|
||||||
File f = getFile();
|
|
||||||
FileOutputStream fos = new FileOutputStream(f);
|
|
||||||
NBTOutputStream out = new NBTOutputStream(fos);
|
|
||||||
out.writeTag(compound);
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getZ() {
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,262 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.hunk.io;
|
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.engine.object.tile.TileData;
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
|
||||||
import com.volmit.iris.util.collection.KMap;
|
|
||||||
import com.volmit.iris.util.collection.KSet;
|
|
||||||
import com.volmit.iris.util.function.Function2;
|
|
||||||
import com.volmit.iris.util.function.Function3;
|
|
||||||
import com.volmit.iris.util.hunk.Hunk;
|
|
||||||
import com.volmit.iris.util.math.M;
|
|
||||||
import com.volmit.iris.util.math.Position2;
|
|
||||||
import com.volmit.iris.util.oldnbt.ByteArrayTag;
|
|
||||||
import com.volmit.iris.util.oldnbt.CompoundTag;
|
|
||||||
import com.volmit.iris.util.oldnbt.Tag;
|
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
|
||||||
import org.bukkit.block.TileState;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
public class HunkRegionSlice<T> {
|
|
||||||
public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BlockDataHunkIOAdapter(), c, "blockdata");
|
|
||||||
public static final Function2<Integer, CompoundTag, HunkRegionSlice<TileData<? extends TileState>>> TILE = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new TileDataHunkIOAdapter(), c, "tile");
|
|
||||||
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t);
|
|
||||||
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t);
|
|
||||||
private final Function3<Integer, Integer, Integer, Hunk<T>> factory;
|
|
||||||
private final HunkIOAdapter<T> adapter;
|
|
||||||
private final CompoundTag compound;
|
|
||||||
private final String key;
|
|
||||||
private final KMap<Position2, Hunk<T>> loadedChunks;
|
|
||||||
private final KMap<Position2, Long> lastUse;
|
|
||||||
private final KSet<Position2> save;
|
|
||||||
private final int height;
|
|
||||||
|
|
||||||
public HunkRegionSlice(int height, Function3<Integer, Integer, Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key) {
|
|
||||||
this.height = height;
|
|
||||||
this.loadedChunks = new KMap<>();
|
|
||||||
this.factory = factory;
|
|
||||||
this.adapter = adapter;
|
|
||||||
this.compound = compound;
|
|
||||||
this.save = new KSet<>();
|
|
||||||
this.key = key;
|
|
||||||
this.lastUse = new KMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized int cleanup(long t) {
|
|
||||||
int v = 0;
|
|
||||||
if (loadedChunks.size() != lastUse.size()) {
|
|
||||||
Iris.warn("Incorrect chunk use counts in " + key + " region slice.");
|
|
||||||
|
|
||||||
for (Position2 i : lastUse.k()) {
|
|
||||||
if (!loadedChunks.containsKey(i)) {
|
|
||||||
Iris.warn(" Missing LoadChunkKey " + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Position2 i : lastUse.k()) {
|
|
||||||
Long l = lastUse.get(i);
|
|
||||||
if (l == null || M.ms() - l > t) {
|
|
||||||
v++;
|
|
||||||
MultiBurst.burst.lazy(() -> {
|
|
||||||
unload(i.getX(), i.getZ());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void clear() {
|
|
||||||
for (String i : new KList<>(compound.getValue().keySet())) {
|
|
||||||
if (i.startsWith(key + ".")) {
|
|
||||||
compound.getValue().remove(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void save(MultiBurst burst) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (Position2 i : save.copy()) {
|
|
||||||
if (i == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
save(i.getX(), i.getZ());
|
|
||||||
|
|
||||||
try {
|
|
||||||
save.remove(i);
|
|
||||||
} catch (Throwable eer) {
|
|
||||||
Iris.reportError(eer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Throwable ee) {
|
|
||||||
Iris.reportError(ee);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean contains(int x, int z) {
|
|
||||||
return compound.getValue().containsKey(key(x, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete(int x, int z) {
|
|
||||||
compound.getValue().remove(key(x, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hunk<T> read(int x, int z) throws IOException {
|
|
||||||
AtomicReference<IOException> e = new AtomicReference<>();
|
|
||||||
Hunk<T> xt = null;
|
|
||||||
|
|
||||||
Tag t = compound.getValue().get(key(x, z));
|
|
||||||
|
|
||||||
if ((t instanceof ByteArrayTag)) {
|
|
||||||
try {
|
|
||||||
xt = adapter.read(factory, (ByteArrayTag) t);
|
|
||||||
} catch (IOException xe) {
|
|
||||||
Iris.reportError(xe);
|
|
||||||
e.set(xe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xt != null) {
|
|
||||||
return xt;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.get() != null) {
|
|
||||||
throw e.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(Hunk<T> hunk, int x, int z) throws IOException {
|
|
||||||
compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized int unloadAll() {
|
|
||||||
int v = 0;
|
|
||||||
for (Position2 i : loadedChunks.k()) {
|
|
||||||
unload(i.getX(), i.getZ());
|
|
||||||
v++;
|
|
||||||
}
|
|
||||||
|
|
||||||
save.clear();
|
|
||||||
loadedChunks.clear();
|
|
||||||
lastUse.clear();
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(Hunk<T> region, int x, int z) {
|
|
||||||
try {
|
|
||||||
write(region, x, z);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLoaded(int x, int z) {
|
|
||||||
return loadedChunks.containsKey(new Position2(x, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(int x, int z) {
|
|
||||||
if (isLoaded(x, z)) {
|
|
||||||
save(get(x, z), x, z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unload(int x, int z) {
|
|
||||||
Position2 key = new Position2(x, z);
|
|
||||||
if (isLoaded(x, z)) {
|
|
||||||
if (save.contains(key)) {
|
|
||||||
save(x, z);
|
|
||||||
save.remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
lastUse.remove(key);
|
|
||||||
loadedChunks.remove(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hunk<T> load(int x, int z) {
|
|
||||||
if (isLoaded(x, z)) {
|
|
||||||
return loadedChunks.get(new Position2(x, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
Hunk<T> v = null;
|
|
||||||
|
|
||||||
if (contains(x, z)) {
|
|
||||||
try {
|
|
||||||
v = read(x, z);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (v == null) {
|
|
||||||
v = factory.apply(16, height, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
loadedChunks.put(new Position2(x, z), v);
|
|
||||||
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hunk<T> get(int x, int z) {
|
|
||||||
Position2 key = new Position2(x, z);
|
|
||||||
|
|
||||||
Hunk<T> c = loadedChunks.get(key);
|
|
||||||
|
|
||||||
if (c == null) {
|
|
||||||
c = load(x, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
lastUse.put(new Position2(x, z), M.ms());
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hunk<T> getR(int x, int z) {
|
|
||||||
return get(x, z).readOnly();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hunk<T> getRW(int x, int z) {
|
|
||||||
save.add(new Position2(x, z));
|
|
||||||
return get(x, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String key(int x, int z) {
|
|
||||||
if (x < 0 || x >= 32 || z < 0 || z >= 32) {
|
|
||||||
throw new IndexOutOfBoundsException("The chunk " + x + " " + z + " is out of bounds max is 31x31");
|
|
||||||
}
|
|
||||||
|
|
||||||
return key + "." + x + "." + z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLoadCount() {
|
|
||||||
return loadedChunks.size();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.hunk.io;
|
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.util.data.DataPalette;
|
|
||||||
import com.volmit.iris.util.function.Function3;
|
|
||||||
import com.volmit.iris.util.hunk.Hunk;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
public abstract class PaletteHunkIOAdapter<T> implements HunkIOAdapter<T> {
|
|
||||||
@Override
|
|
||||||
public void write(Hunk<T> t, OutputStream out) throws IOException {
|
|
||||||
DataOutputStream dos = new DataOutputStream(out);
|
|
||||||
dos.writeShort(t.getWidth() + Short.MIN_VALUE);
|
|
||||||
dos.writeShort(t.getHeight() + Short.MIN_VALUE);
|
|
||||||
dos.writeShort(t.getDepth() + Short.MIN_VALUE);
|
|
||||||
AtomicInteger nonNull = new AtomicInteger(0);
|
|
||||||
DataPalette<T> palette = new DataPalette<>();
|
|
||||||
|
|
||||||
t.iterateSync((x, y, z, w) -> {
|
|
||||||
if (w != null) {
|
|
||||||
palette.getIndex(w);
|
|
||||||
nonNull.getAndAdd(1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
palette.write(this, dos);
|
|
||||||
dos.writeInt(nonNull.get() + Integer.MIN_VALUE);
|
|
||||||
AtomicBoolean failure = new AtomicBoolean(false);
|
|
||||||
t.iterateSync((x, y, z, w) -> {
|
|
||||||
if (w != null) {
|
|
||||||
try {
|
|
||||||
dos.writeShort(x + Short.MIN_VALUE);
|
|
||||||
dos.writeShort(y + Short.MIN_VALUE);
|
|
||||||
dos.writeShort(z + Short.MIN_VALUE);
|
|
||||||
dos.writeShort(palette.getIndex(w) + Short.MIN_VALUE);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
failure.set(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dos.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, InputStream in) throws IOException {
|
|
||||||
DataInputStream din = new DataInputStream(in);
|
|
||||||
int w = din.readShort() - Short.MIN_VALUE;
|
|
||||||
int h = din.readShort() - Short.MIN_VALUE;
|
|
||||||
int d = din.readShort() - Short.MIN_VALUE;
|
|
||||||
DataPalette<T> palette = DataPalette.getPalette(this, din);
|
|
||||||
int e = din.readInt() - Integer.MIN_VALUE;
|
|
||||||
Hunk<T> t = factory.apply(w, h, d);
|
|
||||||
|
|
||||||
for (int i = 0; i < e; i++) {
|
|
||||||
int x = din.readShort() - Short.MIN_VALUE;
|
|
||||||
int y = din.readShort() - Short.MIN_VALUE;
|
|
||||||
int z = din.readShort() - Short.MIN_VALUE;
|
|
||||||
int vf = din.readShort() - Short.MIN_VALUE;
|
|
||||||
|
|
||||||
T v = null;
|
|
||||||
if (palette.getPalette().hasIndex(vf)) {
|
|
||||||
v = palette.getPalette().get(vf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (v != null) {
|
|
||||||
t.setRaw(x, y, z, v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
in.close();
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.hunk.io;
|
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.engine.object.tile.TileData;
|
|
||||||
import org.bukkit.block.TileState;
|
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class TileDataHunkIOAdapter extends PaletteHunkIOAdapter<TileData<? extends TileState>> {
|
|
||||||
@Override
|
|
||||||
public void write(TileData<? extends TileState> data, DataOutputStream dos) throws IOException {
|
|
||||||
data.toBinary(dos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TileData<? extends TileState> read(DataInputStream din) throws IOException {
|
|
||||||
try {
|
|
||||||
return TileData.read(din);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_Byte_Array</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class ByteArrayTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final byte[] value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public ByteArrayTag(String name, byte[] value) {
|
|
||||||
super(name);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder hex = new StringBuilder();
|
|
||||||
for (byte b : value) {
|
|
||||||
String hexDigits = Integer.toHexString(b).toUpperCase();
|
|
||||||
if (hexDigits.length() == 1) {
|
|
||||||
hex.append("0");
|
|
||||||
}
|
|
||||||
hex.append(hexDigits).append(" ");
|
|
||||||
}
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
return "TAG_Byte_Array" + append + ": " + hex;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_Byte</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class ByteTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final byte value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public ByteTag(String name, byte value) {
|
|
||||||
super(name);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Byte getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
return "TAG_Byte" + append + ": " + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_Compound</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class CompoundTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final Map<String, Tag> value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public CompoundTag(String name, Map<String, Tag> value) {
|
|
||||||
super(name);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Tag> getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
StringBuilder bldr = new StringBuilder();
|
|
||||||
bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n");
|
|
||||||
for (Map.Entry<String, Tag> entry : value.entrySet()) {
|
|
||||||
bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
|
||||||
}
|
|
||||||
bldr.append("}");
|
|
||||||
return bldr.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_Double</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class DoubleTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final double value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public DoubleTag(String name, double value) {
|
|
||||||
super(name);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Double getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
return "TAG_Double" + append + ": " + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_End</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class EndTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*/
|
|
||||||
public EndTag() {
|
|
||||||
super("");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getValue() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "TAG_End";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_Float</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class FloatTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final float value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public FloatTag(String name, float value) {
|
|
||||||
super(name);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Float getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
return "TAG_Float" + append + ": " + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_Int_Array</code> tag.
|
|
||||||
*
|
|
||||||
* @author Neil Wightman
|
|
||||||
*/
|
|
||||||
public final class IntArrayTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final int[] value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public IntArrayTag(String name, int[] value) {
|
|
||||||
super(name);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int[] getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
return "TAG_Int_Array" + append + ": " + Arrays.toString(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_Int</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class IntTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final int value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public IntTag(String name, int value) {
|
|
||||||
super(name);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
return "TAG_Int" + append + ": " + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_List</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class ListTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type.
|
|
||||||
*/
|
|
||||||
private final Class<? extends Tag> type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final List<Tag> value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param type The type of item in the list.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public ListTag(String name, Class<? extends Tag> type, List<Tag> value) {
|
|
||||||
super(name);
|
|
||||||
this.type = type;
|
|
||||||
this.value = Collections.unmodifiableList(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the type of item in this list.
|
|
||||||
*
|
|
||||||
* @return The type of item in this list.
|
|
||||||
*/
|
|
||||||
public Class<? extends Tag> getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Tag> getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
StringBuilder bldr = new StringBuilder();
|
|
||||||
bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n");
|
|
||||||
for (Tag t : value) {
|
|
||||||
bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
|
||||||
}
|
|
||||||
bldr.append("}");
|
|
||||||
return bldr.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_Long</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class LongTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final long value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public LongTag(String name, long value) {
|
|
||||||
super(name);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
return "TAG_Long" + append + ": " + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Changes : Neil Wightman - Support 19133 Tag_Int_Array tag
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class which holds constant values.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class NBTConstants {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The character set used by NBT (UTF-8).
|
|
||||||
*/
|
|
||||||
public static final Charset CHARSET = StandardCharsets.UTF_8;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tag type constants.
|
|
||||||
*/
|
|
||||||
public static final int TYPE_END = 0,
|
|
||||||
TYPE_BYTE = 1,
|
|
||||||
TYPE_SHORT = 2,
|
|
||||||
TYPE_INT = 3,
|
|
||||||
TYPE_LONG = 4,
|
|
||||||
TYPE_FLOAT = 5,
|
|
||||||
TYPE_DOUBLE = 6,
|
|
||||||
TYPE_BYTE_ARRAY = 7,
|
|
||||||
TYPE_STRING = 8,
|
|
||||||
TYPE_LIST = 9,
|
|
||||||
TYPE_COMPOUND = 10,
|
|
||||||
TYPE_INT_ARRAY = 11;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default private constructor.
|
|
||||||
*/
|
|
||||||
private NBTConstants() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,189 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Changes :
|
|
||||||
Neil Wightman - Support 19133 Tag_Int_Array tag
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* This class reads <strong>NBT</strong>, or
|
|
||||||
* <strong>Named Binary Tag</strong> streams, and produces an object graph of subclasses of the <code>Tag</code> object.</p>
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* The NBT format was created by Markus Persson, and the specification may be found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
|
||||||
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class NBTInputStream implements Closeable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The data input stream.
|
|
||||||
*/
|
|
||||||
private final DataInputStream is;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new <code>NBTInputStream</code>, which will source its data from the specified input stream.
|
|
||||||
*
|
|
||||||
* @param is The output stream
|
|
||||||
*/
|
|
||||||
public NBTInputStream(DataInputStream is) {
|
|
||||||
this.is = is;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new <code>NBTInputStream</code>, which will source its data from the specified input stream.
|
|
||||||
* The stream will be decompressed using GZIP.
|
|
||||||
*
|
|
||||||
* @param is The input stream.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
public NBTInputStream(InputStream is) throws IOException {
|
|
||||||
this.is = new DataInputStream(new GZIPInputStream(is));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads an NBT tag from the stream.
|
|
||||||
*
|
|
||||||
* @return The tag that was read.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
public Tag readTag() throws IOException {
|
|
||||||
return readTag(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads an NBT from the stream.
|
|
||||||
*
|
|
||||||
* @param depth The depth of this tag.
|
|
||||||
* @return The tag that was read.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private Tag readTag(int depth) throws IOException {
|
|
||||||
int type = is.readByte() & 0xFF;
|
|
||||||
|
|
||||||
String name;
|
|
||||||
if (type != NBTConstants.TYPE_END) {
|
|
||||||
int nameLength = is.readShort() & 0xFFFF;
|
|
||||||
byte[] nameBytes = new byte[nameLength];
|
|
||||||
is.readFully(nameBytes);
|
|
||||||
name = new String(nameBytes, NBTConstants.CHARSET);
|
|
||||||
} else {
|
|
||||||
name = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return readTagPayload(type, name, depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the payload of a tag, given the name and type.
|
|
||||||
*
|
|
||||||
* @param type The type.
|
|
||||||
* @param name The name.
|
|
||||||
* @param depth The depth.
|
|
||||||
* @return The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private Tag readTagPayload(int type, String name, int depth) throws IOException {
|
|
||||||
switch (type) {
|
|
||||||
case NBTConstants.TYPE_END:
|
|
||||||
if (depth == 0) {
|
|
||||||
throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
|
||||||
} else {
|
|
||||||
return new EndTag();
|
|
||||||
}
|
|
||||||
case NBTConstants.TYPE_BYTE:
|
|
||||||
return new ByteTag(name, is.readByte());
|
|
||||||
case NBTConstants.TYPE_SHORT:
|
|
||||||
return new ShortTag(name, is.readShort());
|
|
||||||
case NBTConstants.TYPE_INT:
|
|
||||||
return new IntTag(name, is.readInt());
|
|
||||||
case NBTConstants.TYPE_LONG:
|
|
||||||
return new LongTag(name, is.readLong());
|
|
||||||
case NBTConstants.TYPE_FLOAT:
|
|
||||||
return new FloatTag(name, is.readFloat());
|
|
||||||
case NBTConstants.TYPE_DOUBLE:
|
|
||||||
return new DoubleTag(name, is.readDouble());
|
|
||||||
case NBTConstants.TYPE_BYTE_ARRAY:
|
|
||||||
int length = is.readInt();
|
|
||||||
byte[] bytes = new byte[length];
|
|
||||||
is.readFully(bytes);
|
|
||||||
return new ByteArrayTag(name, bytes);
|
|
||||||
case NBTConstants.TYPE_STRING:
|
|
||||||
length = is.readShort();
|
|
||||||
bytes = new byte[length];
|
|
||||||
is.readFully(bytes);
|
|
||||||
return new StringTag(name, new String(bytes, NBTConstants.CHARSET));
|
|
||||||
case NBTConstants.TYPE_LIST:
|
|
||||||
int childType = is.readByte();
|
|
||||||
length = is.readInt();
|
|
||||||
|
|
||||||
List<Tag> tagList = new ArrayList<>();
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
Tag tag = readTagPayload(childType, "", depth + 1);
|
|
||||||
if (tag instanceof EndTag) {
|
|
||||||
throw new IOException("TAG_End not permitted in a list.");
|
|
||||||
}
|
|
||||||
tagList.add(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ListTag(name, NBTUtils.getTypeClass(childType), tagList);
|
|
||||||
case NBTConstants.TYPE_COMPOUND:
|
|
||||||
Map<String, Tag> tagMap = new HashMap<>();
|
|
||||||
while (true) {
|
|
||||||
Tag tag = readTag(depth + 1);
|
|
||||||
if (tag instanceof EndTag) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
tagMap.put(tag.getName(), tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CompoundTag(name, tagMap);
|
|
||||||
case NBTConstants.TYPE_INT_ARRAY:
|
|
||||||
length = is.readInt();
|
|
||||||
int[] value = new int[length];
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
value[i] = is.readInt();
|
|
||||||
}
|
|
||||||
return new IntArrayTag(name, value);
|
|
||||||
default:
|
|
||||||
throw new IOException("Invalid tag type: " + type + ".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
is.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,262 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
/*
|
|
||||||
Changes : Neil Wightman - Support 19133 Tag_Int_Array tag
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* This class writes <strong>NBT</strong>, or
|
|
||||||
* <strong>Named Binary Tag</strong> <code>Tag</code> objects to an underlying <code>OutputStream</code>.</p>
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* The NBT format was created by Markus Persson, and the specification may be found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
|
||||||
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"EmptyMethod", "JavaDoc"})
|
|
||||||
public final class NBTOutputStream implements Closeable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The output stream.
|
|
||||||
*/
|
|
||||||
private final DataOutputStream os;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new <code>NBTOutputStream</code>, which will write data to the specified underlying output stream.
|
|
||||||
*
|
|
||||||
* @param os The output stream
|
|
||||||
*/
|
|
||||||
public NBTOutputStream(DataOutputStream os) {
|
|
||||||
this.os = os;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new <code>NBTOutputStream</code>, which will write data to the specified underlying output stream.
|
|
||||||
* the stream will be compressed using GZIP.
|
|
||||||
*
|
|
||||||
* @param os The output stream.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
public NBTOutputStream(OutputStream os) throws IOException {
|
|
||||||
this.os = new DataOutputStream(new GZIPOutputStream(os));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag to write.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
public void writeTag(Tag tag) throws IOException {
|
|
||||||
int type = NBTUtils.getTypeCode(tag.getClass());
|
|
||||||
String name = tag.getName();
|
|
||||||
byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
|
||||||
|
|
||||||
os.writeByte(type);
|
|
||||||
os.writeShort(nameBytes.length);
|
|
||||||
os.write(nameBytes);
|
|
||||||
|
|
||||||
if (type == NBTConstants.TYPE_END) {
|
|
||||||
throw new IOException("Named TAG_End not permitted.");
|
|
||||||
}
|
|
||||||
|
|
||||||
writeTagPayload(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes tag payload.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeTagPayload(Tag tag) throws IOException {
|
|
||||||
int type = NBTUtils.getTypeCode(tag.getClass());
|
|
||||||
switch (type) {
|
|
||||||
case NBTConstants.TYPE_END -> writeEndTagPayload((EndTag) tag);
|
|
||||||
case NBTConstants.TYPE_BYTE -> writeByteTagPayload((ByteTag) tag);
|
|
||||||
case NBTConstants.TYPE_SHORT -> writeShortTagPayload((ShortTag) tag);
|
|
||||||
case NBTConstants.TYPE_INT -> writeIntTagPayload((IntTag) tag);
|
|
||||||
case NBTConstants.TYPE_LONG -> writeLongTagPayload((LongTag) tag);
|
|
||||||
case NBTConstants.TYPE_FLOAT -> writeFloatTagPayload((FloatTag) tag);
|
|
||||||
case NBTConstants.TYPE_DOUBLE -> writeDoubleTagPayload((DoubleTag) tag);
|
|
||||||
case NBTConstants.TYPE_BYTE_ARRAY -> writeByteArrayTagPayload((ByteArrayTag) tag);
|
|
||||||
case NBTConstants.TYPE_STRING -> writeStringTagPayload((StringTag) tag);
|
|
||||||
case NBTConstants.TYPE_LIST -> writeListTagPayload((ListTag) tag);
|
|
||||||
case NBTConstants.TYPE_COMPOUND -> writeCompoundTagPayload((CompoundTag) tag);
|
|
||||||
case NBTConstants.TYPE_INT_ARRAY -> writeIntArrayTagPayload((IntArrayTag) tag);
|
|
||||||
default -> throw new IOException("Invalid tag type: " + type + ".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_Byte</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeByteTagPayload(ByteTag tag) throws IOException {
|
|
||||||
os.writeByte(tag.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_Byte_Array</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException {
|
|
||||||
byte[] bytes = tag.getValue();
|
|
||||||
os.writeInt(bytes.length);
|
|
||||||
os.write(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_Compound</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
|
|
||||||
for (Tag childTag : tag.getValue().values()) {
|
|
||||||
writeTag(childTag);
|
|
||||||
}
|
|
||||||
os.writeByte((byte) 0); // end tag - better way?
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_List</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeListTagPayload(ListTag tag) throws IOException {
|
|
||||||
Class<? extends Tag> clazz = tag.getType();
|
|
||||||
List<Tag> tags = tag.getValue();
|
|
||||||
int size = tags.size();
|
|
||||||
|
|
||||||
os.writeByte(NBTUtils.getTypeCode(clazz));
|
|
||||||
os.writeInt(size);
|
|
||||||
for (Tag value : tags) {
|
|
||||||
writeTagPayload(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_String</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeStringTagPayload(StringTag tag) throws IOException {
|
|
||||||
byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
|
|
||||||
os.writeShort(bytes.length);
|
|
||||||
os.write(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_Double</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeDoubleTagPayload(DoubleTag tag) throws IOException {
|
|
||||||
os.writeDouble(tag.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_Float</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeFloatTagPayload(FloatTag tag) throws IOException {
|
|
||||||
os.writeFloat(tag.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_Long</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeLongTagPayload(LongTag tag) throws IOException {
|
|
||||||
os.writeLong(tag.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_Int</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeIntTagPayload(IntTag tag) throws IOException {
|
|
||||||
os.writeInt(tag.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_Short</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeShortTagPayload(ShortTag tag) throws IOException {
|
|
||||||
os.writeShort(tag.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_Empty</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeEndTagPayload(EndTag tag) {
|
|
||||||
/* empty */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a <code>TAG_Int_Array</code> tag.
|
|
||||||
*
|
|
||||||
* @param tag The tag.
|
|
||||||
* @throws IOException if an I/O error occurs.
|
|
||||||
*/
|
|
||||||
private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
|
|
||||||
final int[] values = tag.getValue();
|
|
||||||
os.writeInt(values.length);
|
|
||||||
for (final int value : values) {
|
|
||||||
os.writeInt(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
os.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,137 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Changes : Neil Wightman - Support 19133 Tag_Int_Array tag
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class which contains NBT-related utility methods. This currently supports reading 19133 but <b>only</b> writing 19132.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class NBTUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the type name of a tag.
|
|
||||||
*
|
|
||||||
* @param clazz The tag class.
|
|
||||||
* @return The type name.
|
|
||||||
*/
|
|
||||||
public static String getTypeName(Class<? extends Tag> clazz) {
|
|
||||||
if (clazz.equals(ByteArrayTag.class)) {
|
|
||||||
return "TAG_Byte_Array";
|
|
||||||
} else if (clazz.equals(ByteTag.class)) {
|
|
||||||
return "TAG_Byte";
|
|
||||||
} else if (clazz.equals(CompoundTag.class)) {
|
|
||||||
return "TAG_Compound";
|
|
||||||
} else if (clazz.equals(DoubleTag.class)) {
|
|
||||||
return "TAG_Double";
|
|
||||||
} else if (clazz.equals(EndTag.class)) {
|
|
||||||
return "TAG_End";
|
|
||||||
} else if (clazz.equals(FloatTag.class)) {
|
|
||||||
return "TAG_Float";
|
|
||||||
} else if (clazz.equals(IntTag.class)) {
|
|
||||||
return "TAG_Int";
|
|
||||||
} else if (clazz.equals(ListTag.class)) {
|
|
||||||
return "TAG_List";
|
|
||||||
} else if (clazz.equals(LongTag.class)) {
|
|
||||||
return "TAG_Long";
|
|
||||||
} else if (clazz.equals(ShortTag.class)) {
|
|
||||||
return "TAG_Short";
|
|
||||||
} else if (clazz.equals(StringTag.class)) {
|
|
||||||
return "TAG_String";
|
|
||||||
} else if (clazz.equals(IntArrayTag.class)) {
|
|
||||||
return "TAG_Int_Array";
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the type code of a tag class.
|
|
||||||
*
|
|
||||||
* @param clazz The tag class.
|
|
||||||
* @return The type code.
|
|
||||||
* @throws IllegalArgumentException if the tag class is invalid.
|
|
||||||
*/
|
|
||||||
public static int getTypeCode(Class<? extends Tag> clazz) {
|
|
||||||
if (clazz.equals(ByteArrayTag.class)) {
|
|
||||||
return NBTConstants.TYPE_BYTE_ARRAY;
|
|
||||||
} else if (clazz.equals(ByteTag.class)) {
|
|
||||||
return NBTConstants.TYPE_BYTE;
|
|
||||||
} else if (clazz.equals(CompoundTag.class)) {
|
|
||||||
return NBTConstants.TYPE_COMPOUND;
|
|
||||||
} else if (clazz.equals(DoubleTag.class)) {
|
|
||||||
return NBTConstants.TYPE_DOUBLE;
|
|
||||||
} else if (clazz.equals(EndTag.class)) {
|
|
||||||
return NBTConstants.TYPE_END;
|
|
||||||
} else if (clazz.equals(FloatTag.class)) {
|
|
||||||
return NBTConstants.TYPE_FLOAT;
|
|
||||||
} else if (clazz.equals(IntTag.class)) {
|
|
||||||
return NBTConstants.TYPE_INT;
|
|
||||||
} else if (clazz.equals(ListTag.class)) {
|
|
||||||
return NBTConstants.TYPE_LIST;
|
|
||||||
} else if (clazz.equals(LongTag.class)) {
|
|
||||||
return NBTConstants.TYPE_LONG;
|
|
||||||
} else if (clazz.equals(ShortTag.class)) {
|
|
||||||
return NBTConstants.TYPE_SHORT;
|
|
||||||
} else if (clazz.equals(StringTag.class)) {
|
|
||||||
return NBTConstants.TYPE_STRING;
|
|
||||||
} else if (clazz.equals(IntArrayTag.class)) {
|
|
||||||
return NBTConstants.TYPE_INT_ARRAY;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ").");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the class of a type of tag.
|
|
||||||
*
|
|
||||||
* @param type The type.
|
|
||||||
* @return The class.
|
|
||||||
* @throws IllegalArgumentException if the tag type is invalid.
|
|
||||||
*/
|
|
||||||
public static Class<? extends Tag> getTypeClass(int type) {
|
|
||||||
return switch (type) {
|
|
||||||
case NBTConstants.TYPE_END -> EndTag.class;
|
|
||||||
case NBTConstants.TYPE_BYTE -> ByteTag.class;
|
|
||||||
case NBTConstants.TYPE_SHORT -> ShortTag.class;
|
|
||||||
case NBTConstants.TYPE_INT -> IntTag.class;
|
|
||||||
case NBTConstants.TYPE_LONG -> LongTag.class;
|
|
||||||
case NBTConstants.TYPE_FLOAT -> FloatTag.class;
|
|
||||||
case NBTConstants.TYPE_DOUBLE -> DoubleTag.class;
|
|
||||||
case NBTConstants.TYPE_BYTE_ARRAY -> ByteArrayTag.class;
|
|
||||||
case NBTConstants.TYPE_STRING -> StringTag.class;
|
|
||||||
case NBTConstants.TYPE_LIST -> ListTag.class;
|
|
||||||
case NBTConstants.TYPE_COMPOUND -> CompoundTag.class;
|
|
||||||
case NBTConstants.TYPE_INT_ARRAY -> IntArrayTag.class;
|
|
||||||
default -> throw new IllegalArgumentException("Invalid tag type : " + type + ".");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default private constructor.
|
|
||||||
*/
|
|
||||||
private NBTUtils() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_Short</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class ShortTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final short value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public ShortTag(String name, short value) {
|
|
||||||
super(name);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Short getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
return "TAG_Short" + append + ": " + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The <code>TAG_String</code> tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public final class StringTag extends Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value.
|
|
||||||
*/
|
|
||||||
private final String value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
* @param value The value.
|
|
||||||
*/
|
|
||||||
public StringTag(String name, String value) {
|
|
||||||
super(name);
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String name = getName();
|
|
||||||
String append = "";
|
|
||||||
if (name != null && !name.equals("")) {
|
|
||||||
append = "(\"" + this.getName() + "\")";
|
|
||||||
}
|
|
||||||
return "TAG_String" + append + ": " + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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 com.volmit.iris.util.oldnbt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a single NBT tag.
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*/
|
|
||||||
public abstract class Tag {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of this tag.
|
|
||||||
*/
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the tag with the specified name.
|
|
||||||
*
|
|
||||||
* @param name The name.
|
|
||||||
*/
|
|
||||||
public Tag(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the name of this tag.
|
|
||||||
*
|
|
||||||
* @return The name of this tag.
|
|
||||||
*/
|
|
||||||
public final String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of this tag.
|
|
||||||
*
|
|
||||||
* @return The value of this tag.
|
|
||||||
*/
|
|
||||||
public abstract Object getValue();
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user