mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-27 11:09:06 +00:00
Reorganize
This commit is contained in:
85
src/main/java/com/volmit/iris/util/Average.java
Normal file
85
src/main/java/com/volmit/iris/util/Average.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
/**
|
||||
* Provides an incredibly fast averaging object. It swaps values from a sum
|
||||
* using an array. Averages do not use any form of looping. An average of 10,000
|
||||
* entries is the same speed as an average with 5 entries.
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
*/
|
||||
public class Average {
|
||||
protected double[] values;
|
||||
private double average;
|
||||
private double lastSum;
|
||||
private boolean dirty;
|
||||
protected int cursor;
|
||||
private boolean brandNew;
|
||||
|
||||
/**
|
||||
* Create an average holder
|
||||
*
|
||||
* @param size the size of entries to keep
|
||||
*/
|
||||
public Average(int size) {
|
||||
values = new double[size];
|
||||
DoubleArrayUtils.fill(values, 0);
|
||||
brandNew = true;
|
||||
average = 0;
|
||||
cursor = 0;
|
||||
lastSum = 0;
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value into the average (rolls over if full)
|
||||
*
|
||||
* @param i the value
|
||||
*/
|
||||
public void put(double i) {
|
||||
|
||||
dirty = true;
|
||||
|
||||
if(brandNew)
|
||||
{
|
||||
DoubleArrayUtils.fill(values, i);
|
||||
lastSum = size() * i;
|
||||
brandNew = false;
|
||||
return;
|
||||
}
|
||||
|
||||
double current = values[cursor];
|
||||
lastSum = (lastSum - current) + i;
|
||||
values[cursor] = i;
|
||||
cursor = cursor + 1 < size() ? cursor + 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current average
|
||||
*
|
||||
* @return the average
|
||||
*/
|
||||
public double getAverage() {
|
||||
if (dirty) {
|
||||
calculateAverage();
|
||||
return getAverage();
|
||||
}
|
||||
|
||||
return average;
|
||||
}
|
||||
|
||||
private void calculateAverage() {
|
||||
average = lastSum / (double) size();
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return values.length;
|
||||
}
|
||||
|
||||
public boolean isDirty()
|
||||
{
|
||||
return dirty;
|
||||
}
|
||||
}
|
||||
31
src/main/java/com/volmit/iris/util/Axis.java
Normal file
31
src/main/java/com/volmit/iris/util/Axis.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public enum Axis
|
||||
{
|
||||
X(1, 0, 0),
|
||||
Y(0, 1, 0),
|
||||
Z(0, 0, 1);
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
private Axis(int x, int y, int z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector positive()
|
||||
{
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
public Vector negative()
|
||||
{
|
||||
return VectorMath.reverse(positive());
|
||||
}
|
||||
}
|
||||
219
src/main/java/com/volmit/iris/util/BasePerlinNoiseGenerator.java
Normal file
219
src/main/java/com/volmit/iris/util/BasePerlinNoiseGenerator.java
Normal file
@@ -0,0 +1,219 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Generates noise using the "classic" perlin generator
|
||||
*
|
||||
* @see SimplexNoiseC "Improved" and faster version with slighly
|
||||
* different results
|
||||
*/
|
||||
public class BasePerlinNoiseGenerator extends NoiseGenerator
|
||||
{
|
||||
protected static final int grad3[][] = {{1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {1, 0, 1}, {-1, 0, 1}, {1, 0, -1}, {-1, 0, -1}, {0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}};
|
||||
private static final BasePerlinNoiseGenerator instance = new BasePerlinNoiseGenerator();
|
||||
|
||||
protected BasePerlinNoiseGenerator()
|
||||
{
|
||||
int p[] = {151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
|
||||
|
||||
for(int i = 0; i < 512; i++)
|
||||
{
|
||||
perm[i] = p[i & 255];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a seeded perlin noise generator for the given seed
|
||||
*
|
||||
* @param seed
|
||||
* Seed to construct this generator for
|
||||
*/
|
||||
public BasePerlinNoiseGenerator(long seed)
|
||||
{
|
||||
this(new Random(seed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a seeded perlin noise generator with the given Random
|
||||
*
|
||||
* @param rand
|
||||
* Random to construct with
|
||||
*/
|
||||
public BasePerlinNoiseGenerator(Random rand)
|
||||
{
|
||||
offsetX = rand.nextDouble() * 256;
|
||||
offsetY = rand.nextDouble() * 256;
|
||||
offsetZ = rand.nextDouble() * 256;
|
||||
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
perm[i] = rand.nextInt(256);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
int pos = rand.nextInt(256 - i) + i;
|
||||
int old = perm[i];
|
||||
|
||||
perm[i] = perm[pos];
|
||||
perm[pos] = old;
|
||||
perm[i + 256] = perm[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes and returns the 1D unseeded perlin noise for the given coordinates
|
||||
* in 1D space
|
||||
*
|
||||
* @param x
|
||||
* X coordinate
|
||||
* @return Noise at given location, from range -1 to 1
|
||||
*/
|
||||
public static double getNoise(double x)
|
||||
{
|
||||
return instance.noise(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes and returns the 2D unseeded perlin noise for the given coordinates
|
||||
* in 2D space
|
||||
*
|
||||
* @param x
|
||||
* X coordinate
|
||||
* @param y
|
||||
* Y coordinate
|
||||
* @return Noise at given location, from range -1 to 1
|
||||
*/
|
||||
public static double getNoise(double x, double y)
|
||||
{
|
||||
return instance.noise(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes and returns the 3D unseeded perlin noise for the given coordinates
|
||||
* in 3D space
|
||||
*
|
||||
* @param x
|
||||
* X coordinate
|
||||
* @param y
|
||||
* Y coordinate
|
||||
* @param z
|
||||
* Z coordinate
|
||||
* @return Noise at given location, from range -1 to 1
|
||||
*/
|
||||
public static double getNoise(double x, double y, double z)
|
||||
{
|
||||
return instance.noise(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the singleton unseeded instance of this generator
|
||||
*
|
||||
* @return Singleton
|
||||
*/
|
||||
public static BasePerlinNoiseGenerator getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z)
|
||||
{
|
||||
x += offsetX;
|
||||
y += offsetY;
|
||||
z += offsetZ;
|
||||
|
||||
int floorX = floor(x);
|
||||
int floorY = floor(y);
|
||||
int floorZ = floor(z);
|
||||
|
||||
// Find unit cube containing the point
|
||||
int X = floorX & 255;
|
||||
int Y = floorY & 255;
|
||||
int Z = floorZ & 255;
|
||||
|
||||
// Get relative xyz coordinates of the point within the cube
|
||||
x -= floorX;
|
||||
y -= floorY;
|
||||
z -= floorZ;
|
||||
|
||||
// Compute fade curves for xyz
|
||||
double fX = fade(x);
|
||||
double fY = fade(y);
|
||||
double fZ = fade(z);
|
||||
|
||||
// Hash coordinates of the cube corners
|
||||
int A = perm[X] + Y;
|
||||
int AA = perm[A] + Z;
|
||||
int AB = perm[A + 1] + Z;
|
||||
int B = perm[X + 1] + Y;
|
||||
int BA = perm[B] + Z;
|
||||
int BB = perm[B + 1] + Z;
|
||||
|
||||
return lerp(fZ, lerp(fY, lerp(fX, grad(perm[AA], x, y, z), grad(perm[BA], x - 1, y, z)), lerp(fX, grad(perm[AB], x, y - 1, z), grad(perm[BB], x - 1, y - 1, z))), lerp(fY, lerp(fX, grad(perm[AA + 1], x, y, z - 1), grad(perm[BA + 1], x - 1, y, z - 1)), lerp(fX, grad(perm[AB + 1], x, y - 1, z - 1), grad(perm[BB + 1], x - 1, y - 1, z - 1))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates noise for the 1D coordinates using the specified number of octaves
|
||||
* and parameters
|
||||
*
|
||||
* @param x
|
||||
* X-coordinate
|
||||
* @param octaves
|
||||
* Number of octaves to use
|
||||
* @param frequency
|
||||
* How much to alter the frequency by each octave
|
||||
* @param amplitude
|
||||
* How much to alter the amplitude by each octave
|
||||
* @return Resulting noise
|
||||
*/
|
||||
public static double getNoise(double x, int octaves, double frequency, double amplitude)
|
||||
{
|
||||
return instance.noise(x, octaves, frequency, amplitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates noise for the 2D coordinates using the specified number of octaves
|
||||
* and parameters
|
||||
*
|
||||
* @param x
|
||||
* X-coordinate
|
||||
* @param y
|
||||
* Y-coordinate
|
||||
* @param octaves
|
||||
* Number of octaves to use
|
||||
* @param frequency
|
||||
* How much to alter the frequency by each octave
|
||||
* @param amplitude
|
||||
* How much to alter the amplitude by each octave
|
||||
* @return Resulting noise
|
||||
*/
|
||||
public static double getNoise(double x, double y, int octaves, double frequency, double amplitude)
|
||||
{
|
||||
return instance.noise(x, y, octaves, frequency, amplitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates noise for the 3D coordinates using the specified number of octaves
|
||||
* and parameters
|
||||
*
|
||||
* @param x
|
||||
* X-coordinate
|
||||
* @param y
|
||||
* Y-coordinate
|
||||
* @param z
|
||||
* Z-coordinate
|
||||
* @param octaves
|
||||
* Number of octaves to use
|
||||
* @param frequency
|
||||
* How much to alter the frequency by each octave
|
||||
* @param amplitude
|
||||
* How much to alter the amplitude by each octave
|
||||
* @return Resulting noise
|
||||
*/
|
||||
public static double getNoise(double x, double y, double z, int octaves, double frequency, double amplitude)
|
||||
{
|
||||
return instance.noise(x, y, z, octaves, frequency, amplitude);
|
||||
}
|
||||
}
|
||||
9
src/main/java/com/volmit/iris/util/BiomeDominance.java
Normal file
9
src/main/java/com/volmit/iris/util/BiomeDominance.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import ninja.bytecode.iris.object.IrisBiome;
|
||||
import ninja.bytecode.shuriken.collections.KMap;
|
||||
|
||||
public class BiomeDominance extends KMap<IrisBiome, Double>
|
||||
{
|
||||
private static final long serialVersionUID = 9055245062942178392L;
|
||||
}
|
||||
23
src/main/java/com/volmit/iris/util/BiomeMap.java
Normal file
23
src/main/java/com/volmit/iris/util/BiomeMap.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import ninja.bytecode.iris.object.IrisBiome;
|
||||
|
||||
public class BiomeMap
|
||||
{
|
||||
private final IrisBiome[] height;
|
||||
|
||||
public BiomeMap()
|
||||
{
|
||||
height = new IrisBiome[256];
|
||||
}
|
||||
|
||||
public void setBiome(int x, int z, IrisBiome h)
|
||||
{
|
||||
height[x * 16 + z] = h;
|
||||
}
|
||||
|
||||
public IrisBiome getBiome(int x, int z)
|
||||
{
|
||||
return height[x * 16 + z];
|
||||
}
|
||||
}
|
||||
22
src/main/java/com/volmit/iris/util/BiomeResult.java
Normal file
22
src/main/java/com/volmit/iris/util/BiomeResult.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import lombok.Data;
|
||||
import ninja.bytecode.iris.object.IrisBiome;
|
||||
|
||||
@Data
|
||||
public class BiomeResult
|
||||
{
|
||||
private IrisBiome biome;
|
||||
private double distance;
|
||||
|
||||
public BiomeResult(IrisBiome biome, double distance)
|
||||
{
|
||||
this.biome = biome;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public boolean is(BiomeResult r)
|
||||
{
|
||||
return biome.getName().equals(r.biome.getName());
|
||||
}
|
||||
}
|
||||
82
src/main/java/com/volmit/iris/util/BlockDataTools.java
Normal file
82
src/main/java/com/volmit/iris/util/BlockDataTools.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.shuriken.collections.KList;
|
||||
import ninja.bytecode.shuriken.collections.KMap;
|
||||
|
||||
public class BlockDataTools
|
||||
{
|
||||
private static final KMap<String, BlockData> bdc = new KMap<>();
|
||||
private static final KList<String> nulls = new KList<>();
|
||||
|
||||
public static BlockData getBlockData(String bd)
|
||||
{
|
||||
if(bdc.containsKey(bd))
|
||||
{
|
||||
return bdc.get(bd).clone();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
BlockData bdx = parseBlockData(bd);
|
||||
|
||||
if(bdx == null)
|
||||
{
|
||||
Iris.warn("Unknown Block Data '" + bd + "'");
|
||||
nulls.add(bd);
|
||||
return bdx;
|
||||
}
|
||||
|
||||
bdc.put(bd, bdx);
|
||||
|
||||
return bdx;
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
Iris.warn("Unknown Block Data '" + bd + "'");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static BlockData parseBlockData(String ix)
|
||||
{
|
||||
try
|
||||
{
|
||||
BlockData bx = Bukkit.createBlockData(ix);
|
||||
|
||||
if(bx != null)
|
||||
{
|
||||
return bx;
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
String i = ix.toUpperCase().trim();
|
||||
i = i.equals("WOOL") ? "WHITE_WOOL" : i;
|
||||
i = i.equals("CONCRETE") ? "WHITE_CONCRETE" : i;
|
||||
|
||||
try
|
||||
{
|
||||
Material m = Material.valueOf(i);
|
||||
|
||||
return m.createBlockData();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
28
src/main/java/com/volmit/iris/util/BlockPosition.java
Normal file
28
src/main/java/com/volmit/iris/util/BlockPosition.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BlockPosition
|
||||
{
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
public BlockPosition(int x, int y, int z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public int getChunkX()
|
||||
{
|
||||
return x >> 4;
|
||||
}
|
||||
|
||||
public int getChunkZ()
|
||||
{
|
||||
return z >> 4;
|
||||
}
|
||||
}
|
||||
131
src/main/java/com/volmit/iris/util/Board.java
Normal file
131
src/main/java/com/volmit/iris/util/Board.java
Normal file
@@ -0,0 +1,131 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author Missionary (missionarymc@gmail.com)
|
||||
* @since 3/23/2018
|
||||
*/
|
||||
public class Board {
|
||||
|
||||
private static final String[] CACHED_ENTRIES = new String[ChatColor.values().length];
|
||||
|
||||
private static final Function<String, String> APPLY_COLOR_TRANSLATION = s -> ChatColor.translateAlternateColorCodes('&', s);
|
||||
|
||||
static {
|
||||
IntStream.range(0, 15).forEach(i -> CACHED_ENTRIES[i] = ChatColor.values()[i].toString() + ChatColor.RESET);
|
||||
}
|
||||
|
||||
private final Player player;
|
||||
private final Objective objective;
|
||||
private final Team team;
|
||||
@Setter private BoardSettings boardSettings;
|
||||
private boolean ready;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public Board(@NonNull final Player player, final BoardSettings boardSettings) {
|
||||
this.player = player;
|
||||
this.boardSettings = boardSettings;
|
||||
this.objective = this.getScoreboard().getObjective("board") == null ? this.getScoreboard().registerNewObjective("board", "dummy") : this.getScoreboard().getObjective("board");
|
||||
this.objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
this.team = this.getScoreboard().getTeam("board") == null ? this.getScoreboard().registerNewTeam("board") : this.getScoreboard().getTeam("board");
|
||||
this.team.setAllowFriendlyFire(true);
|
||||
this.team.setCanSeeFriendlyInvisibles(false);
|
||||
this.team.setPrefix("");
|
||||
this.team.setSuffix("");
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
public Scoreboard getScoreboard() {
|
||||
return (player != null) ? player.getScoreboard() : null;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
this.resetScoreboard();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
// Checking if we are ready to start updating the Scoreboard.
|
||||
if (!ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Making sure the player is connected.
|
||||
if (!player.isOnline()) {
|
||||
remove();
|
||||
return;
|
||||
}
|
||||
|
||||
// Making sure the Scoreboard Provider is set.
|
||||
if (boardSettings == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Getting their Scoreboard display from the Scoreboard Provider.
|
||||
final List<String> entries = boardSettings.getBoardProvider().getLines(player).stream().map(APPLY_COLOR_TRANSLATION).collect(Collectors.toList());
|
||||
|
||||
if (boardSettings.getScoreDirection() == ScoreDirection.UP) {
|
||||
Collections.reverse(entries);
|
||||
}
|
||||
|
||||
// Setting the Scoreboard title
|
||||
String title = boardSettings.getBoardProvider().getTitle(player);
|
||||
if (title.length() > 32) {
|
||||
Bukkit.getLogger().warning("The title " + title + " is over 32 characters in length, substringing to prevent errors.");
|
||||
title = title.substring(0, 32);
|
||||
}
|
||||
objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', title));
|
||||
|
||||
// Clearing previous Scoreboard values if entry sizes don't match.
|
||||
if (this.getScoreboard().getEntries().size() != entries.size())
|
||||
this.getScoreboard().getEntries().forEach(this::removeEntry);
|
||||
|
||||
// Setting Scoreboard lines.
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
String str = entries.get(i);
|
||||
BoardEntry entry = BoardEntry.translateToEntry(str);
|
||||
Team team = getScoreboard().getTeam(CACHED_ENTRIES[i]);
|
||||
|
||||
if (team == null) {
|
||||
team = this.getScoreboard().registerNewTeam(CACHED_ENTRIES[i]);
|
||||
team.addEntry(team.getName());
|
||||
}
|
||||
|
||||
team.setPrefix(entry.getPrefix());
|
||||
team.setSuffix(entry.getSuffix());
|
||||
|
||||
switch (boardSettings.getScoreDirection()) {
|
||||
case UP:
|
||||
objective.getScore(team.getName()).setScore(1 + i);
|
||||
break;
|
||||
case DOWN:
|
||||
objective.getScore(team.getName()).setScore(15 - i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeEntry(String id) {
|
||||
this.getScoreboard().resetScores(id);
|
||||
}
|
||||
|
||||
public void resetScoreboard() {
|
||||
ready = false;
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
}
|
||||
}
|
||||
40
src/main/java/com/volmit/iris/util/BoardEntry.java
Normal file
40
src/main/java/com/volmit/iris/util/BoardEntry.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* @author Missionary (missionarymc@gmail.com)
|
||||
* @since 3/29/2018
|
||||
*/
|
||||
public class BoardEntry {
|
||||
|
||||
@Getter
|
||||
private final String prefix, suffix;
|
||||
|
||||
private BoardEntry(final String prefix, final String suffix) {
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
public static BoardEntry translateToEntry(String input) {
|
||||
if (input.isEmpty()) {
|
||||
return new BoardEntry("", "");
|
||||
}
|
||||
if (input.length() <= 16) {
|
||||
return new BoardEntry(input, "");
|
||||
} else {
|
||||
String prefix = input.substring(0, 16);
|
||||
String suffix = "";
|
||||
|
||||
if (prefix.endsWith("\u00a7")) {
|
||||
prefix = prefix.substring(0, prefix.length() - 1);
|
||||
suffix = "\u00a7" + suffix;
|
||||
}
|
||||
|
||||
suffix = StringUtils.left(ChatColor.getLastColors(prefix) + suffix + input.substring(16), 16);
|
||||
return new BoardEntry(prefix, suffix);
|
||||
}
|
||||
}
|
||||
}
|
||||
86
src/main/java/com/volmit/iris/util/BoardManager.java
Normal file
86
src/main/java/com/volmit/iris/util/BoardManager.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author Missionary (missionarymc@gmail.com)
|
||||
* @since 3/23/2018
|
||||
*/
|
||||
public class BoardManager implements Listener {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private BoardSettings boardSettings;
|
||||
private Map<UUID, Board> scoreboards;
|
||||
private BukkitTask updateTask;
|
||||
|
||||
public BoardManager(JavaPlugin plugin, BoardSettings boardSettings) {
|
||||
this.plugin = plugin;
|
||||
this.boardSettings = boardSettings;
|
||||
this.scoreboards = new ConcurrentHashMap<>();
|
||||
this.updateTask = new BoardUpdateTask(this).runTaskTimer(plugin, 2L, 2L);
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
plugin.getServer().getOnlinePlayers().forEach(this::setup);
|
||||
}
|
||||
|
||||
public void setBoardSettings(BoardSettings boardSettings) {
|
||||
this.boardSettings = boardSettings;
|
||||
scoreboards.values().forEach(board -> board.setBoardSettings(boardSettings));
|
||||
}
|
||||
|
||||
public boolean hasBoard(Player player) {
|
||||
return scoreboards.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public Optional<Board> getBoard(Player player) {
|
||||
return Optional.ofNullable(scoreboards.get(player.getUniqueId()));
|
||||
}
|
||||
|
||||
private void setup(Player player) {
|
||||
Optional.ofNullable(scoreboards.remove(player.getUniqueId())).ifPresent(Board::resetScoreboard);
|
||||
if (player.getScoreboard() == Bukkit.getScoreboardManager().getMainScoreboard()) {
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
|
||||
}
|
||||
scoreboards.put(player.getUniqueId(), new Board(player, boardSettings));
|
||||
}
|
||||
|
||||
private void remove(Player player) {
|
||||
Optional.ofNullable(scoreboards.remove(player.getUniqueId())).ifPresent(Board::remove);
|
||||
}
|
||||
|
||||
public Map<UUID, Board> getScoreboards() {
|
||||
return Collections.unmodifiableMap(scoreboards);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(final PlayerJoinEvent e) {
|
||||
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
|
||||
if (e.getPlayer().isOnline()) { // Set this up 2 ticks later.
|
||||
setup(e.getPlayer());
|
||||
}
|
||||
}, 2L);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(final PlayerQuitEvent e) {
|
||||
this.remove(e.getPlayer());
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
updateTask.cancel();
|
||||
plugin.getServer().getOnlinePlayers().forEach(this::remove);
|
||||
scoreboards.clear();
|
||||
}
|
||||
}
|
||||
25
src/main/java/com/volmit/iris/util/BoardProvider.java
Normal file
25
src/main/java/com/volmit/iris/util/BoardProvider.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BoardProvider {
|
||||
|
||||
/**
|
||||
* Gets the title for {@link Objective#getDisplayName()}
|
||||
*
|
||||
* @param player The {@link Player} to supply
|
||||
* @return The title for the objective
|
||||
*/
|
||||
String getTitle(Player player);
|
||||
|
||||
/**
|
||||
* Gets the contents to be displayed on the {@link Board}
|
||||
*
|
||||
* @param player The {@link Player} to supply
|
||||
* @return The {@link List} of contents
|
||||
*/
|
||||
List<String> getLines(Player player);
|
||||
}
|
||||
18
src/main/java/com/volmit/iris/util/BoardSettings.java
Normal file
18
src/main/java/com/volmit/iris/util/BoardSettings.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author Missionary (missionarymc@gmail.com)
|
||||
* @since 5/31/2018
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class BoardSettings {
|
||||
|
||||
private BoardProvider boardProvider;
|
||||
|
||||
private ScoreDirection scoreDirection;
|
||||
|
||||
}
|
||||
26
src/main/java/com/volmit/iris/util/BoardUpdateTask.java
Normal file
26
src/main/java/com/volmit/iris/util/BoardUpdateTask.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @author Missionary (missionarymc@gmail.com)
|
||||
* @since 5/31/2018
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class BoardUpdateTask extends BukkitRunnable {
|
||||
|
||||
private static final Predicate<UUID> PLAYER_IS_ONLINE = uuid -> Bukkit.getPlayer(uuid) != null;
|
||||
|
||||
private final BoardManager boardManager;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
boardManager.getScoreboards().entrySet().stream().filter(entrySet -> PLAYER_IS_ONLINE.test(entrySet.getKey())).forEach(entrySet -> entrySet.getValue().update());
|
||||
}
|
||||
}
|
||||
7
src/main/java/com/volmit/iris/util/BorderCheck.java
Normal file
7
src/main/java/com/volmit/iris/util/BorderCheck.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BorderCheck<T>
|
||||
{
|
||||
public T get(double x, double z);
|
||||
}
|
||||
44
src/main/java/com/volmit/iris/util/Borders.java
Normal file
44
src/main/java/com/volmit/iris/util/Borders.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import ninja.bytecode.shuriken.math.M;
|
||||
|
||||
public class Borders
|
||||
{
|
||||
public static <T> double getDistanceToBorder(double x, double z, int samples, double minRadius, double maxRadius, double jump, BorderCheck<T> check)
|
||||
{
|
||||
double offset = 0;
|
||||
double fract = 1;
|
||||
|
||||
for(double i = minRadius; i < maxRadius; i += jump * fract)
|
||||
{
|
||||
offset += jump / 3D;
|
||||
fract += 0.333;
|
||||
|
||||
if(isBorderWithin(x, z, samples, maxRadius, offset, check))
|
||||
{
|
||||
return minRadius;
|
||||
}
|
||||
}
|
||||
|
||||
return maxRadius;
|
||||
}
|
||||
|
||||
public static <T> boolean isBorderWithin(double x, double z, int samples, double radius, double offset, BorderCheck<T> check)
|
||||
{
|
||||
T center = check.get(x, z);
|
||||
double ajump = Math.toRadians(360D / (double) samples) + offset;
|
||||
|
||||
for(int i = 0; i < samples; i++)
|
||||
{
|
||||
double dx = M.sin((float) ajump * i) * radius;
|
||||
double dz = M.cos((float) ajump * i) * radius;
|
||||
|
||||
if(!center.equals(check.get(x + dx, z + dz)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
82
src/main/java/com/volmit/iris/util/ByteArrayTag.java
Normal file
82
src/main/java/com/volmit/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/com/volmit/iris/util/ByteTag.java
Normal file
74
src/main/java/com/volmit/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;
|
||||
}
|
||||
|
||||
}
|
||||
49
src/main/java/com/volmit/iris/util/CDou.java
Normal file
49
src/main/java/com/volmit/iris/util/CDou.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
public class CDou
|
||||
{
|
||||
private double number;
|
||||
private double max;
|
||||
|
||||
public CDou(double max)
|
||||
{
|
||||
number = 0;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public CDou set(double n)
|
||||
{
|
||||
number = n;
|
||||
circ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public CDou add(double a)
|
||||
{
|
||||
number += a;
|
||||
circ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public CDou sub(double a)
|
||||
{
|
||||
number -= a;
|
||||
circ();
|
||||
return this;
|
||||
}
|
||||
|
||||
public double get()
|
||||
{
|
||||
return number;
|
||||
}
|
||||
|
||||
public void circ()
|
||||
{
|
||||
if(number < 0)
|
||||
{
|
||||
number = max - (Math.abs(number) > max ? max : Math.abs(number));
|
||||
}
|
||||
|
||||
number = number % (max);
|
||||
}
|
||||
}
|
||||
225
src/main/java/com/volmit/iris/util/CNG.java
Normal file
225
src/main/java/com/volmit/iris/util/CNG.java
Normal file
@@ -0,0 +1,225 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import ninja.bytecode.shuriken.collections.KList;
|
||||
|
||||
public class CNG
|
||||
{
|
||||
public static long hits = 0;
|
||||
public static long creates = 0;
|
||||
public static final NoiseInjector ADD = (s, v) -> new double[] {s + v, 1};
|
||||
public static final NoiseInjector SRC_SUBTRACT = (s, v) -> new double[] {s - v < 0 ? 0 : s - v, -1};
|
||||
public static final NoiseInjector DST_SUBTRACT = (s, v) -> new double[] {v - s < 0 ? 0 : s - v, -1};
|
||||
public static final NoiseInjector MULTIPLY = (s, v) -> new double[] {s * v, 0};
|
||||
public static final NoiseInjector MAX = (s, v) -> new double[] {Math.max(s, v), 0};
|
||||
public static final NoiseInjector MIN = (s, v) -> new double[] {Math.min(s, v), 0};
|
||||
public static final NoiseInjector SRC_MOD = (s, v) -> new double[] {s % v, 0};
|
||||
public static final NoiseInjector SRC_POW = (s, v) -> new double[] {Math.pow(s, v), 0};
|
||||
public static final NoiseInjector DST_MOD = (s, v) -> new double[] {v % s, 0};
|
||||
public static final NoiseInjector DST_POW = (s, v) -> new double[] {Math.pow(v, s), 0};
|
||||
private double freq;
|
||||
private double amp;
|
||||
private double scale;
|
||||
private double fscale;
|
||||
private KList<CNG> children;
|
||||
private CNG fracture;
|
||||
private SNG generator;
|
||||
private final double opacity;
|
||||
private NoiseInjector injector;
|
||||
private RNG rng;
|
||||
private int oct;
|
||||
private double patch;
|
||||
private double up;
|
||||
private double down;
|
||||
private double power;
|
||||
|
||||
public static CNG signature(RNG rng)
|
||||
{
|
||||
//@builder
|
||||
return new CNG(rng.nextParallelRNG(17), 1D, 3)
|
||||
.scale(0.012)
|
||||
.fractureWith(new CNG(rng.nextParallelRNG(18), 1, 2)
|
||||
.scale(0.018)
|
||||
.child(new CNG(rng.nextParallelRNG(19), 1, 2)
|
||||
.scale(0.1))
|
||||
.fractureWith(new CNG(rng.nextParallelRNG(20), 1, 2)
|
||||
.scale(0.15), 24), 44).down(0.3).patch(2.5);
|
||||
//@done
|
||||
}
|
||||
|
||||
public CNG(RNG random)
|
||||
{
|
||||
this(random, 1);
|
||||
}
|
||||
|
||||
public CNG(RNG random, int octaves)
|
||||
{
|
||||
this(random, 1D, octaves);
|
||||
}
|
||||
|
||||
public CNG(RNG random, double opacity, int octaves)
|
||||
{
|
||||
creates += octaves;
|
||||
this.oct = octaves;
|
||||
this.rng = random;
|
||||
power = 1;
|
||||
freq = 1;
|
||||
amp = 1;
|
||||
scale = 1;
|
||||
patch = 1;
|
||||
fscale = 1;
|
||||
fracture = null;
|
||||
generator = new SNG(random);
|
||||
this.opacity = opacity;
|
||||
this.injector = ADD;
|
||||
}
|
||||
|
||||
public CNG child(CNG c)
|
||||
{
|
||||
if(children == null)
|
||||
{
|
||||
children = new KList<>();
|
||||
}
|
||||
|
||||
children.add(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public RNG nextRNG()
|
||||
{
|
||||
return getRNG().nextRNG();
|
||||
}
|
||||
|
||||
public RNG getRNG()
|
||||
{
|
||||
return rng;
|
||||
}
|
||||
|
||||
public CNG fractureWith(CNG c, double scale)
|
||||
{
|
||||
fracture = c;
|
||||
fscale = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG scale(double c)
|
||||
{
|
||||
scale = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG freq(double c)
|
||||
{
|
||||
freq = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG amp(double c)
|
||||
{
|
||||
amp = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG patch(double c)
|
||||
{
|
||||
patch = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG up(double c)
|
||||
{
|
||||
up = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG down(double c)
|
||||
{
|
||||
down = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG injectWith(NoiseInjector i)
|
||||
{
|
||||
injector = i;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int fit(int min, int max, double... dim)
|
||||
{
|
||||
if(min == max)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
|
||||
double noise = noise(dim);
|
||||
|
||||
return (int) Math.round(IrisInterpolation.lerp(min, max, noise));
|
||||
}
|
||||
|
||||
public int fitDouble(double min, double max, double... dim)
|
||||
{
|
||||
if(min == max)
|
||||
{
|
||||
return (int) Math.round(min);
|
||||
}
|
||||
|
||||
double noise = noise(dim);
|
||||
|
||||
return (int) Math.round(IrisInterpolation.lerp(min, max, noise));
|
||||
}
|
||||
|
||||
public double fitDoubleD(double min, double max, double... dim)
|
||||
{
|
||||
if(min == max)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
|
||||
double noise = noise(dim);
|
||||
|
||||
return IrisInterpolation.lerp(min, max, noise);
|
||||
}
|
||||
|
||||
public int fitDoubleExponent(double min, double max, double exponent, double... dim)
|
||||
{
|
||||
if(min == max)
|
||||
{
|
||||
return (int) Math.round(min);
|
||||
}
|
||||
|
||||
double noise = noise(dim);
|
||||
|
||||
return (int) Math.round(IrisInterpolation.lerp(min, max, exponent == 1 ? noise : Math.pow(noise, exponent)));
|
||||
}
|
||||
|
||||
public double noise(double... dim)
|
||||
{
|
||||
double f = fracture != null ? (fracture.noise(dim) - 0.5) * fscale : 0D;
|
||||
double x = dim.length > 0 ? dim[0] + f : 0D;
|
||||
double y = dim.length > 1 ? dim[1] - f : 0D;
|
||||
double z = dim.length > 2 ? dim[2] + f : 0D;
|
||||
double n = ((generator.noise(x * scale, y * scale, z * scale, oct, freq, amp, true) / 2D) + 0.5D) * opacity;
|
||||
n = power != 1D ? Math.pow(n, power) : n;
|
||||
double m = 1;
|
||||
hits += oct;
|
||||
if(children == null)
|
||||
{
|
||||
return (n - down + up) * patch;
|
||||
}
|
||||
|
||||
for(CNG i : children)
|
||||
{
|
||||
double[] r = injector.combine(n, i.noise(dim));
|
||||
n = r[0];
|
||||
m += r[1];
|
||||
}
|
||||
|
||||
return ((n / m) - down + up) * patch;
|
||||
}
|
||||
|
||||
public CNG pow(double power)
|
||||
{
|
||||
this.power = power;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
6
src/main/java/com/volmit/iris/util/CallbackCV.java
Normal file
6
src/main/java/com/volmit/iris/util/CallbackCV.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
public interface Callback<T>
|
||||
{
|
||||
public void run(T t);
|
||||
}
|
||||
16
src/main/java/com/volmit/iris/util/CaveResult.java
Normal file
16
src/main/java/com/volmit/iris/util/CaveResult.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CaveResult
|
||||
{
|
||||
private int floor;
|
||||
private int ceiling;
|
||||
|
||||
public CaveResult(int floor, int ceiling)
|
||||
{
|
||||
this.floor = floor;
|
||||
this.ceiling = ceiling;
|
||||
}
|
||||
}
|
||||
59
src/main/java/com/volmit/iris/util/CellGenerator.java
Normal file
59
src/main/java/com/volmit/iris/util/CellGenerator.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import ninja.bytecode.iris.util.FastNoise.CellularDistanceFunction;
|
||||
import ninja.bytecode.iris.util.FastNoise.CellularReturnType;
|
||||
import ninja.bytecode.iris.util.FastNoise.NoiseType;
|
||||
|
||||
public class CellGenerator
|
||||
{
|
||||
private FastNoise fn;
|
||||
private FastNoise fd;
|
||||
private CNG cng;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double cellScale;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double shuffle;
|
||||
|
||||
public CellGenerator(RNG rng)
|
||||
{
|
||||
shuffle = 128;
|
||||
cellScale = 0.73;
|
||||
cng = CNG.signature(rng.nextParallelRNG(3204));
|
||||
RNG rx = rng.nextParallelRNG(8735652);
|
||||
int s = rx.nextInt();
|
||||
fn = new FastNoise(s);
|
||||
fn.SetNoiseType(NoiseType.Cellular);
|
||||
fn.SetCellularReturnType(CellularReturnType.CellValue);
|
||||
fn.SetCellularDistanceFunction(CellularDistanceFunction.Natural);
|
||||
fd = new FastNoise(s);
|
||||
fd.SetNoiseType(NoiseType.Cellular);
|
||||
fd.SetCellularReturnType(CellularReturnType.Distance2Sub);
|
||||
fd.SetCellularDistanceFunction(CellularDistanceFunction.Natural);
|
||||
}
|
||||
|
||||
public float getDistance(double x, double z)
|
||||
{
|
||||
return ((fd.GetCellular((float) ((x * cellScale) + (cng.noise(x, z) * shuffle)), (float) ((z * cellScale) + (cng.noise(z, x) * shuffle)))) + 1f) / 2f;
|
||||
}
|
||||
|
||||
public float getDistance(double x, double y, double z)
|
||||
{
|
||||
return ((fd.GetCellular((float) ((x * cellScale) + (cng.noise(x, y, z) * shuffle)), (float) ((y * cellScale) + (cng.noise(x, y, z) * shuffle)), (float) ((z * cellScale) + (cng.noise(z, y, x) * shuffle)))) + 1f) / 2f;
|
||||
}
|
||||
|
||||
public float getValue(double x, double z, int possibilities)
|
||||
{
|
||||
return ((fn.GetCellular((float) ((x * cellScale) + (cng.noise(x, z) * shuffle)), (float) ((z * cellScale) + (cng.noise(z, x) * shuffle))) + 1f) / 2f) * (possibilities - 1);
|
||||
}
|
||||
|
||||
public int getIndex(double x, double z, int possibilities)
|
||||
{
|
||||
return (int) Math.round(getValue(x, z, possibilities));
|
||||
}
|
||||
}
|
||||
29
src/main/java/com/volmit/iris/util/ChronoLatch.java
Normal file
29
src/main/java/com/volmit/iris/util/ChronoLatch.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
public class ChronoLatch
|
||||
{
|
||||
private long interval;
|
||||
private long since;
|
||||
|
||||
public ChronoLatch(long interval, boolean openedAtStart)
|
||||
{
|
||||
this.interval = interval;
|
||||
since = System.currentTimeMillis() - (openedAtStart ? interval * 2 : 0);
|
||||
}
|
||||
|
||||
public ChronoLatch(long interval)
|
||||
{
|
||||
this(interval, true);
|
||||
}
|
||||
|
||||
public boolean flip()
|
||||
{
|
||||
if(System.currentTimeMillis() - since > interval)
|
||||
{
|
||||
since = System.currentTimeMillis();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
16
src/main/java/com/volmit/iris/util/ChunkPosition.java
Normal file
16
src/main/java/com/volmit/iris/util/ChunkPosition.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ChunkPosition
|
||||
{
|
||||
private int x;
|
||||
private int z;
|
||||
|
||||
public ChunkPosition(int x, int z)
|
||||
{
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
83
src/main/java/com/volmit/iris/util/CompoundTag.java
Normal file
83
src/main/java/com/volmit/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();
|
||||
}
|
||||
|
||||
}
|
||||
7
src/main/java/com/volmit/iris/util/Consumer2.java
Normal file
7
src/main/java/com/volmit/iris/util/Consumer2.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Consumer2<A, B>
|
||||
{
|
||||
public void accept(A a, B b);
|
||||
}
|
||||
7
src/main/java/com/volmit/iris/util/Consumer3.java
Normal file
7
src/main/java/com/volmit/iris/util/Consumer3.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Consumer3<A, B, C>
|
||||
{
|
||||
public void accept(A a, B b, C c);
|
||||
}
|
||||
33
src/main/java/com/volmit/iris/util/Contained.java
Normal file
33
src/main/java/com/volmit/iris/util/Contained.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Contained<T>
|
||||
{
|
||||
private T t;
|
||||
|
||||
public Contained(T t)
|
||||
{
|
||||
set(t);
|
||||
}
|
||||
|
||||
public Contained()
|
||||
{
|
||||
this(null);
|
||||
}
|
||||
|
||||
public void mod(Function<T, T> x)
|
||||
{
|
||||
set(x.apply(t));
|
||||
}
|
||||
|
||||
public T get()
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
public void set(T t)
|
||||
{
|
||||
this.t = t;
|
||||
}
|
||||
}
|
||||
884
src/main/java/com/volmit/iris/util/Cuboid.java
Normal file
884
src/main/java/com/volmit/iris/util/Cuboid.java
Normal file
@@ -0,0 +1,884 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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 ninja.bytecode.shuriken.collections.KList;
|
||||
|
||||
/**
|
||||
* Cuboids
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializable
|
||||
{
|
||||
protected final String worldName;
|
||||
protected int x1, y1, z1;
|
||||
protected int x2, y2, z2;
|
||||
|
||||
/**
|
||||
* Construct a Cuboid given two Location objects which represent any two corners
|
||||
* of the Cuboid.
|
||||
*
|
||||
* @param l1
|
||||
* one of the corners
|
||||
* @param l2
|
||||
* the other corner
|
||||
*/
|
||||
public Cuboid(Location l1, Location l2)
|
||||
{
|
||||
if(!l1.getWorld().equals(l2.getWorld()))
|
||||
{
|
||||
throw new IllegalArgumentException("locations must be on the same world");
|
||||
}
|
||||
|
||||
worldName = l1.getWorld().getName();
|
||||
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());
|
||||
}
|
||||
|
||||
public KList<Entity> getEntities()
|
||||
{
|
||||
KList<Entity> en = new KList<Entity>();
|
||||
|
||||
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.
|
||||
*
|
||||
* @param l1
|
||||
* location of the Cuboid
|
||||
*/
|
||||
public Cuboid(Location l1)
|
||||
{
|
||||
this(l1, l1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param other
|
||||
* the Cuboid to copy
|
||||
*/
|
||||
public Cuboid(Cuboid other)
|
||||
{
|
||||
this(other.getWorld().getName(), other.x1, other.y1, other.z1, other.x2, other.y2, other.z2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Cuboid in the given World and xyz co-ordinates
|
||||
*
|
||||
* @param world
|
||||
* the Cuboid's world
|
||||
* @param x1
|
||||
* X co-ordinate of corner 1
|
||||
* @param y1
|
||||
* Y co-ordinate of corner 1
|
||||
* @param z1
|
||||
* Z co-ordinate of corner 1
|
||||
* @param x2
|
||||
* X co-ordinate of corner 2
|
||||
* @param y2
|
||||
* Y co-ordinate of corner 2
|
||||
* @param z2
|
||||
* Z co-ordinate of corner 2
|
||||
*/
|
||||
public Cuboid(World world, int x1, int y1, int z1, int x2, int y2, int z2)
|
||||
{
|
||||
this.worldName = world.getName();
|
||||
this.x1 = Math.min(x1, x2);
|
||||
this.x2 = Math.max(x1, x2);
|
||||
this.y1 = Math.min(y1, y2);
|
||||
this.y2 = Math.max(y1, y2);
|
||||
this.z1 = Math.min(z1, z2);
|
||||
this.z2 = Math.max(z1, z2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Cuboid in the given world name and xyz co-ordinates.
|
||||
*
|
||||
* @param worldName
|
||||
* the Cuboid's world name
|
||||
* @param x1
|
||||
* X co-ordinate of corner 1
|
||||
* @param y1
|
||||
* Y co-ordinate of corner 1
|
||||
* @param z1
|
||||
* Z co-ordinate of corner 1
|
||||
* @param x2
|
||||
* X co-ordinate of corner 2
|
||||
* @param y2
|
||||
* Y co-ordinate of corner 2
|
||||
* @param z2
|
||||
* Z co-ordinate of corner 2
|
||||
*/
|
||||
private Cuboid(String worldName, int x1, int y1, int z1, int x2, int y2, int z2)
|
||||
{
|
||||
this.worldName = worldName;
|
||||
this.x1 = Math.min(x1, x2);
|
||||
this.x2 = Math.max(x1, x2);
|
||||
this.y1 = Math.min(y1, y2);
|
||||
this.y2 = Math.max(y1, y2);
|
||||
this.z1 = Math.min(z1, z2);
|
||||
this.z2 = Math.max(z1, z2);
|
||||
}
|
||||
|
||||
public Cuboid(Map<String, Object> map)
|
||||
{
|
||||
worldName = (String) map.get("worldName");
|
||||
x1 = (Integer) map.get("x1");
|
||||
x2 = (Integer) map.get("x2");
|
||||
y1 = (Integer) map.get("y1");
|
||||
y2 = (Integer) map.get("y2");
|
||||
z1 = (Integer) map.get("z1");
|
||||
z2 = (Integer) map.get("z2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize()
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("worldName", worldName);
|
||||
map.put("x1", x1);
|
||||
map.put("y1", y1);
|
||||
map.put("z1", z1);
|
||||
map.put("x2", x2);
|
||||
map.put("y2", y2);
|
||||
map.put("z2", z2);
|
||||
return map;
|
||||
}
|
||||
|
||||
public Cuboid flatten(int level)
|
||||
{
|
||||
return new Cuboid(getWorld(), x1, level, z1, x2, level, z2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Location of the lower northeast corner of the Cuboid (minimum XYZ
|
||||
* co-ordinates).
|
||||
*
|
||||
* @return Location of the lower northeast corner
|
||||
*/
|
||||
public Location getLowerNE()
|
||||
{
|
||||
return new Location(getWorld(), x1, y1, z1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Location of the upper southwest corner of the Cuboid (maximum XYZ
|
||||
* co-ordinates).
|
||||
*
|
||||
* @return Location of the upper southwest corner
|
||||
*/
|
||||
public Location getUpperSW()
|
||||
{
|
||||
return new Location(getWorld(), x2, y2, z2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the the centre of the Cuboid
|
||||
*
|
||||
* @return Location at the centre of the Cuboid
|
||||
*/
|
||||
public Location getCenter()
|
||||
{
|
||||
int x1 = getUpperX() + 1;
|
||||
int y1 = getUpperY() + 1;
|
||||
int z1 = getUpperZ() + 1;
|
||||
return new Location(getWorld(), getLowerX() + (x1 - getLowerX()) / 2.0, getLowerY() + (y1 - getLowerY()) / 2.0, getLowerZ() + (z1 - getLowerZ()) / 2.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Cuboid's world.
|
||||
*
|
||||
* @return the World object representing this Cuboid's world
|
||||
* @throws IllegalStateException
|
||||
* if the world is not loaded
|
||||
*/
|
||||
public World getWorld()
|
||||
{
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if(world == null)
|
||||
{
|
||||
throw new IllegalStateException("world '" + worldName + "' is not loaded");
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of this Cuboid along the X axis
|
||||
*
|
||||
* @return Size of Cuboid along the X axis
|
||||
*/
|
||||
public int getSizeX()
|
||||
{
|
||||
return (x2 - x1) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of this Cuboid along the Y axis
|
||||
*
|
||||
* @return Size of Cuboid along the Y axis
|
||||
*/
|
||||
public int getSizeY()
|
||||
{
|
||||
return (y2 - y1) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of this Cuboid along the Z axis
|
||||
*
|
||||
* @return Size of Cuboid along the Z axis
|
||||
*/
|
||||
public int getSizeZ()
|
||||
{
|
||||
return (z2 - z1) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cuboid dimensions
|
||||
*
|
||||
* @return the dimensions
|
||||
*/
|
||||
public Dimension getDimension()
|
||||
{
|
||||
return new Dimension(getSizeX(), getSizeY(), getSizeZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum X co-ordinate of this Cuboid
|
||||
*
|
||||
* @return the minimum X co-ordinate
|
||||
*/
|
||||
public int getLowerX()
|
||||
{
|
||||
return x1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum Y co-ordinate of this Cuboid
|
||||
*
|
||||
* @return the minimum Y co-ordinate
|
||||
*/
|
||||
public int getLowerY()
|
||||
{
|
||||
return y1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum Z co-ordinate of this Cuboid
|
||||
*
|
||||
* @return the minimum Z co-ordinate
|
||||
*/
|
||||
public int getLowerZ()
|
||||
{
|
||||
return z1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum X co-ordinate of this Cuboid
|
||||
*
|
||||
* @return the maximum X co-ordinate
|
||||
*/
|
||||
public int getUpperX()
|
||||
{
|
||||
return x2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum Y co-ordinate of this Cuboid
|
||||
*
|
||||
* @return the maximum Y co-ordinate
|
||||
*/
|
||||
public int getUpperY()
|
||||
{
|
||||
return y2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum Z co-ordinate of this Cuboid
|
||||
*
|
||||
* @return the maximum Z co-ordinate
|
||||
*/
|
||||
public int getUpperZ()
|
||||
{
|
||||
return z2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Blocks at the eight corners of the Cuboid.
|
||||
*
|
||||
* @return array of Block objects representing the Cuboid corners
|
||||
*/
|
||||
public Block[] corners()
|
||||
{
|
||||
Block[] res = new Block[8];
|
||||
World w = getWorld();
|
||||
res[0] = w.getBlockAt(x1, y1, z1);
|
||||
res[1] = w.getBlockAt(x1, y1, z2);
|
||||
res[2] = w.getBlockAt(x1, y2, z1);
|
||||
res[3] = w.getBlockAt(x1, y2, z2);
|
||||
res[4] = w.getBlockAt(x2, y1, z1);
|
||||
res[5] = w.getBlockAt(x2, y1, z2);
|
||||
res[6] = w.getBlockAt(x2, y2, z1);
|
||||
res[7] = w.getBlockAt(x2, y2, z2);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand the Cuboid in the given direction by the given amount. Negative
|
||||
* amounts will shrink the Cuboid in the given direction. Shrinking a cuboid's
|
||||
* face past the opposite face is not an error and will return a valid Cuboid.
|
||||
*
|
||||
* @param dir
|
||||
* the direction in which to expand
|
||||
* @param amount
|
||||
* the number of blocks by which to expand
|
||||
* @return a new Cuboid expanded by the given direction and amount
|
||||
*/
|
||||
public Cuboid expand(CuboidDirection dir, int amount)
|
||||
{
|
||||
switch(dir)
|
||||
{
|
||||
case North:
|
||||
return new Cuboid(worldName, x1 - amount, y1, z1, x2, y2, z2);
|
||||
case South:
|
||||
return new Cuboid(worldName, x1, y1, z1, x2 + amount, y2, z2);
|
||||
case East:
|
||||
return new Cuboid(worldName, x1, y1, z1 - amount, x2, y2, z2);
|
||||
case West:
|
||||
return new Cuboid(worldName, x1, y1, z1, x2, y2, z2 + amount);
|
||||
case Down:
|
||||
return new Cuboid(worldName, x1, y1 - amount, z1, x2, y2, z2);
|
||||
case Up:
|
||||
return new Cuboid(worldName, x1, y1, z1, x2, y2 + amount, z2);
|
||||
default:
|
||||
throw new IllegalArgumentException("invalid direction " + dir);
|
||||
}
|
||||
}
|
||||
|
||||
public Cuboid expand(Direction dir, int amount)
|
||||
{
|
||||
int ax = dir.toVector().getBlockX() == 1 ? amount : 0;
|
||||
int sx = dir.toVector().getBlockX() == -1 ? -amount : 0;
|
||||
int ay = dir.toVector().getBlockY() == 1 ? amount : 0;
|
||||
int sy = dir.toVector().getBlockY() == -1 ? -amount : 0;
|
||||
int az = dir.toVector().getBlockZ() == 1 ? amount : 0;
|
||||
int sz = dir.toVector().getBlockZ() == -1 ? -amount : 0;
|
||||
return new Cuboid(worldName, x1 + sx, y1 + sy, z1 + sz, x2 + ax, y2 + ay, z2 + az);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift the Cuboid in the given direction by the given amount.
|
||||
*
|
||||
* @param dir
|
||||
* the direction in which to shift
|
||||
* @param amount
|
||||
* the number of blocks by which to shift
|
||||
* @return a new Cuboid shifted by the given direction and amount
|
||||
*/
|
||||
public Cuboid shift(CuboidDirection dir, int amount)
|
||||
{
|
||||
return expand(dir, amount).expand(dir.opposite(), -amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outset (grow) the Cuboid in the given direction by the given amount.
|
||||
*
|
||||
* @param dir
|
||||
* the direction in which to outset (must be Horizontal, Vertical, or
|
||||
* Both)
|
||||
* @param amount
|
||||
* the number of blocks by which to outset
|
||||
* @return a new Cuboid outset by the given direction and amount
|
||||
*/
|
||||
public Cuboid outset(CuboidDirection dir, int amount)
|
||||
{
|
||||
Cuboid c;
|
||||
switch(dir)
|
||||
{
|
||||
case Horizontal:
|
||||
c = expand(CuboidDirection.North, amount).expand(CuboidDirection.South, amount).expand(CuboidDirection.East, amount).expand(CuboidDirection.West, amount);
|
||||
break;
|
||||
case Vertical:
|
||||
c = expand(CuboidDirection.Down, amount).expand(CuboidDirection.Up, amount);
|
||||
break;
|
||||
case Both:
|
||||
c = outset(CuboidDirection.Horizontal, amount).outset(CuboidDirection.Vertical, amount);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("invalid direction " + dir);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inset (shrink) the Cuboid in the given direction by the given amount.
|
||||
* Equivalent to calling outset() with a negative amount.
|
||||
*
|
||||
* @param dir
|
||||
* the direction in which to inset (must be Horizontal, Vertical, or
|
||||
* Both)
|
||||
* @param amount
|
||||
* the number of blocks by which to inset
|
||||
* @return a new Cuboid inset by the given direction and amount
|
||||
*/
|
||||
public Cuboid inset(CuboidDirection dir, int amount)
|
||||
{
|
||||
return outset(dir, -amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the point at (x,y,z) is contained within this Cuboid.
|
||||
*
|
||||
* @param x
|
||||
* the X co-ordinate
|
||||
* @param y
|
||||
* the Y co-ordinate
|
||||
* @param z
|
||||
* the Z co-ordinate
|
||||
* @return true if the given point is within this Cuboid, false otherwise
|
||||
*/
|
||||
public boolean contains(int x, int y, int z)
|
||||
{
|
||||
return x >= x1 && x <= x2 && y >= y1 && y <= y2 && z >= z1 && z <= z2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given Block is contained within this Cuboid.
|
||||
*
|
||||
* @param b
|
||||
* the Block to check for
|
||||
* @return true if the Block is within this Cuboid, false otherwise
|
||||
*/
|
||||
public boolean contains(Block b)
|
||||
{
|
||||
return contains(b.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given Location is contained within this Cuboid.
|
||||
*
|
||||
* @param l
|
||||
* the Location to check for
|
||||
* @return true if the Location is within this Cuboid, false otherwise
|
||||
*/
|
||||
public boolean contains(Location l)
|
||||
{
|
||||
return worldName.equals(l.getWorld().getName()) && contains(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the volume of this Cuboid.
|
||||
*
|
||||
* @return the Cuboid volume, in blocks
|
||||
*/
|
||||
public int volume()
|
||||
{
|
||||
return getSizeX() * getSizeY() * getSizeZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the average light level of all empty (air) blocks in the Cuboid. Returns
|
||||
* 0 if there are no empty blocks.
|
||||
*
|
||||
* @return the average light level of this Cuboid
|
||||
*/
|
||||
public byte averageLightLevel()
|
||||
{
|
||||
long total = 0;
|
||||
int n = 0;
|
||||
for(Block b : this)
|
||||
{
|
||||
if(b.isEmpty())
|
||||
{
|
||||
total += b.getLightLevel();
|
||||
++n;
|
||||
}
|
||||
}
|
||||
return n > 0 ? (byte) (total / n) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contract the Cuboid, returning a Cuboid with any air around the edges
|
||||
* removed, just large enough to include all non-air blocks.
|
||||
*
|
||||
* @return a new Cuboid with no external air blocks
|
||||
*/
|
||||
public Cuboid contract()
|
||||
{
|
||||
return this.contract(CuboidDirection.Down).contract(CuboidDirection.South).contract(CuboidDirection.East).contract(CuboidDirection.Up).contract(CuboidDirection.North).contract(CuboidDirection.West);
|
||||
}
|
||||
|
||||
/**
|
||||
* Contract the Cuboid in the given direction, returning a new Cuboid which has
|
||||
* no exterior empty space. E.g. a direction of Down will push the top face
|
||||
* downwards as much as possible.
|
||||
*
|
||||
* @param dir
|
||||
* the direction in which to contract
|
||||
* @return a new Cuboid contracted in the given direction
|
||||
*/
|
||||
public Cuboid contract(CuboidDirection dir)
|
||||
{
|
||||
Cuboid face = getFace(dir.opposite());
|
||||
switch(dir)
|
||||
{
|
||||
case Down:
|
||||
while(face.containsOnly(Material.AIR) && face.getLowerY() > this.getLowerY())
|
||||
{
|
||||
face = face.shift(CuboidDirection.Down, 1);
|
||||
}
|
||||
return new Cuboid(worldName, x1, y1, z1, x2, face.getUpperY(), z2);
|
||||
case Up:
|
||||
while(face.containsOnly(Material.AIR) && face.getUpperY() < this.getUpperY())
|
||||
{
|
||||
face = face.shift(CuboidDirection.Up, 1);
|
||||
}
|
||||
return new Cuboid(worldName, x1, face.getLowerY(), z1, x2, y2, z2);
|
||||
case North:
|
||||
while(face.containsOnly(Material.AIR) && face.getLowerX() > this.getLowerX())
|
||||
{
|
||||
face = face.shift(CuboidDirection.North, 1);
|
||||
}
|
||||
return new Cuboid(worldName, x1, y1, z1, face.getUpperX(), y2, z2);
|
||||
case South:
|
||||
while(face.containsOnly(Material.AIR) && face.getUpperX() < this.getUpperX())
|
||||
{
|
||||
face = face.shift(CuboidDirection.South, 1);
|
||||
}
|
||||
return new Cuboid(worldName, face.getLowerX(), y1, z1, x2, y2, z2);
|
||||
case East:
|
||||
while(face.containsOnly(Material.AIR) && face.getLowerZ() > this.getLowerZ())
|
||||
{
|
||||
face = face.shift(CuboidDirection.East, 1);
|
||||
}
|
||||
return new Cuboid(worldName, x1, y1, z1, x2, y2, face.getUpperZ());
|
||||
case West:
|
||||
while(face.containsOnly(Material.AIR) && face.getUpperZ() < this.getUpperZ())
|
||||
{
|
||||
face = face.shift(CuboidDirection.West, 1);
|
||||
}
|
||||
return new Cuboid(worldName, x1, y1, face.getLowerZ(), x2, y2, z2);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid direction " + dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Cuboid representing the face of this Cuboid. The resulting Cuboid
|
||||
* will be one block thick in the axis perpendicular to the requested face.
|
||||
*
|
||||
* @param dir
|
||||
* which face of the Cuboid to get
|
||||
* @return the Cuboid representing this Cuboid's requested face
|
||||
*/
|
||||
public Cuboid getFace(CuboidDirection dir)
|
||||
{
|
||||
switch(dir)
|
||||
{
|
||||
case Down:
|
||||
return new Cuboid(worldName, x1, y1, z1, x2, y1, z2);
|
||||
case Up:
|
||||
return new Cuboid(worldName, x1, y2, z1, x2, y2, z2);
|
||||
case North:
|
||||
return new Cuboid(worldName, x1, y1, z1, x1, y2, z2);
|
||||
case South:
|
||||
return new Cuboid(worldName, x2, y1, z1, x2, y2, z2);
|
||||
case East:
|
||||
return new Cuboid(worldName, x1, y1, z1, x2, y2, z1);
|
||||
case West:
|
||||
return new Cuboid(worldName, x1, y1, z2, x2, y2, z2);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid direction " + dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Cuboid contains only blocks of the given type
|
||||
*
|
||||
* @param material
|
||||
* the material to check for
|
||||
* @return true if this Cuboid contains only blocks of the given type
|
||||
*/
|
||||
public boolean containsOnly(Material material)
|
||||
{
|
||||
for(Block b : this)
|
||||
{
|
||||
if(b.getType() != material)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Cuboid big enough to hold both this Cuboid and the given one.
|
||||
*
|
||||
* @param other
|
||||
* the other Cuboid to include
|
||||
* @return a new Cuboid large enough to hold this Cuboid and the given Cuboid
|
||||
*/
|
||||
public Cuboid getBoundingCuboid(Cuboid other)
|
||||
{
|
||||
if(other == null)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
int xMin = Math.min(getLowerX(), other.getLowerX());
|
||||
int yMin = Math.min(getLowerY(), other.getLowerY());
|
||||
int zMin = Math.min(getLowerZ(), other.getLowerZ());
|
||||
int xMax = Math.max(getUpperX(), other.getUpperX());
|
||||
int yMax = Math.max(getUpperY(), other.getUpperY());
|
||||
int zMax = Math.max(getUpperZ(), other.getUpperZ());
|
||||
|
||||
return new Cuboid(worldName, xMin, yMin, zMin, xMax, yMax, zMax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block relative to the lower NE point of the Cuboid.
|
||||
*
|
||||
* @param x
|
||||
* the X co-ordinate
|
||||
* @param y
|
||||
* the Y co-ordinate
|
||||
* @param z
|
||||
* the Z co-ordinate
|
||||
* @return the block at the given position
|
||||
*/
|
||||
public Block getRelativeBlock(int x, int y, int z)
|
||||
{
|
||||
return getWorld().getBlockAt(x1 + x, y1 + y, z1 + z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block relative to the lower NE point of the Cuboid in the given World.
|
||||
* This version of getRelativeBlock() should be used if being called many times,
|
||||
* to avoid excessive calls to getWorld().
|
||||
*
|
||||
* @param w
|
||||
* the World
|
||||
* @param x
|
||||
* the X co-ordinate
|
||||
* @param y
|
||||
* the Y co-ordinate
|
||||
* @param z
|
||||
* the Z co-ordinate
|
||||
* @return the block at the given position
|
||||
*/
|
||||
public Block getRelativeBlock(World w, int x, int y, int z)
|
||||
{
|
||||
return w.getBlockAt(x1 + x, y1 + y, z1 + z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the chunks which are fully or partially contained in this
|
||||
* cuboid.
|
||||
*
|
||||
* @return a list of Chunk objects
|
||||
*/
|
||||
public List<Chunk> getChunks()
|
||||
{
|
||||
List<Chunk> res = new ArrayList<Chunk>();
|
||||
|
||||
World w = getWorld();
|
||||
int x1 = getLowerX() & ~0xf;
|
||||
int x2 = getUpperX() & ~0xf;
|
||||
int z1 = getLowerZ() & ~0xf;
|
||||
int z2 = getUpperZ() & ~0xf;
|
||||
for(int x = x1; x <= x2; x += 16)
|
||||
{
|
||||
for(int z = z1; z <= z2; z += 16)
|
||||
{
|
||||
res.add(w.getChunkAt(x >> 4, z >> 4));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all the blocks within the Cuboid to the given MaterialData, using a
|
||||
* MassBlockUpdate object for fast updates.
|
||||
*
|
||||
* @param mat
|
||||
* the MaterialData to set
|
||||
* @param mbu
|
||||
* the MassBlockUpdate object
|
||||
*/
|
||||
|
||||
/**
|
||||
* Reset the light level of all blocks within this Cuboid.
|
||||
*/
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Iterable#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Block> iterator()
|
||||
{
|
||||
return new CuboidIterator(getWorld(), x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
public Cuboid clone() throws CloneNotSupportedException
|
||||
{
|
||||
return new Cuboid(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Cuboid: " + worldName + "," + x1 + "," + y1 + "," + z1 + "=>" + x2 + "," + y2 + "," + z2;
|
||||
}
|
||||
|
||||
public class CuboidIterator implements Iterator<Block>
|
||||
{
|
||||
private World w;
|
||||
private int baseX, baseY, baseZ;
|
||||
private int x, y, z;
|
||||
private int sizeX, sizeY, sizeZ;
|
||||
|
||||
public CuboidIterator(World w, int x1, int y1, int z1, int x2, int y2, int z2)
|
||||
{
|
||||
this.w = w;
|
||||
baseX = x1;
|
||||
baseY = y1;
|
||||
baseZ = z1;
|
||||
sizeX = Math.abs(x2 - x1) + 1;
|
||||
sizeY = Math.abs(y2 - y1) + 1;
|
||||
sizeZ = Math.abs(z2 - z1) + 1;
|
||||
x = y = z = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return x < sizeX && y < sizeY && z < sizeZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block next()
|
||||
{
|
||||
Block b = w.getBlockAt(baseX + x, baseY + y, baseZ + z);
|
||||
if(++x >= sizeX)
|
||||
{
|
||||
x = 0;
|
||||
if(++y >= sizeY)
|
||||
{
|
||||
y = 0;
|
||||
++z;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
// nop
|
||||
}
|
||||
}
|
||||
|
||||
public enum CuboidDirection
|
||||
{
|
||||
|
||||
North,
|
||||
East,
|
||||
South,
|
||||
West,
|
||||
Up,
|
||||
Down,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
Both,
|
||||
Unknown;
|
||||
|
||||
public CuboidDirection opposite()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case North:
|
||||
return South;
|
||||
case East:
|
||||
return West;
|
||||
case South:
|
||||
return North;
|
||||
case West:
|
||||
return East;
|
||||
case Horizontal:
|
||||
return Vertical;
|
||||
case Vertical:
|
||||
return Horizontal;
|
||||
case Up:
|
||||
return Down;
|
||||
case Down:
|
||||
return Up;
|
||||
case Both:
|
||||
return Both;
|
||||
default:
|
||||
return Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
16
src/main/java/com/volmit/iris/util/CuboidException.java
Normal file
16
src/main/java/com/volmit/iris/util/CuboidException.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
/**
|
||||
* Represents a cuboid exception
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class CuboidException extends Exception
|
||||
{
|
||||
public CuboidException(String string)
|
||||
{
|
||||
super(string);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
20
src/main/java/com/volmit/iris/util/DOP.java
Normal file
20
src/main/java/com/volmit/iris/util/DOP.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public abstract class DOP
|
||||
{
|
||||
private String type;
|
||||
|
||||
public DOP(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public abstract Vector op(Vector v);
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
14
src/main/java/com/volmit/iris/util/Desc.java
Normal file
14
src/main/java/com/volmit/iris/util/Desc.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target({PARAMETER, TYPE, FIELD})
|
||||
public @interface Desc
|
||||
{
|
||||
String value();
|
||||
}
|
||||
86
src/main/java/com/volmit/iris/util/Dimension.java
Normal file
86
src/main/java/com/volmit/iris/util/Dimension.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
/**
|
||||
* Dimensions
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class Dimension
|
||||
{
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int depth;
|
||||
|
||||
/**
|
||||
* Make a dimension
|
||||
*
|
||||
* @param width
|
||||
* width of this (X)
|
||||
* @param height
|
||||
* the height (Y)
|
||||
* @param depth
|
||||
* the depth (Z)
|
||||
*/
|
||||
public Dimension(int width, int height, int depth)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a dimension
|
||||
*
|
||||
* @param width
|
||||
* width of this (X)
|
||||
* @param height
|
||||
* the height (Y)
|
||||
*/
|
||||
public Dimension(int width, int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the direction of the flat part of this dimension (null if no thin
|
||||
* face)
|
||||
*
|
||||
* @return the direction of the flat pane or null
|
||||
*/
|
||||
public DimensionFace getPane()
|
||||
{
|
||||
if(width == 1)
|
||||
{
|
||||
return DimensionFace.X;
|
||||
}
|
||||
|
||||
if(height == 1)
|
||||
{
|
||||
return DimensionFace.Y;
|
||||
}
|
||||
|
||||
if(depth == 1)
|
||||
{
|
||||
return DimensionFace.Z;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getDepth()
|
||||
{
|
||||
return depth;
|
||||
}
|
||||
}
|
||||
24
src/main/java/com/volmit/iris/util/DimensionFace.java
Normal file
24
src/main/java/com/volmit/iris/util/DimensionFace.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
/**
|
||||
* Represents a dimension (coordinates not worlds)
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public enum DimensionFace
|
||||
{
|
||||
/**
|
||||
* The X dimension (width)
|
||||
*/
|
||||
X,
|
||||
|
||||
/**
|
||||
* The Y dimension (height)
|
||||
*/
|
||||
Y,
|
||||
|
||||
/**
|
||||
* The Z dimension (depth)
|
||||
*/
|
||||
Z
|
||||
}
|
||||
535
src/main/java/com/volmit/iris/util/Direction.java
Normal file
535
src/main/java/com/volmit/iris/util/Direction.java
Normal file
@@ -0,0 +1,535 @@
|
||||
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import ninja.bytecode.iris.util.Cuboid.CuboidDirection;
|
||||
import ninja.bytecode.shuriken.collections.KList;
|
||||
import ninja.bytecode.shuriken.collections.KMap;
|
||||
|
||||
/**
|
||||
* Directions
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public enum Direction
|
||||
{
|
||||
U(0, 1, 0, CuboidDirection.Up),
|
||||
D(0, -1, 0, CuboidDirection.Down),
|
||||
N(0, 0, -1, CuboidDirection.North),
|
||||
S(0, 0, 1, CuboidDirection.South),
|
||||
E(1, 0, 0, CuboidDirection.East),
|
||||
W(-1, 0, 0, CuboidDirection.West);
|
||||
|
||||
private static KMap<GBiset<Direction, Direction>, DOP> permute = null;
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private CuboidDirection f;
|
||||
|
||||
public static Direction getDirection(BlockFace f)
|
||||
{
|
||||
switch(f)
|
||||
{
|
||||
case DOWN:
|
||||
return D;
|
||||
case EAST:
|
||||
return E;
|
||||
case EAST_NORTH_EAST:
|
||||
return E;
|
||||
case EAST_SOUTH_EAST:
|
||||
return E;
|
||||
case NORTH:
|
||||
return N;
|
||||
case NORTH_EAST:
|
||||
return N;
|
||||
case NORTH_NORTH_EAST:
|
||||
return N;
|
||||
case NORTH_NORTH_WEST:
|
||||
return N;
|
||||
case NORTH_WEST:
|
||||
return N;
|
||||
case SELF:
|
||||
return U;
|
||||
case SOUTH:
|
||||
return S;
|
||||
case SOUTH_EAST:
|
||||
return S;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return S;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return S;
|
||||
case SOUTH_WEST:
|
||||
return S;
|
||||
case UP:
|
||||
return U;
|
||||
case WEST:
|
||||
return W;
|
||||
case WEST_NORTH_WEST:
|
||||
return W;
|
||||
case WEST_SOUTH_WEST:
|
||||
return W;
|
||||
}
|
||||
|
||||
return D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case D:
|
||||
return "Down";
|
||||
case E:
|
||||
return "East";
|
||||
case N:
|
||||
return "North";
|
||||
case S:
|
||||
return "South";
|
||||
case U:
|
||||
return "Up";
|
||||
case W:
|
||||
return "West";
|
||||
}
|
||||
|
||||
return "?";
|
||||
}
|
||||
|
||||
public boolean isVertical()
|
||||
{
|
||||
return equals(D) || equals(U);
|
||||
}
|
||||
|
||||
public static Direction closest(Vector v)
|
||||
{
|
||||
double m = Double.MAX_VALUE;
|
||||
Direction s = null;
|
||||
|
||||
for(Direction i : values())
|
||||
{
|
||||
Vector x = i.toVector();
|
||||
double g = x.dot(v);
|
||||
|
||||
if(g < m)
|
||||
{
|
||||
m = g;
|
||||
s = i;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static Direction closest(Vector v, Direction... d)
|
||||
{
|
||||
double m = Double.MAX_VALUE;
|
||||
Direction s = null;
|
||||
|
||||
for(Direction i : d)
|
||||
{
|
||||
Vector x = i.toVector();
|
||||
double g = x.distance(v);
|
||||
|
||||
if(g < m)
|
||||
{
|
||||
m = g;
|
||||
s = i;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static Direction closest(Vector v, KList<Direction> d)
|
||||
{
|
||||
double m = Double.MAX_VALUE;
|
||||
Direction s = null;
|
||||
|
||||
for(Direction i : d)
|
||||
{
|
||||
Vector x = i.toVector();
|
||||
double g = x.distance(v);
|
||||
|
||||
if(g < m)
|
||||
{
|
||||
m = g;
|
||||
s = i;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public Vector toVector()
|
||||
{
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
public boolean isCrooked(Direction to)
|
||||
{
|
||||
if(equals(to.reverse()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(equals(to))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Direction(int x, int y, int z, CuboidDirection f)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
public Vector angle(Vector initial, Direction d)
|
||||
{
|
||||
calculatePermutations();
|
||||
|
||||
for(GBiset<Direction, Direction> i : permute.keySet())
|
||||
{
|
||||
if(i.getA().equals(this) && i.getB().equals(d))
|
||||
{
|
||||
return permute.get(i).op(initial);
|
||||
}
|
||||
}
|
||||
|
||||
return initial;
|
||||
}
|
||||
|
||||
public Direction reverse()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case D:
|
||||
return U;
|
||||
case E:
|
||||
return W;
|
||||
case N:
|
||||
return S;
|
||||
case S:
|
||||
return N;
|
||||
case U:
|
||||
return D;
|
||||
case W:
|
||||
return E;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int x()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
public int y()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
public int z()
|
||||
{
|
||||
return z;
|
||||
}
|
||||
|
||||
public CuboidDirection f()
|
||||
{
|
||||
return f;
|
||||
}
|
||||
|
||||
public static KList<Direction> news()
|
||||
{
|
||||
return new KList<Direction>().add(N, E, W, S);
|
||||
}
|
||||
|
||||
public static Direction getDirection(Vector v)
|
||||
{
|
||||
Vector k = VectorMath.triNormalize(v.clone().normalize());
|
||||
|
||||
for(Direction i : udnews())
|
||||
{
|
||||
if(i.x == k.getBlockX() && i.y == k.getBlockY() && i.z == k.getBlockZ())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return Direction.N;
|
||||
}
|
||||
|
||||
public static KList<Direction> udnews()
|
||||
{
|
||||
return new KList<Direction>().add(U, D, N, E, W, S);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the directional value from the given byte from common directional blocks
|
||||
* (MUST BE BETWEEN 0 and 5 INCLUSIVE)
|
||||
*
|
||||
* @param b
|
||||
* the byte
|
||||
* @return the direction or null if the byte is outside of the inclusive range
|
||||
* 0-5
|
||||
*/
|
||||
public static Direction fromByte(byte b)
|
||||
{
|
||||
if(b > 5 || b < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(b == 0)
|
||||
{
|
||||
return D;
|
||||
}
|
||||
|
||||
else if(b == 1)
|
||||
{
|
||||
return U;
|
||||
}
|
||||
|
||||
else if(b == 2)
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
else if(b == 3)
|
||||
{
|
||||
return S;
|
||||
}
|
||||
|
||||
else if(b == 4)
|
||||
{
|
||||
return W;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return E;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the byte value represented in some directional blocks
|
||||
*
|
||||
* @return the byte value
|
||||
*/
|
||||
public byte byteValue()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case D:
|
||||
return 0;
|
||||
case E:
|
||||
return 5;
|
||||
case N:
|
||||
return 2;
|
||||
case S:
|
||||
return 3;
|
||||
case U:
|
||||
return 1;
|
||||
case W:
|
||||
return 4;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void calculatePermutations()
|
||||
{
|
||||
if(permute != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
permute = new KMap<GBiset<Direction, Direction>, DOP>();
|
||||
|
||||
for(Direction i : udnews())
|
||||
{
|
||||
for(Direction j : udnews())
|
||||
{
|
||||
GBiset<Direction, Direction> b = new GBiset<Direction, Direction>(i, j);
|
||||
|
||||
if(i.equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("DIRECT")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(i.reverse().equals(j))
|
||||
{
|
||||
if(i.isVertical())
|
||||
{
|
||||
permute.put(b, new DOP("R180CCZ")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CCZ(VectorMath.rotate90CCZ(v));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
permute.put(b, new DOP("R180CCY")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CCY(VectorMath.rotate90CCY(v));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CX(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CX")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CX(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CCX(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CCX")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CCX(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CY(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CY")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CY(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CCY(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CCY")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CCY(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CZ(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CZ")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CZ(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else if(getDirection(VectorMath.rotate90CCZ(i.toVector())).equals(j))
|
||||
{
|
||||
permute.put(b, new DOP("R90CCZ")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return VectorMath.rotate90CCZ(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
permute.put(b, new DOP("FAIL")
|
||||
{
|
||||
@Override
|
||||
public Vector op(Vector v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlockFace getFace()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case D:
|
||||
return BlockFace.DOWN;
|
||||
case E:
|
||||
return BlockFace.EAST;
|
||||
case N:
|
||||
return BlockFace.NORTH;
|
||||
case S:
|
||||
return BlockFace.SOUTH;
|
||||
case U:
|
||||
return BlockFace.UP;
|
||||
case W:
|
||||
return BlockFace.WEST;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Axis getAxis()
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
case D:
|
||||
return Axis.Y;
|
||||
case E:
|
||||
return Axis.X;
|
||||
case N:
|
||||
return Axis.Z;
|
||||
case S:
|
||||
return Axis.Z;
|
||||
case U:
|
||||
return Axis.Y;
|
||||
case W:
|
||||
return Axis.X;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
29
src/main/java/com/volmit/iris/util/DoubleArrayUtils.java
Normal file
29
src/main/java/com/volmit/iris/util/DoubleArrayUtils.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
|
||||
public class DoubleArrayUtils
|
||||
{
|
||||
public static void shiftRight(double[] values, double push)
|
||||
{
|
||||
for(int index = values.length - 2; index >= 0; index--)
|
||||
{
|
||||
values[index + 1] = values[index];
|
||||
}
|
||||
|
||||
values[0] = push;
|
||||
}
|
||||
|
||||
public static void wrapRight(double[] values)
|
||||
{
|
||||
double last = values[values.length - 1];
|
||||
shiftRight(values, last);
|
||||
}
|
||||
|
||||
public static void fill(double[] values, double value)
|
||||
{
|
||||
for(int i = 0; i < values.length; i++)
|
||||
{
|
||||
values[i] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
74
src/main/java/com/volmit/iris/util/DoubleTag.java
Normal file
74
src/main/java/com/volmit/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/com/volmit/iris/util/EndTag.java
Normal file
60
src/main/java/com/volmit/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";
|
||||
}
|
||||
|
||||
}
|
||||
2197
src/main/java/com/volmit/iris/util/FastNoise.java
Normal file
2197
src/main/java/com/volmit/iris/util/FastNoise.java
Normal file
File diff suppressed because it is too large
Load Diff
161
src/main/java/com/volmit/iris/util/FastParticle.java
Normal file
161
src/main/java/com/volmit/iris/util/FastParticle.java
Normal file
@@ -0,0 +1,161 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Simple Bukkit Particles API with 1.7 to 1.13.2 support !
|
||||
* <p>
|
||||
* You can find the project on <a href="https://github.com/MrMicky-FR/FastParticles">GitHub</a>
|
||||
*
|
||||
* @author MrMicky
|
||||
*/
|
||||
public final class FastParticle {
|
||||
|
||||
private static final ParticleSender PARTICLE_SENDER;
|
||||
|
||||
static {
|
||||
if (FastReflection.optionalClass("org.bukkit.Particle$DustOptions").isPresent()) {
|
||||
PARTICLE_SENDER = new ParticleSender.ParticleSender1_13();
|
||||
} else if (FastReflection.optionalClass("org.bukkit.Particle").isPresent()) {
|
||||
PARTICLE_SENDER = new ParticleSender.ParticleSenderImpl();
|
||||
} else {
|
||||
PARTICLE_SENDER = new ParticleSenderLegacy();
|
||||
}
|
||||
}
|
||||
|
||||
private FastParticle() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/*
|
||||
* Worlds methods
|
||||
*/
|
||||
public static void spawnParticle(World world, ParticleType particle, Location location, int count) {
|
||||
spawnParticle(world, particle, location.getX(), location.getY(), location.getZ(), count);
|
||||
}
|
||||
|
||||
public static void spawnParticle(World world, ParticleType particle, double x, double y, double z, int count) {
|
||||
spawnParticle(world, particle, x, y, z, count, null);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(World world, ParticleType particle, Location location, int count, T data) {
|
||||
spawnParticle(world, particle, location.getX(), location.getY(), location.getZ(), count, data);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(World world, ParticleType particle, double x, double y, double z, int count,
|
||||
T data) {
|
||||
spawnParticle(world, particle, x, y, z, count, 0.0D, 0.0D, 0.0D, data);
|
||||
}
|
||||
|
||||
public static void spawnParticle(World world, ParticleType particle, Location location, int count, double offsetX,
|
||||
double offsetY, double offsetZ) {
|
||||
spawnParticle(world, particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ);
|
||||
}
|
||||
|
||||
public static void spawnParticle(World world, ParticleType particle, double x, double y, double z, int count,
|
||||
double offsetX, double offsetY, double offsetZ) {
|
||||
spawnParticle(world, particle, x, y, z, count, offsetX, offsetY, offsetZ, null);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(World world, ParticleType particle, Location location, int count,
|
||||
double offsetX, double offsetY, double offsetZ, T data) {
|
||||
spawnParticle(world, particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY,
|
||||
offsetZ, data);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(World world, ParticleType particle, double x, double y, double z, int count,
|
||||
double offsetX, double offsetY, double offsetZ, T data) {
|
||||
spawnParticle(world, particle, x, y, z, count, offsetX, offsetY, offsetZ, 1.0D, data);
|
||||
}
|
||||
|
||||
public static void spawnParticle(World world, ParticleType particle, Location location, int count, double offsetX,
|
||||
double offsetY, double offsetZ, double extra) {
|
||||
spawnParticle(world, particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra);
|
||||
}
|
||||
|
||||
public static void spawnParticle(World world, ParticleType particle, double x, double y, double z, int count,
|
||||
double offsetX, double offsetY, double offsetZ, double extra) {
|
||||
spawnParticle(world, particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, null);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(World world, ParticleType particle, Location location, int count,
|
||||
double offsetX, double offsetY, double offsetZ, double extra, T data) {
|
||||
spawnParticle(world, particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra, data);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(World world, ParticleType particle, double x, double y, double z, int count,
|
||||
double offsetX, double offsetY, double offsetZ, double extra, T data) {
|
||||
sendParticle(world, particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Player methods
|
||||
*/
|
||||
public static void spawnParticle(Player player, ParticleType particle, Location location, int count) {
|
||||
spawnParticle(player, particle, location.getX(), location.getY(), location.getZ(), count);
|
||||
}
|
||||
|
||||
public static void spawnParticle(Player player, ParticleType particle, double x, double y, double z, int count) {
|
||||
spawnParticle(player, particle, x, y, z, count, null);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(Player player, ParticleType particle, Location location, int count, T data) {
|
||||
spawnParticle(player, particle, location.getX(), location.getY(), location.getZ(), count, data);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(Player player, ParticleType particle, double x, double y, double z, int count,
|
||||
T data) {
|
||||
spawnParticle(player, particle, x, y, z, count, 0.0D, 0.0D, 0.0D, data);
|
||||
}
|
||||
|
||||
public static void spawnParticle(Player player, ParticleType particle, Location location, int count, double offsetX,
|
||||
double offsetY, double offsetZ) {
|
||||
spawnParticle(player, particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ);
|
||||
}
|
||||
|
||||
public static void spawnParticle(Player player, ParticleType particle, double x, double y, double z, int count,
|
||||
double offsetX, double offsetY, double offsetZ) {
|
||||
spawnParticle(player, particle, x, y, z, count, offsetX, offsetY, offsetZ, null);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(Player player, ParticleType particle, Location location, int count,
|
||||
double offsetX, double offsetY, double offsetZ, T data) {
|
||||
spawnParticle(player, particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, data);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(Player player, ParticleType particle, double x, double y, double z, int count,
|
||||
double offsetX, double offsetY, double offsetZ, T data) {
|
||||
spawnParticle(player, particle, x, y, z, count, offsetX, offsetY, offsetZ, 1.0D, data);
|
||||
}
|
||||
|
||||
public static void spawnParticle(Player player, ParticleType particle, Location location, int count, double offsetX,
|
||||
double offsetY, double offsetZ, double extra) {
|
||||
spawnParticle(player, particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra);
|
||||
}
|
||||
|
||||
public static void spawnParticle(Player player, ParticleType particle, double x, double y, double z, int count,
|
||||
double offsetX, double offsetY, double offsetZ, double extra) {
|
||||
spawnParticle(player, particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, null);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(Player player, ParticleType particle, Location location, int count,
|
||||
double offsetX, double offsetY, double offsetZ, double extra, T data) {
|
||||
spawnParticle(player, particle, location.getX(), location.getY(), location.getZ(), count, offsetX, offsetY, offsetZ, extra, data);
|
||||
}
|
||||
|
||||
public static <T> void spawnParticle(Player player, ParticleType particle, double x, double y, double z, int count,
|
||||
double offsetX, double offsetY, double offsetZ, double extra, T data) {
|
||||
sendParticle(player, particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, data);
|
||||
}
|
||||
|
||||
private static void sendParticle(Object receiver, ParticleType particle, double x, double y, double z, int count,
|
||||
double offsetX, double offsetY, double offsetZ, double extra, Object data) {
|
||||
if (!particle.isSupported()) {
|
||||
throw new IllegalArgumentException("The particle '" + particle + "' is not compatible with your server version");
|
||||
}
|
||||
|
||||
PARTICLE_SENDER.spawnParticle(receiver, particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, data);
|
||||
}
|
||||
}
|
||||
59
src/main/java/com/volmit/iris/util/FastReflection.java
Normal file
59
src/main/java/com/volmit/iris/util/FastReflection.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Small reflection class to use CraftBukkit and NMS
|
||||
*
|
||||
* @author MrMicky
|
||||
*/
|
||||
public final class FastReflection {
|
||||
|
||||
public static final String OBC_PACKAGE = "org.bukkit.craftbukkit";
|
||||
public static final String NMS_PACKAGE = "net.minecraft.server";
|
||||
|
||||
public static final String VERSION = Bukkit.getServer().getClass().getPackage().getName().substring(OBC_PACKAGE.length() + 1);
|
||||
|
||||
private FastReflection() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static String nmsClassName(String className) {
|
||||
return NMS_PACKAGE + '.' + VERSION + '.' + className;
|
||||
}
|
||||
|
||||
public static Class<?> nmsClass(String className) throws ClassNotFoundException {
|
||||
return Class.forName(nmsClassName(className));
|
||||
}
|
||||
|
||||
public static Optional<Class<?>> nmsOptionalClass(String className) {
|
||||
return optionalClass(nmsClassName(className));
|
||||
}
|
||||
|
||||
public static String obcClassName(String className) {
|
||||
return OBC_PACKAGE + '.' + VERSION + '.' + className;
|
||||
}
|
||||
|
||||
public static Class<?> obcClass(String className) throws ClassNotFoundException {
|
||||
return Class.forName(obcClassName(className));
|
||||
}
|
||||
|
||||
public static Optional<Class<?>> obcOptionalClass(String className) {
|
||||
return optionalClass(obcClassName(className));
|
||||
}
|
||||
|
||||
public static Optional<Class<?>> optionalClass(String className) {
|
||||
try {
|
||||
return Optional.of(Class.forName(className));
|
||||
} catch (ClassNotFoundException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public static Object enumValueOf(Class<?> enumClass, String enumName) {
|
||||
return Enum.valueOf((Class<Enum>) enumClass, enumName.toUpperCase());
|
||||
}
|
||||
}
|
||||
44
src/main/java/com/volmit/iris/util/FileWatcher.java
Normal file
44
src/main/java/com/volmit/iris/util/FileWatcher.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
@Data
|
||||
public class FileWatcher
|
||||
{
|
||||
@Getter
|
||||
private final File file;
|
||||
private boolean exists;
|
||||
private long lastModified;
|
||||
private long size;
|
||||
|
||||
public FileWatcher(File file)
|
||||
{
|
||||
this.file = file;
|
||||
readProperties();
|
||||
}
|
||||
|
||||
private void readProperties()
|
||||
{
|
||||
exists = file.exists();
|
||||
lastModified = exists ? file.lastModified() : -1;
|
||||
size = exists ? file.length() : -1;
|
||||
}
|
||||
|
||||
public boolean checkModified()
|
||||
{
|
||||
long m = lastModified;
|
||||
long g = size;
|
||||
boolean mod = false;
|
||||
readProperties();
|
||||
|
||||
if(lastModified != m || g != size)
|
||||
{
|
||||
mod = true;
|
||||
}
|
||||
|
||||
return mod;
|
||||
}
|
||||
}
|
||||
74
src/main/java/com/volmit/iris/util/FloatTag.java
Normal file
74
src/main/java/com/volmit/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;
|
||||
}
|
||||
|
||||
}
|
||||
77
src/main/java/com/volmit/iris/util/GBiset.java
Normal file
77
src/main/java/com/volmit/iris/util/GBiset.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A Biset
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
* @param <A>
|
||||
* the first object type
|
||||
* @param <B>
|
||||
* the second object type
|
||||
*/
|
||||
@SuppressWarnings("hiding")
|
||||
public class GBiset<A, B> implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private A a;
|
||||
private B b;
|
||||
|
||||
/**
|
||||
* Create a new Biset
|
||||
*
|
||||
* @param a
|
||||
* the first object
|
||||
* @param b
|
||||
* the second object
|
||||
*/
|
||||
public GBiset(A a, B b)
|
||||
{
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object of the type A
|
||||
*
|
||||
* @return the first object
|
||||
*/
|
||||
public A getA()
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the first object
|
||||
*
|
||||
* @param a
|
||||
* the first object A
|
||||
*/
|
||||
public void setA(A a)
|
||||
{
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the second object
|
||||
*
|
||||
* @return the second object
|
||||
*/
|
||||
public B getB()
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the second object
|
||||
*
|
||||
* @param b
|
||||
*/
|
||||
public void setB(B b)
|
||||
{
|
||||
this.b = b;
|
||||
}
|
||||
}
|
||||
51
src/main/java/com/volmit/iris/util/GListAdapter.java
Normal file
51
src/main/java/com/volmit/iris/util/GListAdapter.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ninja.bytecode.shuriken.collections.KList;
|
||||
|
||||
/**
|
||||
* Adapts a list of objects into a list of other objects
|
||||
*
|
||||
* @author cyberpwn
|
||||
* @param <FROM>
|
||||
* the from object in lists (the item INSIDE the list)
|
||||
* @param <TO>
|
||||
* the to object in lists (the item INSIDE the list)
|
||||
*/
|
||||
public abstract class GListAdapter<FROM, TO>
|
||||
{
|
||||
/**
|
||||
* Adapts a list of FROM to a list of TO
|
||||
*
|
||||
* @param from
|
||||
* the from list
|
||||
* @return the to list
|
||||
*/
|
||||
public List<TO> adapt(List<FROM> from)
|
||||
{
|
||||
List<TO> adapted = new KList<TO>();
|
||||
|
||||
for(FROM i : from)
|
||||
{
|
||||
TO t = onAdapt(i);
|
||||
|
||||
if(t != null)
|
||||
{
|
||||
adapted.add(onAdapt(i));
|
||||
}
|
||||
}
|
||||
|
||||
return adapted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts a list object FROM to TO for use with the adapt method
|
||||
*
|
||||
* @param from
|
||||
* the from object
|
||||
* @return the to object
|
||||
*/
|
||||
public abstract TO onAdapt(FROM from);
|
||||
}
|
||||
17
src/main/java/com/volmit/iris/util/GenLayer.java
Normal file
17
src/main/java/com/volmit/iris/util/GenLayer.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import ninja.bytecode.iris.generator.DimensionChunkGenerator;
|
||||
|
||||
public abstract class GenLayer
|
||||
{
|
||||
protected final RNG rng;
|
||||
protected final DimensionChunkGenerator iris;
|
||||
|
||||
public GenLayer(DimensionChunkGenerator iris, RNG rng)
|
||||
{
|
||||
this.iris = iris;
|
||||
this.rng = rng;
|
||||
}
|
||||
|
||||
public abstract double generate(double x, double z);
|
||||
}
|
||||
132
src/main/java/com/volmit/iris/util/GroupedExecutor.java
Normal file
132
src/main/java/com/volmit/iris/util/GroupedExecutor.java
Normal file
@@ -0,0 +1,132 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import ninja.bytecode.shuriken.collections.KMap;
|
||||
import ninja.bytecode.shuriken.execution.J;
|
||||
import ninja.bytecode.shuriken.execution.NastyRunnable;
|
||||
|
||||
public class GroupedExecutor
|
||||
{
|
||||
private int xc;
|
||||
private ExecutorService service;
|
||||
private ReentrantLock lock;
|
||||
private KMap<String, Integer> mirror;
|
||||
|
||||
public GroupedExecutor(int threadLimit, int priority, String name)
|
||||
{
|
||||
xc = 1;
|
||||
lock = new ReentrantLock();
|
||||
mirror = new KMap<String, Integer>();
|
||||
|
||||
if(threadLimit == 1)
|
||||
{
|
||||
service = Executors.newSingleThreadExecutor((r) ->
|
||||
{
|
||||
Thread t = new Thread(r);
|
||||
t.setName(name);
|
||||
t.setPriority(priority);
|
||||
|
||||
return t;
|
||||
});
|
||||
}
|
||||
|
||||
else if(threadLimit > 1)
|
||||
{
|
||||
final ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory()
|
||||
{
|
||||
@Override
|
||||
public ForkJoinWorkerThread newThread(ForkJoinPool pool)
|
||||
{
|
||||
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
|
||||
worker.setName(name + " " + xc++);
|
||||
worker.setPriority(priority);
|
||||
return worker;
|
||||
}
|
||||
};
|
||||
|
||||
service = new ForkJoinPool(threadLimit, factory, null, false);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
service = Executors.newCachedThreadPool((r) ->
|
||||
{
|
||||
Thread t = new Thread(r);
|
||||
t.setName(name + " " + xc++);
|
||||
t.setPriority(priority);
|
||||
|
||||
return t;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void waitFor(String g)
|
||||
{
|
||||
if(g == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!mirror.containsKey(g))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while(true)
|
||||
{
|
||||
J.sleep(1);
|
||||
|
||||
if(mirror.get(g) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void queue(String q, NastyRunnable r)
|
||||
{
|
||||
lock.lock();
|
||||
if(!mirror.containsKey(q))
|
||||
{
|
||||
mirror.put(q, 0);
|
||||
}
|
||||
mirror.put(q, mirror.get(q) + 1);
|
||||
lock.unlock();
|
||||
service.execute(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
r.run();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
mirror.put(q, mirror.get(q) - 1);
|
||||
lock.unlock();
|
||||
});
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
J.a(() ->
|
||||
{
|
||||
J.sleep(10000);
|
||||
service.shutdown();
|
||||
});
|
||||
}
|
||||
|
||||
public void closeNow()
|
||||
{
|
||||
service.shutdown();
|
||||
}
|
||||
}
|
||||
24
src/main/java/com/volmit/iris/util/HeightMap.java
Normal file
24
src/main/java/com/volmit/iris/util/HeightMap.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class HeightMap
|
||||
{
|
||||
private final byte[] height;
|
||||
|
||||
public HeightMap()
|
||||
{
|
||||
height = new byte[256];
|
||||
Arrays.fill(height, Byte.MIN_VALUE);
|
||||
}
|
||||
|
||||
public void setHeight(int x, int z, int h)
|
||||
{
|
||||
height[x * 16 + z] = (byte) (h + Byte.MIN_VALUE);
|
||||
}
|
||||
|
||||
public int getHeight(int x, int z)
|
||||
{
|
||||
return height[x * 16 + z] - Byte.MIN_VALUE;
|
||||
}
|
||||
}
|
||||
9
src/main/java/com/volmit/iris/util/ING.java
Normal file
9
src/main/java/com/volmit/iris/util/ING.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
public class ING
|
||||
{
|
||||
public ING(RNG rng)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
1912
src/main/java/com/volmit/iris/util/IO.java
Normal file
1912
src/main/java/com/volmit/iris/util/IO.java
Normal file
File diff suppressed because it is too large
Load Diff
20
src/main/java/com/volmit/iris/util/IObjectPlacer.java
Normal file
20
src/main/java/com/volmit/iris/util/IObjectPlacer.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public interface IObjectPlacer
|
||||
{
|
||||
public int getHighest(int x, int z);
|
||||
|
||||
public int getHighest(int x, int z, boolean ignoreFluid);
|
||||
|
||||
public void set(int x, int y, int z, BlockData d);
|
||||
|
||||
public BlockData get(int x, int y, int z);
|
||||
|
||||
public boolean isPreventingDecay();
|
||||
|
||||
public boolean isSolid(int x, int y, int z);
|
||||
|
||||
public boolean isUnderwater(int x, int z);
|
||||
}
|
||||
14
src/main/java/com/volmit/iris/util/IPostBlockAccess.java
Normal file
14
src/main/java/com/volmit/iris/util/IPostBlockAccess.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public interface IPostBlockAccess
|
||||
{
|
||||
public BlockData getPostBlock(int x, int y, int z);
|
||||
|
||||
public void setPostBlock(int x, int y, int z, BlockData d);
|
||||
|
||||
public int highestTerrainOrFluidBlock(int x, int z);
|
||||
|
||||
public int highestTerrainBlock(int x, int z);
|
||||
}
|
||||
76
src/main/java/com/volmit/iris/util/IntArrayTag.java
Normal file
76
src/main/java/com/volmit/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/com/volmit/iris/util/IntTag.java
Normal file
74
src/main/java/com/volmit/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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
public enum InterpolationType
|
||||
{
|
||||
LINEAR,
|
||||
PARAMETRIC_2,
|
||||
PARAMETRIC_4,
|
||||
BEZIER,
|
||||
NONE;
|
||||
}
|
||||
40
src/main/java/com/volmit/iris/util/InvertedBiomeGrid.java
Normal file
40
src/main/java/com/volmit/iris/util/InvertedBiomeGrid.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
|
||||
public class InvertedBiomeGrid implements BiomeGrid
|
||||
{
|
||||
private BiomeGrid grid;
|
||||
|
||||
public InvertedBiomeGrid(BiomeGrid real)
|
||||
{
|
||||
this.grid = real;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Biome getBiome(int arg0, int arg1)
|
||||
{
|
||||
return grid.getBiome(arg0, arg1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int arg0, int arg1, int arg2)
|
||||
{
|
||||
return grid.getBiome(arg0, 255 - arg1, arg2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void setBiome(int arg0, int arg1, Biome arg2)
|
||||
{
|
||||
grid.setBiome(arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int arg0, int arg1, int arg2, Biome arg3)
|
||||
{
|
||||
grid.setBiome(arg0, 255 - arg1, arg2, arg3);
|
||||
}
|
||||
}
|
||||
251
src/main/java/com/volmit/iris/util/IrisInterpolation.java
Normal file
251
src/main/java/com/volmit/iris/util/IrisInterpolation.java
Normal file
@@ -0,0 +1,251 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import ninja.bytecode.iris.object.InterpolationMethod;
|
||||
|
||||
public class IrisInterpolation
|
||||
{
|
||||
public static double bezier(double t)
|
||||
{
|
||||
return t * t * (3.0d - 2.0d * t);
|
||||
}
|
||||
|
||||
public static double parametric(double t, double alpha)
|
||||
{
|
||||
double sqt = Math.pow(t, alpha);
|
||||
return sqt / (alpha * (sqt - Math.pow(t, alpha - 1)) + 1.0d);
|
||||
}
|
||||
|
||||
public static double lerp(double a, double b, double f)
|
||||
{
|
||||
return a + (f * (b - a));
|
||||
}
|
||||
|
||||
public static float lerpf(float a, float b, float f)
|
||||
{
|
||||
return a + (f * (b - a));
|
||||
}
|
||||
|
||||
public static double lerpBezier(double a, double b, double f)
|
||||
{
|
||||
return a + (bezier(f) * (b - a));
|
||||
}
|
||||
|
||||
public static double sinCenter(double f)
|
||||
{
|
||||
return Math.sin(f * Math.PI);
|
||||
}
|
||||
|
||||
public static double lerpCenterSinBezier(double a, double b, double f)
|
||||
{
|
||||
return lerpBezier(a, b, sinCenter(f));
|
||||
}
|
||||
|
||||
public static double lerpCenterSin(double a, double b, double f)
|
||||
{
|
||||
return lerpBezier(a, b, sinCenter(f));
|
||||
}
|
||||
|
||||
public static double lerpParametric(double a, double b, double f, double v)
|
||||
{
|
||||
return a + (parametric(f, v) * (b - a));
|
||||
}
|
||||
|
||||
public static double blerp(double a, double b, double c, double d, double tx, double ty)
|
||||
{
|
||||
return lerp(lerp(a, b, tx), lerp(c, d, tx), ty);
|
||||
}
|
||||
|
||||
public static double blerp(double a, double b, double c, double d, double tx, double ty, InterpolationType type)
|
||||
{
|
||||
if(type.equals(InterpolationType.LINEAR))
|
||||
{
|
||||
return blerp(a, b, c, d, tx, ty);
|
||||
}
|
||||
|
||||
if(type.equals(InterpolationType.BEZIER))
|
||||
{
|
||||
return blerpBezier(a, b, c, d, tx, ty);
|
||||
}
|
||||
|
||||
if(type.equals(InterpolationType.PARAMETRIC_2))
|
||||
{
|
||||
return blerpParametric(a, b, c, d, tx, ty, 2);
|
||||
}
|
||||
|
||||
if(type.equals(InterpolationType.PARAMETRIC_4))
|
||||
{
|
||||
return blerpParametric(a, b, c, d, tx, ty, 4);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double blerpBezier(double a, double b, double c, double d, double tx, double ty)
|
||||
{
|
||||
return lerpBezier(lerpBezier(a, b, tx), lerpBezier(c, d, tx), ty);
|
||||
}
|
||||
|
||||
public static double blerpParametric(double a, double b, double c, double d, double tx, double ty, double v)
|
||||
{
|
||||
return lerpParametric(lerpParametric(a, b, tx, v), lerpParametric(c, d, tx, v), ty, v);
|
||||
}
|
||||
|
||||
public static double hermite(double p0, double p1, double p2, double p3, double mu, double tension, double bias)
|
||||
{
|
||||
double m0, m1, mu2, mu3;
|
||||
double a0, a1, a2, a3;
|
||||
|
||||
mu2 = mu * mu;
|
||||
mu3 = mu2 * mu;
|
||||
m0 = (p1 - p0) * (1 + bias) * (1 - tension) / 2;
|
||||
m0 += (p2 - p1) * (1 - bias) * (1 - tension) / 2;
|
||||
m1 = (p2 - p1) * (1 + bias) * (1 - tension) / 2;
|
||||
m1 += (p3 - p2) * (1 - bias) * (1 - tension) / 2;
|
||||
a0 = 2 * mu3 - 3 * mu2 + 1;
|
||||
a1 = mu3 - 2 * mu2 + mu;
|
||||
a2 = mu3 - mu2;
|
||||
a3 = -2 * mu3 + 3 * mu2;
|
||||
|
||||
return (a0 * p1 + a1 * m0 + a2 * m1 + a3 * p2);
|
||||
}
|
||||
|
||||
public static double bihermite(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy, double tension, double bias)
|
||||
{
|
||||
return hermite(hermite(p00, p01, p02, p03, muy, tension, bias), hermite(p10, p11, p12, p13, muy, tension, bias), hermite(p20, p21, p22, p23, muy, tension, bias), hermite(p30, p31, p32, p33, muy, tension, bias), mux, tension, bias);
|
||||
}
|
||||
|
||||
public static double cubic(double p0, double p1, double p2, double p3, double mu)
|
||||
{
|
||||
double a0, a1, a2, a3, mu2;
|
||||
|
||||
mu2 = mu * mu;
|
||||
a0 = p3 - p2 - p0 + p1;
|
||||
a1 = p0 - p1 - a0;
|
||||
a2 = p2 - p0;
|
||||
a3 = p1;
|
||||
|
||||
return a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3;
|
||||
}
|
||||
|
||||
public static double bicubic(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy)
|
||||
{
|
||||
return cubic(cubic(p00, p01, p02, p03, muy), cubic(p10, p11, p12, p13, muy), cubic(p20, p21, p22, p23, muy), cubic(p30, p31, p32, p33, muy), mux);
|
||||
}
|
||||
|
||||
public static double getBilinearNoise(int x, int z, double rad, NoiseProvider n)
|
||||
{
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
int z1 = (int) Math.round(fz * rad);
|
||||
int x2 = (int) Math.round((fx + 1) * rad);
|
||||
int z2 = (int) Math.round((fz + 1) * rad);
|
||||
double px = rangeScale(0, 1, x1, x2, x);
|
||||
double pz = rangeScale(0, 1, z1, z2, z);
|
||||
//@builder
|
||||
return blerpBezier(
|
||||
n.noise(x1, z1),
|
||||
n.noise(x2, z1),
|
||||
n.noise(x1, z2),
|
||||
n.noise(x2, z2),
|
||||
px, pz);
|
||||
//@done
|
||||
}
|
||||
|
||||
public static double getBicubicNoise(int x, int z, double rad, NoiseProvider n)
|
||||
{
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int x0 = (int) Math.round((fx - 1) * rad);
|
||||
int z0 = (int) Math.round((fz - 1) * rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
int z1 = (int) Math.round(fz * rad);
|
||||
int x2 = (int) Math.round((fx + 1) * rad);
|
||||
int z2 = (int) Math.round((fz + 1) * rad);
|
||||
int x3 = (int) Math.round((fx + 2) * rad);
|
||||
int z3 = (int) Math.round((fz + 2) * rad);
|
||||
double px = rangeScale(0, 1, x1, x2, x);
|
||||
double pz = rangeScale(0, 1, z1, z2, z);
|
||||
//@builder
|
||||
return bicubic(
|
||||
n.noise(x0, z0),
|
||||
n.noise(x0, z1),
|
||||
n.noise(x0, z2),
|
||||
n.noise(x0, z3),
|
||||
n.noise(x1, z0),
|
||||
n.noise(x1, z1),
|
||||
n.noise(x1, z2),
|
||||
n.noise(x1, z3),
|
||||
n.noise(x2, z0),
|
||||
n.noise(x2, z1),
|
||||
n.noise(x2, z2),
|
||||
n.noise(x2, z3),
|
||||
n.noise(x3, z0),
|
||||
n.noise(x3, z1),
|
||||
n.noise(x3, z2),
|
||||
n.noise(x3, z3),
|
||||
px, pz);
|
||||
//@done
|
||||
}
|
||||
|
||||
public static double getHermiteNoise(int x, int z, double rad, NoiseProvider n)
|
||||
{
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
int x0 = (int) Math.round((fx - 1) * rad);
|
||||
int z0 = (int) Math.round((fz - 1) * rad);
|
||||
int x1 = (int) Math.round(fx * rad);
|
||||
int z1 = (int) Math.round(fz * rad);
|
||||
int x2 = (int) Math.round((fx + 1) * rad);
|
||||
int z2 = (int) Math.round((fz + 1) * rad);
|
||||
int x3 = (int) Math.round((fx + 2) * rad);
|
||||
int z3 = (int) Math.round((fz + 2) * rad);
|
||||
double px = rangeScale(0, 1, x1, x2, x);
|
||||
double pz = rangeScale(0, 1, z1, z2, z);
|
||||
//@builder
|
||||
return bihermite(
|
||||
n.noise(x0, z0),
|
||||
n.noise(x0, z1),
|
||||
n.noise(x0, z2),
|
||||
n.noise(x0, z3),
|
||||
n.noise(x1, z0),
|
||||
n.noise(x1, z1),
|
||||
n.noise(x1, z2),
|
||||
n.noise(x1, z3),
|
||||
n.noise(x2, z0),
|
||||
n.noise(x2, z1),
|
||||
n.noise(x2, z2),
|
||||
n.noise(x2, z3),
|
||||
n.noise(x3, z0),
|
||||
n.noise(x3, z1),
|
||||
n.noise(x3, z2),
|
||||
n.noise(x3, z3),
|
||||
px, pz, 0.0000000001, 0.5);
|
||||
//@done
|
||||
}
|
||||
|
||||
public static double getNoise(InterpolationMethod method, int x, int z, double rad, NoiseProvider n)
|
||||
{
|
||||
if(method.equals(InterpolationMethod.BILINEAR))
|
||||
{
|
||||
return getBilinearNoise(x, z, rad, n);
|
||||
}
|
||||
|
||||
else if(method.equals(InterpolationMethod.BICUBIC))
|
||||
{
|
||||
return getBicubicNoise(x, z, rad, n);
|
||||
}
|
||||
|
||||
else if(method.equals(InterpolationMethod.HERMITE))
|
||||
{
|
||||
return getHermiteNoise(x, z, rad, n);
|
||||
}
|
||||
|
||||
return n.noise(x, z);
|
||||
}
|
||||
|
||||
public static double rangeScale(double amin, double amax, double bmin, double bmax, double b)
|
||||
{
|
||||
return amin + ((amax - amin) * ((b - bmin) / (bmax - bmin)));
|
||||
}
|
||||
}
|
||||
41
src/main/java/com/volmit/iris/util/IrisPostBlockFilter.java
Normal file
41
src/main/java/com/volmit/iris/util/IrisPostBlockFilter.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import ninja.bytecode.iris.generator.PostBlockChunkGenerator;
|
||||
|
||||
public abstract class IrisPostBlockFilter implements IPostBlockAccess
|
||||
{
|
||||
public PostBlockChunkGenerator gen;
|
||||
|
||||
public IrisPostBlockFilter(PostBlockChunkGenerator gen)
|
||||
{
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
public abstract void onPost(int x, int z);
|
||||
|
||||
@Override
|
||||
public BlockData getPostBlock(int x, int y, int z)
|
||||
{
|
||||
return gen.getPostBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPostBlock(int x, int y, int z, BlockData d)
|
||||
{
|
||||
gen.setPostBlock(x, y, z, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int highestTerrainOrFluidBlock(int x, int z)
|
||||
{
|
||||
return gen.highestTerrainOrFluidBlock(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int highestTerrainBlock(int x, int z)
|
||||
{
|
||||
return gen.highestTerrainBlock(x, z);
|
||||
}
|
||||
}
|
||||
99
src/main/java/com/volmit/iris/util/ListTag.java
Normal file
99
src/main/java/com/volmit/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/com/volmit/iris/util/LongTag.java
Normal file
74
src/main/java/com/volmit/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/com/volmit/iris/util/NBTConstants.java
Normal file
77
src/main/java/com/volmit/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/com/volmit/iris/util/NBTInputStream.java
Normal file
205
src/main/java/com/volmit/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/com/volmit/iris/util/NBTOutputStream.java
Normal file
301
src/main/java/com/volmit/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/com/volmit/iris/util/NBTUtils.java
Normal file
165
src/main/java/com/volmit/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() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
231
src/main/java/com/volmit/iris/util/NoiseGenerator.java
Normal file
231
src/main/java/com/volmit/iris/util/NoiseGenerator.java
Normal file
@@ -0,0 +1,231 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
/**
|
||||
* Base class for all noise generators
|
||||
*/
|
||||
public abstract class NoiseGenerator
|
||||
{
|
||||
protected final int perm[] = new int[512];
|
||||
protected double offsetX;
|
||||
protected double offsetY;
|
||||
protected double offsetZ;
|
||||
|
||||
/**
|
||||
* Speedy floor, faster than (int)Math.floor(x)
|
||||
*
|
||||
* @param x
|
||||
* Value to floor
|
||||
* @return Floored value
|
||||
*/
|
||||
public static int floor(double x)
|
||||
{
|
||||
return x >= 0 ? (int) x : (int) x - 1;
|
||||
}
|
||||
|
||||
protected static double fade(double x)
|
||||
{
|
||||
return x * x * x * (x * (x * 6 - 15) + 10);
|
||||
}
|
||||
|
||||
protected static double lerp(double x, double y, double z)
|
||||
{
|
||||
return y + x * (z - y);
|
||||
}
|
||||
|
||||
protected static double grad(int hash, double x, double y, double z)
|
||||
{
|
||||
hash &= 15;
|
||||
double u = hash < 8 ? x : y;
|
||||
double v = hash < 4 ? y : hash == 12 || hash == 14 ? x : z;
|
||||
return ((hash & 1) == 0 ? u : -u) + ((hash & 2) == 0 ? v : -v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes and returns the 1D noise for the given coordinate in 1D space
|
||||
*
|
||||
* @param x
|
||||
* X coordinate
|
||||
* @return Noise at given location, from range -1 to 1
|
||||
*/
|
||||
public double noise(double x)
|
||||
{
|
||||
return noise(x, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes and returns the 2D noise for the given coordinates in 2D space
|
||||
*
|
||||
* @param x
|
||||
* X coordinate
|
||||
* @param y
|
||||
* Y coordinate
|
||||
* @return Noise at given location, from range -1 to 1
|
||||
*/
|
||||
public double noise(double x, double y)
|
||||
{
|
||||
return noise(x, y, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes and returns the 3D noise for the given coordinates in 3D space
|
||||
*
|
||||
* @param x
|
||||
* X coordinate
|
||||
* @param y
|
||||
* Y coordinate
|
||||
* @param z
|
||||
* Z coordinate
|
||||
* @return Noise at given location, from range -1 to 1
|
||||
*/
|
||||
public abstract double noise(double x, double y, double z);
|
||||
|
||||
/**
|
||||
* Generates noise for the 1D coordinates using the specified number of octaves
|
||||
* and parameters
|
||||
*
|
||||
* @param x
|
||||
* X-coordinate
|
||||
* @param octaves
|
||||
* Number of octaves to use
|
||||
* @param frequency
|
||||
* How much to alter the frequency by each octave
|
||||
* @param amplitude
|
||||
* How much to alter the amplitude by each octave
|
||||
* @return Resulting noise
|
||||
*/
|
||||
public double noise(double x, int octaves, double frequency, double amplitude)
|
||||
{
|
||||
return noise(x, 0, 0, octaves, frequency, amplitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates noise for the 1D coordinates using the specified number of octaves
|
||||
* and parameters
|
||||
*
|
||||
* @param x
|
||||
* X-coordinate
|
||||
* @param octaves
|
||||
* Number of octaves to use
|
||||
* @param frequency
|
||||
* How much to alter the frequency by each octave
|
||||
* @param amplitude
|
||||
* How much to alter the amplitude by each octave
|
||||
* @param normalized
|
||||
* If true, normalize the value to [-1, 1]
|
||||
* @return Resulting noise
|
||||
*/
|
||||
public double noise(double x, int octaves, double frequency, double amplitude, boolean normalized)
|
||||
{
|
||||
return noise(x, 0, 0, octaves, frequency, amplitude, normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates noise for the 2D coordinates using the specified number of octaves
|
||||
* and parameters
|
||||
*
|
||||
* @param x
|
||||
* X-coordinate
|
||||
* @param y
|
||||
* Y-coordinate
|
||||
* @param octaves
|
||||
* Number of octaves to use
|
||||
* @param frequency
|
||||
* How much to alter the frequency by each octave
|
||||
* @param amplitude
|
||||
* How much to alter the amplitude by each octave
|
||||
* @return Resulting noise
|
||||
*/
|
||||
public double noise(double x, double y, int octaves, double frequency, double amplitude)
|
||||
{
|
||||
return noise(x, y, 0, octaves, frequency, amplitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates noise for the 2D coordinates using the specified number of octaves
|
||||
* and parameters
|
||||
*
|
||||
* @param x
|
||||
* X-coordinate
|
||||
* @param y
|
||||
* Y-coordinate
|
||||
* @param octaves
|
||||
* Number of octaves to use
|
||||
* @param frequency
|
||||
* How much to alter the frequency by each octave
|
||||
* @param amplitude
|
||||
* How much to alter the amplitude by each octave
|
||||
* @param normalized
|
||||
* If true, normalize the value to [-1, 1]
|
||||
* @return Resulting noise
|
||||
*/
|
||||
public double noise(double x, double y, int octaves, double frequency, double amplitude, boolean normalized)
|
||||
{
|
||||
return noise(x, y, 0, octaves, frequency, amplitude, normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates noise for the 3D coordinates using the specified number of octaves
|
||||
* and parameters
|
||||
*
|
||||
* @param x
|
||||
* X-coordinate
|
||||
* @param y
|
||||
* Y-coordinate
|
||||
* @param z
|
||||
* Z-coordinate
|
||||
* @param octaves
|
||||
* Number of octaves to use
|
||||
* @param frequency
|
||||
* How much to alter the frequency by each octave
|
||||
* @param amplitude
|
||||
* How much to alter the amplitude by each octave
|
||||
* @return Resulting noise
|
||||
*/
|
||||
public double noise(double x, double y, double z, int octaves, double frequency, double amplitude)
|
||||
{
|
||||
return noise(x, y, z, octaves, frequency, amplitude, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates noise for the 3D coordinates using the specified number of octaves
|
||||
* and parameters
|
||||
*
|
||||
* @param x
|
||||
* X-coordinate
|
||||
* @param y
|
||||
* Y-coordinate
|
||||
* @param z
|
||||
* Z-coordinate
|
||||
* @param octaves
|
||||
* Number of octaves to use
|
||||
* @param frequency
|
||||
* How much to alter the frequency by each octave
|
||||
* @param amplitude
|
||||
* How much to alter the amplitude by each octave
|
||||
* @param normalized
|
||||
* If true, normalize the value to [-1, 1]
|
||||
* @return Resulting noise
|
||||
*/
|
||||
public double noise(double x, double y, double z, int octaves, double frequency, double amplitude, boolean normalized)
|
||||
{
|
||||
double result = 0;
|
||||
double amp = 1;
|
||||
double freq = 1;
|
||||
double max = 0;
|
||||
|
||||
for(int i = 0; i < octaves; i++)
|
||||
{
|
||||
result += noise(x * freq, y * freq, z * freq) * amp;
|
||||
max += amp;
|
||||
freq *= frequency;
|
||||
amp *= amplitude;
|
||||
}
|
||||
|
||||
if(normalized)
|
||||
{
|
||||
result /= max;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
7
src/main/java/com/volmit/iris/util/NoiseInjector.java
Normal file
7
src/main/java/com/volmit/iris/util/NoiseInjector.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface NoiseInjector
|
||||
{
|
||||
public double[] combine(double src, double value);
|
||||
}
|
||||
6
src/main/java/com/volmit/iris/util/NoiseProvider.java
Normal file
6
src/main/java/com/volmit/iris/util/NoiseProvider.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
@FunctionalInterface
|
||||
public interface NoiseProvider
|
||||
{
|
||||
public double noise(double x, double z);
|
||||
}
|
||||
6
src/main/java/com/volmit/iris/util/ObjectConverter.java
Normal file
6
src/main/java/com/volmit/iris/util/ObjectConverter.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
public class ObjectConverter
|
||||
{
|
||||
|
||||
}
|
||||
216
src/main/java/com/volmit/iris/util/ObjectResourceLoader.java
Normal file
216
src/main/java/com/volmit/iris/util/ObjectResourceLoader.java
Normal file
@@ -0,0 +1,216 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.object.IrisObject;
|
||||
import ninja.bytecode.shuriken.collections.KMap;
|
||||
import ninja.bytecode.shuriken.math.M;
|
||||
|
||||
public class ObjectResourceLoader extends ResourceLoader<IrisObject>
|
||||
{
|
||||
private ChunkPosition parallaxSize;
|
||||
private ChronoLatch useFlip = new ChronoLatch(2863);
|
||||
private KMap<String, Long> useCache = new KMap<>();
|
||||
|
||||
public ObjectResourceLoader(File root, String folderName, String resourceTypeName)
|
||||
{
|
||||
super(root, folderName, resourceTypeName, IrisObject.class);
|
||||
}
|
||||
|
||||
public int getTotalStorage()
|
||||
{
|
||||
int m = 0;
|
||||
|
||||
for(IrisObject i : loadCache.values())
|
||||
{
|
||||
m += i.getBlocks().size();
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
public void clean()
|
||||
{
|
||||
if(useFlip.flip())
|
||||
{
|
||||
if(loadCache.size() > 15 && getTotalStorage() > 20000)
|
||||
{
|
||||
unloadLast(30000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadLast(long age)
|
||||
{
|
||||
String v = getOldest();
|
||||
|
||||
if(v == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(M.ms() - useCache.get(v) > age)
|
||||
{
|
||||
unload(v);
|
||||
}
|
||||
}
|
||||
|
||||
private String getOldest()
|
||||
{
|
||||
long min = M.ms();
|
||||
String v = null;
|
||||
|
||||
for(String i : useCache.k())
|
||||
{
|
||||
long t = useCache.get(i);
|
||||
if(t < min)
|
||||
{
|
||||
min = t;
|
||||
v = i;
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
private void unload(String v)
|
||||
{
|
||||
lock.lock();
|
||||
useCache.remove(v);
|
||||
loadCache.remove(v);
|
||||
lock.unlock();
|
||||
Iris.info("Unloaded Object: " + v);
|
||||
}
|
||||
|
||||
public ChunkPosition getParallaxSize()
|
||||
{
|
||||
lock.lock();
|
||||
if(parallaxSize == null)
|
||||
{
|
||||
int x = 0;
|
||||
int z = 0;
|
||||
|
||||
for(File i : getFolders())
|
||||
{
|
||||
for(File j : i.listFiles())
|
||||
{
|
||||
if(j.isFile() && j.getName().endsWith(".iob"))
|
||||
{
|
||||
try
|
||||
{
|
||||
BlockVector b = IrisObject.sampleSize(j);
|
||||
x = b.getBlockX() > x ? b.getBlockX() : x;
|
||||
z = b.getBlockZ() > z ? b.getBlockZ() : z;
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
x = (Math.max(x, 16) + 16) >> 4;
|
||||
z = (Math.max(z, 16) + 16) >> 4;
|
||||
x = x % 2 == 0 ? x + 1 : x;
|
||||
z = z % 2 == 0 ? z + 1 : z;
|
||||
parallaxSize = new ChunkPosition(x, z);
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
|
||||
return parallaxSize;
|
||||
}
|
||||
|
||||
public IrisObject loadFile(File j, String key, String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
IrisObject t = new IrisObject(0, 0, 0);
|
||||
t.read(j);
|
||||
loadCache.put(key, t);
|
||||
Iris.hotloader.track(j);
|
||||
Iris.info("Loading " + resourceTypeName + ": " + j.getPath());
|
||||
t.setLoadKey(name);
|
||||
parallaxSize = null;
|
||||
lock.unlock();
|
||||
return t;
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
lock.unlock();
|
||||
Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public File findFile(String name)
|
||||
{
|
||||
lock.lock();
|
||||
for(File i : getFolders(name))
|
||||
{
|
||||
for(File j : i.listFiles())
|
||||
{
|
||||
if(j.isFile() && j.getName().endsWith(".iob") && j.getName().split("\\Q.\\E")[0].equals(name))
|
||||
{
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(i, name + ".iob");
|
||||
|
||||
if(file.exists())
|
||||
{
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
|
||||
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
|
||||
public IrisObject load(String name)
|
||||
{
|
||||
String key = name + "-" + objectClass.getCanonicalName();
|
||||
|
||||
if(loadCache.containsKey(key))
|
||||
{
|
||||
IrisObject t = loadCache.get(key);
|
||||
useCache.put(key, M.ms());
|
||||
return t;
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
for(File i : getFolders(name))
|
||||
{
|
||||
for(File j : i.listFiles())
|
||||
{
|
||||
if(j.isFile() && j.getName().endsWith(".iob") && j.getName().split("\\Q.\\E")[0].equals(name))
|
||||
{
|
||||
useCache.put(key, M.ms());
|
||||
return loadFile(j, key, name);
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(i, name + ".iob");
|
||||
|
||||
if(file.exists())
|
||||
{
|
||||
useCache.put(key, M.ms());
|
||||
return loadFile(file, key, name);
|
||||
}
|
||||
}
|
||||
|
||||
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
|
||||
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
130
src/main/java/com/volmit/iris/util/ParticleSender.java
Normal file
130
src/main/java/com/volmit/iris/util/ParticleSender.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
/**
|
||||
* Particle sender using the Bukkit particles API for 1.9+ servers
|
||||
*
|
||||
* @author MrMicky
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
interface ParticleSender
|
||||
{
|
||||
|
||||
void spawnParticle(Object receiver, ParticleType particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, Object data);
|
||||
|
||||
Object getParticle(ParticleType particle);
|
||||
|
||||
boolean isValidData(Object particle, Object data);
|
||||
|
||||
default double color(double color)
|
||||
{
|
||||
return color / 255.0;
|
||||
}
|
||||
|
||||
class ParticleSenderImpl implements ParticleSender
|
||||
{
|
||||
|
||||
@Override
|
||||
public void spawnParticle(Object receiver, ParticleType particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, Object data)
|
||||
{
|
||||
Particle bukkitParticle = Particle.valueOf(particle.toString());
|
||||
|
||||
if(data instanceof Color)
|
||||
{
|
||||
if(particle.getDataType() == Color.class)
|
||||
{
|
||||
Color color = (Color) data;
|
||||
count = 0;
|
||||
offsetX = color(color.getRed());
|
||||
offsetY = color(color.getGreen());
|
||||
offsetZ = color(color.getBlue());
|
||||
extra = 1.0;
|
||||
}
|
||||
data = null;
|
||||
}
|
||||
|
||||
if(receiver instanceof World)
|
||||
{
|
||||
((World) receiver).spawnParticle(bukkitParticle, x, y, z, count, offsetX, offsetY, offsetZ, extra, data);
|
||||
}
|
||||
else if(receiver instanceof Player)
|
||||
{
|
||||
((Player) receiver).spawnParticle(bukkitParticle, x, y, z, count, offsetX, offsetY, offsetZ, extra, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle(ParticleType particle)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Particle.valueOf(particle.toString());
|
||||
}
|
||||
catch(IllegalArgumentException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidData(Object particle, Object data)
|
||||
{
|
||||
return isValidDataBukkit((Particle) particle, data);
|
||||
}
|
||||
|
||||
public boolean isValidDataBukkit(Particle particle, Object data)
|
||||
{
|
||||
return particle.getDataType() == Void.class || particle.getDataType().isInstance(data);
|
||||
}
|
||||
}
|
||||
|
||||
class ParticleSender1_13 extends ParticleSenderImpl
|
||||
{
|
||||
@Override
|
||||
public void spawnParticle(Object receiver, ParticleType particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, Object data)
|
||||
{
|
||||
Particle bukkitParticle = Particle.valueOf(particle.toString());
|
||||
|
||||
if(bukkitParticle.getDataType() == Particle.DustOptions.class)
|
||||
{
|
||||
if(data instanceof Color)
|
||||
{
|
||||
data = new Particle.DustOptions((Color) data, 1);
|
||||
}
|
||||
else if(data == null)
|
||||
{
|
||||
data = new Particle.DustOptions(Color.RED, 1);
|
||||
}
|
||||
}
|
||||
else if(bukkitParticle.getDataType() == BlockData.class && data instanceof MaterialData)
|
||||
{
|
||||
data = Bukkit.createBlockData(((MaterialData) data).getItemType());
|
||||
}
|
||||
|
||||
super.spawnParticle(receiver, particle, x, y, z, count, offsetX, offsetY, offsetZ, extra, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidDataBukkit(Particle particle, Object data)
|
||||
{
|
||||
if(particle.getDataType() == Particle.DustOptions.class && data instanceof Color)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(particle.getDataType() == BlockData.class && data instanceof MaterialData)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.isValidDataBukkit(particle, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
166
src/main/java/com/volmit/iris/util/ParticleSenderLegacy.java
Normal file
166
src/main/java/com/volmit/iris/util/ParticleSenderLegacy.java
Normal file
@@ -0,0 +1,166 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Legacy particle sender with NMS for 1.7/1.8 servers
|
||||
*
|
||||
* @author MrMicky
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
class ParticleSenderLegacy implements ParticleSender {
|
||||
|
||||
private static final boolean SERVER_IS_1_8;
|
||||
|
||||
private static final Constructor<?> PACKET_PARTICLE;
|
||||
private static final Class<?> ENUM_PARTICLE;
|
||||
|
||||
private static final Method WORLD_GET_HANDLE;
|
||||
private static final Method WORLD_SEND_PARTICLE;
|
||||
|
||||
private static final Method PLAYER_GET_HANDLE;
|
||||
private static final Field PLAYER_CONNECTION;
|
||||
private static final Method SEND_PACKET;
|
||||
private static final int[] EMPTY = new int[0];
|
||||
|
||||
static {
|
||||
ENUM_PARTICLE = FastReflection.nmsOptionalClass("EnumParticle").orElse(null);
|
||||
SERVER_IS_1_8 = ENUM_PARTICLE != null;
|
||||
|
||||
try {
|
||||
Class<?> packetParticleClass = FastReflection.nmsClass("PacketPlayOutWorldParticles");
|
||||
Class<?> playerClass = FastReflection.nmsClass("EntityPlayer");
|
||||
Class<?> playerConnectionClass = FastReflection.nmsClass("PlayerConnection");
|
||||
Class<?> worldClass = FastReflection.nmsClass("WorldServer");
|
||||
Class<?> entityPlayerClass = FastReflection.nmsClass("EntityPlayer");
|
||||
|
||||
Class<?> craftPlayerClass = FastReflection.obcClass("entity.CraftPlayer");
|
||||
Class<?> craftWorldClass = FastReflection.obcClass("CraftWorld");
|
||||
|
||||
if (SERVER_IS_1_8) {
|
||||
PACKET_PARTICLE = packetParticleClass.getConstructor(ENUM_PARTICLE, boolean.class, float.class,
|
||||
float.class, float.class, float.class, float.class, float.class, float.class, int.class,
|
||||
int[].class);
|
||||
WORLD_SEND_PARTICLE = worldClass.getDeclaredMethod("sendParticles", entityPlayerClass, ENUM_PARTICLE,
|
||||
boolean.class, double.class, double.class, double.class, int.class, double.class, double.class,
|
||||
double.class, double.class, int[].class);
|
||||
} else {
|
||||
PACKET_PARTICLE = packetParticleClass.getConstructor(String.class, float.class, float.class, float.class,
|
||||
float.class, float.class, float.class, float.class, int.class);
|
||||
WORLD_SEND_PARTICLE = worldClass.getDeclaredMethod("a", String.class, double.class, double.class,
|
||||
double.class, int.class, double.class, double.class, double.class, double.class);
|
||||
}
|
||||
|
||||
WORLD_GET_HANDLE = craftWorldClass.getDeclaredMethod("getHandle");
|
||||
PLAYER_GET_HANDLE = craftPlayerClass.getDeclaredMethod("getHandle");
|
||||
PLAYER_CONNECTION = playerClass.getField("playerConnection");
|
||||
SEND_PACKET = playerConnectionClass.getMethod("sendPacket", FastReflection.nmsClass("Packet"));
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(Object receiver, ParticleType particle, double x, double y, double z, int count, double offsetX, double offsetY,
|
||||
double offsetZ, double extra, Object data) {
|
||||
try {
|
||||
int[] datas = toData(particle, data);
|
||||
|
||||
if (data instanceof Color) {
|
||||
if (particle.getDataType() == Color.class) {
|
||||
Color color = (Color) data;
|
||||
count = 0;
|
||||
offsetX = color(color.getRed());
|
||||
offsetY = color(color.getGreen());
|
||||
offsetZ = color(color.getBlue());
|
||||
extra = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
if (receiver instanceof World) {
|
||||
Object worldServer = WORLD_GET_HANDLE.invoke(receiver);
|
||||
|
||||
if (SERVER_IS_1_8) {
|
||||
WORLD_SEND_PARTICLE.invoke(worldServer, null, getEnumParticle(particle), true, x, y, z, count, offsetX, offsetY, offsetZ, extra, datas);
|
||||
} else {
|
||||
String particleName = particle.getLegacyName() + (datas.length != 2 ? "" : "_" + datas[0] + "_" + datas[1]);
|
||||
WORLD_SEND_PARTICLE.invoke(worldServer, particleName, x, y, z, count, offsetX, offsetY, offsetZ, extra);
|
||||
}
|
||||
} else if (receiver instanceof Player) {
|
||||
Object packet;
|
||||
|
||||
if (SERVER_IS_1_8) {
|
||||
packet = PACKET_PARTICLE.newInstance(getEnumParticle(particle), true, (float) x, (float) y,
|
||||
(float) z, (float) offsetX, (float) offsetY, (float) offsetZ, (float) extra, count, datas);
|
||||
} else {
|
||||
String particleName = particle.getLegacyName() + (datas.length != 2 ? "" : "_" + datas[0] + "_" + datas[1]);
|
||||
packet = PACKET_PARTICLE.newInstance(particleName, (float) x, (float) y, (float) z,
|
||||
(float) offsetX, (float) offsetY, (float) offsetZ, (float) extra, count);
|
||||
}
|
||||
|
||||
Object entityPlayer = PLAYER_GET_HANDLE.invoke(receiver);
|
||||
Object playerConnection = PLAYER_CONNECTION.get(entityPlayer);
|
||||
SEND_PACKET.invoke(playerConnection, packet);
|
||||
}
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidData(Object particle, Object data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParticle(ParticleType particle) {
|
||||
if (!SERVER_IS_1_8) {
|
||||
return particle.getLegacyName();
|
||||
}
|
||||
|
||||
try {
|
||||
return getEnumParticle(particle);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Object getEnumParticle(ParticleType particleType) {
|
||||
return FastReflection.enumValueOf(ENUM_PARTICLE, particleType.toString());
|
||||
}
|
||||
|
||||
private int[] toData(ParticleType particle, Object data) {
|
||||
Class<?> dataType = particle.getDataType();
|
||||
if (dataType == ItemStack.class) {
|
||||
if (!(data instanceof ItemStack)) {
|
||||
return SERVER_IS_1_8 ? new int[2] : new int[]{1, 0};
|
||||
}
|
||||
|
||||
ItemStack itemStack = (ItemStack) data;
|
||||
return new int[]{itemStack.getType().getId(), itemStack.getDurability()};
|
||||
}
|
||||
|
||||
if (dataType == MaterialData.class) {
|
||||
if (!(data instanceof MaterialData)) {
|
||||
return SERVER_IS_1_8 ? new int[1] : new int[]{1, 0};
|
||||
}
|
||||
|
||||
MaterialData materialData = (MaterialData) data;
|
||||
if (SERVER_IS_1_8) {
|
||||
return new int[]{materialData.getItemType().getId() + (materialData.getData() << 12)};
|
||||
} else {
|
||||
return new int[]{materialData.getItemType().getId(), materialData.getData()};
|
||||
}
|
||||
}
|
||||
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
177
src/main/java/com/volmit/iris/util/ParticleType.java
Normal file
177
src/main/java/com/volmit/iris/util/ParticleType.java
Normal file
@@ -0,0 +1,177 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
/**
|
||||
* @author MrMicky
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public enum ParticleType {
|
||||
|
||||
// 1.7+
|
||||
EXPLOSION_NORMAL("explode", "poof"),
|
||||
EXPLOSION_LARGE("largeexplode", "explosion"),
|
||||
EXPLOSION_HUGE("hugeexplosion", "explosion_emitter"),
|
||||
FIREWORKS_SPARK("fireworksSpark", "firework"),
|
||||
WATER_BUBBLE("bubble", "bubble"),
|
||||
WATER_SPLASH("splash", "splash"),
|
||||
WATER_WAKE("wake", "fishing"),
|
||||
SUSPENDED("suspended", "underwater"),
|
||||
SUSPENDED_DEPTH("depthsuspend", "underwater"),
|
||||
CRIT("crit", "crit"),
|
||||
CRIT_MAGIC("magicCrit", "enchanted_hit"),
|
||||
SMOKE_NORMAL("smoke", "smoke"),
|
||||
SMOKE_LARGE("largesmoke", "large_smoke"),
|
||||
SPELL("spell", "effect"),
|
||||
SPELL_INSTANT("instantSpell", "instant_effect"),
|
||||
SPELL_MOB("mobSpell", "entity_effect"),
|
||||
SPELL_MOB_AMBIENT("mobSpellAmbient", "ambient_entity_effect"),
|
||||
SPELL_WITCH("witchMagic", "witch"),
|
||||
DRIP_WATER("dripWater", "dripping_water"),
|
||||
DRIP_LAVA("dripLava", "dripping_lava"),
|
||||
VILLAGER_ANGRY("angryVillager", "angry_villager"),
|
||||
VILLAGER_HAPPY("happyVillager", "happy_villager"),
|
||||
TOWN_AURA("townaura", "mycelium"),
|
||||
NOTE("note", "note"),
|
||||
PORTAL("portal", "portal"),
|
||||
ENCHANTMENT_TABLE("enchantmenttable", "enchant"),
|
||||
FLAME("flame", "flame"),
|
||||
LAVA("lava", "lava"),
|
||||
// FOOTSTEP("footstep", null),
|
||||
CLOUD("cloud", "cloud"),
|
||||
REDSTONE("reddust", "dust"),
|
||||
SNOWBALL("snowballpoof", "item_snowball"),
|
||||
SNOW_SHOVEL("snowshovel", "item_snowball"),
|
||||
SLIME("slime", "item_slime"),
|
||||
HEART("heart", "heart"),
|
||||
ITEM_CRACK("iconcrack", "item"),
|
||||
BLOCK_CRACK("blockcrack", "block"),
|
||||
BLOCK_DUST("blockdust", "block"),
|
||||
|
||||
// 1.8+
|
||||
BARRIER("barrier", "barrier", 8),
|
||||
WATER_DROP("droplet", "rain", 8),
|
||||
MOB_APPEARANCE("mobappearance", "elder_guardian", 8),
|
||||
// ITEM_TAKE("take", null, 8),
|
||||
|
||||
// 1.9+
|
||||
DRAGON_BREATH("dragonbreath", "dragon_breath", 9),
|
||||
END_ROD("endRod", "end_rod", 9),
|
||||
DAMAGE_INDICATOR("damageIndicator", "damage_indicator", 9),
|
||||
SWEEP_ATTACK("sweepAttack", "sweep_attack", 9),
|
||||
|
||||
// 1.10+
|
||||
FALLING_DUST("fallingdust", "falling_dust", 10),
|
||||
|
||||
// 1.11+
|
||||
TOTEM("totem", "totem_of_undying", 11),
|
||||
SPIT("spit", "spit", 11),
|
||||
|
||||
// 1.13+
|
||||
SQUID_INK(13),
|
||||
BUBBLE_POP(13),
|
||||
CURRENT_DOWN(13),
|
||||
BUBBLE_COLUMN_UP(13),
|
||||
NAUTILUS(13),
|
||||
DOLPHIN(13),
|
||||
|
||||
// 1.14+
|
||||
SNEEZE(14),
|
||||
CAMPFIRE_COSY_SMOKE(14),
|
||||
CAMPFIRE_SIGNAL_SMOKE(14),
|
||||
COMPOSTER(14),
|
||||
FLASH(14),
|
||||
FALLING_LAVA(14),
|
||||
LANDING_LAVA(14),
|
||||
FALLING_WATER(14),
|
||||
|
||||
// 1.15+
|
||||
DRIPPING_HONEY(15),
|
||||
FALLING_HONEY(15),
|
||||
LANDING_HONEY(15),
|
||||
FALLING_NECTAR(15);
|
||||
|
||||
private static final int SERVER_VERSION_ID;
|
||||
|
||||
static {
|
||||
String ver = FastReflection.VERSION;
|
||||
SERVER_VERSION_ID = ver.charAt(4) == '_' ? Character.getNumericValue(ver.charAt(3)) : Integer.parseInt(ver.substring(3, 5));
|
||||
}
|
||||
|
||||
private final String legacyName;
|
||||
private final String name;
|
||||
private final int minimumVersion;
|
||||
|
||||
// 1.7 particles
|
||||
ParticleType(String legacyName, String name) {
|
||||
this(legacyName, name, -1);
|
||||
}
|
||||
|
||||
// 1.13+ particles
|
||||
ParticleType(int minimumVersion) {
|
||||
this.legacyName = null;
|
||||
this.name = name().toLowerCase();
|
||||
this.minimumVersion = minimumVersion;
|
||||
}
|
||||
|
||||
// 1.8-1.12 particles
|
||||
ParticleType(String legacyName, String name, int minimumVersion) {
|
||||
this.legacyName = legacyName;
|
||||
this.name = name;
|
||||
this.minimumVersion = minimumVersion;
|
||||
}
|
||||
|
||||
public boolean hasLegacyName() {
|
||||
return legacyName != null;
|
||||
}
|
||||
|
||||
public String getLegacyName() {
|
||||
if (!hasLegacyName()) {
|
||||
throw new IllegalStateException("Particle " + name() + " don't have legacy name");
|
||||
}
|
||||
return legacyName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isSupported() {
|
||||
return minimumVersion <= 0 || SERVER_VERSION_ID >= minimumVersion;
|
||||
}
|
||||
|
||||
public Class<?> getDataType() {
|
||||
switch (this) {
|
||||
case ITEM_CRACK:
|
||||
return ItemStack.class;
|
||||
case BLOCK_CRACK:
|
||||
case BLOCK_DUST:
|
||||
case FALLING_DUST:
|
||||
//noinspection deprecation
|
||||
return MaterialData.class;
|
||||
case REDSTONE:
|
||||
return Color.class;
|
||||
default:
|
||||
return Void.class;
|
||||
}
|
||||
}
|
||||
|
||||
public static ParticleType getParticle(String particleName) {
|
||||
try {
|
||||
return ParticleType.valueOf(particleName.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
for (ParticleType particle : values()) {
|
||||
if (particle.getName().equalsIgnoreCase(particleName)) {
|
||||
return particle;
|
||||
}
|
||||
|
||||
if (particle.hasLegacyName() && particle.getLegacyName().equalsIgnoreCase(particleName)) {
|
||||
return particle;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
175
src/main/java/com/volmit/iris/util/PerlinNoise.java
Normal file
175
src/main/java/com/volmit/iris/util/PerlinNoise.java
Normal file
@@ -0,0 +1,175 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class PerlinNoise extends BasePerlinNoiseGenerator
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates an instance using the given PRNG.
|
||||
*
|
||||
* @param rand
|
||||
* the PRNG used to generate the seed permutation
|
||||
*/
|
||||
public PerlinNoise(Random rand)
|
||||
{
|
||||
offsetX = rand.nextDouble() * 256;
|
||||
offsetY = rand.nextDouble() * 256;
|
||||
offsetZ = rand.nextDouble() * 256;
|
||||
// The only reason why I'm re-implementing the constructor code is that I've
|
||||
// read
|
||||
// on at least 3 different sources that the permutation table should initially
|
||||
// be
|
||||
// populated with indices.
|
||||
// "The permutation table is his answer to the issue of random numbers.
|
||||
// First take an array of decent length, usually 256 values. Fill it
|
||||
// sequentially with each
|
||||
// number in that range: so index 1 gets 1, index 8 gets 8, index 251 gets 251,
|
||||
// etc...
|
||||
// Then randomly shuffle the values so you have a table of 256 random values,
|
||||
// but only
|
||||
// contains the values between 0 and 255."
|
||||
// source: https://code.google.com/p/fractalterraingeneration/wiki/Perlin_Noise
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
perm[i] = i;
|
||||
}
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
int pos = rand.nextInt(256 - i) + i;
|
||||
int old = perm[i];
|
||||
perm[i] = perm[pos];
|
||||
perm[pos] = old;
|
||||
perm[i + 256] = perm[i];
|
||||
}
|
||||
}
|
||||
|
||||
public static int floor(double x)
|
||||
{
|
||||
int floored = (int) x;
|
||||
return x < floored ? floored - 1 : floored;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a rectangular section of this generator's noise.
|
||||
*
|
||||
* @param noise
|
||||
* the output of the previous noise layer
|
||||
* @param x
|
||||
* the X offset
|
||||
* @param y
|
||||
* the Y offset
|
||||
* @param z
|
||||
* the Z offset
|
||||
* @param sizeX
|
||||
* the size on the X axis
|
||||
* @param sizeY
|
||||
* the size on the Y axis
|
||||
* @param sizeZ
|
||||
* the size on the Z axis
|
||||
* @param scaleX
|
||||
* the X scale parameter
|
||||
* @param scaleY
|
||||
* the Y scale parameter
|
||||
* @param scaleZ
|
||||
* the Z scale parameter
|
||||
* @param amplitude
|
||||
* the amplitude parameter
|
||||
* @return {@code noise} with this layer of noise added
|
||||
*/
|
||||
public double[] getNoise(double[] noise, double x, double y, double z, int sizeX, int sizeY, int sizeZ, double scaleX, double scaleY, double scaleZ, double amplitude)
|
||||
{
|
||||
if(sizeY == 1)
|
||||
{
|
||||
return get2dNoise(noise, x, z, sizeX, sizeZ, scaleX, scaleZ, amplitude);
|
||||
}
|
||||
else
|
||||
{
|
||||
return get3dNoise(noise, x, y, z, sizeX, sizeY, sizeZ, scaleX, scaleY, scaleZ, amplitude);
|
||||
}
|
||||
}
|
||||
|
||||
protected double[] get2dNoise(double[] noise, double x, double z, int sizeX, int sizeZ, double scaleX, double scaleZ, double amplitude)
|
||||
{
|
||||
int index = 0;
|
||||
for(int i = 0; i < sizeX; i++)
|
||||
{
|
||||
double dx = x + offsetX + i * scaleX;
|
||||
int floorX = floor(dx);
|
||||
int ix = floorX & 255;
|
||||
dx -= floorX;
|
||||
double fx = fade(dx);
|
||||
for(int j = 0; j < sizeZ; j++)
|
||||
{
|
||||
double dz = z + offsetZ + j * scaleZ;
|
||||
int floorZ = floor(dz);
|
||||
int iz = floorZ & 255;
|
||||
dz -= floorZ;
|
||||
double fz = fade(dz);
|
||||
// Hash coordinates of the square corners
|
||||
int a = perm[ix];
|
||||
int aa = perm[a] + iz;
|
||||
int b = perm[ix + 1];
|
||||
int ba = perm[b] + iz;
|
||||
double x1 = lerp(fx, grad(perm[aa], dx, 0, dz), grad(perm[ba], dx - 1, 0, dz));
|
||||
double x2 = lerp(fx, grad(perm[aa + 1], dx, 0, dz - 1), grad(perm[ba + 1], dx - 1, 0, dz - 1));
|
||||
noise[index++] += lerp(fz, x1, x2) * amplitude;
|
||||
}
|
||||
}
|
||||
return noise;
|
||||
}
|
||||
|
||||
protected double[] get3dNoise(double[] noise, double x, double y, double z, int sizeX, int sizeY, int sizeZ, double scaleX, double scaleY, double scaleZ, double amplitude)
|
||||
{
|
||||
int n = -1;
|
||||
double x1 = 0;
|
||||
double x2 = 0;
|
||||
double x3 = 0;
|
||||
double x4 = 0;
|
||||
int index = 0;
|
||||
for(int i = 0; i < sizeX; i++)
|
||||
{
|
||||
double dx = x + offsetX + i * scaleX;
|
||||
int floorX = floor(dx);
|
||||
int ix = floorX & 255;
|
||||
dx -= floorX;
|
||||
double fx = fade(dx);
|
||||
for(int j = 0; j < sizeZ; j++)
|
||||
{
|
||||
double dz = z + offsetZ + j * scaleZ;
|
||||
int floorZ = floor(dz);
|
||||
int iz = floorZ & 255;
|
||||
dz -= floorZ;
|
||||
double fz = fade(dz);
|
||||
for(int k = 0; k < sizeY; k++)
|
||||
{
|
||||
double dy = y + offsetY + k * scaleY;
|
||||
int floorY = floor(dy);
|
||||
int iy = floorY & 255;
|
||||
dy -= floorY;
|
||||
double fy = fade(dy);
|
||||
if(k == 0 || iy != n)
|
||||
{
|
||||
n = iy;
|
||||
// Hash coordinates of the cube corners
|
||||
int a = perm[ix] + iy;
|
||||
int aa = perm[a] + iz;
|
||||
int ab = perm[a + 1] + iz;
|
||||
int b = perm[ix + 1] + iy;
|
||||
int ba = perm[b] + iz;
|
||||
int bb = perm[b + 1] + iz;
|
||||
x1 = lerp(fx, grad(perm[aa], dx, dy, dz), grad(perm[ba], dx - 1, dy, dz));
|
||||
x2 = lerp(fx, grad(perm[ab], dx, dy - 1, dz), grad(perm[bb], dx - 1, dy - 1, dz));
|
||||
x3 = lerp(fx, grad(perm[aa + 1], dx, dy, dz - 1), grad(perm[ba + 1], dx - 1, dy, dz - 1));
|
||||
x4 = lerp(fx, grad(perm[ab + 1], dx, dy - 1, dz - 1), grad(perm[bb + 1], dx - 1, dy - 1, dz - 1));
|
||||
}
|
||||
double y1 = lerp(fy, x1, x2);
|
||||
double y2 = lerp(fy, x3, x4);
|
||||
|
||||
noise[index++] += lerp(fz, y1, y2) * amplitude;
|
||||
}
|
||||
}
|
||||
}
|
||||
return noise;
|
||||
}
|
||||
}
|
||||
58
src/main/java/com/volmit/iris/util/PhasicBiomeStorage.java
Normal file
58
src/main/java/com/volmit/iris/util/PhasicBiomeStorage.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
public class PhasicBiomeStorage
|
||||
{
|
||||
private static final int e = (int) Math.round(Math.log(16.0D) / Math.log(2.0D)) - 2;
|
||||
private static final int f = (int) Math.round(Math.log(256.0D) / Math.log(2.0D)) - 2;
|
||||
public static final int a;
|
||||
public static final int b;
|
||||
public static final int c;
|
||||
private final Biome[] g;
|
||||
|
||||
static
|
||||
{
|
||||
a = 1 << e + e + f;
|
||||
b = (1 << e) - 1;
|
||||
c = (1 << f) - 1;
|
||||
}
|
||||
|
||||
public PhasicBiomeStorage(Biome[] abiomebase)
|
||||
{
|
||||
this.g = abiomebase;
|
||||
}
|
||||
|
||||
public PhasicBiomeStorage()
|
||||
{
|
||||
this(new Biome[a]);
|
||||
}
|
||||
|
||||
public static int clamp(int var0, int var1, int var2)
|
||||
{
|
||||
if(var0 < var1)
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return var0 > var2 ? var2 : var0;
|
||||
}
|
||||
}
|
||||
|
||||
public Biome getBiome(int i, int j, int k)
|
||||
{
|
||||
int l = i & b;
|
||||
int i1 = clamp(j, 0, c);
|
||||
int j1 = k & b;
|
||||
return this.g[i1 << e + e | j1 << e | l];
|
||||
}
|
||||
|
||||
public void setBiome(int i, int j, int k, Biome biome)
|
||||
{
|
||||
int l = i & b;
|
||||
int i1 = clamp(j, 0, c);
|
||||
int j1 = k & b;
|
||||
this.g[i1 << e + e | j1 << e | l] = biome;
|
||||
}
|
||||
}
|
||||
218
src/main/java/com/volmit/iris/util/PolygonGenerator.java
Normal file
218
src/main/java/com/volmit/iris/util/PolygonGenerator.java
Normal file
@@ -0,0 +1,218 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import ninja.bytecode.shuriken.collections.KList;
|
||||
import ninja.bytecode.shuriken.collections.KMap;
|
||||
import ninja.bytecode.shuriken.math.M;
|
||||
|
||||
public class PolygonGenerator
|
||||
{
|
||||
private double[] rarity;
|
||||
private CNG[] gen;
|
||||
private int bits;
|
||||
private int possibilities;
|
||||
private boolean useRarity;
|
||||
|
||||
public PolygonGenerator(RNG rng, int possibilities, double scale, int octaves, Function<CNG, CNG> factory)
|
||||
{
|
||||
useRarity = false;
|
||||
bits = 1;
|
||||
this.possibilities = possibilities;
|
||||
|
||||
while(Math.pow(2, bits) <= possibilities)
|
||||
{
|
||||
bits++;
|
||||
}
|
||||
|
||||
bits++;
|
||||
bits = bits > 32 ? 32 : bits;
|
||||
rarity = new double[possibilities];
|
||||
gen = new CNG[bits];
|
||||
|
||||
for(int i = 0; i < bits; i++)
|
||||
{
|
||||
gen[i] = new CNG(rng.nextParallelRNG(2118 + (i * 3305)), 1D, 1).scale(scale / possibilities);
|
||||
gen[i] = factory.apply(gen[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public PolygonGenerator useRarity()
|
||||
{
|
||||
useRarity = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setRarity(int index, double r)
|
||||
{
|
||||
rarity[index] = 1D - Math.pow(0.5, r);
|
||||
}
|
||||
|
||||
public boolean hasBorder(int checks, double distance, double... dims)
|
||||
{
|
||||
int current = getIndex(dims);
|
||||
double ajump = 360D / (double) checks;
|
||||
|
||||
if(dims.length == 2)
|
||||
{
|
||||
for(int i = 0; i < checks; i++)
|
||||
{
|
||||
double dx = M.sin((float) Math.toRadians(ajump * i));
|
||||
double dz = M.cos((float) Math.toRadians(ajump * i));
|
||||
if(current != getIndex((dx * distance) + dims[0], (dz * distance) + dims[1]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(dims.length == 3)
|
||||
{
|
||||
for(int i = 0; i < checks; i++)
|
||||
{
|
||||
double dx = M.sin((float) Math.toRadians(ajump * i));
|
||||
double dz = M.cos((float) Math.toRadians(ajump * i));
|
||||
double dy = Math.tan(Math.toRadians(ajump * i));
|
||||
if(current != getIndex((dx * distance) + dims[0], (dz * distance) + dims[1], (dy * distance) + dims[2]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasBorder3D(int checks, double distance, double... dims)
|
||||
{
|
||||
int current = getIndex(dims);
|
||||
double ajump = 360D / (double) checks;
|
||||
int hit = -1;
|
||||
|
||||
if(dims.length == 3)
|
||||
{
|
||||
for(int i = 0; i < checks; i++)
|
||||
{
|
||||
double dx = M.sin((float) Math.toRadians(ajump * i));
|
||||
double dz = M.cos((float) Math.toRadians(ajump * i));
|
||||
double dy = Math.tan(Math.toRadians(ajump * i));
|
||||
int d = getIndex((dx * distance) + dims[0], (dz * distance) + dims[1], (dy * distance) + dims[2]);
|
||||
if(current != d)
|
||||
{
|
||||
if(hit >= 0 && hit != current && hit != d)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(hit < 0)
|
||||
{
|
||||
hit = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 0.0 to 1.0 where 0.0 is directly on the border of another region and
|
||||
* 1.0 is perfectly in the center of a region
|
||||
*
|
||||
* @param x
|
||||
* the x
|
||||
* @param z
|
||||
* the z
|
||||
* @return the closest neighbor threshold.
|
||||
*/
|
||||
public double getClosestNeighbor(double... dim)
|
||||
{
|
||||
double closest = 0.5;
|
||||
|
||||
for(int i = 0; i < gen.length; i++)
|
||||
{
|
||||
double distance = Math.abs(gen[i].noise(dim) - 0.5);
|
||||
|
||||
if(distance < closest)
|
||||
{
|
||||
closest = distance;
|
||||
}
|
||||
}
|
||||
|
||||
return (closest * 2);
|
||||
}
|
||||
|
||||
public int getIndex(double... dim)
|
||||
{
|
||||
int data = 0;
|
||||
int adjusted = 0;
|
||||
double[] noise = new double[gen.length];
|
||||
|
||||
for(int i = 0; i < gen.length; i++)
|
||||
{
|
||||
data |= (noise[i] = gen[i].noise(dim)) > 0.5 ? i == 0 ? 1 : 1 << i : 0;
|
||||
}
|
||||
|
||||
if(!useRarity)
|
||||
{
|
||||
return data % possibilities;
|
||||
}
|
||||
|
||||
double r = rarity[data % possibilities];
|
||||
|
||||
for(int i = 0; i < gen.length; i++)
|
||||
{
|
||||
adjusted |= noise[i] > r ? i == 0 ? 1 : 1 << i : 0;
|
||||
}
|
||||
|
||||
return adjusted % possibilities;
|
||||
}
|
||||
|
||||
public static class EnumPolygonGenerator<T> extends PolygonGenerator
|
||||
{
|
||||
private T[] choices;
|
||||
|
||||
|
||||
public EnumPolygonGenerator(RNG rng, double scale, int octaves, T[] choices, Function<CNG, CNG> factory)
|
||||
{
|
||||
super(rng, choices.length, scale / (double) choices.length, octaves, factory);
|
||||
this.choices = choices;
|
||||
}
|
||||
|
||||
public EnumPolygonGenerator<T> useRarity()
|
||||
{
|
||||
super.useRarity();
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public EnumPolygonGenerator(RNG rng, double scale, int octaves, KList<T> c, KMap<T, Double> choiceRarities, Function<CNG, CNG> factory)
|
||||
{
|
||||
super(rng, choiceRarities.size(), scale / (double) choiceRarities.size(), octaves, factory);
|
||||
this.choices = (T[]) c.toArray();
|
||||
int m = 0;
|
||||
|
||||
for(T i : c)
|
||||
{
|
||||
setRarity(m++, choiceRarities.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void setRarity(T t, double rarity)
|
||||
{
|
||||
for(int i = 0; i < choices.length; i++)
|
||||
{
|
||||
if(choices[i].equals(t))
|
||||
{
|
||||
setRarity(i, rarity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T getChoice(double... dim)
|
||||
{
|
||||
return choices[getIndex(dim)];
|
||||
}
|
||||
}
|
||||
}
|
||||
176
src/main/java/com/volmit/iris/util/RNG.java
Normal file
176
src/main/java/com/volmit/iris/util/RNG.java
Normal file
@@ -0,0 +1,176 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RNG extends Random
|
||||
{
|
||||
private static final char[] CHARGEN = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-=!@#$%^&*()_+`~[];',./<>?:\\\"{}|\\\\".toCharArray();
|
||||
private static final long serialVersionUID = 5222938581174415179L;
|
||||
public static final RNG r = new RNG();
|
||||
private final long sx;
|
||||
public RNG()
|
||||
{
|
||||
super();
|
||||
sx = 0;
|
||||
}
|
||||
|
||||
public RNG(long seed)
|
||||
{
|
||||
super(seed);
|
||||
this.sx = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a seed (long) from the hash of the seed string
|
||||
*
|
||||
* @param seed
|
||||
* the seed (string)
|
||||
*/
|
||||
public RNG(String seed)
|
||||
{
|
||||
this(UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).getLeastSignificantBits() + UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).getMostSignificantBits() + (seed.length() * 32564));
|
||||
}
|
||||
|
||||
public RNG nextParallelRNG(int signature)
|
||||
{
|
||||
return new RNG(sx + signature);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public RNG nextRNG()
|
||||
{
|
||||
return new RNG(nextLong());
|
||||
}
|
||||
|
||||
public String s(int length)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
sb.append(c());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public char c()
|
||||
{
|
||||
return CHARGEN[i(CHARGEN.length - 1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick a random enum
|
||||
*
|
||||
* @param t
|
||||
* the enum class
|
||||
* @return the enum
|
||||
*/
|
||||
public <T> T e(Class<T> t)
|
||||
{
|
||||
T[] c = t.getEnumConstants();
|
||||
return c[i(c.length)];
|
||||
}
|
||||
|
||||
public boolean b()
|
||||
{
|
||||
return nextBoolean();
|
||||
}
|
||||
|
||||
public boolean b(double percent)
|
||||
{
|
||||
return d() > percent;
|
||||
}
|
||||
|
||||
public short si(int lowerBound, int upperBound)
|
||||
{
|
||||
return (short) (lowerBound + (nextFloat() * ((upperBound - lowerBound) + 1)));
|
||||
}
|
||||
|
||||
public short si(int upperBound)
|
||||
{
|
||||
return si(0, upperBound);
|
||||
}
|
||||
|
||||
public short si()
|
||||
{
|
||||
return si(1);
|
||||
}
|
||||
|
||||
public float f(float lowerBound, float upperBound)
|
||||
{
|
||||
return lowerBound + (nextFloat() * ((upperBound - lowerBound)));
|
||||
}
|
||||
|
||||
public float f(float upperBound)
|
||||
{
|
||||
return f(0, upperBound);
|
||||
}
|
||||
|
||||
public float f()
|
||||
{
|
||||
return f(1);
|
||||
}
|
||||
|
||||
public double d(double lowerBound, double upperBound)
|
||||
{
|
||||
return lowerBound + (nextDouble() * ((upperBound - lowerBound)));
|
||||
}
|
||||
|
||||
public double d(double upperBound)
|
||||
{
|
||||
return d(0, upperBound);
|
||||
}
|
||||
|
||||
public double d()
|
||||
{
|
||||
return d(1);
|
||||
}
|
||||
|
||||
public int i(int lowerBound, int upperBound)
|
||||
{
|
||||
return (int) Math.round(d(lowerBound, upperBound));
|
||||
}
|
||||
|
||||
public int i(int upperBound)
|
||||
{
|
||||
return i(0, upperBound);
|
||||
}
|
||||
|
||||
public long l(long lowerBound, long upperBound)
|
||||
{
|
||||
return Math.round(d(lowerBound, upperBound));
|
||||
}
|
||||
|
||||
public long l(long upperBound)
|
||||
{
|
||||
return l(0, upperBound);
|
||||
}
|
||||
|
||||
public int imax()
|
||||
{
|
||||
return i(Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public long lmax()
|
||||
{
|
||||
return l(Long.MIN_VALUE, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
public float fmax()
|
||||
{
|
||||
return f(Float.MIN_VALUE, Float.MAX_VALUE);
|
||||
}
|
||||
|
||||
public double dmax()
|
||||
{
|
||||
return d(Double.MIN_VALUE, Double.MAX_VALUE);
|
||||
}
|
||||
|
||||
public short simax()
|
||||
{
|
||||
return si(Short.MIN_VALUE, Short.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
174
src/main/java/com/volmit/iris/util/ResourceLoader.java
Normal file
174
src/main/java/com/volmit/iris/util/ResourceLoader.java
Normal file
@@ -0,0 +1,174 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.object.IrisRegistrant;
|
||||
import ninja.bytecode.shuriken.collections.KList;
|
||||
import ninja.bytecode.shuriken.collections.KMap;
|
||||
|
||||
public class ResourceLoader<T extends IrisRegistrant>
|
||||
{
|
||||
protected File root;
|
||||
protected String folderName;
|
||||
protected String resourceTypeName;
|
||||
protected KMap<String, File> folderMapCache;
|
||||
protected KMap<String, T> loadCache;
|
||||
protected KList<File> folderCache;
|
||||
protected Class<? extends T> objectClass;
|
||||
protected String cname;
|
||||
protected ReentrantLock lock;
|
||||
|
||||
public ResourceLoader(File root, String folderName, String resourceTypeName, Class<? extends T> objectClass)
|
||||
{
|
||||
lock = new ReentrantLock();
|
||||
folderMapCache = new KMap<>();
|
||||
this.objectClass = objectClass;
|
||||
cname = objectClass.getCanonicalName();
|
||||
this.resourceTypeName = resourceTypeName;
|
||||
this.root = root;
|
||||
this.folderName = folderName;
|
||||
loadCache = new KMap<>();
|
||||
}
|
||||
|
||||
public long count()
|
||||
{
|
||||
return loadCache.size();
|
||||
}
|
||||
|
||||
protected T loadFile(File j, String key, String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
T t = new Gson().fromJson(IO.readAll(j), objectClass);
|
||||
loadCache.put(key, t);
|
||||
Iris.hotloader.track(j);
|
||||
Iris.info("Loading " + resourceTypeName + ": " + j.getPath());
|
||||
t.setLoadKey(name);
|
||||
lock.unlock();
|
||||
return t;
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
lock.unlock();
|
||||
Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public T load(String name)
|
||||
{
|
||||
String key = name + "-" + cname;
|
||||
|
||||
if(loadCache.containsKey(key))
|
||||
{
|
||||
T t = loadCache.get(key);
|
||||
return t;
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
for(File i : getFolders(name))
|
||||
{
|
||||
for(File j : i.listFiles())
|
||||
{
|
||||
if(j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(name))
|
||||
{
|
||||
return loadFile(j, key, name);
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(i, name + ".json");
|
||||
|
||||
if(file.exists())
|
||||
{
|
||||
return loadFile(file, key, name);
|
||||
}
|
||||
}
|
||||
|
||||
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
|
||||
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
|
||||
public KList<File> getFolders()
|
||||
{
|
||||
if(folderCache == null)
|
||||
{
|
||||
folderCache = new KList<>();
|
||||
|
||||
for(File i : root.listFiles())
|
||||
{
|
||||
if(i.isDirectory())
|
||||
{
|
||||
for(File j : i.listFiles())
|
||||
{
|
||||
if(j.isDirectory() && j.getName().equals(folderName))
|
||||
{
|
||||
folderCache.add(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return folderCache;
|
||||
}
|
||||
|
||||
public KList<File> getFolders(String rc)
|
||||
{
|
||||
KList<File> folders = getFolders().copy();
|
||||
|
||||
if(rc.contains(":"))
|
||||
{
|
||||
for(File i : folders.copy())
|
||||
{
|
||||
if(!rc.startsWith(i.getName() + ":"))
|
||||
{
|
||||
folders.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return folders;
|
||||
}
|
||||
|
||||
public void clearCache()
|
||||
{
|
||||
loadCache.clear();
|
||||
folderCache = null;
|
||||
}
|
||||
|
||||
public File fileFor(T b)
|
||||
{
|
||||
for(File i : getFolders())
|
||||
{
|
||||
for(File j : i.listFiles())
|
||||
{
|
||||
if(j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(b.getLoadKey()))
|
||||
{
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(i, b.getLoadKey() + ".json");
|
||||
|
||||
if(file.exists())
|
||||
{
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isLoaded(String next)
|
||||
{
|
||||
return loadCache.containsKey(next);
|
||||
}
|
||||
}
|
||||
377
src/main/java/com/volmit/iris/util/SNG.java
Normal file
377
src/main/java/com/volmit/iris/util/SNG.java
Normal file
@@ -0,0 +1,377 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* A speed-improved simplex noise algorithm.
|
||||
*
|
||||
* <p>
|
||||
* Based on example code by Stefan Gustavson (stegu@itn.liu.se). Optimisations
|
||||
* by Peter Eastman (peastman@drizzle.stanford.edu). Better rank ordering method
|
||||
* by Stefan Gustavson in 2012.
|
||||
*
|
||||
* <p>
|
||||
* This could be sped up even further, but it's useful as is.
|
||||
*/
|
||||
public class SNG extends PerlinNoise
|
||||
{
|
||||
|
||||
protected static final double SQRT_3 = 1.7320508075688772; // Math.sqrt(3)
|
||||
protected static final double F2 = 0.5 * (SQRT_3 - 1);
|
||||
protected static final double G2 = (3 - SQRT_3) / 6;
|
||||
protected static final double G22 = G2 * 2.0 - 1;
|
||||
protected static final double F3 = 1.0 / 3.0;
|
||||
protected static final double G3 = 1.0 / 6.0;
|
||||
protected static final double G32 = G3 * 2.0;
|
||||
protected static final double G33 = G3 * 3.0 - 1.0;
|
||||
private static Grad[] grad3 = {new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0), new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1), new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)};
|
||||
protected final int[] permMod12 = new int[512];
|
||||
|
||||
/**
|
||||
* Creates a simplex noise generator.
|
||||
*
|
||||
* @param rand
|
||||
* the PRNG to use
|
||||
*/
|
||||
public SNG(Random rand)
|
||||
{
|
||||
super(rand);
|
||||
for(int i = 0; i < 512; i++)
|
||||
{
|
||||
permMod12[i] = perm[i] % 12;
|
||||
}
|
||||
}
|
||||
|
||||
public static int floor(double x)
|
||||
{
|
||||
return x > 0 ? (int) x : (int) x - 1;
|
||||
}
|
||||
|
||||
protected static double dot(Grad g, double x, double y)
|
||||
{
|
||||
return g.x * x + g.y * y;
|
||||
}
|
||||
|
||||
protected static double dot(Grad g, double x, double y, double z)
|
||||
{
|
||||
return g.x * x + g.y * y + g.z * z;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double[] get2dNoise(double[] noise, double x, double z, int sizeX, int sizeY, double scaleX, double scaleY, double amplitude)
|
||||
{
|
||||
int index = 0;
|
||||
for(int i = 0; i < sizeY; i++)
|
||||
{
|
||||
double zin = offsetY + (z + i) * scaleY;
|
||||
for(int j = 0; j < sizeX; j++)
|
||||
{
|
||||
double xin = offsetX + (x + j) * scaleX;
|
||||
noise[index++] += simplex2D(xin, zin) * amplitude;
|
||||
}
|
||||
}
|
||||
return noise;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double[] get3dNoise(double[] noise, double x, double y, double z, int sizeX, int sizeY, int sizeZ, double scaleX, double scaleY, double scaleZ, double amplitude)
|
||||
{
|
||||
int index = 0;
|
||||
for(int i = 0; i < sizeZ; i++)
|
||||
{
|
||||
double zin = offsetZ + (z + i) * scaleZ;
|
||||
for(int j = 0; j < sizeX; j++)
|
||||
{
|
||||
double xin = offsetX + (x + j) * scaleX;
|
||||
for(int k = 0; k < sizeY; k++)
|
||||
{
|
||||
double yin = offsetY + (y + k) * scaleY;
|
||||
noise[index++] += simplex3D(xin, yin, zin) * amplitude;
|
||||
}
|
||||
}
|
||||
}
|
||||
return noise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double xin, double yin)
|
||||
{
|
||||
xin += offsetX;
|
||||
yin += offsetY;
|
||||
return simplex2D(xin, yin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double xin, double yin, double zin)
|
||||
{
|
||||
xin += offsetX;
|
||||
yin += offsetY;
|
||||
zin += offsetZ;
|
||||
return simplex3D(xin, yin, zin);
|
||||
}
|
||||
|
||||
private double simplex2D(double xin, double yin)
|
||||
{
|
||||
// Skew the input space to determine which simplex cell we're in
|
||||
double s = (xin + yin) * F2; // Hairy factor for 2D
|
||||
int i = floor(xin + s);
|
||||
int j = floor(yin + s);
|
||||
double t = (i + j) * G2;
|
||||
double dx0 = i - t; // Unskew the cell origin back to (x,y) space
|
||||
double dy0 = j - t;
|
||||
double x0 = xin - dx0; // The x,y distances from the cell origin
|
||||
double y0 = yin - dy0;
|
||||
|
||||
// For the 2D case, the simplex shape is an equilateral triangle.
|
||||
|
||||
// Determine which simplex we are in.
|
||||
int i1; // Offsets for second (middle) corner of simplex in (i,j) coords
|
||||
int j1;
|
||||
if(x0 > y0)
|
||||
{
|
||||
i1 = 1; // lower triangle, XY order: (0,0)->(1,0)->(1,1)
|
||||
j1 = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
i1 = 0; // upper triangle, YX order: (0,0)->(0,1)->(1,1)
|
||||
j1 = 1;
|
||||
}
|
||||
|
||||
// A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
|
||||
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
|
||||
// c = (3-sqrt(3))/6
|
||||
|
||||
double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
|
||||
double y1 = y0 - j1 + G2;
|
||||
double x2 = x0 + G22; // Offsets for last corner in (x,y) unskewed coords
|
||||
double y2 = y0 + G22;
|
||||
|
||||
// Work out the hashed gradient indices of the three simplex corners
|
||||
int ii = i & 255;
|
||||
int jj = j & 255;
|
||||
int gi0 = permMod12[ii + perm[jj]];
|
||||
int gi1 = permMod12[ii + i1 + perm[jj + j1]];
|
||||
int gi2 = permMod12[ii + 1 + perm[jj + 1]];
|
||||
|
||||
// Calculate the contribution from the three corners
|
||||
double t0 = 0.5 - x0 * x0 - y0 * y0;
|
||||
double n0;
|
||||
if(t0 < 0)
|
||||
{
|
||||
n0 = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient
|
||||
}
|
||||
|
||||
double t1 = 0.5 - x1 * x1 - y1 * y1;
|
||||
double n1;
|
||||
if(t1 < 0)
|
||||
{
|
||||
n1 = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t1 *= t1;
|
||||
n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
|
||||
}
|
||||
|
||||
double t2 = 0.5 - x2 * x2 - y2 * y2;
|
||||
double n2;
|
||||
if(t2 < 0)
|
||||
{
|
||||
n2 = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t2 *= t2;
|
||||
n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
|
||||
}
|
||||
|
||||
// Add contributions from each corner to get the final noise value.
|
||||
// The result is scaled to return values in the interval [-1,1].
|
||||
return 70.0 * (n0 + n1 + n2);
|
||||
}
|
||||
|
||||
private double simplex3D(double xin, double yin, double zin)
|
||||
{
|
||||
// Skew the input space to determine which simplex cell we're in
|
||||
double s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D
|
||||
int i = floor(xin + s);
|
||||
int j = floor(yin + s);
|
||||
int k = floor(zin + s);
|
||||
double t = (i + j + k) * G3;
|
||||
double dx0 = i - t; // Unskew the cell origin back to (x,y,z) space
|
||||
double dy0 = j - t;
|
||||
double dz0 = k - t;
|
||||
|
||||
// For the 3D case, the simplex shape is a slightly irregular tetrahedron.
|
||||
|
||||
int i1; // Offsets for second corner of simplex in (i,j,k) coords
|
||||
int j1;
|
||||
int k1;
|
||||
int i2; // Offsets for third corner of simplex in (i,j,k) coords
|
||||
int j2;
|
||||
int k2;
|
||||
|
||||
double x0 = xin - dx0; // The x,y,z distances from the cell origin
|
||||
double y0 = yin - dy0;
|
||||
double z0 = zin - dz0;
|
||||
// Determine which simplex we are in
|
||||
if(x0 >= y0)
|
||||
{
|
||||
if(y0 >= z0)
|
||||
{
|
||||
i1 = 1; // X Y Z order
|
||||
j1 = 0;
|
||||
k1 = 0;
|
||||
i2 = 1;
|
||||
j2 = 1;
|
||||
k2 = 0;
|
||||
}
|
||||
else if(x0 >= z0)
|
||||
{
|
||||
i1 = 1; // X Z Y order
|
||||
j1 = 0;
|
||||
k1 = 0;
|
||||
i2 = 1;
|
||||
j2 = 0;
|
||||
k2 = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
i1 = 0; // Z X Y order
|
||||
j1 = 0;
|
||||
k1 = 1;
|
||||
i2 = 1;
|
||||
j2 = 0;
|
||||
k2 = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // x0<y0
|
||||
if(y0 < z0)
|
||||
{
|
||||
i1 = 0; // Z Y X order
|
||||
j1 = 0;
|
||||
k1 = 1;
|
||||
i2 = 0;
|
||||
j2 = 1;
|
||||
k2 = 1;
|
||||
}
|
||||
else if(x0 < z0)
|
||||
{
|
||||
i1 = 0; // Y Z X order
|
||||
j1 = 1;
|
||||
k1 = 0;
|
||||
i2 = 0;
|
||||
j2 = 1;
|
||||
k2 = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
i1 = 0; // Y X Z order
|
||||
j1 = 1;
|
||||
k1 = 0;
|
||||
i2 = 1;
|
||||
j2 = 1;
|
||||
k2 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
|
||||
// a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
|
||||
// a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
|
||||
// c = 1/6.
|
||||
double x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords
|
||||
double y1 = y0 - j1 + G3;
|
||||
double z1 = z0 - k1 + G3;
|
||||
double x2 = x0 - i2 + G32; // Offsets for third corner in (x,y,z) coords
|
||||
double y2 = y0 - j2 + G32;
|
||||
double z2 = z0 - k2 + G32;
|
||||
|
||||
// Work out the hashed gradient indices of the four simplex corners
|
||||
int ii = i & 255;
|
||||
int jj = j & 255;
|
||||
int kk = k & 255;
|
||||
int gi0 = permMod12[ii + perm[jj + perm[kk]]];
|
||||
int gi1 = permMod12[ii + i1 + perm[jj + j1 + perm[kk + k1]]];
|
||||
int gi2 = permMod12[ii + i2 + perm[jj + j2 + perm[kk + k2]]];
|
||||
int gi3 = permMod12[ii + 1 + perm[jj + 1 + perm[kk + 1]]];
|
||||
|
||||
// Calculate the contribution from the four corners
|
||||
double t0 = 0.5 - x0 * x0 - y0 * y0 - z0 * z0;
|
||||
double n0; // Noise contributions from the four corners
|
||||
if(t0 < 0)
|
||||
{
|
||||
n0 = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * dot(grad3[gi0], x0, y0, z0);
|
||||
}
|
||||
|
||||
double t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1;
|
||||
double n1;
|
||||
if(t1 < 0)
|
||||
{
|
||||
n1 = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t1 *= t1;
|
||||
n1 = t1 * t1 * dot(grad3[gi1], x1, y1, z1);
|
||||
}
|
||||
|
||||
double t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2;
|
||||
double n2;
|
||||
if(t2 < 0)
|
||||
{
|
||||
n2 = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t2 *= t2;
|
||||
n2 = t2 * t2 * dot(grad3[gi2], x2, y2, z2);
|
||||
}
|
||||
|
||||
double x3 = x0 + G33; // Offsets for last corner in (x,y,z) coords
|
||||
double y3 = y0 + G33;
|
||||
double z3 = z0 + G33;
|
||||
double t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3;
|
||||
double n3;
|
||||
if(t3 < 0)
|
||||
{
|
||||
n3 = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t3 *= t3;
|
||||
n3 = t3 * t3 * dot(grad3[gi3], x3, y3, z3);
|
||||
}
|
||||
|
||||
// Add contributions from each corner to get the final noise value.
|
||||
// The result is scaled to stay just inside [-1,1]
|
||||
return 32.0 * (n0 + n1 + n2 + n3);
|
||||
}
|
||||
|
||||
// Inner class to speed up gradient computations
|
||||
// (array access is a lot slower than member access)
|
||||
private static class Grad
|
||||
{
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
|
||||
Grad(double x, double y, double z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/main/java/com/volmit/iris/util/ScoreDirection.java
Normal file
10
src/main/java/com/volmit/iris/util/ScoreDirection.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
/**
|
||||
* @author Missionary (missionarymc@gmail.com)
|
||||
* @since 5/31/2018
|
||||
*/
|
||||
public enum ScoreDirection {
|
||||
UP,
|
||||
DOWN
|
||||
}
|
||||
74
src/main/java/com/volmit/iris/util/ShortTag.java
Normal file
74
src/main/java/com/volmit/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;
|
||||
}
|
||||
|
||||
}
|
||||
26
src/main/java/com/volmit/iris/util/Shrinkwrap.java
Normal file
26
src/main/java/com/volmit/iris/util/Shrinkwrap.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
public class Shrinkwrap<T>
|
||||
{
|
||||
private T t;
|
||||
|
||||
public Shrinkwrap(T t)
|
||||
{
|
||||
set(t);
|
||||
}
|
||||
|
||||
public Shrinkwrap()
|
||||
{
|
||||
this(null);
|
||||
}
|
||||
|
||||
public T get()
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
public void set(T t)
|
||||
{
|
||||
this.t = t;
|
||||
}
|
||||
}
|
||||
74
src/main/java/com/volmit/iris/util/StringTag.java
Normal file
74
src/main/java/com/volmit/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/com/volmit/iris/util/Tag.java
Normal file
73
src/main/java/com/volmit/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();
|
||||
|
||||
}
|
||||
755
src/main/java/com/volmit/iris/util/VectorMath.java
Normal file
755
src/main/java/com/volmit/iris/util/VectorMath.java
Normal file
@@ -0,0 +1,755 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import ninja.bytecode.shuriken.collections.KList;
|
||||
import ninja.bytecode.shuriken.format.Form;
|
||||
|
||||
/**
|
||||
* Vector utilities
|
||||
*
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class VectorMath
|
||||
{
|
||||
public static Vector scaleStatic(Axis x, Vector v, double amt)
|
||||
{
|
||||
switch(x)
|
||||
{
|
||||
case X:
|
||||
return scaleX(v, amt);
|
||||
case Y:
|
||||
return scaleY(v, amt);
|
||||
case Z:
|
||||
return scaleZ(v, amt);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Vector scaleX(Vector v, double amt)
|
||||
{
|
||||
double x = v.getX();
|
||||
double y = v.getY();
|
||||
double z = v.getZ();
|
||||
double rx = x == 0 ? 1 : amt / x;
|
||||
|
||||
return new Vector(x * rx, y * rx, z * rx);
|
||||
}
|
||||
|
||||
public static Vector scaleY(Vector v, double amt)
|
||||
{
|
||||
double x = v.getX();
|
||||
double y = v.getY();
|
||||
double z = v.getZ();
|
||||
double rx = y == 0 ? 1 : amt / y;
|
||||
|
||||
return new Vector(x * rx, y * rx, z * rx);
|
||||
}
|
||||
|
||||
public static Vector scaleZ(Vector v, double amt)
|
||||
{
|
||||
double x = v.getX();
|
||||
double y = v.getY();
|
||||
double z = v.getZ();
|
||||
double rx = z == 0 ? 1 : amt / z;
|
||||
|
||||
return new Vector(x * rx, y * rx, z * rx);
|
||||
}
|
||||
|
||||
public static Vector reverseXZ(Vector v)
|
||||
{
|
||||
v.setX(-v.getX());
|
||||
v.setZ(-v.getZ());
|
||||
return v;
|
||||
}
|
||||
|
||||
public static boolean isLookingNear(Location a, Location b, double maxOff)
|
||||
{
|
||||
Vector perfect = VectorMath.direction(a, b);
|
||||
Vector actual = a.getDirection();
|
||||
|
||||
return perfect.distance(actual) <= maxOff;
|
||||
}
|
||||
|
||||
public static Vector rotate(Direction current, Direction to, Vector v)
|
||||
{
|
||||
if(current.equals(to))
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
else if(current.equals(to.reverse()))
|
||||
{
|
||||
if(current.isVertical())
|
||||
{
|
||||
return new Vector(v.getX(), -v.getY(), v.getZ());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return new Vector(-v.getX(), v.getY(), -v.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Vector c = current.toVector().clone().add(to.toVector());
|
||||
|
||||
if(c.getX() == 0)
|
||||
{
|
||||
if(c.getY() != c.getZ())
|
||||
{
|
||||
return rotate90CX(v);
|
||||
}
|
||||
|
||||
return rotate90CCX(v);
|
||||
}
|
||||
|
||||
else if(c.getY() == 0)
|
||||
{
|
||||
if(c.getX() != c.getZ())
|
||||
{
|
||||
return rotate90CY(v);
|
||||
}
|
||||
|
||||
return rotate90CCY(v);
|
||||
}
|
||||
|
||||
else if(c.getZ() == 0)
|
||||
{
|
||||
if(c.getX() != c.getY())
|
||||
{
|
||||
return rotate90CZ(v);
|
||||
}
|
||||
|
||||
return rotate90CCZ(v);
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
// Y X 0 0
|
||||
// X Z 0 0
|
||||
|
||||
// 0 X Y 0
|
||||
// 0 Z X 0
|
||||
|
||||
public static Vector rotate(Direction current, Direction to, Vector v, int w, int h, int d)
|
||||
{
|
||||
if(current.equals(to))
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
else if(current.equals(to.reverse()))
|
||||
{
|
||||
if(current.isVertical())
|
||||
{
|
||||
return new Vector(v.getX(), -v.getY() + h, v.getZ());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return new Vector(-v.getX() + w, v.getY(), -v.getZ() + d);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Vector c = current.toVector().clone().add(to.toVector());
|
||||
|
||||
if(c.getX() == 0)
|
||||
{
|
||||
if(c.getY() != c.getZ())
|
||||
{
|
||||
return rotate90CX(v, d);
|
||||
}
|
||||
|
||||
return rotate90CCX(v, h);
|
||||
}
|
||||
|
||||
else if(c.getY() == 0)
|
||||
{
|
||||
if(c.getX() != c.getZ())
|
||||
{
|
||||
return rotate90CY(v, d);
|
||||
}
|
||||
|
||||
return rotate90CCY(v, w);
|
||||
}
|
||||
|
||||
else if(c.getZ() == 0)
|
||||
{
|
||||
if(c.getX() != c.getY())
|
||||
{
|
||||
return rotate90CZ(v, w);
|
||||
}
|
||||
|
||||
return rotate90CCZ(v, h);
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public static Vector rotate90CX(Vector v)
|
||||
{
|
||||
return new Vector(v.getX(), -v.getZ(), v.getY());
|
||||
}
|
||||
|
||||
public static Vector rotate90CCX(Vector v)
|
||||
{
|
||||
return new Vector(v.getX(), v.getZ(), -v.getY());
|
||||
}
|
||||
|
||||
public static Vector rotate90CY(Vector v)
|
||||
{
|
||||
return new Vector(-v.getZ(), v.getY(), v.getX());
|
||||
}
|
||||
|
||||
public static Vector rotate90CCY(Vector v)
|
||||
{
|
||||
return new Vector(v.getZ(), v.getY(), -v.getX());
|
||||
}
|
||||
|
||||
public static Vector rotate90CZ(Vector v)
|
||||
{
|
||||
return new Vector(v.getY(), -v.getX(), v.getZ());
|
||||
}
|
||||
|
||||
public static Vector rotate90CCZ(Vector v)
|
||||
{
|
||||
return new Vector(-v.getY(), v.getX(), v.getZ());
|
||||
}
|
||||
|
||||
public static Vector rotate90CX(Vector v, int s)
|
||||
{
|
||||
return new Vector(v.getX(), -v.getZ() + s, v.getY());
|
||||
}
|
||||
|
||||
public static Vector rotate90CCX(Vector v, int s)
|
||||
{
|
||||
return new Vector(v.getX(), v.getZ(), -v.getY() + s);
|
||||
}
|
||||
|
||||
public static Vector rotate90CY(Vector v, int s)
|
||||
{
|
||||
return new Vector(-v.getZ() + s, v.getY(), v.getX());
|
||||
}
|
||||
|
||||
public static Vector rotate90CCY(Vector v, int s)
|
||||
{
|
||||
return new Vector(v.getZ(), v.getY(), -v.getX() + s);
|
||||
}
|
||||
|
||||
public static Vector rotate90CZ(Vector v, int s)
|
||||
{
|
||||
return new Vector(v.getY(), -v.getX() + s, v.getZ());
|
||||
}
|
||||
|
||||
public static Vector rotate90CCZ(Vector v, int s)
|
||||
{
|
||||
return new Vector(-v.getY() + s, v.getX(), v.getZ());
|
||||
}
|
||||
|
||||
public static Vector getAxis(Direction current, Direction to)
|
||||
{
|
||||
if(current.equals(Direction.U) || current.equals(Direction.D))
|
||||
{
|
||||
if(to.equals(Direction.U) || to.equals(Direction.D))
|
||||
{
|
||||
return new Vector(1, 0, 0);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if(current.equals(Direction.N) || current.equals(Direction.S))
|
||||
{
|
||||
return Direction.E.toVector();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return Direction.S.toVector();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Vector(0, 1, 0);
|
||||
}
|
||||
|
||||
private static double round(double value, int precision)
|
||||
{
|
||||
return Double.valueOf(Form.f(value, precision));
|
||||
}
|
||||
|
||||
public static Vector clip(Vector v, int decimals)
|
||||
{
|
||||
v.setX(round(v.getX(), decimals));
|
||||
v.setY(round(v.getY(), decimals));
|
||||
v.setZ(round(v.getZ(), decimals));
|
||||
return v;
|
||||
}
|
||||
|
||||
public static Vector rotateVectorCC(Vector vec, Vector axis, double deg)
|
||||
{
|
||||
double theta = Math.toRadians(deg);
|
||||
double x, y, z;
|
||||
double u, v, w;
|
||||
x = vec.getX();
|
||||
y = vec.getY();
|
||||
z = vec.getZ();
|
||||
u = axis.getX();
|
||||
v = axis.getY();
|
||||
w = axis.getZ();
|
||||
double xPrime = u * (u * x + v * y + w * z) * (1d - Math.cos(theta)) + x * Math.cos(theta) + (-w * y + v * z) * Math.sin(theta);
|
||||
double yPrime = v * (u * x + v * y + w * z) * (1d - Math.cos(theta)) + y * Math.cos(theta) + (w * x - u * z) * Math.sin(theta);
|
||||
double zPrime = w * (u * x + v * y + w * z) * (1d - Math.cos(theta)) + z * Math.cos(theta) + (-v * x + u * y) * Math.sin(theta);
|
||||
|
||||
return clip(new Vector(xPrime, yPrime, zPrime), 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all SIMPLE block faces from a more specific block face (SOUTH_EAST) =
|
||||
* (south, east)
|
||||
*
|
||||
* @param f
|
||||
* the block face
|
||||
* @return multiple faces, or one if the face is already simple
|
||||
*/
|
||||
public static KList<BlockFace> split(BlockFace f)
|
||||
{
|
||||
KList<BlockFace> faces = new KList<BlockFace>();
|
||||
|
||||
switch(f)
|
||||
{
|
||||
case DOWN:
|
||||
faces.add(BlockFace.DOWN);
|
||||
break;
|
||||
case EAST:
|
||||
faces.add(BlockFace.EAST);
|
||||
break;
|
||||
case EAST_NORTH_EAST:
|
||||
faces.add(BlockFace.EAST);
|
||||
faces.add(BlockFace.EAST);
|
||||
faces.add(BlockFace.NORTH);
|
||||
break;
|
||||
case EAST_SOUTH_EAST:
|
||||
faces.add(BlockFace.EAST);
|
||||
faces.add(BlockFace.EAST);
|
||||
faces.add(BlockFace.SOUTH);
|
||||
break;
|
||||
case NORTH:
|
||||
faces.add(BlockFace.NORTH);
|
||||
break;
|
||||
case NORTH_EAST:
|
||||
faces.add(BlockFace.NORTH);
|
||||
faces.add(BlockFace.EAST);
|
||||
break;
|
||||
case NORTH_NORTH_EAST:
|
||||
faces.add(BlockFace.NORTH);
|
||||
faces.add(BlockFace.NORTH);
|
||||
faces.add(BlockFace.EAST);
|
||||
break;
|
||||
case NORTH_NORTH_WEST:
|
||||
faces.add(BlockFace.NORTH);
|
||||
faces.add(BlockFace.NORTH);
|
||||
faces.add(BlockFace.WEST);
|
||||
break;
|
||||
case NORTH_WEST:
|
||||
faces.add(BlockFace.NORTH);
|
||||
faces.add(BlockFace.WEST);
|
||||
break;
|
||||
case SELF:
|
||||
faces.add(BlockFace.SELF);
|
||||
break;
|
||||
case SOUTH:
|
||||
faces.add(BlockFace.SOUTH);
|
||||
break;
|
||||
case SOUTH_EAST:
|
||||
faces.add(BlockFace.SOUTH);
|
||||
faces.add(BlockFace.EAST);
|
||||
break;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
faces.add(BlockFace.SOUTH);
|
||||
faces.add(BlockFace.SOUTH);
|
||||
faces.add(BlockFace.EAST);
|
||||
break;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
faces.add(BlockFace.SOUTH);
|
||||
faces.add(BlockFace.SOUTH);
|
||||
faces.add(BlockFace.WEST);
|
||||
break;
|
||||
case SOUTH_WEST:
|
||||
faces.add(BlockFace.SOUTH);
|
||||
faces.add(BlockFace.WEST);
|
||||
break;
|
||||
case UP:
|
||||
faces.add(BlockFace.UP);
|
||||
break;
|
||||
case WEST:
|
||||
faces.add(BlockFace.WEST);
|
||||
break;
|
||||
case WEST_NORTH_WEST:
|
||||
faces.add(BlockFace.WEST);
|
||||
faces.add(BlockFace.WEST);
|
||||
faces.add(BlockFace.NORTH);
|
||||
break;
|
||||
case WEST_SOUTH_WEST:
|
||||
faces.add(BlockFace.WEST);
|
||||
faces.add(BlockFace.WEST);
|
||||
faces.add(BlockFace.SOUTH);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return faces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a normalized vector going from a location to another
|
||||
*
|
||||
* @param from
|
||||
* from here
|
||||
* @param to
|
||||
* to here
|
||||
* @return the normalized vector direction
|
||||
*/
|
||||
public static Vector direction(Location from, Location to)
|
||||
{
|
||||
return to.clone().subtract(from.clone()).toVector().normalize();
|
||||
}
|
||||
|
||||
public static Vector directionNoNormal(Location from, Location to)
|
||||
{
|
||||
return to.clone().subtract(from.clone()).toVector();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vector direction from the yaw and pitch
|
||||
*
|
||||
* @param yaw
|
||||
* the yaw
|
||||
* @param pitch
|
||||
* the pitch
|
||||
* @return the vector
|
||||
*/
|
||||
public static Vector toVector(float yaw, float pitch)
|
||||
{
|
||||
return new Vector(Math.cos(pitch) * Math.cos(yaw), Math.sin(pitch), Math.cos(pitch) * Math.sin(-yaw));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an impulse (force) to an entity
|
||||
*
|
||||
* @param e
|
||||
* the entity
|
||||
* @param v
|
||||
* the vector
|
||||
*/
|
||||
public static void impulse(Entity e, Vector v)
|
||||
{
|
||||
impulse(e, v, 1.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an impulse (force) on an entity
|
||||
*
|
||||
* @param e
|
||||
* the entity
|
||||
* @param v
|
||||
* the vector
|
||||
* @param effectiveness
|
||||
* the effectiveness
|
||||
*/
|
||||
public static void impulse(Entity e, Vector v, double effectiveness)
|
||||
{
|
||||
Vector vx = e.getVelocity();
|
||||
vx.add(v.clone().multiply(effectiveness));
|
||||
e.setVelocity(vx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse a direction
|
||||
*
|
||||
* @param v
|
||||
* the direction
|
||||
* @return the reversed direction
|
||||
*/
|
||||
public static Vector reverse(Vector v)
|
||||
{
|
||||
if(v.getX() != 0)
|
||||
{
|
||||
v.setX(-v.getX());
|
||||
}
|
||||
|
||||
if(v.getY() != 0)
|
||||
{
|
||||
v.setY(-v.getY());
|
||||
}
|
||||
|
||||
if(v.getZ() != 0)
|
||||
{
|
||||
v.setZ(-v.getZ());
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a speed value from a vector (velocity)
|
||||
*
|
||||
* @param v
|
||||
* the vector
|
||||
* @return the speed
|
||||
*/
|
||||
public static double getSpeed(Vector v)
|
||||
{
|
||||
Vector vi = new Vector(0, 0, 0);
|
||||
Vector vt = new Vector(0, 0, 0).add(v);
|
||||
|
||||
return vi.distance(vt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift all vectors based on the given vector
|
||||
*
|
||||
* @param vector
|
||||
* the vector direction to shift the vectors
|
||||
* @param vectors
|
||||
* the vectors to be shifted
|
||||
* @return the shifted vectors
|
||||
*/
|
||||
public static KList<Vector> shift(Vector vector, KList<Vector> vectors)
|
||||
{
|
||||
return new KList<Vector>(new GListAdapter<Vector, Vector>()
|
||||
{
|
||||
@Override
|
||||
public Vector onAdapt(Vector from)
|
||||
{
|
||||
return from.add(vector);
|
||||
}
|
||||
}.adapt(vectors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to get the blockFace for the vector (will be tri-normalized)
|
||||
*
|
||||
* @param v
|
||||
* the vector
|
||||
* @return the block face or null
|
||||
*/
|
||||
public static BlockFace getBlockFace(Vector v)
|
||||
{
|
||||
Vector p = triNormalize(v);
|
||||
|
||||
for(BlockFace i : BlockFace.values())
|
||||
{
|
||||
if(p.getX() == i.getModX() && p.getY() == i.getModY() && p.getZ() == i.getModZ())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
for(BlockFace i : BlockFace.values())
|
||||
{
|
||||
if(p.getX() == i.getModX() && p.getZ() == i.getModZ())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
for(BlockFace i : BlockFace.values())
|
||||
{
|
||||
if(p.getY() == i.getModY() && p.getZ() == i.getModZ())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
for(BlockFace i : BlockFace.values())
|
||||
{
|
||||
if(p.getX() == i.getModX() || p.getY() == i.getModY())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
for(BlockFace i : BlockFace.values())
|
||||
{
|
||||
if(p.getX() == i.getModX() || p.getY() == i.getModY() || p.getZ() == i.getModZ())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Angle the vector in a self relative direction
|
||||
*
|
||||
* @param v
|
||||
* the initial direction
|
||||
* @param amt
|
||||
* the amount to shift in the direction
|
||||
* @return the shifted direction
|
||||
*/
|
||||
public static Vector angleLeft(Vector v, float amt)
|
||||
{
|
||||
Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
l.setDirection(v);
|
||||
float y = l.getYaw();
|
||||
float p = l.getPitch();
|
||||
CDou cy = new CDou(360);
|
||||
CDou cp = new CDou(180);
|
||||
cy.set(y);
|
||||
cp.set(p);
|
||||
cy.sub(amt);
|
||||
l.setYaw((float) cy.get());
|
||||
l.setPitch((float) cp.get());
|
||||
|
||||
return l.getDirection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Angle the vector in a self relative direction
|
||||
*
|
||||
* @param v
|
||||
* the initial direction
|
||||
* @param amt
|
||||
* the amount to shift in the direction
|
||||
* @return the shifted direction
|
||||
*/
|
||||
public static Vector angleRight(Vector v, float amt)
|
||||
{
|
||||
Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
l.setDirection(v);
|
||||
float y = l.getYaw();
|
||||
float p = l.getPitch();
|
||||
CDou cy = new CDou(360);
|
||||
CDou cp = new CDou(180);
|
||||
cy.set(y);
|
||||
cp.set(p);
|
||||
cy.add(amt);
|
||||
l.setYaw((float) cy.get());
|
||||
l.setPitch((float) cp.get());
|
||||
|
||||
return l.getDirection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Angle the vector in a self relative direction
|
||||
*
|
||||
* @param v
|
||||
* the initial direction
|
||||
* @param amt
|
||||
* the amount to shift in the direction
|
||||
* @return the shifted direction
|
||||
*/
|
||||
public static Vector angleUp(Vector v, float amt)
|
||||
{
|
||||
Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
l.setDirection(v);
|
||||
float y = l.getYaw();
|
||||
float p = l.getPitch();
|
||||
CDou cy = new CDou(360);
|
||||
cy.set(y);
|
||||
l.setYaw((float) cy.get());
|
||||
l.setPitch((float) Math.max(-90, p - amt));
|
||||
|
||||
return l.getDirection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Angle the vector in a self relative direction
|
||||
*
|
||||
* @param v
|
||||
* the initial direction
|
||||
* @param amt
|
||||
* the amount to shift in the direction
|
||||
* @return the shifted direction
|
||||
*/
|
||||
public static Vector angleDown(Vector v, float amt)
|
||||
{
|
||||
Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
|
||||
l.setDirection(v);
|
||||
float y = l.getYaw();
|
||||
float p = l.getPitch();
|
||||
CDou cy = new CDou(360);
|
||||
cy.set(y);
|
||||
l.setYaw((float) cy.get());
|
||||
l.setPitch((float) Math.min(90, p + amt));
|
||||
|
||||
return l.getDirection();
|
||||
}
|
||||
|
||||
/**
|
||||
* (clone) Force normalize the vector into three points, 1, 0, or -1. If the
|
||||
* value is > 0.333 (1) if the value is less than -0.333 (-1) else 0
|
||||
*
|
||||
* @param direction
|
||||
* the direction
|
||||
* @return the vector
|
||||
*/
|
||||
public static Vector triNormalize(Vector direction)
|
||||
{
|
||||
Vector v = direction.clone();
|
||||
v.normalize();
|
||||
|
||||
if(v.getX() > 0.333)
|
||||
{
|
||||
v.setX(1);
|
||||
}
|
||||
|
||||
else if(v.getX() < -0.333)
|
||||
{
|
||||
v.setX(-1);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
v.setX(0);
|
||||
}
|
||||
|
||||
if(v.getY() > 0.333)
|
||||
{
|
||||
v.setY(1);
|
||||
}
|
||||
|
||||
else if(v.getY() < -0.333)
|
||||
{
|
||||
v.setY(-1);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
v.setY(0);
|
||||
}
|
||||
|
||||
if(v.getZ() > 0.333)
|
||||
{
|
||||
v.setZ(1);
|
||||
}
|
||||
|
||||
else if(v.getZ() < -0.333)
|
||||
{
|
||||
v.setZ(-1);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
v.setZ(0);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
53
src/main/java/com/volmit/iris/util/WeightMap.java
Normal file
53
src/main/java/com/volmit/iris/util/WeightMap.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import ninja.bytecode.shuriken.collections.KMap;
|
||||
|
||||
public class WeightMap<T> extends KMap<T, Double>
|
||||
{
|
||||
private static final long serialVersionUID = 87558033900969389L;
|
||||
private boolean modified = false;
|
||||
private double lastWeight = 0;
|
||||
|
||||
public double getPercentChance(T t)
|
||||
{
|
||||
if(totalWeight() <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getWeight(t) / totalWeight();
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
modified = true;
|
||||
}
|
||||
|
||||
public WeightMap<T> setWeight(T t, double weight)
|
||||
{
|
||||
modified = true;
|
||||
put(t, weight);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getWeight(T t)
|
||||
{
|
||||
return get(t);
|
||||
}
|
||||
|
||||
public double totalWeight()
|
||||
{
|
||||
if(!modified)
|
||||
{
|
||||
return lastWeight;
|
||||
}
|
||||
|
||||
modified = false;
|
||||
Shrinkwrap<Double> s = new Shrinkwrap<Double>(0D);
|
||||
forEachKey(Integer.MAX_VALUE, (d) -> s.set(s.get() + 1));
|
||||
lastWeight = s.get();
|
||||
|
||||
return lastWeight;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user