mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Better gen hittests
This commit is contained in:
parent
b81765adda
commit
2b8d5541af
@ -1,13 +1,13 @@
|
||||
package com.volmit.iris.scaffold.jigsaw;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.object.IrisJigsawPiece;
|
||||
import com.volmit.iris.object.IrisJigsawPieceConnector;
|
||||
import com.volmit.iris.object.IrisJigsawStructure;
|
||||
import com.volmit.iris.object.IrisPosition;
|
||||
import com.volmit.iris.object.*;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.RNG;
|
||||
import lombok.Data;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.World;
|
||||
|
||||
@Data
|
||||
public class PlannedStructure {
|
||||
@ -16,37 +16,71 @@ public class PlannedStructure {
|
||||
private IrisPosition position;
|
||||
private IrisDataManager data;
|
||||
private RNG rng;
|
||||
private boolean verbose;
|
||||
|
||||
public PlannedStructure(IrisJigsawStructure structure, IrisPosition position, RNG rng)
|
||||
{
|
||||
verbose = true;
|
||||
this.pieces = new KList<>();
|
||||
this.structure = structure;
|
||||
this.position = position;
|
||||
this.rng = rng;
|
||||
this.data = structure.getLoader();
|
||||
|
||||
v("Creating Structure " + structure.getLoadKey() + " at " + position.toString() + " with depth of " + structure.getMaxDepth());
|
||||
generateStartPiece();
|
||||
|
||||
for(int i = 0; i < structure.getMaxDepth(); i++)
|
||||
{
|
||||
v("--- Layer " + i + " ---");
|
||||
generateOutwards(i);
|
||||
}
|
||||
|
||||
generateTerminators();
|
||||
}
|
||||
|
||||
private void generateOutwards(int layer) {
|
||||
for(PlannedPiece i : getPiecesWithAvailableConnectors())
|
||||
public void v(String v)
|
||||
{
|
||||
if(!verbose)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Iris.info("[Jigsaw]: " + v);
|
||||
}
|
||||
|
||||
public void place(World world)
|
||||
{
|
||||
for(PlannedPiece i : pieces)
|
||||
{
|
||||
i.place(world);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateOutwards(int layer) {
|
||||
if(getPiecesWithAvailableConnectors().isEmpty())
|
||||
{
|
||||
v("There are no more available pieces with open connections!");
|
||||
}
|
||||
|
||||
for(PlannedPiece i : getPiecesWithAvailableConnectors().shuffleCopy(rng))
|
||||
{
|
||||
v(" Expanding Piece: " + i.toString());
|
||||
generatePieceOutwards(i);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean generatePieceOutwards(PlannedPiece piece) {
|
||||
for(IrisJigsawPieceConnector i : piece.getAvailableConnectors())
|
||||
if(piece.getAvailableConnectors().isEmpty())
|
||||
{
|
||||
v("Piece " + piece.toString() + " has no more connectors!");
|
||||
}
|
||||
|
||||
for(IrisJigsawPieceConnector i : piece.getAvailableConnectors().shuffleCopy(rng))
|
||||
{
|
||||
v(" Expanding Piece " + piece + " Connector: " + i);
|
||||
if(generateConnectorOutwards(piece, i))
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,17 +100,46 @@ public class PlannedStructure {
|
||||
}
|
||||
|
||||
private boolean generateRotatedPiece(PlannedPiece piece, IrisJigsawPieceConnector pieceConnector, IrisJigsawPiece idea) {
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
PlannedPiece test = new PlannedPiece(piece.getPosition(), idea, 0, i, 0);
|
||||
KList<Integer> forder1 = new KList<Integer>().qadd(0).qadd(1).qadd(2).qadd(3).shuffle(rng);
|
||||
KList<Integer> forder2 = new KList<Integer>().qadd(0).qadd(1).qadd(2).qadd(3).shuffle(rng);
|
||||
|
||||
for(IrisJigsawPieceConnector j : test.getPiece().getConnectors())
|
||||
for(Integer i : forder1)
|
||||
{
|
||||
if(pieceConnector.isRotateConnector() && !pieceConnector.getDirection().getAxis().equals(Axis.Y))
|
||||
{
|
||||
if(generatePositionedPiece(piece, pieceConnector, test, j))
|
||||
for(Integer j : forder2)
|
||||
{
|
||||
return true;
|
||||
if(pieceConnector.getDirection().getAxis().equals(Axis.X) && generateRotatedPiece(piece, pieceConnector, idea, j, i, 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(pieceConnector.getDirection().getAxis().equals(Axis.Z) && generateRotatedPiece(piece, pieceConnector, idea, 0, i, j))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (generateRotatedPiece(piece, pieceConnector, idea, 0, i, 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean generateRotatedPiece(PlannedPiece piece, IrisJigsawPieceConnector pieceConnector, IrisJigsawPiece idea, int x, int y, int z)
|
||||
{
|
||||
PlannedPiece test = new PlannedPiece(piece.getPosition(), idea, x, y, z);
|
||||
|
||||
for(IrisJigsawPieceConnector j : test.getPiece().getConnectors().shuffleCopy(rng))
|
||||
{
|
||||
if(generatePositionedPiece(piece, pieceConnector, test, j))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -86,20 +149,29 @@ public class PlannedStructure {
|
||||
IrisJigsawPieceConnector pieceConnector,
|
||||
PlannedPiece test,
|
||||
IrisJigsawPieceConnector testConnector) {
|
||||
IrisPosition rParent = pieceConnector.getPosition();
|
||||
IrisPosition rTest = testConnector.getPosition();
|
||||
test.setPosition(piece.getPosition().add(rParent).sub(rTest));
|
||||
test.setPosition(new IrisPosition(0,0,0));
|
||||
IrisPosition connector = piece.getWorldPosition(pieceConnector);
|
||||
IrisDirection desiredDirection = pieceConnector.getDirection().reverse();
|
||||
IrisPosition desiredPosition = connector.sub(new IrisPosition(desiredDirection.toVector()));
|
||||
|
||||
if(collidesWith(test, piece))
|
||||
if(!testConnector.getDirection().equals(desiredDirection))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!pieceConnector.isInnerConnector() && piece.collidesWith(test))
|
||||
IrisPosition shift = test.getWorldPosition(testConnector);
|
||||
test.setPosition(desiredPosition.sub(shift));
|
||||
|
||||
if(collidesWith(test))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
v("Connected {" + test + "/" + testConnector + "} <==> {" + piece + "/" + pieceConnector + "}");
|
||||
piece.connect(pieceConnector);
|
||||
test.connect(testConnector);
|
||||
|
||||
pieces.add(test);
|
||||
|
||||
return true;
|
||||
@ -109,9 +181,9 @@ public class PlannedStructure {
|
||||
{
|
||||
KList<IrisJigsawPiece> p = new KList<>();
|
||||
|
||||
for(String i : c.getPools())
|
||||
for(String i : c.getPools().shuffleCopy(rng))
|
||||
{
|
||||
for(String j : getData().getJigsawPoolLoader().load(i).getPieces())
|
||||
for(String j : getData().getJigsawPoolLoader().load(i).getPieces().shuffleCopy(rng))
|
||||
{
|
||||
p.addIfMissing(getData().getJigsawPieceLoader().load(j));
|
||||
}
|
||||
@ -121,7 +193,7 @@ public class PlannedStructure {
|
||||
}
|
||||
|
||||
private void generateStartPiece() {
|
||||
pieces.add(new PlannedPiece(position, getData().getJigsawPieceLoader().load(rng.pick(getStructure().getPieces()))));
|
||||
pieces.add(new PlannedPiece(position, getData().getJigsawPieceLoader().load(rng.pick(getStructure().getPieces())), 0, rng.nextInt(4), 0));
|
||||
}
|
||||
|
||||
private void generateTerminators() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user