Small fixes
This commit is contained in:
@@ -218,8 +218,8 @@ inline class TraverseDirection(val bits: Int) {
|
||||
|
||||
fun comesFirst(current: Vec3i, block: Vec3i) =
|
||||
comesFirst(current, block, Dimension.X)
|
||||
&& comesFirst(current, block, Dimension.Y)
|
||||
&& comesFirst(current, block, Dimension.Z)
|
||||
&& comesFirst(current, block, Dimension.Y)
|
||||
&& comesFirst(current, block, Dimension.Z)
|
||||
|
||||
companion object {
|
||||
operator fun invoke(x: Int, y: Int, z: Int) = invoke(Vec3i(x, y, z))
|
||||
@@ -229,7 +229,7 @@ inline class TraverseDirection(val bits: Int) {
|
||||
var bits = 0
|
||||
if (block.x > 0) bits = bits or 1
|
||||
if (block.y > 0) bits = bits or 2
|
||||
if (block.z > 0) bits = bits or 3
|
||||
if (block.z > 0) bits = bits or 4
|
||||
return TraverseDirection(bits)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class CommandsAdmin(plugin: ParcelsPlugin) : AbstractParcelCommands(plugin) {
|
||||
val parcel2 = (target as ParcelTarget.ByID).getParcel()
|
||||
?: throw CommandException("Invalid parcel target")
|
||||
|
||||
Validate.isTrue(parcel2.world == world, "Parcel must be in the same world")
|
||||
// Validate.isTrue(parcel2.world == world, "Parcel must be in the same world")
|
||||
Validate.isTrue(!parcel2.hasBlockVisitors, "A process is already running in this parcel")
|
||||
|
||||
val data = parcel.data
|
||||
|
||||
@@ -32,9 +32,11 @@ class DefaultParcelGenerator(
|
||||
private var _world: World? = null
|
||||
override val world: World
|
||||
get() {
|
||||
if (_world == null) _world = Bukkit.getWorld(worldName)!!.also {
|
||||
maxHeight = it.maxHeight
|
||||
return it
|
||||
if (_world == null) {
|
||||
val world = Bukkit.getWorld(worldName)
|
||||
maxHeight = world.maxHeight
|
||||
_world = world
|
||||
return world
|
||||
}
|
||||
return _world!!
|
||||
}
|
||||
@@ -175,7 +177,17 @@ class DefaultParcelGenerator(
|
||||
|
||||
override fun getRegion(parcel: ParcelId): Region {
|
||||
val bottom = getBottomBlock(parcel)
|
||||
return Region(Vec3i(bottom.x, 0, bottom.z), Vec3i(o.parcelSize, maxHeight + 1, o.parcelSize))
|
||||
return Region(Vec3i(bottom.x, 0, bottom.z), Vec3i(o.parcelSize, maxHeight, o.parcelSize))
|
||||
}
|
||||
|
||||
private fun getRegionConsideringWorld(parcel: ParcelId): Region {
|
||||
if (parcel.worldId != worldId) {
|
||||
(parcel.worldId as? ParcelWorld)?.let {
|
||||
return it.blockManager.getRegion(parcel)
|
||||
}
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
return getRegion(parcel)
|
||||
}
|
||||
|
||||
override fun setOwnerBlock(parcel: ParcelId, owner: PlayerProfile?) {
|
||||
@@ -277,10 +289,19 @@ class DefaultParcelGenerator(
|
||||
}
|
||||
|
||||
override fun swapParcels(parcel1: ParcelId, parcel2: ParcelId): Worker = submitBlockVisitor(parcel1, parcel2) {
|
||||
val schematicOf1 = delegateWork(0.25) { Schematic().apply { load(world, getRegion(parcel1)) } }
|
||||
val schematicOf2 = delegateWork(0.25) { Schematic().apply { load(world, getRegion(parcel2)) } }
|
||||
delegateWork(0.25) { with(schematicOf1) { paste(world, getRegion(parcel2).origin) } }
|
||||
delegateWork(0.25) { with(schematicOf2) { paste(world, getRegion(parcel1).origin) } }
|
||||
var region1 = getRegionConsideringWorld(parcel1)
|
||||
var region2 = getRegionConsideringWorld(parcel2)
|
||||
|
||||
val size = region1.size.clampMax(region2.size)
|
||||
if (size != region1.size) {
|
||||
region1 = region1.withSize(size)
|
||||
region2 = region2.withSize(size)
|
||||
}
|
||||
|
||||
val schematicOf1 = delegateWork(0.25) { Schematic().apply { load(world, region1) } }
|
||||
val schematicOf2 = delegateWork(0.25) { Schematic().apply { load(world, region2) } }
|
||||
delegateWork(0.25) { with(schematicOf1) { paste(world, region2.origin) } }
|
||||
delegateWork(0.25) { with(schematicOf2) { paste(world, region1.origin) } }
|
||||
}
|
||||
|
||||
override fun getParcelsWithOwnerBlockIn(chunk: Chunk): Collection<Vec2i> {
|
||||
|
||||
@@ -10,4 +10,9 @@ data class Region(val origin: Vec3i, val size: Vec3i) {
|
||||
val z = (origin.z + size.z) / 2.0
|
||||
return Vec3d(x, y, z)
|
||||
}
|
||||
|
||||
fun withSize(size: Vec3i): Region {
|
||||
if (size == this.size) return this
|
||||
return Region(origin, size)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.dico.parcels2.util
|
||||
|
||||
import io.dico.parcels2.util.ext.clampMax
|
||||
import org.bukkit.World
|
||||
import org.bukkit.block.Block
|
||||
import org.bukkit.block.BlockFace
|
||||
@@ -35,6 +36,7 @@ data class Vec3i(
|
||||
infix fun withZ(o: Int) = Vec3i(x, y, o)
|
||||
fun add(ox: Int, oy: Int, oz: Int) = Vec3i(x + ox, y + oy, z + oz)
|
||||
fun neg() = Vec3i(-x, -y, -z)
|
||||
fun clampMax(o: Vec3i) = Vec3i(x.clampMax(o.x), y.clampMax(o.y), z.clampMax(o.z))
|
||||
|
||||
companion object {
|
||||
private operator fun invoke(face: BlockFace) = Vec3i(face.modX, face.modY, face.modZ)
|
||||
|
||||
Reference in New Issue
Block a user