9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-26 02:29:14 +00:00
This commit is contained in:
Daniel Mills
2020-01-04 14:01:10 -05:00
parent 7934be70ee
commit 93e02093be
20 changed files with 1793 additions and 138 deletions

View File

@@ -20,6 +20,7 @@ import org.bukkit.util.Vector;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.biome.IrisBiome;
import ninja.bytecode.iris.util.Direction;
import ninja.bytecode.shuriken.bench.Profiler;
import ninja.bytecode.shuriken.collections.GMap;
import ninja.bytecode.shuriken.collections.GSet;
@@ -36,6 +37,7 @@ public class Iris extends JavaPlugin implements Listener
public void onEnable()
{
Direction.calculatePermutations();
profiler = new Profiler(512);
values = new GMap<>();
instance = this;
@@ -46,23 +48,29 @@ public class Iris extends JavaPlugin implements Listener
new WandManager();
// Debug world regens
GSet<String> ws = new GSet<>();
World w = createIrisWorld();
for(Player i : Bukkit.getOnlinePlayers())
if(settings.performance.loadonstart)
{
Location m = i.getLocation();
ws.add(i.getWorld().getName());
i.teleport(new Location(w, m.getX(), m.getY(), m.getZ(), m.getYaw(), m.getPitch()));
i.setFlying(true);
i.setGameMode(GameMode.SPECTATOR);
}
GSet<String> ws = new GSet<>();
for(String i : ws)
{
Bukkit.unloadWorld(i, false);
World w = createIrisWorld();
for(Player i : Bukkit.getOnlinePlayers())
{
Location m = i.getLocation();
ws.add(i.getWorld().getName());
i.teleport(new Location(w, m.getX(), m.getY(), m.getZ(), m.getYaw(), m.getPitch()));
i.setFlying(true);
i.setGameMode(GameMode.SPECTATOR);
}
for(String i : ws)
{
Bukkit.unloadWorld(i, false);
}
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
for(World i : Bukkit.getWorlds())
{

View File

@@ -12,6 +12,7 @@ public class Settings
public PerformanceMode performanceMode = PerformanceMode.HALF_CPU;
public int threadCount = 12;
public int threadPriority = Thread.MIN_PRIORITY;
public boolean loadonstart = false;
}
public static class GeneratorSettings
@@ -27,6 +28,6 @@ public class Settings
public int seaLevel = 63;
public double biomeScale = 2.46;
public boolean flatBedrock = false;
public boolean doTrees = false;
public boolean doSchematics = false;
}
}

View File

@@ -199,6 +199,50 @@ public class WandManager implements Listener
e.getPlayer().getInventory().setItemInMainHand(WandUtil.createWand(b[0], b[1]));
e.getPlayer().updateInventory();
}
if(e.getMessage().startsWith("/ivert"))
{
e.setCancelled(true);
Location[] b = WandUtil.getCuboid(e.getPlayer().getInventory().getItemInMainHand());
Location a1 = b[0].clone();
Location a2 = b[1].clone();
Location a1x = b[0].clone();
Location a2x = b[1].clone();
Cuboid cursor = new Cuboid(a1, a2);
Cuboid cursorx = new Cuboid(a1, a2);
while(!cursor.containsOnly(Material.AIR))
{
a1.add(new Vector(0, 1, 0));
a2.add(new Vector(0, 1, 0));
cursor = new Cuboid(a1, a2);
}
a1.add(new Vector(0, -1, 0));
a2.add(new Vector(0, -1, 0));
while(!cursorx.containsOnly(Material.AIR))
{
a1x.add(new Vector(0, -1, 0));
a2x.add(new Vector(0, -1, 0));
cursorx = new Cuboid(a1x, a2x);
}
a1x.add(new Vector(0, 1, 0));
a2x.add(new Vector(0, 1, 0));
b[0] = a1;
b[1] = a2x;
cursor = new Cuboid(b[0], b[1]);
cursor = cursor.contract(CuboidDirection.North);
cursor = cursor.contract(CuboidDirection.South);
cursor = cursor.contract(CuboidDirection.East);
cursor = cursor.contract(CuboidDirection.West);
b[0] = cursor.getLowerNE();
b[1] = cursor.getUpperSW();
e.getPlayer().getInventory().setItemInMainHand(WandUtil.createWand(b[0], b[1]));
e.getPlayer().updateInventory();
}
if(e.getMessage().equals("/iris wand"))
{

View File

@@ -1,9 +1,12 @@
package ninja.bytecode.iris.generator;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
@@ -24,13 +27,16 @@ import ninja.bytecode.iris.generator.layer.GenLayerOreLapis;
import ninja.bytecode.iris.generator.layer.GenLayerRidge;
import ninja.bytecode.iris.generator.populator.BiomeBiasSchematicPopulator;
import ninja.bytecode.iris.schematic.Schematic;
import ninja.bytecode.iris.schematic.SchematicGroup;
import ninja.bytecode.iris.util.AtomicChunkData;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.IrisInterpolation;
import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.ParallelChunkGenerator;
import ninja.bytecode.shuriken.collections.GList;
import ninja.bytecode.shuriken.collections.GMap;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.io.IO;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.M;
import ninja.bytecode.shuriken.math.RNG;
@@ -70,6 +76,7 @@ public class IrisGenerator extends ParallelChunkGenerator
private GenLayerOreDiamond glOreDiamond;
private RNG rTerrain;
private World world;
private GMap<String, SchematicGroup> schematicCache = new GMap<>();
@Override
public void onInit(World world, Random random)
@@ -157,7 +164,7 @@ public class IrisGenerator extends ParallelChunkGenerator
mb = biome.getSurface(wx, wz, rTerrain);
MB mbx = biome.getScatterChanceSingle();
if(!mbx.material.equals(Material.AIR))
{
setBlock(x, i + 1, z, mbx.material, mbx.data);
@@ -209,42 +216,109 @@ public class IrisGenerator extends ParallelChunkGenerator
public List<BlockPopulator> getDefaultPopulators(World world)
{
GList<BlockPopulator> p = new GList<>();
int b = 0;
for(IrisBiome i : IrisBiome.getAllBiomes())
if(Iris.settings.gen.doSchematics)
{
b++;
L.i("Processing Populators for Biome " + i.getName());
for(String j : i.getSchematicGroups().keySet())
int b = 0;
int sch = 0;
for(IrisBiome i : IrisBiome.getAllBiomes())
{
p.add(new BiomeBiasSchematicPopulator(i.getSchematicGroups().get(j), i, loadSchematics(j)));
b++;
L.i("Processing Populators for Biome " + i.getName());
for(String j : i.getSchematicGroups().keySet())
{
SchematicGroup gs = loadSchematics(j);
sch += gs.size();
p.add(new BiomeBiasSchematicPopulator(i.getSchematicGroups().get(j), i, gs.getSchematics().toArray(new Schematic[gs.size()])));
}
}
p.add(new BlockPopulator()
{
@SuppressWarnings("deprecation")
@Override
public void populate(World world, Random random, Chunk source)
{
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> world.refreshChunk(source.getX(), source.getZ()), 50);
}
});
L.i("Initialized " + b + " Biomes with " + p.size() + " Populators using " + sch + " Schematics");
}
L.i("Initialized " + b + " Biomes and " + p.size() + " Populators");
L.flush();
return p;
}
private Schematic[] loadSchematics(String folder)
private SchematicGroup loadSchematics(String folder)
{
if(schematicCache.containsKey(folder))
{
return schematicCache.get(folder);
}
File f = new File(Iris.instance.getDataFolder(), "objects/" + folder);
GList<Schematic> s = new GList<>();
GList<String> flags = new GList<>();
if(f.exists() && f.isDirectory())
{
for(File i : f.listFiles())
{
if(i.isFile() && i.getName().endsWith(".ifl"))
{
try
{
flags.add(IO.readAll(i).split("\\Q\n\\E"));
}
catch(IOException e)
{
e.printStackTrace();
}
}
if(i.isFile() && i.getName().endsWith(".ish"))
{
J.attempt(()-> s.add(Schematic.load(i)));
J.attempt(() ->
{
Schematic sc = Schematic.load(i);
s.add(sc);
});
}
}
}
for(String i : flags)
{
String flag = i.trim().toLowerCase();
if(flag.equals("center"))
{
for(Schematic j : s)
{
j.setCenteredHeight();
}
L.i("Centered " + s.size() + " Schematics");
}
}
L.i("Loaded " + s.size() + " Schematics in " + folder);
return s.toArray(new Schematic[s.size()]);
SchematicGroup g = new SchematicGroup(folder);
g.setSchematics(s);
g.setFlags(flags);
for(String i : flags)
{
if(i.startsWith("priority="))
{
J.attempt(() -> g.setPriority(Integer.valueOf(i.split("\\Q=\\E")[1]).intValue()));
}
}
schematicCache.put(folder, g);
return g;
}
private double getBiomedHeight(int x, int z, ChunkPlan plan)

View File

@@ -24,10 +24,12 @@ public class IrisBiome
.surface(MB.of(Material.SAND));
public static final IrisBiome BEACH = new IrisBiome("Beach", Biome.BEACHES)
.surface(MB.of(Material.SAND))
.schematic("boulder/sandy", 0.009)
.height(0.12)
.schematic("palm", 0.83);
.schematic("tree/palm", 0.83);
public static final IrisBiome ROAD_GRAVEL = new IrisBiome("Gravel Road", Biome.PLAINS)
.surface(MB.of(Material.GRAVEL), MB.of(Material.COBBLESTONE))
.schematic("boulder/smooth", 0.001)
.scatter(MB.of(Material.TORCH), 0.05);
public static final IrisBiome ROAD_GRASSY = new IrisBiome("Grass Path", Biome.PLAINS)
.surface(MB.of(Material.GRASS_PATH))
@@ -46,109 +48,116 @@ public class IrisBiome
.height(-0.07);
public static final IrisBiome DESERT = new IrisBiome("Desert", Biome.DESERT)
.surface(MB.of(Material.SAND))
.schematic("deadwood", 0.03)
.schematic("boulder/sandy", 0.023)
.schematic("tree/deadwood", 0.03)
.scatter(MB.of(Material.DEAD_BUSH, 0), 0.008)
.dirt(MB.of(Material.SANDSTONE));
public static final IrisBiome DESERT_RED = new IrisBiome("Red Desert", Biome.DESERT)
.surface(MB.of(Material.SAND, 1))
.schematic("deadwood", 0.03)
.schematic("tree/deadwood", 0.045)
.scatter(MB.of(Material.DEAD_BUSH, 0), 0.008)
.dirt(MB.of(Material.RED_SANDSTONE));
public static final IrisBiome DESERT_COMBINED = new IrisBiome("Combined Desert", Biome.DESERT)
.surface(MB.of(Material.SAND), MB.of(Material.SAND, 1))
.scatter(MB.of(Material.DEAD_BUSH, 0), 0.008)
.schematic("deadwood", 0.05)
.schematic("tree/deadwood", 0.0443)
.dirt(MB.of(Material.SANDSTONE), MB.of(Material.RED_SANDSTONE))
.simplexSurface();
public static final IrisBiome DESERT_HILLS = new IrisBiome("Desert Hills", Biome.DESERT_HILLS)
.surface(MB.of(Material.SAND))
.amp(0.75)
.height(0.137)
.schematic("deadwood", 0.03)
.schematic("tree/deadwood", 0.03)
.schematic("boulder/sandy", 0.015)
.scatter(MB.of(Material.DEAD_BUSH, 0), 0.08)
.dirt(MB.of(Material.SANDSTONE));
public static final IrisBiome MESA = new IrisBiome("Mesa", Biome.MESA)
.surface(MB.of(Material.HARD_CLAY), MB.of(Material.STAINED_CLAY, 1), MB.of(Material.STAINED_CLAY, 8), MB.of(Material.STAINED_CLAY, 12))
.dirt(MB.of(Material.CLAY), MB.of(Material.SAND), MB.of(Material.SAND, 1))
.schematic("boulder", 0.02)
.schematic("boulder/sandy", 0.02)
.simplexSurface();
public static final IrisBiome SAVANNA = new IrisBiome("Savanna", Biome.SAVANNA)
.schematic("deadwood", 0.03)
.schematic("tree/deadwood", 0.03)
.schematic("boulder/sandy", 0.02)
.schematic("boulder", 0.02)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.18);
public static final IrisBiome SAVANNA_HILLS = new IrisBiome("Savanna Hills", Biome.SAVANNA_ROCK)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.18)
.schematic("deadwood", 0.01)
.schematic("tree/deadwood", 0.01)
.schematic("boulder", 0.02)
.schematic("boulder/sandy", 0.02)
.height(0.13)
.amp(0.75);
public static final IrisBiome OCEAN_2 = new IrisBiome("Ocean 2", Biome.OCEAN)
.surface(MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.CLAY), MB.of(Material.GRAVEL))
.simplexSurface()
.height(-0.03);
public static final IrisBiome JUNGLE = new IrisBiome("Jungle", Biome.JUNGLE)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.058)
.schematic("boulder", 0.02)
.schematic("boulder/smooth", 0.02)
.schematic("tree/oak/massive", 0.045)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.013);
public static final IrisBiome JUNGLE_HILLS = new IrisBiome("Jungle Hills", Biome.JUNGLE_HILLS)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.081)
.schematic("boulder", 0.02)
.schematic("boulder/smooth", 0.02)
.schematic("tree/oak/massive", 0.045)
.amp(1.75)
.height(0.13)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.02);
public static final IrisBiome SWAMP = new IrisBiome("Swamp", Biome.SWAMPLAND)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.04)
.schematic("willow", 2.5)
.schematic("tree/willow", 2.5)
.schematic("boulder", 0.02)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.03);
public static final IrisBiome PLAINS = new IrisBiome("Plains", Biome.PLAINS)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.38)
.schematic("oak_bush", 0.25)
.schematic("tree/oak/bush", 0.25)
.schematic("boulder", 0.02)
.amp(0.4)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.03);
public static final IrisBiome OCEAN_3 = new IrisBiome("Ocean 3", Biome.OCEAN)
.surface(MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.CLAY), MB.of(Material.GRAVEL))
.simplexSurface()
.height(-0.03);
public static final IrisBiome DECAYING_PLAINS = new IrisBiome("Decaying Plains", Biome.PLAINS)
.surface(MB.of(Material.GRASS_PATH), MB.of(Material.GRASS))
.scatter(MB.of(Material.LONG_GRASS, 1), 0.04)
.schematic("deadwood", 0.03)
.schematic("tree/deadwood", 0.03)
.schematic("boulder/sandy", 0.01)
.simplexSurface();
public static final IrisBiome FOREST = new IrisBiome("Forest", Biome.FOREST)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.23)
.schematic("oak", 2.31)
.schematic("tree/oak", 2.31)
.schematic("boulder", 0.02)
.schematic("cracked_oak", 0.03)
.schematic("oak_large", 1.41)
.schematic("boulder/smooth", 0.01)
.schematic("tree/oak/cracked", 0.03)
.schematic("tree/oak/large", 1.41)
.schematic("tree/oak/massive", 0.045)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.13);
public static final IrisBiome FOREST_HILLS = new IrisBiome("Forest Hills", Biome.FOREST_HILLS)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.23)
.schematic("oak", 2.31)
.schematic("tree/oak", 2.31)
.schematic("boulder", 0.02)
.schematic("cracked_oak", 0.03)
.schematic("oak_large", 0.31)
.schematic("boulder/smooth", 0.01)
.schematic("tree/oak/cracked", 0.03)
.schematic("tree/oak/massive", 0.045)
.schematic("tree/oak/large", 0.31)
.amp(0.75)
.height(0.13)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.13);
public static final IrisBiome FOREST_MOUNTAINS = new IrisBiome("Forest Mountains", Biome.MUTATED_EXTREME_HILLS_WITH_TREES)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.13)
.amp(2.25)
.schematic("pine", 2.31)
.schematic("tree/pine", 2.31)
.schematic("boulder", 0.04)
.schematic("redwood", 1.11)
.schematic("redwood_tall", 2.51)
.schematic("boulder/smooth", 0.01)
.schematic("tree/redwood", 1.11)
.schematic("tree/redwood/tall", 2.51)
.height(0.165)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.13);
public static final IrisBiome HAUNTED_FOREST = new IrisBiome("Haunted Forest", Biome.MUTATED_SWAMPLAND)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.13)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.13)
.schematic("willow", 2.31)
.schematic("oak", 1.31)
.schematic("tree/willow", 1.21)
.schematic("tree/oak", 0.71)
.schematic("boulder", 0.01)
.schematic("cracked_oak", 0.03)
.schematic("oak_bush", 1.83)
.schematic("boulder/smooth", 0.02)
.schematic("tree/oak/cracked", 0.03)
.schematic("tree/oak/massive", 0.4)
.schematic("tree/oak/bush", 1.83)
.schematic("structure/magical", 0.002)
.addEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 100, 0))
.addEffect(new PotionEffect(PotionEffectType.SLOW, 100, 0))
.addEffect(new PotionEffect(PotionEffectType.HUNGER, 100, 0))
@@ -156,71 +165,74 @@ public class IrisBiome
.scatterSurface();
public static final IrisBiome BIRCH_FOREST = new IrisBiome("Birch Forest", Biome.BIRCH_FOREST)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.23)
.schematic("birch", 2.51)
.schematic("tree/birch", 2.51)
.schematic("boulder", 0.02)
.schematic("birch_small", 3.25)
.schematic("boulder/smooth", 0.01)
.schematic("tree/birch/small", 3.25)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.13);
public static final IrisBiome BIRCH_FOREST_HILLS = new IrisBiome("Birch Forest Hills", Biome.BIRCH_FOREST_HILLS)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.23)
.schematic("birch", 2.51)
.schematic("tree/birch", 2.51)
.schematic("boulder/smooth", 0.01)
.schematic("boulder", 0.02)
.schematic("birch_small", 3.25)
.schematic("tree/birch/small", 3.25)
.amp(0.75)
.height(0.13)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.13);
public static final IrisBiome OCEAN_4 = new IrisBiome("Ocean 4", Biome.OCEAN)
.surface(MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.CLAY), MB.of(Material.GRAVEL))
.simplexSurface()
.height(-0.03);
public static final IrisBiome ROOFED_FOREST = new IrisBiome("Roofed Forest", Biome.ROOFED_FOREST)
.scatter(MB.of(Material.LONG_GRASS, 1), 0.23)
.schematic("boulder", 0.02)
.schematic("tree/oak/massive", 0.02)
.schematic("tree/oak/roofed", 0.78)
.schematic("boulder/smooth", 0.01)
.schematic("structure/magical", 0.009)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.13);
public static final IrisBiome TAIGA = new IrisBiome("Taiga", Biome.TAIGA)
.schematic("cracked_pine", 0.03)
.schematic("pine", 2.51)
.schematic("boulder", 0.08)
.schematic("tree/pine/cracked", 0.03)
.schematic("tree/pine", 2.51)
.schematic("boulder", 0.02)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.07);
public static final IrisBiome EXTREME_HILLS = new IrisBiome("Extreme Hills", Biome.EXTREME_HILLS)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.04)
.amp(1.565)
.schematic("boulder/smooth", 0.01)
.height(0.142);
public static final IrisBiome EXTREME_HILLS_TREES = new IrisBiome("Extreme Hills +", Biome.EXTREME_HILLS_WITH_TREES)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.09)
.schematic("boulder", 0.02)
.schematic("pine", 1.02)
.schematic("redwood_tall", 3.02)
.schematic("tree/pine", 1.02)
.schematic("boulder/smooth", 0.01)
.schematic("tree/redwood/tall", 3.02)
.amp(1.525)
.height(0.152);
public static final IrisBiome TAIGA_COLD = new IrisBiome("Taiga Cold", Biome.TAIGA_COLD)
.scatter(MB.of(Material.LONG_GRASS, 2), 0.04)
.schematic("pine", 2.51)
.schematic("boulder", 0.02)
.schematic("cracked_pine", 0.03);
.schematic("tree/pine", 2.51)
.schematic("boulder/snowy", 0.02)
.schematic("tree/pine/cracked", 0.03);
public static final IrisBiome TAIGA_COLD_HILLS = new IrisBiome("Taiga Cold Hills", Biome.TAIGA_COLD_HILLS)
.schematic("pine", 2.51)
.schematic("boulder", 0.02)
.schematic("cracked_pine", 0.03);
public static final IrisBiome ICE_FLATS = new IrisBiome("Ice Flats", Biome.ICE_FLATS);
.schematic("tree/pine", 2.51)
.schematic("boulder/snowy", 0.02)
.schematic("tree/pine/cracked", 0.03);
public static final IrisBiome ICE_FLATS = new IrisBiome("Ice Flats", Biome.ICE_FLATS)
.schematic("boulder/snowy", 0.03);
public static final IrisBiome ICE_MOUNTAINS = new IrisBiome("Ice Mountains", Biome.ICE_MOUNTAINS)
.schematic("boulder/snowy", 0.03)
.amp(1.45);
public static final IrisBiome OCEAN_5 = new IrisBiome("Ocean 5", Biome.OCEAN)
.surface(MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.SAND), MB.of(Material.CLAY), MB.of(Material.GRAVEL))
.simplexSurface()
.height(-0.03);
public static final IrisBiome REDWOOD_TAIGA = new IrisBiome("Redwood Taiga", Biome.REDWOOD_TAIGA)
.surface(MB.of(Material.DIRT, 2), MB.of(Material.DIRT, 1))
.schematic("redwood_large", 0.87)
.schematic("cracked_pine", 0.03)
.schematic("tree/redwood/large", 0.87)
.schematic("tree/redwood/massive", 0.2)
.schematic("tree/pine/cracked", 0.03)
.schematic("boulder", 0.02)
.schematic("redwood", 3.5)
.schematic("tree/redwood", 3.5)
.simplexSurface();
public static final IrisBiome REDWOOD_TAIGA_HILLS = new IrisBiome("Redwood Taiga Hills", Biome.REDWOOD_TAIGA_HILLS)
.surface(MB.of(Material.DIRT, 2), MB.of(Material.DIRT, 1))
.schematic("redwood_large", 0.87)
.schematic("cracked_pine", 0.03)
.schematic("tree/redwood/large", 0.87)
.schematic("tree/pine/cracked", 0.03)
.schematic("boulder", 0.02)
.schematic("redwood", 3.5)
.schematic("tree/redwood", 3.5)
.amp(0.75)
.simplexSurface();
@@ -453,4 +465,99 @@ public class IrisBiome
j.addPotionEffect(i);
}
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(amp);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + ((dirt == null) ? 0 : dirt.hashCode());
result = prime * result + ((effects == null) ? 0 : effects.hashCode());
temp = Double.doubleToLongBits(height);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((poly == null) ? 0 : poly.hashCode());
result = prime * result + ((realBiome == null) ? 0 : realBiome.hashCode());
result = prime * result + ((scatterChance == null) ? 0 : scatterChance.hashCode());
result = prime * result + (scatterSurface ? 1231 : 1237);
result = prime * result + ((schematicGroups == null) ? 0 : schematicGroups.hashCode());
result = prime * result + (simplexScatter ? 1231 : 1237);
result = prime * result + ((surface == null) ? 0 : surface.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
IrisBiome other = (IrisBiome) obj;
if(Double.doubleToLongBits(amp) != Double.doubleToLongBits(other.amp))
return false;
if(dirt == null)
{
if(other.dirt != null)
return false;
}
else if(!dirt.equals(other.dirt))
return false;
if(effects == null)
{
if(other.effects != null)
return false;
}
else if(!effects.equals(other.effects))
return false;
if(Double.doubleToLongBits(height) != Double.doubleToLongBits(other.height))
return false;
if(name == null)
{
if(other.name != null)
return false;
}
else if(!name.equals(other.name))
return false;
if(poly == null)
{
if(other.poly != null)
return false;
}
else if(!poly.equals(other.poly))
return false;
if(realBiome != other.realBiome)
return false;
if(scatterChance == null)
{
if(other.scatterChance != null)
return false;
}
else if(!scatterChance.equals(other.scatterChance))
return false;
if(scatterSurface != other.scatterSurface)
return false;
if(schematicGroups == null)
{
if(other.schematicGroups != null)
return false;
}
else if(!schematicGroups.equals(other.schematicGroups))
return false;
if(simplexScatter != other.simplexScatter)
return false;
if(surface == null)
{
if(other.surface != null)
return false;
}
else if(!surface.equals(other.surface))
return false;
return true;
}
}

View File

@@ -27,7 +27,6 @@ public class GenLayerOreDiamond extends GenLayer
clamp = new CNG(rng.nextParallelRNG(299 + shift), 1D, 1).scale(0.0325).fractureWith(new CNG(rng.nextParallelRNG(412 + shift), 1D, 1)
.scale(0.015).fractureWith(new CNG(rng.nextParallelRNG(412 + shift), 1D, 1)
.scale(0.03), 33), 592);
//@done
}
@@ -35,7 +34,7 @@ public class GenLayerOreDiamond extends GenLayer
{
double orenoise = ore.noise(wxx, wzx);
if(clamp.noise(wxx, wzx) > 0.77 && IrisGenerator.ROCK.contains(MB.of(g.getType(x, (int) (orenoise * 12D), z))))
if(clamp.noise(wxx, wzx) > 0.85 && IrisGenerator.ROCK.contains(MB.of(g.getType(x, (int) (orenoise * 12D), z))))
{
g.setBlock(x, (int) (orenoise * 12D), z, Material.DIAMOND_ORE);
}

View File

@@ -34,7 +34,7 @@ public class GenLayerOreGold extends GenLayer
{
double orenoise = ore.noise(wxx, wzx);
if(clamp.noise(wxx, wzx) < 0.4 && (int) (orenoise * 200D) - 42 < 45 && b.getSurface().contains(new MB(Material.GRASS)) && IrisGenerator.ROCK.contains(MB.of(g.getType(x, (int) (orenoise * 200D) - 42, z))))
if(clamp.noise(wxx, wzx) > 0.75 && (int) (orenoise * 200D) - 42 < 45 && b.getSurface().contains(new MB(Material.GRASS)) && IrisGenerator.ROCK.contains(MB.of(g.getType(x, (int) (orenoise * 200D) - 42, z))))
{
g.setBlock(x, (int) (orenoise * 200D) - 42, z, Material.GOLD_ORE);
}

View File

@@ -30,4 +30,33 @@ public class BiomeBiasSchematicPopulator extends SurfaceBiasSchematicPopulator
super.doPopulate(world, random, source, wx, wz);
}
}
@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((biome == null) ? 0 : biome.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(!super.equals(obj))
return false;
if(getClass() != obj.getClass())
return false;
BiomeBiasSchematicPopulator other = (BiomeBiasSchematicPopulator) obj;
if(biome == null)
{
if(other.biome != null)
return false;
}
else if(!biome.equals(other.biome))
return false;
return true;
}
}

View File

@@ -1,5 +1,6 @@
package ninja.bytecode.iris.generator.populator;
import java.util.Arrays;
import java.util.Random;
import org.bukkit.Chunk;
@@ -32,4 +33,28 @@ public class SchematicPopulator extends ChancedPopulator
schematics[random.nextInt(schematics.length)].place(world, wx, b.getY() - 1, wz);
}
@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + Arrays.hashCode(schematics);
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(!super.equals(obj))
return false;
if(getClass() != obj.getClass())
return false;
SchematicPopulator other = (SchematicPopulator) obj;
if(!Arrays.equals(schematics, other.schematics))
return false;
return true;
}
}

View File

@@ -27,6 +27,35 @@ public class SurfaceBiasSchematicPopulator extends SchematicPopulator
return this;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((bias == null) ? 0 : bias.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(!super.equals(obj))
return false;
if(getClass() != obj.getClass())
return false;
SurfaceBiasSchematicPopulator other = (SurfaceBiasSchematicPopulator) obj;
if(bias == null)
{
if(other.bias != null)
return false;
}
else if(!bias.equals(other.bias))
return false;
return true;
}
@Override
public void doPopulate(World world, Random random, Chunk source, int wx, int wz)
{

View File

@@ -22,6 +22,7 @@ import ninja.bytecode.shuriken.logging.L;
public class Schematic
{
private boolean centeredHeight;
private int w;
private int h;
private int d;
@@ -29,7 +30,7 @@ public class Schematic
private int y;
private int z;
private final GMap<BlockVector, MB> s;
public Schematic(int w, int h, int d, int x, int y, int z)
{
this.w = w;
@@ -39,59 +40,49 @@ public class Schematic
this.y = y;
this.z = z;
s = new GMap<>();
centeredHeight = false;
}
public void setCenteredHeight()
{
this.centeredHeight = true;
}
public int getW()
{
return w;
}
public int getH()
{
return h;
}
public int getD()
{
return d;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public int getZ()
{
return z;
}
public GMap<BlockVector, MB> getSchematic()
{
return s;
}
@SuppressWarnings("deprecation")
public void read(InputStream in) throws IOException
{
@@ -105,20 +96,20 @@ public class Schematic
z = din.readInt();
int l = din.readInt();
clear();
for(int i = 0; i < l; i++)
{
s.put(new BlockVector(din.readInt(), din.readInt(), din.readInt()), new MB(Material.getMaterial((int)din.readInt()), din.readInt()));
s.put(new BlockVector(din.readInt(), din.readInt(), din.readInt()), new MB(Material.getMaterial((int) din.readInt()), din.readInt()));
}
din.close();
}
@SuppressWarnings("deprecation")
public void write(OutputStream out) throws IOException
{
CustomOutputStream cos = new CustomOutputStream(out, 9);
DataOutputStream dos = new DataOutputStream(cos);
DataOutputStream dos = new DataOutputStream(cos);
dos.writeInt(w);
dos.writeInt(h);
dos.writeInt(d);
@@ -126,7 +117,7 @@ public class Schematic
dos.writeInt(y);
dos.writeInt(z);
dos.writeInt(s.size());
for(BlockVector i : s.keySet())
{
dos.writeInt(i.getBlockX());
@@ -135,42 +126,43 @@ public class Schematic
dos.writeInt(s.get(i).material.getId());
dos.writeInt(s.get(i).data);
}
dos.close();
}
public BlockVector getOffset()
{
return new BlockVector(x, y, z);
}
public MB get(int x, int y, int z)
{
return s.get(new BlockVector(x, y, z));
}
public boolean has(int x, int y, int z)
{
return s.contains(new BlockVector(x, y, z));
}
public void put(int x, int y, int z, MB mb)
{
s.put(new BlockVector(x, y, z), mb);
}
public Schematic copy()
{
Schematic s = new Schematic(w, h, d, x, y, z);
s.fill(this.s);
s.centeredHeight = centeredHeight;
return s;
}
public void clear()
{
s.clear();
}
public void fill(GMap<BlockVector, MB> b)
{
clear();
@@ -179,7 +171,7 @@ public class Schematic
public void place(World source, int wx, int wy, int wz)
{
Location start = new Location(source, wx, wy, wz).clone().subtract(w / 2, 0, d / 2);
Location start = new Location(source, wx, wy, wz).clone().subtract(w / 2, centeredHeight ? h / 2 : 0, d / 2);
for(BlockVector i : getSchematic().k())
{
@@ -190,12 +182,12 @@ public class Schematic
{
continue;
}
try
{
Catalyst12.setBlock(source, f.getBlockX(), f.getBlockY(), f.getBlockZ(), b);
}
catch(Throwable e)
{
e.printStackTrace();

View File

@@ -0,0 +1,64 @@
package ninja.bytecode.iris.schematic;
import ninja.bytecode.shuriken.collections.GList;
public class SchematicGroup
{
private GList<Schematic> schematics;
private GList<String> flags;
private String name;
private int priority;
public SchematicGroup(String name)
{
this.schematics = new GList<>();
this.flags = new GList<>();
priority = 0;
this.name = name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public GList<Schematic> getSchematics()
{
return schematics;
}
public void setSchematics(GList<Schematic> schematics)
{
this.schematics = schematics;
}
public GList<String> getFlags()
{
return flags;
}
public void setFlags(GList<String> flags)
{
this.flags = flags;
}
public int getPriority()
{
return priority;
}
public void setPriority(int priority)
{
this.priority = priority;
}
public int size()
{
return getSchematics().size();
}
}

View 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());
}
}

View 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);
}
}

View File

@@ -1,7 +1,6 @@
package ninja.bytecode.iris.util;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;

View File

@@ -44,5 +44,31 @@ public abstract class ChancedPopulator extends BlockPopulator
}
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(chance);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
ChancedPopulator other = (ChancedPopulator) obj;
if(Double.doubleToLongBits(chance) != Double.doubleToLongBits(other.chance))
return false;
return true;
}
public abstract void doPopulate(World world, Random random, Chunk source, int x, int z);
}

View 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;
}
}

View File

@@ -1,7 +1,10 @@
package ninja.bytecode.iris.util;
import org.bukkit.util.Vector;
import ninja.bytecode.iris.util.Cuboid.CuboidDirection;
import ninja.bytecode.shuriken.collections.GList;
import ninja.bytecode.shuriken.collections.GMap;
/**
* Directions
@@ -17,11 +20,120 @@ public enum Direction
E(1, 0, 0, CuboidDirection.East),
W(-1, 0, 0, CuboidDirection.West);
private static GMap<GBiset<Direction, Direction>, DOP> permute = null;
private int x;
private int y;
private int z;
private CuboidDirection f;
@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.distance(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, GList<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;
@@ -30,6 +142,44 @@ public enum Direction
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;
@@ -52,12 +202,27 @@ public enum Direction
public static GList<Direction> news()
{
return new GList<Direction>().add(N, E, W, S);
return new GList<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 GList<Direction> udnews()
{
return new GList<Direction>().add(U, D, N, E, W, S);
return new GList<Direction>().add(U,D,N,E,W,S);
}
/**
@@ -134,4 +299,166 @@ public enum Direction
return -1;
}
}
public static void calculatePermutations()
{
if(permute != null)
{
return;
}
permute = new GMap<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 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;
}
}

View 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;
}
}

View File

@@ -0,0 +1,754 @@
package ninja.bytecode.iris.util;
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.GList;
import ninja.bytecode.shuriken.format.F;
/**
* 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(F.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 GList<BlockFace> split(BlockFace f)
{
GList<BlockFace> faces = new GList<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 GList<Vector> shift(Vector vector, GList<Vector> vectors)
{
return new GList<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;
}
}