mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +00:00
Hunk Slices!
This commit is contained in:
parent
39b4649a04
commit
aff7e49024
@ -117,23 +117,53 @@ public class Iris extends MortarPlugin
|
|||||||
|
|
||||||
private static boolean doesSupport3DBiomes()
|
private static boolean doesSupport3DBiomes()
|
||||||
{
|
{
|
||||||
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
|
try
|
||||||
|
{
|
||||||
|
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
|
||||||
|
|
||||||
return v >= 15;
|
return v >= 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean doesSupportCustomModels()
|
private static boolean doesSupportCustomModels()
|
||||||
{
|
{
|
||||||
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
|
try
|
||||||
|
{
|
||||||
|
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
|
||||||
|
|
||||||
return v >= 14;
|
return v >= 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean doesSupportAwareness()
|
private static boolean doesSupportAwareness()
|
||||||
{
|
{
|
||||||
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
|
try
|
||||||
|
{
|
||||||
|
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
|
||||||
|
|
||||||
return v >= 15;
|
return v >= 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -281,17 +311,22 @@ public class Iris extends MortarPlugin
|
|||||||
|
|
||||||
public static void msg(String string)
|
public static void msg(String string)
|
||||||
{
|
{
|
||||||
lock.lock();
|
try
|
||||||
if(instance == null)
|
|
||||||
{
|
{
|
||||||
System.out.println("[Iris]: " + string);
|
if(instance == null)
|
||||||
lock.unlock();
|
{
|
||||||
return;
|
System.out.println("[Iris]: " + string);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String msg = C.GRAY + "[" + C.GREEN + "Iris" + C.GRAY + "]: " + string;
|
||||||
|
Bukkit.getConsoleSender().sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
String msg = C.GRAY + "[" + C.GREEN + "Iris" + C.GRAY + "]: " + string;
|
catch(Throwable e)
|
||||||
Bukkit.getConsoleSender().sendMessage(msg);
|
{
|
||||||
lock.unlock();
|
System.out.println("[Iris]: " + string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getCached(String name, String url)
|
public static File getCached(String name, String url)
|
||||||
@ -389,7 +424,20 @@ public class Iris extends MortarPlugin
|
|||||||
|
|
||||||
public static void verbose(String string)
|
public static void verbose(String string)
|
||||||
{
|
{
|
||||||
if(IrisSettings.get().verbose)
|
if(true)
|
||||||
|
{
|
||||||
|
System.out.println(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(IrisSettings.get().verbose)
|
||||||
|
{
|
||||||
|
msg(C.GRAY + string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
{
|
{
|
||||||
msg(C.GRAY + string);
|
msg(C.GRAY + string);
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,58 @@
|
|||||||
package com.volmit.iris.gen.v2.scaffold.hunk.io;
|
package com.volmit.iris.gen.v2.scaffold.hunk.io;
|
||||||
|
|
||||||
import com.volmit.iris.util.CompoundTag;
|
import java.io.File;
|
||||||
import lombok.Getter;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
import java.io.File;
|
import com.volmit.iris.util.CompoundTag;
|
||||||
|
|
||||||
public class HunkCompoundRegion extends HunkRegion {
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
public class HunkCompoundRegion extends HunkRegion
|
||||||
private HunkRegionSlice<BlockData> parallaxSlice;
|
{
|
||||||
@Getter
|
@Getter
|
||||||
private HunkRegionSlice<String> objectSlice;
|
private HunkRegionSlice<BlockData> blockSlice;
|
||||||
@Getter
|
@Getter
|
||||||
private HunkRegionSlice<Boolean> updateSlice;
|
private HunkRegionSlice<String> objectSlice;
|
||||||
|
@Getter
|
||||||
|
private HunkRegionSlice<Boolean> updateSlice;
|
||||||
|
|
||||||
private final int height;
|
private final int height;
|
||||||
|
|
||||||
public HunkCompoundRegion(int height, File folder, int x, int z, CompoundTag compound) {
|
public HunkCompoundRegion(int height, File folder, int x, int z, CompoundTag compound)
|
||||||
super(folder, x, z, compound);
|
{
|
||||||
this.height = height;
|
super(folder, x, z, compound);
|
||||||
setupSlices();
|
this.height = height;
|
||||||
}
|
setupSlices();
|
||||||
|
}
|
||||||
|
|
||||||
public HunkCompoundRegion(int height, File folder, int x, int z) {
|
public HunkCompoundRegion(int height, File folder, int x, int z)
|
||||||
super(folder, x, z);
|
{
|
||||||
this.height = height;
|
super(folder, x, z);
|
||||||
setupSlices();
|
this.height = height;
|
||||||
}
|
setupSlices();
|
||||||
|
}
|
||||||
|
|
||||||
private void setupSlices() {
|
private void setupSlices()
|
||||||
parallaxSlice = HunkRegionSlice.BLOCKDATA.apply(height, getCompound());
|
{
|
||||||
objectSlice = HunkRegionSlice.STRING.apply(height, getCompound(), "objects");
|
blockSlice = HunkRegionSlice.BLOCKDATA.apply(height, getCompound());
|
||||||
updateSlice = HunkRegionSlice.BOOLEAN.apply(height, getCompound(), "updates");
|
objectSlice = HunkRegionSlice.STRING.apply(height, getCompound(), "objects");
|
||||||
}
|
updateSlice = HunkRegionSlice.BOOLEAN.apply(height, getCompound(), "updates");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() throws IOException
|
||||||
|
{
|
||||||
|
blockSlice.save();
|
||||||
|
objectSlice.save();
|
||||||
|
updateSlice.save();
|
||||||
|
super.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unload()
|
||||||
|
{
|
||||||
|
blockSlice.unloadAll();
|
||||||
|
objectSlice.unloadAll();
|
||||||
|
updateSlice.unloadAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,67 +1,85 @@
|
|||||||
package com.volmit.iris.gen.v2.scaffold.hunk.io;
|
package com.volmit.iris.gen.v2.scaffold.hunk.io;
|
||||||
|
|
||||||
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
|
|
||||||
import com.volmit.iris.util.CompoundTag;
|
|
||||||
import com.volmit.iris.util.KMap;
|
|
||||||
import com.volmit.iris.util.NBTInputStream;
|
|
||||||
import com.volmit.iris.util.NBTOutputStream;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.util.CompoundTag;
|
||||||
|
import com.volmit.iris.util.KMap;
|
||||||
|
import com.volmit.iris.util.NBTInputStream;
|
||||||
|
import com.volmit.iris.util.NBTOutputStream;
|
||||||
|
import com.volmit.iris.util.Tag;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class HunkRegion
|
public class HunkRegion
|
||||||
{
|
{
|
||||||
private final File folder;
|
private final File folder;
|
||||||
private CompoundTag compound;
|
private CompoundTag compound;
|
||||||
private final int x;
|
private final int x;
|
||||||
private final int z;
|
private final int z;
|
||||||
|
|
||||||
public HunkRegion(File folder, int x, int z, CompoundTag compound) {
|
public HunkRegion(File folder, int x, int z, CompoundTag compound)
|
||||||
this.compound = compound;
|
{
|
||||||
this.folder = folder;
|
this.compound = fix(compound);
|
||||||
this.x = x;
|
this.folder = folder;
|
||||||
this.z = z;
|
this.x = x;
|
||||||
folder.mkdirs();
|
this.z = z;
|
||||||
}
|
folder.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
public HunkRegion(File folder, int x, int z) {
|
public HunkRegion(File folder, int x, int z)
|
||||||
this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>()));
|
{
|
||||||
File f = getFile();
|
this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>()));
|
||||||
|
File f = getFile();
|
||||||
|
|
||||||
if(f.exists())
|
if(f.exists())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NBTInputStream in = new NBTInputStream(new FileInputStream(f));
|
NBTInputStream in = new NBTInputStream(new FileInputStream(f));
|
||||||
compound = (CompoundTag) in.readTag();
|
compound = fix((CompoundTag) in.readTag());
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(Throwable e)
|
catch(Throwable e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile()
|
private CompoundTag fix(CompoundTag readTag)
|
||||||
{
|
{
|
||||||
return new File(folder, x + "." + z + ".dat");
|
Map<String, Tag> v = readTag.getValue();
|
||||||
}
|
|
||||||
|
|
||||||
public void save() throws IOException
|
if(!(v instanceof KMap))
|
||||||
{
|
{
|
||||||
synchronized (compound)
|
return new CompoundTag(readTag.getName(), new KMap<String, Tag>(v));
|
||||||
{
|
}
|
||||||
File f = getFile();
|
|
||||||
FileOutputStream fos = new FileOutputStream(f);
|
return readTag;
|
||||||
NBTOutputStream out = new NBTOutputStream(fos);
|
}
|
||||||
out.writeTag(compound);
|
|
||||||
out.close();
|
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();
|
||||||
|
Iris.verbose("Saved Region: " + getX() + " " + getZ());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,190 +1,215 @@
|
|||||||
package com.volmit.iris.gen.v2.scaffold.hunk.io;
|
package com.volmit.iris.gen.v2.scaffold.hunk.io;
|
||||||
|
|
||||||
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
|
import java.io.IOException;
|
||||||
import com.volmit.iris.manager.IrisDataManager;
|
|
||||||
import com.volmit.iris.object.IrisBiome;
|
|
||||||
import com.volmit.iris.object.IrisObject;
|
|
||||||
import com.volmit.iris.util.*;
|
|
||||||
import org.bukkit.block.Biome;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.volmit.iris.Iris;
|
||||||
import java.util.function.Function;
|
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
|
||||||
|
import com.volmit.iris.util.ByteArrayTag;
|
||||||
|
import com.volmit.iris.util.CompoundTag;
|
||||||
|
import com.volmit.iris.util.Function2;
|
||||||
|
import com.volmit.iris.util.Function3;
|
||||||
|
import com.volmit.iris.util.KList;
|
||||||
|
import com.volmit.iris.util.KMap;
|
||||||
|
import com.volmit.iris.util.Tag;
|
||||||
|
|
||||||
public class HunkRegionSlice<T> {
|
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 Function3<Integer, CompoundTag, String,HunkRegionSlice<String>> STRING = (h,c,t) -> new HunkRegionSlice<>(h,Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t);
|
public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BlockDataHunkIOAdapter(), c, "blockdata");
|
||||||
public static final Function3<Integer, CompoundTag, String,HunkRegionSlice<Boolean>> BOOLEAN = (h,c,t) -> new HunkRegionSlice<>(h,Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t);
|
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t);
|
||||||
private final Function3<Integer,Integer,Integer, Hunk<T>> factory;
|
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t);
|
||||||
private final HunkIOAdapter<T> adapter;
|
private final Function3<Integer, Integer, Integer, Hunk<T>> factory;
|
||||||
private final CompoundTag compound;
|
private final HunkIOAdapter<T> adapter;
|
||||||
private final String key;
|
private final CompoundTag compound;
|
||||||
private final KMap<Short, Hunk<T>> loadedChunks;
|
private final String key;
|
||||||
private final KList<Short> save;
|
private final KMap<Short, Hunk<T>> loadedChunks;
|
||||||
private final int height;
|
private final KList<Short> save;
|
||||||
|
private final int height;
|
||||||
|
|
||||||
public HunkRegionSlice(int height, Function3<Integer,Integer,Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key)
|
public HunkRegionSlice(int height, Function3<Integer, Integer, Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key)
|
||||||
{
|
{
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.loadedChunks = new KMap<>();
|
this.loadedChunks = new KMap<>();
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
this.adapter = adapter;
|
this.adapter = adapter;
|
||||||
this.compound = compound;
|
this.compound = compound;
|
||||||
this.save = new KList<>();
|
this.save = new KList<>();
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear()
|
public void clear()
|
||||||
{
|
{
|
||||||
for(String i : new KList<>(compound.getValue().keySet()))
|
synchronized(save)
|
||||||
{
|
{
|
||||||
if(i.startsWith(key + "."))
|
for(String i : new KList<>(compound.getValue().keySet()))
|
||||||
{
|
{
|
||||||
compound.getValue().remove(i);
|
if(i.startsWith(key + "."))
|
||||||
}
|
{
|
||||||
}
|
compound.getValue().remove(i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean contains(int x, int z)
|
public void save()
|
||||||
{
|
{
|
||||||
return compound.getValue().containsKey(key(x, z));
|
for(short i : save)
|
||||||
}
|
{
|
||||||
|
save((byte) (i & 0xFF), (byte) ((i >> 8) & 0xFF));
|
||||||
|
}
|
||||||
|
|
||||||
public void delete(int x, int z)
|
save.clear();
|
||||||
{
|
}
|
||||||
compound.getValue().remove(key(x,z));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hunk<T> read(int x, int z) throws IOException
|
public boolean contains(int x, int z)
|
||||||
{
|
{
|
||||||
Tag t = compound.getValue().get(key(x,z));
|
return compound.getValue().containsKey(key(x, z));
|
||||||
|
}
|
||||||
|
|
||||||
if(!(t instanceof ByteArrayTag))
|
public void delete(int x, int z)
|
||||||
{
|
{
|
||||||
return null;
|
compound.getValue().remove(key(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
return adapter.read(factory, (ByteArrayTag) t);
|
public Hunk<T> read(int x, int z) throws IOException
|
||||||
}
|
{
|
||||||
|
Tag t = compound.getValue().get(key(x, z));
|
||||||
|
|
||||||
public void write(Hunk<T> hunk, int x, int z) throws IOException
|
if(!(t instanceof ByteArrayTag))
|
||||||
{
|
{
|
||||||
compound.getValue().put(key(x,z), hunk.writeByteArrayTag(adapter, key));
|
Iris.verbose("NOT BYTE ARRAY!");
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void close()
|
return adapter.read(factory, (ByteArrayTag) t);
|
||||||
{
|
}
|
||||||
for(Short i : loadedChunks.k())
|
|
||||||
{
|
|
||||||
unload((byte) (i & 0xFF), (byte) ((i >> 8) & 0xFF));
|
|
||||||
}
|
|
||||||
|
|
||||||
save.clear();
|
public void write(Hunk<T> hunk, int x, int z) throws IOException
|
||||||
loadedChunks.clear();
|
{
|
||||||
}
|
compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void save(Hunk<T> region, int x, int z)
|
public synchronized void unloadAll()
|
||||||
{
|
{
|
||||||
try {
|
for(Short i : loadedChunks.k())
|
||||||
write(region, x, z);
|
{
|
||||||
} catch (IOException e) {
|
unload((byte) (i & 0xFF), (byte) ((i >> 8) & 0xFF));
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLoaded(int x, int z)
|
save.clear();
|
||||||
{
|
loadedChunks.clear();
|
||||||
return loadedChunks.containsKey(ikey(x,z));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void save(int x, int z)
|
public synchronized void save(Hunk<T> region, int x, int z)
|
||||||
{
|
{
|
||||||
if(isLoaded(x,z))
|
try
|
||||||
{
|
{
|
||||||
save(get(x,z), x, z);
|
write(region, x, z);
|
||||||
}
|
}
|
||||||
}
|
catch(IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void unload(int x, int z)
|
public boolean isLoaded(int x, int z)
|
||||||
{
|
{
|
||||||
short key = ikey(x,z);
|
return loadedChunks.containsKey(ikey(x, z));
|
||||||
|
}
|
||||||
|
|
||||||
if(isLoaded(x, z))
|
public synchronized void save(int x, int z)
|
||||||
{
|
{
|
||||||
if(save.contains(key))
|
if(isLoaded(x, z))
|
||||||
{
|
{
|
||||||
save(x,z);
|
save(get(x, z), x, z);
|
||||||
save.remove(key);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedChunks.remove(key);
|
public synchronized void unload(int x, int z)
|
||||||
}
|
{
|
||||||
}
|
short key = ikey(x, z);
|
||||||
|
|
||||||
public synchronized Hunk<T> load(int x, int z)
|
if(isLoaded(x, z))
|
||||||
{
|
{
|
||||||
if(isLoaded(x,z))
|
if(save.contains(key))
|
||||||
{
|
{
|
||||||
return loadedChunks.get(ikey(x,z));
|
save(x, z);
|
||||||
}
|
save.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
Hunk<T> v = null;
|
loadedChunks.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(contains(x ,z))
|
public synchronized Hunk<T> load(int x, int z)
|
||||||
{
|
{
|
||||||
try {
|
if(isLoaded(x, z))
|
||||||
v = read(x,z);
|
{
|
||||||
} catch (IOException e) {
|
return loadedChunks.get(ikey(x, z));
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(v == null)
|
Hunk<T> v = null;
|
||||||
{
|
|
||||||
v = factory.apply(16, height, 16);
|
|
||||||
}
|
|
||||||
loadedChunks.put(ikey(x,z), v);
|
|
||||||
|
|
||||||
return v;
|
if(contains(x, z))
|
||||||
}
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
v = read(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
public Hunk<T> get(int x, int z)
|
catch(IOException e)
|
||||||
{
|
{
|
||||||
short key = ikey(x,z);
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Hunk<T> c = loadedChunks.get(key);
|
if(v == null)
|
||||||
|
{
|
||||||
|
v = factory.apply(16, height, 16);
|
||||||
|
}
|
||||||
|
loadedChunks.put(ikey(x, z), v);
|
||||||
|
|
||||||
if(c == null)
|
return v;
|
||||||
{
|
}
|
||||||
c = load(x, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
return c;
|
public Hunk<T> get(int x, int z)
|
||||||
}
|
{
|
||||||
|
short key = ikey(x, z);
|
||||||
|
|
||||||
public Hunk<T> getR(int x, int z)
|
Hunk<T> c = loadedChunks.get(key);
|
||||||
{
|
|
||||||
return get(x,z).readOnly();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hunk<T> getRW(int x, int z)
|
if(c == null)
|
||||||
{
|
{
|
||||||
save.addIfMissing(ikey(x,z));
|
c = load(x, z);
|
||||||
return get(x,z);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private short ikey(int x, int z)
|
return c;
|
||||||
{
|
}
|
||||||
return ((short)(((x & 0xFF) << 8) | (z & 0xFF)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String key(int x, int z)
|
public Hunk<T> getR(int x, int z)
|
||||||
{
|
{
|
||||||
if(x < 0 || x >=32 || z < 0 || z >= 32)
|
return get(x, z).readOnly();
|
||||||
{
|
}
|
||||||
throw new IndexOutOfBoundsException("The chunk " + x + " " + z + " is out of bounds max is 31x31");
|
|
||||||
}
|
|
||||||
|
|
||||||
return key + "." + Integer.toString(((short)(((x & 0xFF) << 8) | (z & 0xFF))), 36);
|
public Hunk<T> getRW(int x, int z)
|
||||||
}
|
{
|
||||||
|
save.addIfMissing(ikey(x, z));
|
||||||
|
return get(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
private short ikey(int x, int z)
|
||||||
|
{
|
||||||
|
return ((short) (((x & 0xFF) << 8) | (z & 0xFF)));
|
||||||
|
}
|
||||||
|
|
||||||
|
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 + "." + Integer.toString(((short) (((x & 0xFF) << 8) | (z & 0xFF))), 36);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,142 +1,154 @@
|
|||||||
package com.volmit.iris.gen.v2.scaffold.parallax;
|
package com.volmit.iris.gen.v2.scaffold.parallax;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
|
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
|
||||||
import com.volmit.iris.gen.v2.scaffold.hunk.io.HunkCompoundRegion;
|
import com.volmit.iris.gen.v2.scaffold.hunk.io.HunkCompoundRegion;
|
||||||
import com.volmit.iris.util.KList;
|
import com.volmit.iris.util.KList;
|
||||||
import com.volmit.iris.util.KMap;
|
import com.volmit.iris.util.KMap;
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
|
|
||||||
import java.io.File;
|
public class ParallaxWorld implements ParallaxAccess
|
||||||
import java.io.IOException;
|
{
|
||||||
|
private final KMap<Long, HunkCompoundRegion> loadedRegions;
|
||||||
|
private final KList<Long> save;
|
||||||
|
private final File folder;
|
||||||
|
private final int height;
|
||||||
|
|
||||||
public class ParallaxWorld implements ParallaxAccess {
|
public ParallaxWorld(int height, File folder)
|
||||||
private final KMap<Long, HunkCompoundRegion> loadedRegions;
|
{
|
||||||
private final KList<Long> save;
|
this.height = height;
|
||||||
private final File folder;
|
this.folder = folder;
|
||||||
private final int height;
|
save = new KList<>();
|
||||||
|
loadedRegions = new KMap<>();
|
||||||
|
folder.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
public ParallaxWorld(int height, File folder)
|
public synchronized void close()
|
||||||
{
|
{
|
||||||
this.height = height;
|
for(HunkCompoundRegion i : loadedRegions.v())
|
||||||
this.folder = folder;
|
{
|
||||||
save = new KList<>();
|
unload(i.getX(), i.getZ());
|
||||||
loadedRegions = new KMap<>();
|
}
|
||||||
folder.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void close()
|
save.clear();
|
||||||
{
|
loadedRegions.clear();
|
||||||
for(HunkCompoundRegion i : loadedRegions.v())
|
}
|
||||||
{
|
|
||||||
unload(i.getX(), i.getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
save.clear();
|
public synchronized void save(HunkCompoundRegion region)
|
||||||
loadedRegions.clear();
|
{
|
||||||
}
|
try
|
||||||
|
{
|
||||||
|
region.save();
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void save(HunkCompoundRegion region)
|
catch(IOException e)
|
||||||
{
|
{
|
||||||
try {
|
e.printStackTrace();
|
||||||
region.save();
|
}
|
||||||
} catch (IOException e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLoaded(int x, int z)
|
public boolean isLoaded(int x, int z)
|
||||||
{
|
{
|
||||||
return loadedRegions.containsKey(key(x,z));
|
return loadedRegions.containsKey(key(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void save(int x, int z)
|
public synchronized void save(int x, int z)
|
||||||
{
|
{
|
||||||
if(isLoaded(x,z))
|
if(isLoaded(x, z))
|
||||||
{
|
{
|
||||||
save(getR(x,z));
|
save(getR(x, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void unload(int x, int z)
|
public synchronized void unload(int x, int z)
|
||||||
{
|
{
|
||||||
long key = key(x,z);
|
long key = key(x, z);
|
||||||
|
|
||||||
if(isLoaded(x, z))
|
if(isLoaded(x, z))
|
||||||
{
|
{
|
||||||
if(save.contains(key))
|
if(save.contains(key))
|
||||||
{
|
{
|
||||||
save(x,z);
|
save(x, z);
|
||||||
save.remove(key);
|
save.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedRegions.remove(key);
|
loadedRegions.remove(key).unload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized HunkCompoundRegion load(int x, int z)
|
public synchronized HunkCompoundRegion load(int x, int z)
|
||||||
{
|
{
|
||||||
if(isLoaded(x,z))
|
if(isLoaded(x, z))
|
||||||
{
|
{
|
||||||
return loadedRegions.get(key(x,z));
|
return loadedRegions.get(key(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
HunkCompoundRegion v = new HunkCompoundRegion(height, folder, x, z);
|
HunkCompoundRegion v = new HunkCompoundRegion(height, folder, x, z);
|
||||||
loadedRegions.put(key(x,z), v);
|
loadedRegions.put(key(x, z), v);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HunkCompoundRegion getR(int x, int z)
|
public HunkCompoundRegion getR(int x, int z)
|
||||||
{
|
{
|
||||||
long key = key(x,z);
|
long key = key(x, z);
|
||||||
|
|
||||||
HunkCompoundRegion region = loadedRegions.get(key);
|
HunkCompoundRegion region = loadedRegions.get(key);
|
||||||
|
|
||||||
if(region == null)
|
if(region == null)
|
||||||
{
|
{
|
||||||
region = load(x, z);
|
region = load(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HunkCompoundRegion getRW(int x, int z)
|
public HunkCompoundRegion getRW(int x, int z)
|
||||||
{
|
{
|
||||||
save.addIfMissing(key(x,z));
|
save.addIfMissing(key(x, z));
|
||||||
return getR(x,z);
|
return getR(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long key(int x, int z)
|
private long key(int x, int z)
|
||||||
{
|
{
|
||||||
return (((long)x) << 32) | (((long)z) & 0xffffffffL);
|
return (((long) x) << 32) | (((long) z) & 0xffffffffL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Hunk<BlockData> getBlocksR(int x, int z) {
|
public Hunk<BlockData> getBlocksR(int x, int z)
|
||||||
return getR(x>>5, z>>5).getParallaxSlice().getR(x & 31,z & 31);
|
{
|
||||||
}
|
return getR(x >> 5, z >> 5).getBlockSlice().getR(x & 31, z & 31);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Hunk<BlockData> getBlocksRW(int x, int z) {
|
public synchronized Hunk<BlockData> getBlocksRW(int x, int z)
|
||||||
return getRW(x>>5, z>>5).getParallaxSlice().getRW(x & 31,z & 31);
|
{
|
||||||
}
|
return getRW(x >> 5, z >> 5).getBlockSlice().getRW(x & 31, z & 31);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Hunk<String> getObjectsR(int x, int z) {
|
public Hunk<String> getObjectsR(int x, int z)
|
||||||
return getR(x>>5, z>>5).getObjectSlice().getR(x & 31,z & 31);
|
{
|
||||||
}
|
return getR(x >> 5, z >> 5).getObjectSlice().getR(x & 31, z & 31);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Hunk<String> getObjectsRW(int x, int z) {
|
public synchronized Hunk<String> getObjectsRW(int x, int z)
|
||||||
return getRW(x>>5, z>>5).getObjectSlice().getRW(x & 31,z & 31);
|
{
|
||||||
}
|
return getRW(x >> 5, z >> 5).getObjectSlice().getRW(x & 31, z & 31);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Hunk<Boolean> getUpdatesR(int x, int z) {
|
public Hunk<Boolean> getUpdatesR(int x, int z)
|
||||||
return getR(x>>5, z>>5).getUpdateSlice().getR(x & 31,z & 31);
|
{
|
||||||
}
|
return getR(x >> 5, z >> 5).getUpdateSlice().getR(x & 31, z & 31);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Hunk<Boolean> getUpdatesRW(int x, int z) {
|
public synchronized Hunk<Boolean> getUpdatesRW(int x, int z)
|
||||||
return getRW(x>>5, z>>5).getUpdateSlice().getRW(x & 31,z & 31);
|
{
|
||||||
}
|
return getRW(x >> 5, z >> 5).getUpdateSlice().getRW(x & 31, z & 31);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,5 @@
|
|||||||
package com.volmit.iris.util;
|
package com.volmit.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;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,43 +8,51 @@ import java.util.Map;
|
|||||||
* @author Graham Edgecombe
|
* @author Graham Edgecombe
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class CompoundTag extends Tag {
|
public final class CompoundTag extends Tag
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The value.
|
* The value.
|
||||||
*/
|
*/
|
||||||
private final Map<String, Tag> value;
|
private final Map<String, Tag> value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the tag.
|
* Creates the tag.
|
||||||
*
|
*
|
||||||
* @param name The name.
|
* @param name
|
||||||
* @param value The value.
|
* The name.
|
||||||
*/
|
* @param value
|
||||||
public CompoundTag(String name, Map<String, Tag> value) {
|
* The value.
|
||||||
super(name);
|
*/
|
||||||
this.value = Collections.unmodifiableMap(value);
|
public CompoundTag(String name, Map<String, Tag> value)
|
||||||
}
|
{
|
||||||
|
super(name);
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Tag> getValue() {
|
public Map<String, Tag> getValue()
|
||||||
return value;
|
{
|
||||||
}
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString()
|
||||||
String name = getName();
|
{
|
||||||
String append = "";
|
String name = getName();
|
||||||
if (name != null && !name.equals("")) {
|
String append = "";
|
||||||
append = "(\"" + this.getName() + "\")";
|
if(name != null && !name.equals(""))
|
||||||
}
|
{
|
||||||
StringBuilder bldr = new StringBuilder();
|
append = "(\"" + this.getName() + "\")";
|
||||||
bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n");
|
}
|
||||||
for (Map.Entry<String, Tag> entry : value.entrySet()) {
|
StringBuilder bldr = new StringBuilder();
|
||||||
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n");
|
bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n");
|
||||||
}
|
for(Map.Entry<String, Tag> entry : value.entrySet())
|
||||||
bldr.append("}");
|
{
|
||||||
return bldr.toString();
|
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n");
|
||||||
}
|
}
|
||||||
|
bldr.append("}");
|
||||||
|
return bldr.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public class KMap<K, V> extends ConcurrentHashMap<K, V>
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KMap(KMap<K, V> gMap)
|
public KMap(Map<K, V> gMap)
|
||||||
{
|
{
|
||||||
this();
|
this();
|
||||||
put(gMap);
|
put(gMap);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user