mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 23:47:50 +00:00
Cleanup Structures, fix several rotation issues
This commit is contained in:
parent
562d93f4e9
commit
24c17f2ee6
@ -21,6 +21,7 @@ import org.bukkit.block.data.Rotatable;
|
||||
import org.bukkit.block.data.type.RedstoneWire;
|
||||
import org.bukkit.inventory.BlockInventoryHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.io.File;
|
||||
@ -104,6 +105,8 @@ public class Structure implements Serializable {
|
||||
} catch(IllegalArgumentException e) {
|
||||
throw new InitializationException("Invalid pull type: " + spawn);
|
||||
}
|
||||
} else {
|
||||
throw new InitializationException("Invalid Magic Sign: \"" + s.getLine(1) + "\"");
|
||||
}
|
||||
} catch(IllegalArgumentException e) {
|
||||
throw new InitializationException("Invalid Block Data on sign: \"" + s.getLine(2) + s.getLine(3) + "\"");
|
||||
@ -138,9 +141,9 @@ public class Structure implements Serializable {
|
||||
* @param r Rotation
|
||||
*/
|
||||
public void paste(@NotNull Location origin, Rotation r) {
|
||||
Range xRange = getRange(Axis.X);
|
||||
Range zRange = getRange(Axis.Z);
|
||||
this.executeForBlocksInRange(xRange, getRange(Axis.Y), zRange, block -> pasteBlock(block, origin, r), r);
|
||||
Range xRange = getRange(Axis.X, r);
|
||||
Range zRange = getRange(Axis.Z, r);
|
||||
this.executeForBlocksInRange(xRange, getRange(Axis.Y, r), zRange, block -> pasteBlock(block, origin, r), r);
|
||||
}
|
||||
|
||||
public boolean checkSpawns(Location origin, Rotation r) {
|
||||
@ -164,12 +167,10 @@ public class Structure implements Serializable {
|
||||
public void paste(Location origin, Chunk chunk, Rotation r) {
|
||||
int xOr = (chunk.getX() << 4);
|
||||
int zOr = (chunk.getZ() << 4);
|
||||
Range intersectX;
|
||||
Range intersectZ;
|
||||
intersectX = new Range(xOr, xOr+16).sub(origin.getBlockX() - structureInfo.getCenterX());
|
||||
intersectZ = new Range(zOr, zOr+16).sub(origin.getBlockZ() - structureInfo.getCenterZ());
|
||||
Range intersectX = new Range(xOr, xOr+16).sub(origin.getBlockX() - structureInfo.getCenterX());
|
||||
Range intersectZ = new Range(zOr, zOr+16).sub(origin.getBlockZ() - structureInfo.getCenterZ());
|
||||
if(intersectX == null || intersectZ == null) return;
|
||||
executeForBlocksInRange(intersectX, getRange(Axis.Y), intersectZ, block -> pasteBlock(block, origin, r), r);
|
||||
executeForBlocksInRange(intersectX, getRange(Axis.Y, r), intersectZ, block -> pasteBlock(block, origin, r), r);
|
||||
Debug.info(intersectX.toString() + " : " + intersectZ.toString());
|
||||
}
|
||||
|
||||
@ -331,7 +332,21 @@ public class Structure implements Serializable {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public Range getRange(Axis a) {
|
||||
@NotNull
|
||||
public Range getRange(@NotNull Axis a, @NotNull Rotation r) {
|
||||
if(a.equals(Axis.Y)) return getRawRange(a);
|
||||
Vector2 center = new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ());
|
||||
Range x = getRawRange(Axis.X);
|
||||
Range z = getRawRange(Axis.Z);
|
||||
Vector2 min = getRotatedCoords(new Vector2(x.getMin(), z.getMin()).subtract(center), r.inverse()).add(center);
|
||||
Vector2 max = getRotatedCoords(new Vector2(x.getMax(), z.getMax()).subtract(center), r.inverse()).add(center);
|
||||
|
||||
if(a.equals(Axis.X)) return new Range((int) Math.floor(Math.min(min.getX(), max.getX())), (int) Math.ceil(Math.max(min.getX(), max.getX())) + 1);
|
||||
else return new Range((int) Math.floor(Math.min(min.getZ(), max.getZ())), (int) Math.ceil(Math.max(min.getZ(), max.getZ())) + 1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Range getRawRange(@NotNull Axis a) {
|
||||
switch(a) {
|
||||
case X:
|
||||
return new Range(0, structureInfo.getSizeX());
|
||||
@ -339,7 +354,7 @@ public class Structure implements Serializable {
|
||||
return new Range(0, structureInfo.getSizeY());
|
||||
case Z:
|
||||
return new Range(0, structureInfo.getSizeZ());
|
||||
default: return null;
|
||||
default: throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.structure;
|
||||
|
||||
import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.structure.serialize.SerializableBlockData;
|
||||
import com.dfsek.terra.structure.serialize.block.SerializableBanner;
|
||||
import com.dfsek.terra.structure.serialize.block.SerializableBlockState;
|
||||
@ -26,10 +27,13 @@ public class StructureContainedBlock implements Serializable {
|
||||
private final StructureSpawnRequirement requirement;
|
||||
public StructureContainedBlock(int x, int y, int z, BlockState state, BlockData d, StructureSpawnRequirement spawn, Pull pull, int pullOffset) {
|
||||
if(state instanceof Sign) {
|
||||
Debug.info("Sign at (" + x + ", " + y + ", " + z + ").");
|
||||
this.state = new SerializableSign((org.bukkit.block.Sign) state);
|
||||
} else if(state instanceof CreatureSpawner) {
|
||||
Debug.info("Monster Spawner at (" + x + ", " + y + ", " + z + ").");
|
||||
this.state = new SerializableMonsterCage((CreatureSpawner) state);
|
||||
} else if(state instanceof Banner) {
|
||||
Debug.info("Banner at (" + x + ", " + y + ", " + z + ").");
|
||||
this.state = new SerializableBanner((Banner) state);
|
||||
} else this.state = null;
|
||||
this.x = x;
|
||||
@ -41,9 +45,7 @@ public class StructureContainedBlock implements Serializable {
|
||||
this.pullOffset = pullOffset;
|
||||
}
|
||||
public StructureContainedBlock(int x, int y, int z, SerializableBlockState state, BlockData d, StructureSpawnRequirement spawn, Pull pull, int pullOffset) {
|
||||
if(state instanceof SerializableSign) {
|
||||
this.state = state;
|
||||
} else this.state = null;
|
||||
this.state = state;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
@ -11,6 +11,7 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SerializableBanner implements SerializableBlockState {
|
||||
public static final long serialVersionUID = 5298928608478640004L;
|
||||
private final DyeColor base;
|
||||
private final ArrayList<Pattern> patterns = new ArrayList<>();
|
||||
|
||||
|
@ -8,6 +8,7 @@ import org.polydev.gaea.math.Range;
|
||||
import java.util.Random;
|
||||
|
||||
public class SerializableMonsterCage implements SerializableBlockState {
|
||||
public static final long serialVersionUID = 529892860847864007L;
|
||||
private final EntityType type;
|
||||
private final int minDelay;
|
||||
private final int maxDelay;
|
||||
@ -35,6 +36,6 @@ public class SerializableMonsterCage implements SerializableBlockState {
|
||||
spawner.setRequiredPlayerRange(playerRange);
|
||||
spawner.setDelay(delay);
|
||||
spawner.setSpawnCount(count);
|
||||
return null;
|
||||
return spawner;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user