mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 03:35:11 +01:00
Uses BoundingBox for copying blocks to schems
https://github.com/BentoBoxWorld/BentoBox/issues/636
This commit is contained in:
parent
b556b3fb0a
commit
cfee1229d1
@ -37,6 +37,7 @@ import org.bukkit.inventory.InventoryHolder;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.material.Attachable;
|
import org.bukkit.material.Attachable;
|
||||||
import org.bukkit.material.Colorable;
|
import org.bukkit.material.Colorable;
|
||||||
|
import org.bukkit.util.BoundingBox;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
@ -131,35 +132,24 @@ public class Clipboard {
|
|||||||
blockConfig = new YamlConfiguration();
|
blockConfig = new YamlConfiguration();
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int minX = Math.max(pos1.getBlockX(),pos2.getBlockX());
|
BoundingBox toCopy = BoundingBox.of(pos1, pos2);
|
||||||
int maxX = Math.min(pos1.getBlockX(), pos2.getBlockX());
|
|
||||||
int minY = Math.max(pos1.getBlockY(),pos2.getBlockY());
|
|
||||||
int maxY = Math.min(pos1.getBlockY(), pos2.getBlockY());
|
|
||||||
int minZ = Math.max(pos1.getBlockZ(),pos2.getBlockZ());
|
|
||||||
int maxZ = Math.min(pos1.getBlockZ(), pos2.getBlockZ());
|
|
||||||
|
|
||||||
for (int x = Math.min(pos1.getBlockX(), pos2.getBlockX()); x <= Math.max(pos1.getBlockX(),pos2.getBlockX()); x++) {
|
for (int x = (int)toCopy.getMinX(); x <= toCopy.getMaxX(); x++) {
|
||||||
for (int y = Math.min(pos1.getBlockY(), pos2.getBlockY()); y <= Math.max(pos1.getBlockY(),pos2.getBlockY()); y++) {
|
for (int y = (int)toCopy.getMinY(); y <= toCopy.getMaxY(); y++) {
|
||||||
for (int z = Math.min(pos1.getBlockZ(), pos2.getBlockZ()); z <= Math.max(pos1.getBlockZ(),pos2.getBlockZ()); z++) {
|
for (int z = (int)toCopy.getMinZ(); z <= toCopy.getMaxZ(); z++) {
|
||||||
Block block = world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
if (copyBlock(block, origin == null ? user.getLocation() : origin, copyAir, world.getLivingEntities().stream()
|
if (copyBlock(block, origin == null ? user.getLocation() : origin, copyAir, world.getLivingEntities().stream()
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.filter(e -> !(e instanceof Player) && e.getLocation().getBlock().equals(block))
|
.filter(e -> !(e instanceof Player) && e.getLocation().getBlock().equals(block))
|
||||||
.collect(Collectors.toList()))) {
|
.collect(Collectors.toList()))) {
|
||||||
minX = Math.min(minX, x);
|
|
||||||
maxX = Math.max(maxX, x);
|
|
||||||
minY = Math.min(minY, y);
|
|
||||||
maxY = Math.max(maxY, y);
|
|
||||||
minZ = Math.min(minZ, z);
|
|
||||||
maxZ = Math.max(maxZ, z);
|
|
||||||
count ++;
|
count ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blockConfig.set("size.xsize", maxX - minX + 1);
|
blockConfig.set("size.xsize", toCopy.getWidthX());
|
||||||
blockConfig.set("size.ysize", maxY - minY + 1);
|
blockConfig.set("size.ysize", toCopy.getHeight());
|
||||||
blockConfig.set("size.zsize", maxZ - minZ + 1);
|
blockConfig.set("size.zsize", toCopy.getWidthZ());
|
||||||
user.sendMessage("commands.admin.schem.copied-blocks", TextVariables.NUMBER, String.valueOf(count));
|
user.sendMessage("commands.admin.schem.copied-blocks", TextVariables.NUMBER, String.valueOf(count));
|
||||||
copied = true;
|
copied = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -90,6 +90,9 @@ public class ClipboardTest {
|
|||||||
when(loc.getBlockZ()).thenReturn(3);
|
when(loc.getBlockZ()).thenReturn(3);
|
||||||
when(loc.getBlock()).thenReturn(block);
|
when(loc.getBlock()).thenReturn(block);
|
||||||
when(loc.toVector()).thenReturn(new Vector(1,2,3));
|
when(loc.toVector()).thenReturn(new Vector(1,2,3));
|
||||||
|
when(loc.getX()).thenReturn(1D);
|
||||||
|
when(loc.getY()).thenReturn(2D);
|
||||||
|
when(loc.getZ()).thenReturn(3D);
|
||||||
|
|
||||||
loc2 = mock(Location.class);
|
loc2 = mock(Location.class);
|
||||||
when(loc2.getWorld()).thenReturn(world);
|
when(loc2.getWorld()).thenReturn(world);
|
||||||
@ -97,6 +100,10 @@ public class ClipboardTest {
|
|||||||
when(loc2.getBlockY()).thenReturn(3);
|
when(loc2.getBlockY()).thenReturn(3);
|
||||||
when(loc2.getBlockZ()).thenReturn(4);
|
when(loc2.getBlockZ()).thenReturn(4);
|
||||||
when(loc2.getBlock()).thenReturn(block);
|
when(loc2.getBlock()).thenReturn(block);
|
||||||
|
when(loc2.toVector()).thenReturn(new Vector(2,3,4));
|
||||||
|
when(loc2.getX()).thenReturn(2D);
|
||||||
|
when(loc2.getY()).thenReturn(3D);
|
||||||
|
when(loc2.getZ()).thenReturn(4D);
|
||||||
// Living entities
|
// Living entities
|
||||||
|
|
||||||
List<LivingEntity> ents = new ArrayList<>();
|
List<LivingEntity> ents = new ArrayList<>();
|
||||||
|
Loading…
Reference in New Issue
Block a user