clipboard from selection logic

This commit is contained in:
2023-04-14 00:10:50 +02:00
parent 0e304e78d4
commit f6d2b86c4b
3 changed files with 65 additions and 42 deletions
@@ -1,5 +1,7 @@
package me.youhavetrouble.blockedit.util;
import org.bukkit.Location;
import org.bukkit.util.Vector;
import org.bukkit.block.BlockState;
import java.util.Collections;
@@ -8,18 +10,38 @@ import java.util.Map;
public class Clipboard {
private HashMap<RelativeLocation, BlockState> blocks = new HashMap<>();
/**
* Map of locations relative to the center of the clipboard and their block states
*/
private final HashMap<Vector, BlockState> blocks = new HashMap<>();
private Location baseLocation;
private Vector baseLocationVector;
public Clipboard() {}
public void setBlocks(HashMap<RelativeLocation, BlockState> newClipboard) {
this.blocks = newClipboard;
public Clipboard(Location baseLocation) {
this.baseLocation = baseLocation;
}
public Map<RelativeLocation, BlockState> getBlocks() {
public void addBlock(Vector relativeLocation, BlockState blockState) {
this.blocks.put(relativeLocation, blockState);
}
public Map<Vector, BlockState> getBlocks() {
return Collections.unmodifiableMap(this.blocks);
}
public void setBaseLocation(Location baseLocation) {
this.baseLocation = baseLocation;
this.baseLocationVector = baseLocation.toVector();
}
public Location getBaseLocation() {
return baseLocation;
}
public Vector getBaseLocationVector() {
return baseLocationVector;
}
public void clear() {
this.blocks.clear();
}
@@ -27,4 +49,16 @@ public class Clipboard {
public boolean isEmpty() {
return this.blocks.isEmpty();
}
/**
* Rotates clipboard by specified degrees around the base location.
* @param angle angle in degrees
*/
public void rotate(int angle) {
for (Map.Entry<Vector, BlockState> entry : this.blocks.entrySet()) {
Vector relativeLocation = entry.getKey();
relativeLocation.rotateAroundAxis(baseLocationVector, angle);
}
}
}