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