mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-05 23:36:12 +00:00
Cleanup
This commit is contained in:
@@ -22,7 +22,11 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSets;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -32,7 +36,6 @@ import org.bukkit.block.data.type.PointedDripstone;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -434,45 +437,30 @@ public class B {
|
||||
}
|
||||
|
||||
if (bx == null) {
|
||||
try
|
||||
{
|
||||
try {
|
||||
bx = Bukkit.createBlockData(ix.toLowerCase());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(bx == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bx == null) {
|
||||
try {
|
||||
bx = Bukkit.createBlockData("minecraft:" + ix.toLowerCase());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(bx == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bx == null) {
|
||||
try {
|
||||
bx = Material.valueOf(ix.toUpperCase()).createBlockData();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(bx == null)
|
||||
{
|
||||
if (bx == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,20 @@ package com.volmit.iris.util.data;
|
||||
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.Direction;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Cuboids
|
||||
@@ -58,35 +66,6 @@ public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializ
|
||||
z2 = Math.max(l1.getBlockZ(), l2.getBlockZ());
|
||||
}
|
||||
|
||||
public KList<Entity> getEntities() {
|
||||
KList<Entity> en = new KList<>();
|
||||
|
||||
for (Chunk i : getChunks()) {
|
||||
for (Entity j : i.getEntities()) {
|
||||
if (contains(j.getLocation())) {
|
||||
en.add(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return en;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the locations
|
||||
*
|
||||
* @param l1 a
|
||||
* @param l2 b
|
||||
*/
|
||||
public void set(Location l1, Location l2) {
|
||||
x1 = Math.min(l1.getBlockX(), l2.getBlockX());
|
||||
y1 = Math.min(l1.getBlockY(), l2.getBlockY());
|
||||
z1 = Math.min(l1.getBlockZ(), l2.getBlockZ());
|
||||
x2 = Math.max(l1.getBlockX(), l2.getBlockX());
|
||||
y2 = Math.max(l1.getBlockY(), l2.getBlockY());
|
||||
z2 = Math.max(l1.getBlockZ(), l2.getBlockZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a one-block Cuboid at the given Location of the Cuboid.
|
||||
*
|
||||
@@ -157,6 +136,35 @@ public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializ
|
||||
z2 = (Integer) map.get("z2");
|
||||
}
|
||||
|
||||
public KList<Entity> getEntities() {
|
||||
KList<Entity> en = new KList<>();
|
||||
|
||||
for (Chunk i : getChunks()) {
|
||||
for (Entity j : i.getEntities()) {
|
||||
if (contains(j.getLocation())) {
|
||||
en.add(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return en;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the locations
|
||||
*
|
||||
* @param l1 a
|
||||
* @param l2 b
|
||||
*/
|
||||
public void set(Location l1, Location l2) {
|
||||
x1 = Math.min(l1.getBlockX(), l2.getBlockX());
|
||||
y1 = Math.min(l1.getBlockY(), l2.getBlockY());
|
||||
z1 = Math.min(l1.getBlockZ(), l2.getBlockZ());
|
||||
x2 = Math.max(l1.getBlockX(), l2.getBlockX());
|
||||
y2 = Math.max(l1.getBlockY(), l2.getBlockY());
|
||||
z2 = Math.max(l1.getBlockZ(), l2.getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
@@ -671,15 +679,44 @@ public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializ
|
||||
return "Cuboid: " + worldName + "," + x1 + "," + y1 + "," + z1 + "=>" + x2 + "," + y2 + "," + z2;
|
||||
}
|
||||
|
||||
public enum CuboidDirection {
|
||||
|
||||
North,
|
||||
East,
|
||||
South,
|
||||
West,
|
||||
Up,
|
||||
Down,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
Both,
|
||||
Unknown;
|
||||
|
||||
public CuboidDirection opposite() {
|
||||
return switch (this) {
|
||||
case North -> South;
|
||||
case East -> West;
|
||||
case South -> North;
|
||||
case West -> East;
|
||||
case Horizontal -> Vertical;
|
||||
case Vertical -> Horizontal;
|
||||
case Up -> Down;
|
||||
case Down -> Up;
|
||||
case Both -> Both;
|
||||
default -> Unknown;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class CuboidIterator implements Iterator<Block> {
|
||||
private final World w;
|
||||
private final int baseX;
|
||||
private final int baseY;
|
||||
private final int baseZ;
|
||||
private int x, y, z;
|
||||
private final int sizeX;
|
||||
private final int sizeY;
|
||||
private final int sizeZ;
|
||||
private int x, y, z;
|
||||
|
||||
public CuboidIterator(World w, int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||
this.w = w;
|
||||
@@ -716,33 +753,4 @@ public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializ
|
||||
}
|
||||
}
|
||||
|
||||
public enum CuboidDirection {
|
||||
|
||||
North,
|
||||
East,
|
||||
South,
|
||||
West,
|
||||
Up,
|
||||
Down,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
Both,
|
||||
Unknown;
|
||||
|
||||
public CuboidDirection opposite() {
|
||||
return switch (this) {
|
||||
case North -> South;
|
||||
case East -> West;
|
||||
case South -> North;
|
||||
case West -> East;
|
||||
case Horizontal -> Vertical;
|
||||
case Vertical -> Horizontal;
|
||||
case Up -> Down;
|
||||
case Down -> Up;
|
||||
case Both -> Both;
|
||||
default -> Unknown;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,9 +24,9 @@ package com.volmit.iris.util.data;
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class CuboidException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CuboidException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -35,6 +35,17 @@ public class DataPalette<T> {
|
||||
this.palette = palette;
|
||||
}
|
||||
|
||||
public static <T> DataPalette<T> getPalette(IOAdapter<T> adapter, DataInputStream din) throws IOException {
|
||||
KList<T> palette = new KList<>();
|
||||
int s = din.readShort() - Short.MIN_VALUE;
|
||||
|
||||
for (int i = 0; i < s; i++) {
|
||||
palette.add(adapter.read(din));
|
||||
}
|
||||
|
||||
return new DataPalette<>(palette);
|
||||
}
|
||||
|
||||
public KList<T> getPalette() {
|
||||
return palette;
|
||||
}
|
||||
@@ -73,15 +84,4 @@ public class DataPalette<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> DataPalette<T> getPalette(IOAdapter<T> adapter, DataInputStream din) throws IOException {
|
||||
KList<T> palette = new KList<>();
|
||||
int s = din.readShort() - Short.MIN_VALUE;
|
||||
|
||||
for (int i = 0; i < s; i++) {
|
||||
palette.add(adapter.read(din));
|
||||
}
|
||||
|
||||
return new DataPalette<>(palette);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,11 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class IrisBiomeStorage implements BiomeGrid {
|
||||
private static final int e;
|
||||
private static final int f;
|
||||
public static final int a;
|
||||
public static final int b;
|
||||
public static final int c;
|
||||
private final Biome[] g;
|
||||
private static final int e;
|
||||
private static final int f;
|
||||
|
||||
static {
|
||||
e = (int) Math.round(Math.log(16.0) / Math.log(2.0)) - 2;
|
||||
@@ -39,6 +38,8 @@ public class IrisBiomeStorage implements BiomeGrid {
|
||||
c = (1 << IrisBiomeStorage.f) - 1;
|
||||
}
|
||||
|
||||
private final Biome[] g;
|
||||
|
||||
public IrisBiomeStorage(final Biome[] aBiome) {
|
||||
this.g = aBiome;
|
||||
}
|
||||
|
||||
@@ -26,11 +26,20 @@ import java.util.Arrays;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class NibbleArray implements Writable {
|
||||
private static final int[] MASKS = new int[8];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < MASKS.length; i++) {
|
||||
MASKS[i] = maskFor(i);
|
||||
}
|
||||
}
|
||||
|
||||
private final int size;
|
||||
private final Object lock = new Object();
|
||||
private byte[] data;
|
||||
private int depth;
|
||||
private final int size;
|
||||
private byte mask;
|
||||
private final Object lock = new Object();
|
||||
private transient int bitIndex, byteIndex, bitInByte;
|
||||
|
||||
public NibbleArray(int capacity, DataInputStream in) throws IOException {
|
||||
size = capacity;
|
||||
@@ -66,6 +75,30 @@ public class NibbleArray implements Writable {
|
||||
}
|
||||
}
|
||||
|
||||
public static int maskFor(int amountOfBits) {
|
||||
return powerOfTwo(amountOfBits) - 1;
|
||||
}
|
||||
|
||||
public static int powerOfTwo(int power) {
|
||||
int result = 1;
|
||||
|
||||
for (int i = 0; i < power; i++) {
|
||||
result *= 2;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String binaryString(byte b, ByteOrder byteOrder) {
|
||||
String str = String.format("%8s", Integer.toBinaryString(b & 0xff)).replace(' ', '0');
|
||||
|
||||
return byteOrder.equals(ByteOrder.BIG_ENDIAN) ? str : reverse(str);
|
||||
}
|
||||
|
||||
public static String reverse(String str) {
|
||||
return new StringBuilder(str).reverse().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream o) throws IOException {
|
||||
o.writeByte(depth + Byte.MIN_VALUE);
|
||||
@@ -108,8 +141,6 @@ public class NibbleArray implements Writable {
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
|
||||
private transient int bitIndex, byteIndex, bitInByte;
|
||||
|
||||
public void set(int x, int y, int z, int nibble) {
|
||||
set(index(x, y, z), nibble);
|
||||
}
|
||||
@@ -160,36 +191,4 @@ public class NibbleArray implements Writable {
|
||||
set(i, (byte) nibble);
|
||||
}
|
||||
}
|
||||
|
||||
public static int maskFor(int amountOfBits) {
|
||||
return powerOfTwo(amountOfBits) - 1;
|
||||
}
|
||||
|
||||
public static int powerOfTwo(int power) {
|
||||
int result = 1;
|
||||
|
||||
for (int i = 0; i < power; i++) {
|
||||
result *= 2;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final int[] MASKS = new int[8];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < MASKS.length; i++) {
|
||||
MASKS[i] = maskFor(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static String binaryString(byte b, ByteOrder byteOrder) {
|
||||
String str = String.format("%8s", Integer.toBinaryString(b & 0xff)).replace(' ', '0');
|
||||
|
||||
return byteOrder.equals(ByteOrder.BIG_ENDIAN) ? str : reverse(str);
|
||||
}
|
||||
|
||||
public static String reverse(String str) {
|
||||
return new StringBuilder(str).reverse().toString();
|
||||
}
|
||||
}
|
||||
@@ -32,38 +32,6 @@ public class VanillaBiomeMap {
|
||||
private static final KMap<Biome, SaturationType> BIOME_SATURATION = new KMap<>();
|
||||
private static final KMap<Biome, Short> BIOME_IDs = new KMap<>();
|
||||
|
||||
private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity, SaturationType saturation) {
|
||||
BIOME_HEX.put(biome, color);
|
||||
BIOME_COLOR.put(biome, randomColor);
|
||||
if (luminosity != null) BIOME_LUMINOSITY.put(biome, luminosity);
|
||||
if (saturation != null) BIOME_SATURATION.put(biome, saturation);
|
||||
BIOME_IDs.put(biome, id);
|
||||
}
|
||||
|
||||
private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity) {
|
||||
add(biome, color, id, randomColor, luminosity, null);
|
||||
}
|
||||
|
||||
public static int getColor(Biome biome) {
|
||||
return BIOME_HEX.get(biome);
|
||||
}
|
||||
|
||||
public static Color getColorType(Biome biome) {
|
||||
return BIOME_COLOR.get(biome);
|
||||
}
|
||||
|
||||
public static Luminosity getColorLuminosity(Biome biome) {
|
||||
return BIOME_LUMINOSITY.get(biome);
|
||||
}
|
||||
|
||||
public static SaturationType getColorSaturatiom(Biome biome) {
|
||||
return BIOME_SATURATION.get(biome);
|
||||
}
|
||||
|
||||
public static short getId(Biome biome) {
|
||||
return BIOME_IDs.get(biome);
|
||||
}
|
||||
|
||||
static {
|
||||
add(Biome.OCEAN, 0x000070, (short) 0, Color.BLUE, Luminosity.BRIGHT, SaturationType.MEDIUM);
|
||||
add(Biome.PLAINS, 0x8DB360, (short) 1, Color.GREEN, Luminosity.LIGHT, SaturationType.MEDIUM);
|
||||
@@ -144,4 +112,36 @@ public class VanillaBiomeMap {
|
||||
add(Biome.WARPED_FOREST, 0x49907B, (short) 172, Color.BLUE, Luminosity.BRIGHT);
|
||||
add(Biome.BASALT_DELTAS, 0x403636, (short) 173, Color.MONOCHROME, Luminosity.DARK);
|
||||
}
|
||||
|
||||
private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity, SaturationType saturation) {
|
||||
BIOME_HEX.put(biome, color);
|
||||
BIOME_COLOR.put(biome, randomColor);
|
||||
if (luminosity != null) BIOME_LUMINOSITY.put(biome, luminosity);
|
||||
if (saturation != null) BIOME_SATURATION.put(biome, saturation);
|
||||
BIOME_IDs.put(biome, id);
|
||||
}
|
||||
|
||||
private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity) {
|
||||
add(biome, color, id, randomColor, luminosity, null);
|
||||
}
|
||||
|
||||
public static int getColor(Biome biome) {
|
||||
return BIOME_HEX.get(biome);
|
||||
}
|
||||
|
||||
public static Color getColorType(Biome biome) {
|
||||
return BIOME_COLOR.get(biome);
|
||||
}
|
||||
|
||||
public static Luminosity getColorLuminosity(Biome biome) {
|
||||
return BIOME_LUMINOSITY.get(biome);
|
||||
}
|
||||
|
||||
public static SaturationType getColorSaturatiom(Biome biome) {
|
||||
return BIOME_SATURATION.get(biome);
|
||||
}
|
||||
|
||||
public static short getId(Biome biome) {
|
||||
return BIOME_IDs.get(biome);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user