mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-05 15:26:28 +00:00
Schematics Support Priority, Rotated Blocks, Sink & NoRotate
This commit is contained in:
@@ -7,10 +7,18 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.material.Directional;
|
||||
import org.bukkit.material.Ladder;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Stairs;
|
||||
import org.bukkit.material.Vine;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@@ -231,7 +239,11 @@ public class GenObject
|
||||
|
||||
public Location place(Location l)
|
||||
{
|
||||
return place(l, new NMSPlacer(l.getWorld()));
|
||||
NMSPlacer p;
|
||||
Location ll = place(l, p = new NMSPlacer(l.getWorld()));
|
||||
p.flush();
|
||||
|
||||
return ll;
|
||||
}
|
||||
|
||||
public Location place(Location l, IPlacer placer)
|
||||
@@ -263,12 +275,6 @@ public class GenObject
|
||||
for(SBlockVector i : s.keySet())
|
||||
{
|
||||
MB b = getSchematic().get(i);
|
||||
|
||||
if(b.material.equals(Material.CONCRETE_POWDER))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Location f = start.clone().add(i.toBlockVector());
|
||||
|
||||
Material m = placer.get(f.clone().subtract(0, 1, 0)).material;
|
||||
@@ -343,13 +349,124 @@ public class GenObject
|
||||
|
||||
for(SBlockVector i : g.keySet())
|
||||
{
|
||||
MB mb = g.get(i);
|
||||
MB mb = rotate(from, to, g.get(i));
|
||||
s.put(new SBlockVector(VectorMath.rotate(from, to, i.toBlockVector()).toBlockVector()), mb);
|
||||
}
|
||||
|
||||
name = name + "-rt" + to.name();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private MB rotate(Direction from, Direction to, MB mb)
|
||||
{
|
||||
try
|
||||
{
|
||||
Material t = mb.material;
|
||||
int i = t.getId();
|
||||
byte d = mb.data;
|
||||
MaterialData data = t.getData().getConstructor(int.class, byte.class).newInstance(i, d);
|
||||
|
||||
if(data instanceof Directional)
|
||||
{
|
||||
Directional dir = (Directional) data;
|
||||
Supplier<BlockFace> get = dir::getFacing;
|
||||
Consumer<BlockFace> set = dir::setFacingDirection;
|
||||
|
||||
if(dir instanceof Ladder)
|
||||
{
|
||||
get = ((Ladder) dir)::getAttachedFace;
|
||||
set = ((Ladder) dir)::setFacingDirection;
|
||||
}
|
||||
|
||||
if(dir instanceof Stairs)
|
||||
{
|
||||
get = ((Stairs) dir)::getAscendingDirection;
|
||||
set = ((Stairs) dir)::setFacingDirection;
|
||||
}
|
||||
|
||||
BlockFace fac = get.get();
|
||||
set.accept(rotate(from, to, fac));
|
||||
d = data.getData();
|
||||
t = data.getItemType();
|
||||
return MB.of(t, d);
|
||||
}
|
||||
|
||||
else if(data instanceof Vine)
|
||||
{
|
||||
Vine vin = (Vine) data;
|
||||
Vine vif = new Vine();
|
||||
|
||||
for(Direction j : Direction.news())
|
||||
{
|
||||
if(vin.isOnFace(j.getFace()))
|
||||
{
|
||||
vif.putOnFace(rotate(from, to, j.getFace()));
|
||||
}
|
||||
}
|
||||
|
||||
d = vif.getData();
|
||||
t = vif.getItemType();
|
||||
return MB.of(t, d);
|
||||
}
|
||||
|
||||
else if(i >= 235 && i <= 250)
|
||||
{
|
||||
BlockFace fac = getGlazedTCDir(d);
|
||||
d = toGlazedTCDir(Direction.getDirection(rotate(from, to, fac)).getFace());
|
||||
t = data.getItemType();
|
||||
return MB.of(t, d);
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return mb;
|
||||
}
|
||||
|
||||
private byte toGlazedTCDir(BlockFace b)
|
||||
{
|
||||
switch(b)
|
||||
{
|
||||
case NORTH:
|
||||
return 0;
|
||||
case EAST:
|
||||
return 1;
|
||||
case SOUTH:
|
||||
return 2;
|
||||
case WEST:
|
||||
return 3;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private BlockFace getGlazedTCDir(byte d2)
|
||||
{
|
||||
switch(d2)
|
||||
{
|
||||
case 0:
|
||||
return BlockFace.NORTH;
|
||||
case 1:
|
||||
return BlockFace.EAST;
|
||||
case 2:
|
||||
return BlockFace.SOUTH;
|
||||
case 3:
|
||||
return BlockFace.WEST;
|
||||
}
|
||||
|
||||
return BlockFace.NORTH;
|
||||
}
|
||||
|
||||
private BlockFace rotate(Direction from, Direction to, BlockFace face)
|
||||
{
|
||||
return Direction.getDirection(from.angle(Direction.getDirection(face).toVector(), to)).getFace();
|
||||
}
|
||||
|
||||
public void computeFlag(String j)
|
||||
{
|
||||
try
|
||||
@@ -379,6 +496,12 @@ public class GenObject
|
||||
int downshift = Integer.valueOf(j.split("\\Q \\E")[1]);
|
||||
shift.subtract(new Vector(0, downshift, 0));
|
||||
}
|
||||
|
||||
if(j.startsWith("raise "))
|
||||
{
|
||||
int downshift = Integer.valueOf(j.split("\\Q \\E")[1]);
|
||||
shift.add(new Vector(0, downshift, 0));
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ninja.bytecode.iris.generator.genobject;
|
||||
|
||||
import java.lang.Thread.State;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -18,21 +18,21 @@ import mortar.logic.format.F;
|
||||
import mortar.util.text.C;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.TimingsController;
|
||||
import ninja.bytecode.iris.generator.IrisGenerator;
|
||||
import ninja.bytecode.iris.generator.placer.BukkitPlacer;
|
||||
import ninja.bytecode.iris.generator.placer.NMSPlacer;
|
||||
import ninja.bytecode.iris.pack.IrisBiome;
|
||||
import ninja.bytecode.iris.util.IPlacer;
|
||||
import ninja.bytecode.shuriken.collections.GList;
|
||||
import ninja.bytecode.shuriken.collections.GMap;
|
||||
import ninja.bytecode.shuriken.collections.GSet;
|
||||
import ninja.bytecode.shuriken.execution.ChronoLatch;
|
||||
import ninja.bytecode.shuriken.execution.J;
|
||||
import ninja.bytecode.shuriken.logging.L;
|
||||
import ninja.bytecode.shuriken.math.M;
|
||||
|
||||
public class GenObjectDecorator extends BlockPopulator
|
||||
{
|
||||
private GMap<IrisBiome, GList<GenObjectGroup>> orderCache;
|
||||
private GMap<IrisBiome, GMap<GenObjectGroup, Double>> populationCache;
|
||||
private IPlacer placer;
|
||||
private Executor ex;
|
||||
@@ -43,11 +43,13 @@ public class GenObjectDecorator extends BlockPopulator
|
||||
{
|
||||
this.g = generator;
|
||||
populationCache = new GMap<>();
|
||||
orderCache = new GMap<>();
|
||||
ex = Executors.newSingleThreadExecutor();
|
||||
|
||||
for(IrisBiome i : generator.getDimension().getBiomes())
|
||||
{
|
||||
GMap<GenObjectGroup, Double> gc = new GMap<>();
|
||||
GMap<Integer, GList<GenObjectGroup>> or = new GMap<>();
|
||||
int ff = 0;
|
||||
for(String j : i.getSchematicGroups().k())
|
||||
{
|
||||
@@ -58,6 +60,13 @@ public class GenObjectDecorator extends BlockPopulator
|
||||
GenObjectGroup g = generator.getDimension().getObjectGroup(j);
|
||||
ff += g.size();
|
||||
gc.put(g, c);
|
||||
|
||||
if(!or.containsKey(g.getPiority()))
|
||||
{
|
||||
or.put(g.getPiority(), new GList<>());
|
||||
}
|
||||
|
||||
or.get(g.getPiority()).add(g);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
@@ -69,6 +78,14 @@ public class GenObjectDecorator extends BlockPopulator
|
||||
|
||||
if(!gc.isEmpty())
|
||||
{
|
||||
GList<GenObjectGroup> g = new GList<>();
|
||||
for(GList<GenObjectGroup> j : or.v())
|
||||
{
|
||||
g.addAll(j);
|
||||
}
|
||||
|
||||
Collections.sort(g, (a, b) -> a.getPiority() - b.getPiority());
|
||||
orderCache.put(i, g);
|
||||
populationCache.put(i, gc);
|
||||
|
||||
if(Iris.settings.performance.verbose)
|
||||
@@ -88,8 +105,9 @@ public class GenObjectDecorator extends BlockPopulator
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ex.execute(() -> {
|
||||
|
||||
ex.execute(() ->
|
||||
{
|
||||
Random random = new Random(((source.getX() - 32) * (source.getZ() + 54)) + world.getSeed());
|
||||
GSet<IrisBiome> hits = new GSet<>();
|
||||
|
||||
@@ -113,7 +131,7 @@ public class GenObjectDecorator extends BlockPopulator
|
||||
|
||||
hits.add(biome);
|
||||
|
||||
populate(world, random, source, biome, objects);
|
||||
populate(world, random, source, biome, objects, orderCache.get(biome));
|
||||
}
|
||||
|
||||
if(Iris.settings.performance.verbose)
|
||||
@@ -123,9 +141,9 @@ public class GenObjectDecorator extends BlockPopulator
|
||||
});
|
||||
}
|
||||
|
||||
private void populate(World world, Random random, Chunk source, IrisBiome biome, GMap<GenObjectGroup, Double> objects)
|
||||
private void populate(World world, Random random, Chunk source, IrisBiome biome, GMap<GenObjectGroup, Double> objects, GList<GenObjectGroup> order)
|
||||
{
|
||||
for(GenObjectGroup i : objects.k())
|
||||
for(GenObjectGroup i : order)
|
||||
{
|
||||
for(int j = 0; j < getTries(objects.get(i)); j++)
|
||||
{
|
||||
@@ -138,6 +156,7 @@ public class GenObjectDecorator extends BlockPopulator
|
||||
|
||||
if(!t.isSolid() || !biome.isSurface(t))
|
||||
{
|
||||
L.w(C.WHITE + "Object " + C.YELLOW + i.getName() + "/*" + C.WHITE + " failed to place in " + C.YELLOW + t.toString().toLowerCase() + C.WHITE + " at " + C.YELLOW + F.f(b.getX()) + " " + F.f(b.getY()) + " " + F.f(b.getZ()));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@ import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.PackController;
|
||||
import ninja.bytecode.iris.util.Direction;
|
||||
import ninja.bytecode.shuriken.collections.GList;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup;
|
||||
import ninja.bytecode.shuriken.format.F;
|
||||
import ninja.bytecode.shuriken.io.IO;
|
||||
import ninja.bytecode.shuriken.logging.L;
|
||||
@@ -22,12 +20,14 @@ public class GenObjectGroup
|
||||
private GList<GenObject> schematics;
|
||||
private GList<String> flags;
|
||||
private String name;
|
||||
private int priority;
|
||||
|
||||
public GenObjectGroup(String name)
|
||||
{
|
||||
this.schematics = new GList<>();
|
||||
this.flags = new GList<>();
|
||||
this.name = name;
|
||||
priority = Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
public void read(DataInputStream din) throws IOException
|
||||
@@ -148,6 +148,23 @@ public class GenObjectGroup
|
||||
return getSchematics().size();
|
||||
}
|
||||
|
||||
public int getPiority()
|
||||
{
|
||||
if(priority == Integer.MIN_VALUE)
|
||||
{
|
||||
for(String i : flags)
|
||||
{
|
||||
if(i.startsWith("priority "))
|
||||
{
|
||||
priority = Integer.valueOf(i.split("\\Q \\E")[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return priority;
|
||||
}
|
||||
|
||||
public static GenObjectGroup load(String string)
|
||||
{
|
||||
File folder = Iris.getController(PackController.class).loadFolder(string);
|
||||
@@ -195,19 +212,6 @@ public class GenObjectGroup
|
||||
|
||||
public void processVariants()
|
||||
{
|
||||
GList<GenObject> inject = new GList<>();
|
||||
for(GenObject i : getSchematics())
|
||||
{
|
||||
for(Direction j : new Direction[] {Direction.S, Direction.E, Direction.W})
|
||||
{
|
||||
GenObject cp = i.copy();
|
||||
GenObject f = cp;
|
||||
f.rotate(Direction.N, j);
|
||||
inject.add(f);
|
||||
}
|
||||
}
|
||||
|
||||
getSchematics().add(inject);
|
||||
for(GenObject i : getSchematics())
|
||||
{
|
||||
i.recalculateMountShift();
|
||||
@@ -218,6 +222,24 @@ public class GenObjectGroup
|
||||
}
|
||||
}
|
||||
|
||||
if(!flags.contains("no rotation"))
|
||||
{
|
||||
GList<GenObject> inject = new GList<>();
|
||||
for(GenObject i : getSchematics())
|
||||
{
|
||||
for(Direction j : new Direction[] {Direction.S, Direction.E, Direction.W})
|
||||
{
|
||||
GenObject cp = i.copy();
|
||||
GenObject f = cp;
|
||||
f.rotate(Direction.N, j);
|
||||
f.recalculateMountShift();
|
||||
inject.add(f);
|
||||
}
|
||||
}
|
||||
|
||||
getSchematics().add(inject);
|
||||
}
|
||||
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Processed " + ChatColor.WHITE + F.f(schematics.size()) + ChatColor.LIGHT_PURPLE + " Schematics in " + ChatColor.WHITE + name);
|
||||
}
|
||||
|
||||
@@ -227,8 +249,50 @@ public class GenObjectGroup
|
||||
{
|
||||
i.dispose();
|
||||
}
|
||||
|
||||
|
||||
schematics.clear();
|
||||
flags.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((flags == null) ? 0 : flags.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + priority;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(this == obj)
|
||||
return true;
|
||||
if(obj == null)
|
||||
return false;
|
||||
if(getClass() != obj.getClass())
|
||||
return false;
|
||||
GenObjectGroup other = (GenObjectGroup) obj;
|
||||
if(flags == null)
|
||||
{
|
||||
if(other.flags != null)
|
||||
return false;
|
||||
}
|
||||
else if(!flags.equals(other.flags))
|
||||
return false;
|
||||
if(name == null)
|
||||
{
|
||||
if(other.name != null)
|
||||
return false;
|
||||
}
|
||||
else if(!name.equals(other.name))
|
||||
return false;
|
||||
if(priority != other.priority)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user