mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Move Rotation stuff for Structures to separate class
This commit is contained in:
parent
69df068c7f
commit
0e3577063e
@ -4,6 +4,7 @@ import com.dfsek.terra.TerraWorld;
|
|||||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
||||||
|
import com.dfsek.terra.structure.Rotation;
|
||||||
import com.dfsek.terra.structure.Structure;
|
import com.dfsek.terra.structure.Structure;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -36,7 +37,7 @@ public class AsyncStructureFinder extends AsyncFeatureFinder<StructureConfig> {
|
|||||||
return false;
|
return false;
|
||||||
Random r2 = new Random(spawn.hashCode());
|
Random r2 = new Random(spawn.hashCode());
|
||||||
Structure struc = target.getStructure(r2);
|
Structure struc = target.getStructure(r2);
|
||||||
Structure.Rotation rotation = Structure.Rotation.fromDegrees(r2.nextInt(4) * 90);
|
Rotation rotation = Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||||
for(int y = target.getSearchStart().get(r2); y > 0; y--) {
|
for(int y = target.getSearchStart().get(r2); y > 0; y--) {
|
||||||
if(!target.getBound().isInRange(y)) return false;
|
if(!target.getBound().isInRange(y)) return false;
|
||||||
spawn.setY(y);
|
spawn.setY(y);
|
||||||
|
@ -2,6 +2,7 @@ package com.dfsek.terra.command.structure;
|
|||||||
|
|
||||||
import com.dfsek.terra.Terra;
|
import com.dfsek.terra.Terra;
|
||||||
import com.dfsek.terra.config.lang.LangUtil;
|
import com.dfsek.terra.config.lang.LangUtil;
|
||||||
|
import com.dfsek.terra.structure.Rotation;
|
||||||
import com.dfsek.terra.structure.Structure;
|
import com.dfsek.terra.structure.Structure;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -23,9 +24,9 @@ public class LoadCommand extends PlayerCommand implements DebugCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
try {
|
try {
|
||||||
Structure.Rotation r;
|
Rotation r;
|
||||||
try {
|
try {
|
||||||
r = Structure.Rotation.fromDegrees(Integer.parseInt(args[1]));
|
r = Rotation.fromDegrees(Integer.parseInt(args[1]));
|
||||||
} catch(NumberFormatException e) {
|
} catch(NumberFormatException e) {
|
||||||
LangUtil.send("command.structure.invalid-rotation", sender, args[1]);
|
LangUtil.send("command.structure.invalid-rotation", sender, args[1]);
|
||||||
return true;
|
return true;
|
||||||
|
@ -6,6 +6,7 @@ import com.dfsek.terra.config.base.ConfigPack;
|
|||||||
import com.dfsek.terra.config.base.ConfigUtil;
|
import com.dfsek.terra.config.base.ConfigUtil;
|
||||||
import com.dfsek.terra.config.exception.ConfigException;
|
import com.dfsek.terra.config.exception.ConfigException;
|
||||||
import com.dfsek.terra.config.exception.NotFoundException;
|
import com.dfsek.terra.config.exception.NotFoundException;
|
||||||
|
import com.dfsek.terra.structure.Rotation;
|
||||||
import com.dfsek.terra.structure.Structure;
|
import com.dfsek.terra.structure.Structure;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -67,7 +68,7 @@ public class TreeConfig extends TerraConfig implements Tree {
|
|||||||
Location mut = location.clone().subtract(0, yOffset, 0);
|
Location mut = location.clone().subtract(0, yOffset, 0);
|
||||||
if(!spawnable.contains(location.getBlock().getType())) return false;
|
if(!spawnable.contains(location.getBlock().getType())) return false;
|
||||||
Structure struc = structure.get(random);
|
Structure struc = structure.get(random);
|
||||||
Structure.Rotation rotation = Structure.Rotation.fromDegrees(random.nextInt(4) * 90);
|
Rotation rotation = Rotation.fromDegrees(random.nextInt(4) * 90);
|
||||||
if(!struc.checkSpawns(mut, rotation)) return false;
|
if(!struc.checkSpawns(mut, rotation)) return false;
|
||||||
struc.paste(mut, rotation);
|
struc.paste(mut, rotation);
|
||||||
return true;
|
return true;
|
||||||
|
@ -8,6 +8,7 @@ import com.dfsek.terra.biome.UserDefinedBiome;
|
|||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
||||||
import com.dfsek.terra.procgen.math.Vector2;
|
import com.dfsek.terra.procgen.math.Vector2;
|
||||||
|
import com.dfsek.terra.structure.Rotation;
|
||||||
import com.dfsek.terra.structure.Structure;
|
import com.dfsek.terra.structure.Structure;
|
||||||
import com.dfsek.terra.structure.StructureContainedInventory;
|
import com.dfsek.terra.structure.StructureContainedInventory;
|
||||||
import com.dfsek.terra.structure.features.Feature;
|
import com.dfsek.terra.structure.features.Feature;
|
||||||
@ -41,7 +42,7 @@ public class StructurePopulator extends BlockPopulator {
|
|||||||
if(!config.getBiome((UserDefinedBiome) grid.getBiome(spawn)).getStructures().contains(conf)) continue;
|
if(!config.getBiome((UserDefinedBiome) grid.getBiome(spawn)).getStructures().contains(conf)) continue;
|
||||||
Random r2 = new Random(spawn.hashCode());
|
Random r2 = new Random(spawn.hashCode());
|
||||||
Structure struc = conf.getStructure(r2);
|
Structure struc = conf.getStructure(r2);
|
||||||
Structure.Rotation rotation = Structure.Rotation.fromDegrees(r2.nextInt(4) * 90);
|
Rotation rotation = Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||||
for(int y = conf.getSearchStart().get(r2); y > 0; y--) {
|
for(int y = conf.getSearchStart().get(r2); y > 0; y--) {
|
||||||
if(!conf.getBound().isInRange(y)) continue structure;
|
if(!conf.getBound().isInRange(y)) continue structure;
|
||||||
spawn.setY(y);
|
spawn.setY(y);
|
||||||
|
48
src/main/java/com/dfsek/terra/structure/Rotation.java
Normal file
48
src/main/java/com/dfsek/terra/structure/Rotation.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package com.dfsek.terra.structure;
|
||||||
|
|
||||||
|
public enum Rotation {
|
||||||
|
CW_90(90), CW_180(180), CCW_90(270), NONE(0);
|
||||||
|
private final int degrees;
|
||||||
|
|
||||||
|
Rotation(int degrees) {
|
||||||
|
this.degrees = degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Rotation fromDegrees(int deg) {
|
||||||
|
switch(Math.floorMod(deg, 360)) {
|
||||||
|
case 0:
|
||||||
|
return Rotation.NONE;
|
||||||
|
case 90:
|
||||||
|
return Rotation.CW_90;
|
||||||
|
case 180:
|
||||||
|
return Rotation.CW_180;
|
||||||
|
case 270:
|
||||||
|
return Rotation.CCW_90;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDegrees() {
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rotation inverse() {
|
||||||
|
switch(this) {
|
||||||
|
case NONE:
|
||||||
|
return NONE;
|
||||||
|
case CCW_90:
|
||||||
|
return CW_90;
|
||||||
|
case CW_90:
|
||||||
|
return CCW_90;
|
||||||
|
case CW_180:
|
||||||
|
return CW_180;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Axis {
|
||||||
|
X, Y, Z
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package com.dfsek.terra.structure;
|
|||||||
|
|
||||||
import com.dfsek.terra.Debug;
|
import com.dfsek.terra.Debug;
|
||||||
import com.dfsek.terra.procgen.math.Vector2;
|
import com.dfsek.terra.procgen.math.Vector2;
|
||||||
|
import com.dfsek.terra.util.structure.RotationUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -11,12 +12,6 @@ import org.bukkit.block.BlockFace;
|
|||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.Directional;
|
|
||||||
import org.bukkit.block.data.MultipleFacing;
|
|
||||||
import org.bukkit.block.data.Orientable;
|
|
||||||
import org.bukkit.block.data.Rail;
|
|
||||||
import org.bukkit.block.data.Rotatable;
|
|
||||||
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.polydev.gaea.math.Range;
|
import org.polydev.gaea.math.Range;
|
||||||
@ -29,14 +24,12 @@ import java.io.InputStream;
|
|||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static com.dfsek.terra.util.structure.RotationUtil.*;
|
import static com.dfsek.terra.util.structure.RotationUtil.getRotatedCoords;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class Structure implements Serializable {
|
public class Structure implements Serializable {
|
||||||
@ -158,9 +151,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, r);
|
Range xRange = getRange(Rotation.Axis.X, r);
|
||||||
Range zRange = getRange(Axis.Z, r);
|
Range zRange = getRange(Rotation.Axis.Z, r);
|
||||||
this.executeForBlocksInRange(xRange, getRange(Axis.Y, r), zRange, block -> pasteBlock(block, origin, r), r);
|
this.executeForBlocksInRange(xRange, getRange(Rotation.Axis.Y, r), zRange, block -> pasteBlock(block, origin, r), r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -176,6 +169,7 @@ public class Structure implements Serializable {
|
|||||||
|
|
||||||
Location loc = origin.clone().add(block.getX(), block.getY(), block.getZ());
|
Location loc = origin.clone().add(block.getX(), block.getY(), block.getZ());
|
||||||
Block worldBlock = loc.getBlock();
|
Block worldBlock = loc.getBlock();
|
||||||
|
|
||||||
main:
|
main:
|
||||||
while(worldBlock.isEmpty()) {
|
while(worldBlock.isEmpty()) {
|
||||||
if(loc.getBlockY() > 255 || loc.getBlockY() < 0) return;
|
if(loc.getBlockY() > 255 || loc.getBlockY() < 0) return;
|
||||||
@ -196,37 +190,8 @@ public class Structure implements Serializable {
|
|||||||
if(offset != 0)
|
if(offset != 0)
|
||||||
worldBlock = worldBlock.getRelative((offset > 0) ? BlockFace.UP : BlockFace.DOWN, Math.abs(offset));
|
worldBlock = worldBlock.getRelative((offset > 0) ? BlockFace.UP : BlockFace.DOWN, Math.abs(offset));
|
||||||
|
|
||||||
if(data instanceof Rotatable) {
|
RotationUtil.rotateBlockData(data, r);
|
||||||
BlockFace rt = getRotatedFace(((Rotatable) data).getRotation(), r);
|
|
||||||
((Rotatable) data).setRotation(rt);
|
|
||||||
} else if(data instanceof Directional) {
|
|
||||||
BlockFace rt = getRotatedFace(((Directional) data).getFacing(), r);
|
|
||||||
((Directional) data).setFacing(rt);
|
|
||||||
} else if(data instanceof MultipleFacing) {
|
|
||||||
MultipleFacing mfData = (MultipleFacing) data;
|
|
||||||
Map<BlockFace, Boolean> faces = new HashMap<>();
|
|
||||||
for(BlockFace f : mfData.getAllowedFaces()) {
|
|
||||||
faces.put(f, mfData.hasFace(f));
|
|
||||||
}
|
|
||||||
for(Map.Entry<BlockFace, Boolean> face : faces.entrySet()) {
|
|
||||||
mfData.setFace(getRotatedFace(face.getKey(), r), face.getValue());
|
|
||||||
}
|
|
||||||
} else if(data instanceof Rail) {
|
|
||||||
Rail.Shape newShape = getRotatedRail(((Rail) data).getShape(), r);
|
|
||||||
((Rail) data).setShape(newShape);
|
|
||||||
} else if(data instanceof Orientable) {
|
|
||||||
org.bukkit.Axis newAxis = getRotatedAxis(((Orientable) data).getAxis(), r);
|
|
||||||
((Orientable) data).setAxis(newAxis);
|
|
||||||
} else if(data instanceof RedstoneWire) {
|
|
||||||
Map<BlockFace, RedstoneWire.Connection> connections = new HashMap<>();
|
|
||||||
RedstoneWire rData = (RedstoneWire) data;
|
|
||||||
for(BlockFace f : rData.getAllowedFaces()) {
|
|
||||||
connections.put(f, rData.getFace(f));
|
|
||||||
}
|
|
||||||
for(Map.Entry<BlockFace, RedstoneWire.Connection> e : connections.entrySet()) {
|
|
||||||
rData.setFace(getRotatedFace(e.getKey(), r), e.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
worldBlock.setBlockData(data, false);
|
worldBlock.setBlockData(data, false);
|
||||||
if(block.getState() != null) {
|
if(block.getState() != null) {
|
||||||
block.getState().getState(worldBlock.getState()).update(true, false);
|
block.getState().getState(worldBlock.getState()).update(true, false);
|
||||||
@ -281,22 +246,22 @@ public class Structure implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Range getRange(@NotNull Axis a, @NotNull Rotation r) {
|
public Range getRange(@NotNull Rotation.Axis a, @NotNull Rotation r) {
|
||||||
if(a.equals(Axis.Y)) return getRawRange(a);
|
if(a.equals(Rotation.Axis.Y)) return getRawRange(a);
|
||||||
Vector2 center = new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ());
|
Vector2 center = new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ());
|
||||||
Range x = getRawRange(Axis.X);
|
Range x = getRawRange(Rotation.Axis.X);
|
||||||
Range z = getRawRange(Axis.Z);
|
Range z = getRawRange(Rotation.Axis.Z);
|
||||||
Vector2 min = getRotatedCoords(new Vector2(x.getMin(), z.getMin()).subtract(center), r.inverse()).add(center);
|
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);
|
Vector2 max = getRotatedCoords(new Vector2(x.getMax(), z.getMax()).subtract(center), r.inverse()).add(center);
|
||||||
|
|
||||||
if(a.equals(Axis.X))
|
if(a.equals(Rotation.Axis.X))
|
||||||
return new Range((int) Math.floor(Math.min(min.getX(), max.getX())), (int) Math.ceil(Math.max(min.getX(), max.getX())) + 1);
|
return new Range((int) Math.floor(Math.min(min.getX(), max.getX())), (int) Math.ceil(Math.max(min.getX(), max.getX())) + 1);
|
||||||
else
|
else
|
||||||
return new Range((int) Math.floor(Math.min(min.getZ(), max.getZ())), (int) Math.ceil(Math.max(min.getZ(), max.getZ())) + 1);
|
return new Range((int) Math.floor(Math.min(min.getZ(), max.getZ())), (int) Math.ceil(Math.max(min.getZ(), max.getZ())) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Range getRawRange(@NotNull Axis a) {
|
private Range getRawRange(@NotNull Rotation.Axis a) {
|
||||||
switch(a) {
|
switch(a) {
|
||||||
case X:
|
case X:
|
||||||
return new Range(0, structureInfo.getSizeX());
|
return new Range(0, structureInfo.getSizeX());
|
||||||
@ -335,7 +300,7 @@ public class Structure implements Serializable {
|
|||||||
Range intersectX = new Range(xOr, xOr + 16).sub(origin.getBlockX() - structureInfo.getCenterX());
|
Range intersectX = new Range(xOr, xOr + 16).sub(origin.getBlockX() - structureInfo.getCenterX());
|
||||||
Range intersectZ = new Range(zOr, zOr + 16).sub(origin.getBlockZ() - structureInfo.getCenterZ());
|
Range 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, r), intersectZ, block -> pasteBlock(block, origin, r), r);
|
executeForBlocksInRange(intersectX, getRange(Rotation.Axis.Y, r), intersectZ, block -> pasteBlock(block, origin, r), r);
|
||||||
Debug.info(intersectX.toString() + " : " + intersectZ.toString());
|
Debug.info(intersectX.toString() + " : " + intersectZ.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,50 +340,4 @@ public class Structure implements Serializable {
|
|||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Axis {
|
|
||||||
X, Y, Z
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Rotation {
|
|
||||||
CW_90(90), CW_180(180), CCW_90(270), NONE(0);
|
|
||||||
private final int degrees;
|
|
||||||
|
|
||||||
Rotation(int degrees) {
|
|
||||||
this.degrees = degrees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Rotation fromDegrees(int deg) {
|
|
||||||
switch(Math.floorMod(deg, 360)) {
|
|
||||||
case 0:
|
|
||||||
return Rotation.NONE;
|
|
||||||
case 90:
|
|
||||||
return Rotation.CW_90;
|
|
||||||
case 180:
|
|
||||||
return Rotation.CW_180;
|
|
||||||
case 270:
|
|
||||||
return Rotation.CCW_90;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDegrees() {
|
|
||||||
return degrees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Rotation inverse() {
|
|
||||||
switch(this) {
|
|
||||||
case NONE:
|
|
||||||
return NONE;
|
|
||||||
case CCW_90:
|
|
||||||
return CW_90;
|
|
||||||
case CW_90:
|
|
||||||
return CCW_90;
|
|
||||||
case CW_180:
|
|
||||||
return CW_180;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
package com.dfsek.terra.util.structure;
|
package com.dfsek.terra.util.structure;
|
||||||
|
|
||||||
import com.dfsek.terra.procgen.math.Vector2;
|
import com.dfsek.terra.procgen.math.Vector2;
|
||||||
import com.dfsek.terra.structure.Structure;
|
import com.dfsek.terra.structure.Rotation;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.Directional;
|
||||||
|
import org.bukkit.block.data.MultipleFacing;
|
||||||
|
import org.bukkit.block.data.Orientable;
|
||||||
import org.bukkit.block.data.Rail;
|
import org.bukkit.block.data.Rail;
|
||||||
|
import org.bukkit.block.data.Rotatable;
|
||||||
|
import org.bukkit.block.data.type.RedstoneWire;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public final class RotationUtil {
|
public final class RotationUtil {
|
||||||
/**
|
/**
|
||||||
@ -13,7 +22,7 @@ public final class RotationUtil {
|
|||||||
* @param r Rotation
|
* @param r Rotation
|
||||||
* @return Rotated coordinate pair
|
* @return Rotated coordinate pair
|
||||||
*/
|
*/
|
||||||
public static Vector2 getRotatedCoords(Vector2 orig, Structure.Rotation r) {
|
public static Vector2 getRotatedCoords(Vector2 orig, Rotation r) {
|
||||||
Vector2 copy = orig.clone();
|
Vector2 copy = orig.clone();
|
||||||
switch(r) {
|
switch(r) {
|
||||||
case CW_90:
|
case CW_90:
|
||||||
@ -36,7 +45,7 @@ public final class RotationUtil {
|
|||||||
* @param r Rotation
|
* @param r Rotation
|
||||||
* @return Rotated BlockFace
|
* @return Rotated BlockFace
|
||||||
*/
|
*/
|
||||||
public static BlockFace getRotatedFace(BlockFace f, Structure.Rotation r) {
|
public static BlockFace getRotatedFace(BlockFace f, Rotation r) {
|
||||||
BlockFace n = f;
|
BlockFace n = f;
|
||||||
int rotateNum = r.getDegrees() / 90;
|
int rotateNum = r.getDegrees() / 90;
|
||||||
int rn = faceRotation(f);
|
int rn = faceRotation(f);
|
||||||
@ -136,9 +145,9 @@ public final class RotationUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static org.bukkit.Axis getRotatedAxis(org.bukkit.Axis orig, Structure.Rotation r) {
|
public static org.bukkit.Axis getRotatedAxis(org.bukkit.Axis orig, Rotation r) {
|
||||||
org.bukkit.Axis other = orig;
|
org.bukkit.Axis other = orig;
|
||||||
final boolean shouldSwitch = r.equals(Structure.Rotation.CW_90) || r.equals(Structure.Rotation.CCW_90);
|
final boolean shouldSwitch = r.equals(Rotation.CW_90) || r.equals(Rotation.CCW_90);
|
||||||
switch(orig) {
|
switch(orig) {
|
||||||
case X:
|
case X:
|
||||||
if(shouldSwitch) other = org.bukkit.Axis.Z;
|
if(shouldSwitch) other = org.bukkit.Axis.Z;
|
||||||
@ -158,7 +167,7 @@ public final class RotationUtil {
|
|||||||
* @return Rotated/mirrored shape
|
* @return Rotated/mirrored shape
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("fallthrough")
|
@SuppressWarnings("fallthrough")
|
||||||
public static Rail.Shape getRotatedRail(Rail.Shape orig, Structure.Rotation r) {
|
public static Rail.Shape getRotatedRail(Rail.Shape orig, Rotation r) {
|
||||||
switch(r) {
|
switch(r) {
|
||||||
case CCW_90:
|
case CCW_90:
|
||||||
switch(orig) {
|
switch(orig) {
|
||||||
@ -232,4 +241,38 @@ public final class RotationUtil {
|
|||||||
}
|
}
|
||||||
return orig;
|
return orig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void rotateBlockData(BlockData data, Rotation r) {
|
||||||
|
if(data instanceof Rotatable) {
|
||||||
|
BlockFace rt = getRotatedFace(((Rotatable) data).getRotation(), r);
|
||||||
|
((Rotatable) data).setRotation(rt);
|
||||||
|
} else if(data instanceof Directional) {
|
||||||
|
BlockFace rt = getRotatedFace(((Directional) data).getFacing(), r);
|
||||||
|
((Directional) data).setFacing(rt);
|
||||||
|
} else if(data instanceof MultipleFacing) {
|
||||||
|
MultipleFacing mfData = (MultipleFacing) data;
|
||||||
|
Map<BlockFace, Boolean> faces = new HashMap<>();
|
||||||
|
for(BlockFace f : mfData.getAllowedFaces()) {
|
||||||
|
faces.put(f, mfData.hasFace(f));
|
||||||
|
}
|
||||||
|
for(Map.Entry<BlockFace, Boolean> face : faces.entrySet()) {
|
||||||
|
mfData.setFace(getRotatedFace(face.getKey(), r), face.getValue());
|
||||||
|
}
|
||||||
|
} else if(data instanceof Rail) {
|
||||||
|
Rail.Shape newShape = getRotatedRail(((Rail) data).getShape(), r);
|
||||||
|
((Rail) data).setShape(newShape);
|
||||||
|
} else if(data instanceof Orientable) {
|
||||||
|
org.bukkit.Axis newAxis = getRotatedAxis(((Orientable) data).getAxis(), r);
|
||||||
|
((Orientable) data).setAxis(newAxis);
|
||||||
|
} else if(data instanceof RedstoneWire) {
|
||||||
|
Map<BlockFace, RedstoneWire.Connection> connections = new HashMap<>();
|
||||||
|
RedstoneWire rData = (RedstoneWire) data;
|
||||||
|
for(BlockFace f : rData.getAllowedFaces()) {
|
||||||
|
connections.put(f, rData.getFace(f));
|
||||||
|
}
|
||||||
|
for(Map.Entry<BlockFace, RedstoneWire.Connection> e : connections.entrySet()) {
|
||||||
|
rData.setFace(getRotatedFace(e.getKey(), r), e.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user