mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 18:55:18 +00:00
Parallax
This commit is contained in:
parent
17df8f23c5
commit
1b2ce750ca
49
src/main/java/ninja/bytecode/iris/object/IrisObject.java
Normal file
49
src/main/java/ninja/bytecode/iris/object/IrisObject.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package ninja.bytecode.iris.object;
|
||||||
|
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
|
|
||||||
|
import ninja.bytecode.shuriken.collections.KMap;
|
||||||
|
import ninja.bytecode.shuriken.collections.KSet;
|
||||||
|
|
||||||
|
public class IrisObject
|
||||||
|
{
|
||||||
|
private String name;
|
||||||
|
private KMap<BlockVector, BlockData> blocks;
|
||||||
|
private KSet<BlockVector> mount;
|
||||||
|
private int w;
|
||||||
|
private int d;
|
||||||
|
private int h;
|
||||||
|
private transient BlockVector center;
|
||||||
|
|
||||||
|
public IrisObject(String name, int w, int h, int d)
|
||||||
|
{
|
||||||
|
blocks = new KMap<>();
|
||||||
|
mount = new KSet<>();
|
||||||
|
this.w = w;
|
||||||
|
this.h = h;
|
||||||
|
this.d = d;
|
||||||
|
this.name = name;
|
||||||
|
center = new BlockVector(w / 2, h / 2, d / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnsigned(int x, int y, int z, BlockData block)
|
||||||
|
{
|
||||||
|
if(x >= w || y >= h || z >= d)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(x + " " + y + " " + z + " exceeds limit of " + w + " " + h + " " + d);
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockVector v = new BlockVector(x, y, z).subtract(center).toBlockVector();
|
||||||
|
|
||||||
|
if(block == null)
|
||||||
|
{
|
||||||
|
blocks.remove(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
blocks.put(v, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
package ninja.bytecode.iris.object.atomics;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import ninja.bytecode.iris.util.ByteArrayTag;
|
||||||
|
import ninja.bytecode.iris.util.CompoundTag;
|
||||||
|
import ninja.bytecode.iris.util.NBTInputStream;
|
||||||
|
import ninja.bytecode.iris.util.NBTOutputStream;
|
||||||
|
import ninja.bytecode.iris.util.Tag;
|
||||||
|
import ninja.bytecode.shuriken.collections.KMap;
|
||||||
|
|
||||||
|
public class AtomicRegionData
|
||||||
|
{
|
||||||
|
private final World world;
|
||||||
|
private KMap<String, Tag> tag;
|
||||||
|
|
||||||
|
public AtomicRegionData(World world)
|
||||||
|
{
|
||||||
|
this.world = world;
|
||||||
|
tag = new KMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void read(InputStream in) throws IOException
|
||||||
|
{
|
||||||
|
NBTInputStream nin = new NBTInputStream(in);
|
||||||
|
tag = new KMap<>();
|
||||||
|
tag.putAll(((CompoundTag) nin.readTag()).getValue());
|
||||||
|
nin.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(OutputStream out) throws IOException
|
||||||
|
{
|
||||||
|
NBTOutputStream nos = new NBTOutputStream(out);
|
||||||
|
nos.writeTag(new CompoundTag("imca", tag));
|
||||||
|
nos.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(int rx, int rz)
|
||||||
|
{
|
||||||
|
return tag.containsKey(rx + "." + rz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(int rx, int rz)
|
||||||
|
{
|
||||||
|
tag.remove(rx + "." + rz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(int rx, int rz, AtomicSliverMap data) throws IOException
|
||||||
|
{
|
||||||
|
ByteArrayOutputStream boas = new ByteArrayOutputStream();
|
||||||
|
data.write(boas);
|
||||||
|
tag.put(rx + "." + rz, new ByteArrayTag(rx + "." + rz, boas.toByteArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomicSliverMap get(int rx, int rz) throws IOException
|
||||||
|
{
|
||||||
|
if(!contains(rx, rz))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
AtomicSliverMap data = new AtomicSliverMap();
|
||||||
|
ByteArrayTag btag = (ByteArrayTag) tag.get(rx + "." + rz);
|
||||||
|
ByteArrayInputStream in = new ByteArrayInputStream(btag.getValue());
|
||||||
|
data.read(in);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public World getWorld()
|
||||||
|
{
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,9 @@
|
|||||||
package ninja.bytecode.iris.object.atomics;
|
package ninja.bytecode.iris.object.atomics;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||||
@ -68,4 +72,41 @@ public class AtomicSliver
|
|||||||
{
|
{
|
||||||
height.setHeight(x, z, highestBlock);
|
height.setHeight(x, z, highestBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void read(DataInputStream din) throws IOException
|
||||||
|
{
|
||||||
|
this.block = new BlockData[256];
|
||||||
|
int h = din.readByte() - Byte.MIN_VALUE;
|
||||||
|
for(int i = 0; i <= h; i++)
|
||||||
|
{
|
||||||
|
block[i] = BlockDataTools.getBlockData(din.readUTF());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(DataOutputStream dos) throws IOException
|
||||||
|
{
|
||||||
|
dos.writeByte(highestBlock + Byte.MIN_VALUE);
|
||||||
|
|
||||||
|
for(int i = 0; i <= highestBlock; i++)
|
||||||
|
{
|
||||||
|
dos.writeUTF(block[i].getAsString(true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insert(AtomicSliver atomicSliver)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
if(block[i] == null || block[i].equals(AIR))
|
||||||
|
{
|
||||||
|
BlockData b = atomicSliver.block[i];
|
||||||
|
if(b == null || b.equals(AIR))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
block[i] = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
package ninja.bytecode.iris.object.atomics;
|
package ninja.bytecode.iris.object.atomics;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||||
|
|
||||||
@ -22,6 +28,34 @@ public class AtomicSliverMap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void insert(AtomicSliverMap map)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
slivers[i].insert(map.slivers[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(OutputStream out) throws IOException
|
||||||
|
{
|
||||||
|
DataOutputStream dos = new DataOutputStream(out);
|
||||||
|
for(int i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
slivers[i].write(dos);
|
||||||
|
}
|
||||||
|
|
||||||
|
dos.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void read(InputStream in) throws IOException
|
||||||
|
{
|
||||||
|
DataInputStream din = new DataInputStream(in);
|
||||||
|
for(int i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
slivers[i].read(din);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public AtomicSliver getSliver(int x, int z)
|
public AtomicSliver getSliver(int x, int z)
|
||||||
{
|
{
|
||||||
return slivers[x * 16 + z];
|
return slivers[x * 16 + z];
|
||||||
|
@ -0,0 +1,163 @@
|
|||||||
|
package ninja.bytecode.iris.object.atomics;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import ninja.bytecode.iris.util.ChunkPosition;
|
||||||
|
import ninja.bytecode.shuriken.collections.KList;
|
||||||
|
import ninja.bytecode.shuriken.collections.KMap;
|
||||||
|
|
||||||
|
public class AtomicWorldData
|
||||||
|
{
|
||||||
|
private World world;
|
||||||
|
private KMap<ChunkPosition, AtomicRegionData> loadedSections;
|
||||||
|
|
||||||
|
public AtomicWorldData(World world)
|
||||||
|
{
|
||||||
|
this.world = world;
|
||||||
|
loadedSections = new KMap<>();
|
||||||
|
getSubregionFolder().mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public KList<ChunkPosition> getLoadedRegions()
|
||||||
|
{
|
||||||
|
return loadedSections.k();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomicRegionData getSubregion(int x, int z) throws IOException
|
||||||
|
{
|
||||||
|
if(!isSectionLoaded(x, z))
|
||||||
|
{
|
||||||
|
loadedSections.put(new ChunkPosition(x, z), loadSection(x, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
AtomicRegionData f = loadedSections.get(new ChunkPosition(x, z));
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveAll() throws IOException
|
||||||
|
{
|
||||||
|
for(ChunkPosition i : loadedSections.keySet())
|
||||||
|
{
|
||||||
|
saveSection(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unloadAll(boolean save) throws IOException
|
||||||
|
{
|
||||||
|
for(ChunkPosition i : loadedSections.keySet())
|
||||||
|
{
|
||||||
|
unloadSection(i, save);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteSection(int x, int z) throws IOException
|
||||||
|
{
|
||||||
|
unloadSection(x, z, false);
|
||||||
|
getSubregionFile(x, z).delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSectionLoaded(int x, int z)
|
||||||
|
{
|
||||||
|
return isSectionLoaded(new ChunkPosition(x, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSectionLoaded(ChunkPosition s)
|
||||||
|
{
|
||||||
|
return loadedSections.containsKey(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean unloadSection(int x, int z, boolean save) throws IOException
|
||||||
|
{
|
||||||
|
return unloadSection(new ChunkPosition(x, z), save);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean unloadSection(ChunkPosition s, boolean save) throws IOException
|
||||||
|
{
|
||||||
|
if(!isSectionLoaded(s))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(save)
|
||||||
|
{
|
||||||
|
saveSection(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadedSections.remove(s);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean saveSection(int x, int z) throws IOException
|
||||||
|
{
|
||||||
|
return saveSection(new ChunkPosition(x, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean saveSection(ChunkPosition s) throws IOException
|
||||||
|
{
|
||||||
|
if(!isSectionLoaded(s.getX(), s.getZ()))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AtomicRegionData data = loadedSections.get(s);
|
||||||
|
FileOutputStream fos = new FileOutputStream(getSubregionFile(s.getX(), s.getZ()));
|
||||||
|
data.write(fos);
|
||||||
|
fos.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomicSliverMap loadChunk(int x, int z) throws IOException
|
||||||
|
{
|
||||||
|
return loadSection(x >> 5, z >> 5).get(x & 31, z & 31);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomicRegionData loadSection(int x, int z) throws IOException
|
||||||
|
{
|
||||||
|
if(isSectionLoaded(x, z))
|
||||||
|
{
|
||||||
|
return loadedSections.get(new ChunkPosition(x, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = getSubregionFile(x, z);
|
||||||
|
|
||||||
|
if(!file.exists())
|
||||||
|
{
|
||||||
|
return createSection(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileInputStream fin = new FileInputStream(file);
|
||||||
|
AtomicRegionData data = new AtomicRegionData(world);
|
||||||
|
data.read(fin);
|
||||||
|
fin.close();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomicRegionData createSection(int x, int z)
|
||||||
|
{
|
||||||
|
if(isSectionLoaded(x, z))
|
||||||
|
{
|
||||||
|
return loadedSections.get(new ChunkPosition(x, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
AtomicRegionData data = new AtomicRegionData(world);
|
||||||
|
loadedSections.put(new ChunkPosition(x, z), data);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getSubregionFile(int x, int z)
|
||||||
|
{
|
||||||
|
return new File(getSubregionFolder(), "sr." + x + "." + z + ".smca");
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getSubregionFolder()
|
||||||
|
{
|
||||||
|
return new File(world.getWorldFolder(), "subregion");
|
||||||
|
}
|
||||||
|
}
|
82
src/main/java/ninja/bytecode/iris/util/ByteArrayTag.java
Normal file
82
src/main/java/ninja/bytecode/iris/util/ByteArrayTag.java
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
74
src/main/java/ninja/bytecode/iris/util/ByteTag.java
Normal file
74
src/main/java/ninja/bytecode/iris/util/ByteTag.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
83
src/main/java/ninja/bytecode/iris/util/CompoundTag.java
Normal file
83
src/main/java/ninja/bytecode/iris/util/CompoundTag.java
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
import java.util.Collections;
|
||||||
|
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 = Collections.unmodifiableMap(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 + ": " + value.size() + " entries\r\n{\r\n");
|
||||||
|
for (Map.Entry<String, Tag> entry : value.entrySet()) {
|
||||||
|
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n");
|
||||||
|
}
|
||||||
|
bldr.append("}");
|
||||||
|
return bldr.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
74
src/main/java/ninja/bytecode/iris/util/DoubleTag.java
Normal file
74
src/main/java/ninja/bytecode/iris/util/DoubleTag.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
src/main/java/ninja/bytecode/iris/util/EndTag.java
Normal file
60
src/main/java/ninja/bytecode/iris/util/EndTag.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
74
src/main/java/ninja/bytecode/iris/util/FloatTag.java
Normal file
74
src/main/java/ninja/bytecode/iris/util/FloatTag.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -14,11 +14,11 @@ public class HeightMap
|
|||||||
|
|
||||||
public void setHeight(int x, int z, int h)
|
public void setHeight(int x, int z, int h)
|
||||||
{
|
{
|
||||||
height[(x & 15) * 16 + (z & 15)] = (byte) (h + Byte.MIN_VALUE);
|
height[x * 16 + z] = (byte) (h + Byte.MIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight(int x, int z)
|
public int getHeight(int x, int z)
|
||||||
{
|
{
|
||||||
return height[(x & 15) * 16 + (z & 15)] - Byte.MIN_VALUE;
|
return height[x * 16 + z] - Byte.MIN_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
76
src/main/java/ninja/bytecode/iris/util/IntArrayTag.java
Normal file
76
src/main/java/ninja/bytecode/iris/util/IntArrayTag.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Neil Wightman
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
74
src/main/java/ninja/bytecode/iris/util/IntTag.java
Normal file
74
src/main/java/ninja/bytecode/iris/util/IntTag.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
99
src/main/java/ninja/bytecode/iris/util/ListTag.java
Normal file
99
src/main/java/ninja/bytecode/iris/util/ListTag.java
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
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 + ": " + value.size() + " entries of type " + NBTUtils.getTypeName(type) + "\r\n{\r\n");
|
||||||
|
for (Tag t : value) {
|
||||||
|
bldr.append(" " + t.toString().replaceAll("\r\n", "\r\n ") + "\r\n");
|
||||||
|
}
|
||||||
|
bldr.append("}");
|
||||||
|
return bldr.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
74
src/main/java/ninja/bytecode/iris/util/LongTag.java
Normal file
74
src/main/java/ninja/bytecode/iris/util/LongTag.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
77
src/main/java/ninja/bytecode/iris/util/NBTConstants.java
Normal file
77
src/main/java/ninja/bytecode/iris/util/NBTConstants.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Neil Wightman
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 = Charset.forName("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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
205
src/main/java/ninja/bytecode/iris/util/NBTInputStream.java
Normal file
205
src/main/java/ninja/bytecode/iris/util/NBTInputStream.java
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Neil Wightman
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<Tag>();
|
||||||
|
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<String, Tag>();
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
301
src/main/java/ninja/bytecode/iris/util/NBTOutputStream.java
Normal file
301
src/main/java/ninja/bytecode/iris/util/NBTOutputStream.java
Normal file
@ -0,0 +1,301 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Neil Wightman
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_BYTE:
|
||||||
|
writeByteTagPayload((ByteTag) tag);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_SHORT:
|
||||||
|
writeShortTagPayload((ShortTag) tag);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_INT:
|
||||||
|
writeIntTagPayload((IntTag) tag);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_LONG:
|
||||||
|
writeLongTagPayload((LongTag) tag);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_FLOAT:
|
||||||
|
writeFloatTagPayload((FloatTag) tag);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_DOUBLE:
|
||||||
|
writeDoubleTagPayload((DoubleTag) tag);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_BYTE_ARRAY:
|
||||||
|
writeByteArrayTagPayload((ByteArrayTag) tag);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_STRING:
|
||||||
|
writeStringTagPayload((StringTag) tag);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_LIST:
|
||||||
|
writeListTagPayload((ListTag) tag);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_COMPOUND:
|
||||||
|
writeCompoundTagPayload((CompoundTag) tag);
|
||||||
|
break;
|
||||||
|
case NBTConstants.TYPE_INT_ARRAY:
|
||||||
|
writeIntArrayTagPayload((IntArrayTag) tag);
|
||||||
|
break;
|
||||||
|
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 (int i = 0; i < size; i++) {
|
||||||
|
writeTagPayload(tags.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
165
src/main/java/ninja/bytecode/iris/util/NBTUtils.java
Normal file
165
src/main/java/ninja/bytecode/iris/util/NBTUtils.java
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Neil Wightman
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
switch (type) {
|
||||||
|
case NBTConstants.TYPE_END:
|
||||||
|
return EndTag.class;
|
||||||
|
case NBTConstants.TYPE_BYTE:
|
||||||
|
return ByteTag.class;
|
||||||
|
case NBTConstants.TYPE_SHORT:
|
||||||
|
return ShortTag.class;
|
||||||
|
case NBTConstants.TYPE_INT:
|
||||||
|
return IntTag.class;
|
||||||
|
case NBTConstants.TYPE_LONG:
|
||||||
|
return LongTag.class;
|
||||||
|
case NBTConstants.TYPE_FLOAT:
|
||||||
|
return FloatTag.class;
|
||||||
|
case NBTConstants.TYPE_DOUBLE:
|
||||||
|
return DoubleTag.class;
|
||||||
|
case NBTConstants.TYPE_BYTE_ARRAY:
|
||||||
|
return ByteArrayTag.class;
|
||||||
|
case NBTConstants.TYPE_STRING:
|
||||||
|
return StringTag.class;
|
||||||
|
case NBTConstants.TYPE_LIST:
|
||||||
|
return ListTag.class;
|
||||||
|
case NBTConstants.TYPE_COMPOUND:
|
||||||
|
return CompoundTag.class;
|
||||||
|
case NBTConstants.TYPE_INT_ARRAY:
|
||||||
|
return IntArrayTag.class;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid tag type : " + type + ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default private constructor.
|
||||||
|
*/
|
||||||
|
private NBTUtils() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
74
src/main/java/ninja/bytecode/iris/util/ShortTag.java
Normal file
74
src/main/java/ninja/bytecode/iris/util/ShortTag.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
74
src/main/java/ninja/bytecode/iris/util/StringTag.java
Normal file
74
src/main/java/ninja/bytecode/iris/util/StringTag.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
src/main/java/ninja/bytecode/iris/util/Tag.java
Normal file
73
src/main/java/ninja/bytecode/iris/util/Tag.java
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package ninja.bytecode.iris.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JNBT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010 Graham Edgecombe
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the JNBT team nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 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