mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-21 15:57:38 +00:00
Loads o fix
This commit is contained in:
1 parent
8a2b69464f
commit
5ab2bae5d7
34 files changed
+7
-100
No files matched your search
File renamed without changes.
@@ -1,4 +1,4 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.util.inventory;
|
||||
|
||||
/**
|
||||
* Callback for async workers
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.util.inventory;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.volmit.iris.util.KList;
|
||||
|
||||
public interface Element
|
||||
{
|
||||
public BlockData getMaterial();
|
||||
public MaterialBlock getMaterial();
|
||||
|
||||
public Element setMaterial(BlockData b);
|
||||
public Element setMaterial(MaterialBlock b);
|
||||
|
||||
public boolean isEnchanted();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.volmit.iris.util;
|
||||
package com.volmit.iris.util.inventory;
|
||||
|
||||
/**
|
||||
* Element Event.
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,157 @@
|
||||
package com.volmit.iris.gen.parallax;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.gen.atomics.AtomicSliver;
|
||||
import com.volmit.iris.util.Writable;
|
||||
|
||||
public class ParallaxChunk implements Writable
|
||||
{
|
||||
private static final ParallaxSection EMPTY = new ParallaxSection();
|
||||
private final ParallaxSection[] sections;
|
||||
private boolean parallaxGenerated;
|
||||
private boolean worldGenerated;
|
||||
|
||||
public ParallaxChunk(DataInputStream in) throws IOException
|
||||
{
|
||||
this();
|
||||
read(in);
|
||||
}
|
||||
|
||||
public ParallaxChunk()
|
||||
{
|
||||
parallaxGenerated = false;
|
||||
worldGenerated = false;
|
||||
sections = new ParallaxSection[16];
|
||||
}
|
||||
|
||||
public boolean isParallaxGenerated()
|
||||
{
|
||||
return parallaxGenerated;
|
||||
}
|
||||
|
||||
public void setParallaxGenerated(boolean parallaxGenerated)
|
||||
{
|
||||
this.parallaxGenerated = parallaxGenerated;
|
||||
}
|
||||
|
||||
public boolean isWorldGenerated()
|
||||
{
|
||||
return worldGenerated;
|
||||
}
|
||||
|
||||
public void setWorldGenerated(boolean worldGenerated)
|
||||
{
|
||||
this.worldGenerated = worldGenerated;
|
||||
}
|
||||
|
||||
public void export(ChunkData d)
|
||||
{
|
||||
for(ParallaxSection i : sections)
|
||||
{
|
||||
if(i != null)
|
||||
{
|
||||
for(int x = 0; x < 16; x++)
|
||||
{
|
||||
for(int y = 0; y < 16; y++)
|
||||
{
|
||||
for(int z = 0; z < 16; z++)
|
||||
{
|
||||
BlockData b = get(x, y, z);
|
||||
|
||||
if(b == null || b.getMaterial().equals(Material.AIR))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
d.setBlock(x, y, z, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void injectUpdates(AtomicSliver sliver, int x, int z)
|
||||
{
|
||||
for(Integer i : sliver.getUpdatables())
|
||||
{
|
||||
if(i > 255 || i < 0)
|
||||
{
|
||||
Iris.warn("Block Update out of bounds: " + i);
|
||||
}
|
||||
|
||||
getSection(i >> 4, true).update(x, i, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream o) throws IOException
|
||||
{
|
||||
o.writeBoolean(isParallaxGenerated());
|
||||
o.writeBoolean(isWorldGenerated());
|
||||
|
||||
for(int i = 15; i > 0; i--)
|
||||
{
|
||||
ParallaxSection c = sections[i];
|
||||
|
||||
if(c != null)
|
||||
{
|
||||
o.writeBoolean(true);
|
||||
c.write(o);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
o.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream i) throws IOException
|
||||
{
|
||||
setParallaxGenerated(i.readBoolean());
|
||||
setWorldGenerated(i.readBoolean());
|
||||
|
||||
for(int iv = 15; iv > 0; iv--)
|
||||
{
|
||||
if(i.readBoolean())
|
||||
{
|
||||
sections[iv] = new ParallaxSection(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlockData get(int x, int y, int z)
|
||||
{
|
||||
return getSection(y >> 4, false).getBlock(x, y & 15, z);
|
||||
}
|
||||
|
||||
public void set(int x, int y, int z, BlockData d)
|
||||
{
|
||||
getSection(y >> 4, true).setBlock(x, y & 15, z, d);
|
||||
}
|
||||
|
||||
private final ParallaxSection getSection(int y, boolean create)
|
||||
{
|
||||
if(sections[y] == null)
|
||||
{
|
||||
if(create)
|
||||
{
|
||||
sections[y] = new ParallaxSection();
|
||||
}
|
||||
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
return sections[y];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.volmit.iris.gen.parallax;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import com.volmit.iris.IrisSettings;
|
||||
import com.volmit.iris.util.CustomOutputStream;
|
||||
import com.volmit.iris.util.M;
|
||||
import com.volmit.iris.util.Writable;
|
||||
|
||||
public class ParallaxRegion implements Writable
|
||||
{
|
||||
private static final ParallaxChunk EMPTY = new ParallaxChunk();
|
||||
private ParallaxChunk[] chunks;
|
||||
private transient long last;
|
||||
|
||||
public ParallaxRegion(File i) throws IOException
|
||||
{
|
||||
this();
|
||||
|
||||
if(i.exists())
|
||||
{
|
||||
FileInputStream in = new FileInputStream(i);
|
||||
GZIPInputStream vin = new GZIPInputStream(in);
|
||||
DataInputStream min = new DataInputStream(vin);
|
||||
read(min);
|
||||
min.close();
|
||||
}
|
||||
}
|
||||
|
||||
public ParallaxRegion(DataInputStream i) throws IOException
|
||||
{
|
||||
this();
|
||||
read(i);
|
||||
}
|
||||
|
||||
public ParallaxRegion()
|
||||
{
|
||||
last = M.ms();
|
||||
chunks = new ParallaxChunk[1024];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream o) throws IOException
|
||||
{
|
||||
int c = 0;
|
||||
|
||||
for(ParallaxChunk i : chunks)
|
||||
{
|
||||
if(i != null)
|
||||
{
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
o.writeShort(c);
|
||||
|
||||
for(int i = 0; i < 1024; i++)
|
||||
{
|
||||
ParallaxChunk ch = chunks[i];
|
||||
if(ch != null)
|
||||
{
|
||||
ch.write(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(File file) throws IOException
|
||||
{
|
||||
file.getParentFile().mkdirs();
|
||||
FileOutputStream o = new FileOutputStream(file);
|
||||
CustomOutputStream g = new CustomOutputStream(o, IrisSettings.get().parallaxCompressionLevel);
|
||||
DataOutputStream d = new DataOutputStream(g);
|
||||
write(d);
|
||||
d.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream i) throws IOException
|
||||
{
|
||||
int v = i.readShort();
|
||||
|
||||
for(int b = 0; b < v; b++)
|
||||
{
|
||||
chunks[b] = new ParallaxChunk(i);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOlderThan(long time)
|
||||
{
|
||||
return M.ms() - time > last;
|
||||
}
|
||||
|
||||
public void set(int x, int y, int z, BlockData d)
|
||||
{
|
||||
getChunk(x >> 4, z >> 4, true).set(x & 15, y, z & 15, d);
|
||||
}
|
||||
|
||||
public BlockData get(int x, int y, int z)
|
||||
{
|
||||
return getChunk(x >> 4, z >> 4, false).get(x & 15, y, z & 15);
|
||||
}
|
||||
|
||||
private final ParallaxChunk getChunk(int x, int z, boolean create)
|
||||
{
|
||||
last = M.ms();
|
||||
int v = (z << 5) | x;
|
||||
|
||||
if(chunks[v] == null)
|
||||
{
|
||||
if(create)
|
||||
{
|
||||
chunks[v] = new ParallaxChunk();
|
||||
}
|
||||
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
return chunks[v];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.volmit.iris.gen.parallax;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import com.volmit.iris.util.B;
|
||||
import com.volmit.iris.util.DataPalette;
|
||||
import com.volmit.iris.util.KSet;
|
||||
import com.volmit.iris.util.Writable;
|
||||
|
||||
public class ParallaxSection implements Writable
|
||||
{
|
||||
private final DataPalette<BlockData> block;
|
||||
private final KSet<Short> updates;
|
||||
|
||||
public ParallaxSection(DataInputStream in) throws IOException
|
||||
{
|
||||
this();
|
||||
read(in);
|
||||
}
|
||||
|
||||
public ParallaxSection()
|
||||
{
|
||||
updates = new KSet<Short>();
|
||||
this.block = new DataPalette<BlockData>(B.get("AIR"))
|
||||
{
|
||||
@Override
|
||||
public void writeType(BlockData t, DataOutputStream o) throws IOException
|
||||
{
|
||||
o.writeUTF(t.getAsString(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData readType(DataInputStream i) throws IOException
|
||||
{
|
||||
return B.get(i.readUTF());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void clearUpdates()
|
||||
{
|
||||
updates.clear();
|
||||
}
|
||||
|
||||
public void update(int x, int y, int z)
|
||||
{
|
||||
updates.add((short) (y << 8 | z << 4 | x));
|
||||
}
|
||||
|
||||
public void dontUpdate(int x, int y, int z)
|
||||
{
|
||||
updates.remove((short) (y << 8 | z << 4 | x));
|
||||
}
|
||||
|
||||
public void setBlock(int x, int y, int z, BlockData d)
|
||||
{
|
||||
block.set(x, y, z, d);
|
||||
|
||||
if(B.isUpdatable(d))
|
||||
{
|
||||
update(x, y, z);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
dontUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
public BlockData getBlock(int x, int y, int z)
|
||||
{
|
||||
return block.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream o) throws IOException
|
||||
{
|
||||
block.write(o);
|
||||
o.writeShort(updates.size());
|
||||
|
||||
for(Short i : updates)
|
||||
{
|
||||
o.writeShort(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream i) throws IOException
|
||||
{
|
||||
block.read(i);
|
||||
updates.clear();
|
||||
int m = i.readShort();
|
||||
|
||||
for(int v = 0; v < m; v++)
|
||||
{
|
||||
updates.add(i.readShort());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.volmit.iris.gen.parallax;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.KMap;
|
||||
|
||||
public class ParallaxWorld
|
||||
{
|
||||
private final KMap<Long, ParallaxRegion> loadedRegions;
|
||||
private final File dataFolder;
|
||||
|
||||
public ParallaxWorld(File dataFolder)
|
||||
{
|
||||
loadedRegions = new KMap<>();
|
||||
this.dataFolder = dataFolder;
|
||||
}
|
||||
|
||||
public void unloadAll()
|
||||
{
|
||||
for(long i : loadedRegions.k())
|
||||
{
|
||||
try
|
||||
{
|
||||
unload(i);
|
||||
}
|
||||
|
||||
catch(IOException e)
|
||||
{
|
||||
Iris.error("Failed to save region " + i);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clean(long time)
|
||||
{
|
||||
for(long i : loadedRegions.k())
|
||||
{
|
||||
ParallaxRegion r = loadedRegions.get(i);
|
||||
|
||||
if(r.isOlderThan(time))
|
||||
{
|
||||
try
|
||||
{
|
||||
unload(i);
|
||||
}
|
||||
|
||||
catch(IOException e)
|
||||
{
|
||||
Iris.error("Failed to save region " + i);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unload(long i) throws IOException
|
||||
{
|
||||
ParallaxRegion r = loadedRegions.get(i);
|
||||
r.write(new File(dataFolder, i + ".plx"));
|
||||
loadedRegions.remove(i);
|
||||
}
|
||||
|
||||
public BlockData getBlock(int x, int y, int z)
|
||||
{
|
||||
if(y > 255 || y < 0)
|
||||
{
|
||||
throw new IllegalArgumentException(y + " exceeds 0-255");
|
||||
}
|
||||
|
||||
return getRegion(x >> 5, z >> 5).get(x & 511, y, z & 511);
|
||||
}
|
||||
|
||||
public void setBlock(int x, int y, int z, BlockData d)
|
||||
{
|
||||
if(d == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Block data cannot be null");
|
||||
}
|
||||
|
||||
if(y > 255 || y < 0)
|
||||
{
|
||||
throw new IllegalArgumentException(y + " exceeds 0-255");
|
||||
}
|
||||
|
||||
getRegion(x >> 5, z >> 5).set(x & 511, y, z & 511, d);
|
||||
}
|
||||
|
||||
public ParallaxRegion getRegion(int x, int z)
|
||||
{
|
||||
Long vb = (((long) x) << 32) | (z & 0xffffffffL);
|
||||
File ff = new File(dataFolder, vb + ".plx");
|
||||
|
||||
return loadedRegions.compute(vb, (k, v) ->
|
||||
{
|
||||
if(k == null || v == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new ParallaxRegion(ff);
|
||||
}
|
||||
|
||||
catch(IOException e)
|
||||
{
|
||||
Iris.error("Failed to load parallax file: " + ff.getAbsolutePath() + " Assuming empty region!");
|
||||
ff.deleteOnExit();
|
||||
ff.delete();
|
||||
return new ParallaxRegion();
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
});
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,21 +0,0 @@
|
||||
package com.volmit.iris.util.inventory;
|
||||
|
||||
/**
|
||||
* Callback for async workers
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
* @param <T>
|
||||
* the type of object to be returned in the runnable
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Callback<T>
|
||||
{
|
||||
/**
|
||||
* Called when the callback calls back...
|
||||
*
|
||||
* @param t
|
||||
* the object to be called back
|
||||
*/
|
||||
public void run(T t);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.volmit.iris.util.inventory;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.volmit.iris.util.KList;
|
||||
|
||||
public interface Element
|
||||
{
|
||||
public MaterialBlock getMaterial();
|
||||
|
||||
public Element setMaterial(MaterialBlock b);
|
||||
|
||||
public boolean isEnchanted();
|
||||
|
||||
public Element setEnchanted(boolean enchanted);
|
||||
|
||||
public String getId();
|
||||
|
||||
public String getName();
|
||||
|
||||
public Element setProgress(double progress);
|
||||
|
||||
public double getProgress();
|
||||
|
||||
public short getEffectiveDurability();
|
||||
|
||||
public Element setCount(int c);
|
||||
|
||||
public int getCount();
|
||||
|
||||
public ItemStack computeItemStack();
|
||||
|
||||
public Element setBackground(boolean bg);
|
||||
|
||||
public boolean isBackgrond();
|
||||
|
||||
public Element setName(String name);
|
||||
|
||||
public Element addLore(String loreLine);
|
||||
|
||||
public KList<String> getLore();
|
||||
|
||||
public Element call(ElementEvent event, Element context);
|
||||
|
||||
public Element onLeftClick(Callback<Element> clicked);
|
||||
|
||||
public Element onRightClick(Callback<Element> clicked);
|
||||
|
||||
public Element onShiftLeftClick(Callback<Element> clicked);
|
||||
|
||||
public Element onShiftRightClick(Callback<Element> clicked);
|
||||
|
||||
public Element onDraggedInto(Callback<Element> into);
|
||||
|
||||
public Element onOtherDraggedInto(Callback<Element> other);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.volmit.iris.util.inventory;
|
||||
|
||||
/**
|
||||
* Element Event.
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
*/
|
||||
public enum ElementEvent
|
||||
{
|
||||
LEFT,
|
||||
RIGHT,
|
||||
SHIFT_LEFT,
|
||||
SHIFT_RIGHT,
|
||||
DRAG_INTO,
|
||||
OTHER_DRAG_INTO;
|
||||
}
|
||||
Reference in new issue
Block a user