Skip to content

Commit

Permalink
fix liner node splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
Gutin1 committed Sep 22, 2024
1 parent 5716200 commit 9ac2120
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ import net.horizonsend.ion.server.miscellaneous.utils.coordinates.getX
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.getY
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.getZ
import net.horizonsend.ion.server.miscellaneous.utils.getBlockDataSafe
import org.bukkit.Axis
import org.bukkit.block.data.Directional

// Aka lightning rod
class FluidLinearNode(network: FluidNodeManager) : LinearNode<FluidNodeManager, FluidLinearNode, FluidLinearNode>(network) {
override val type: NodeType = LIGHTNING_ROD

constructor(network: FluidNodeManager, origin: Long, axis: Axis) : this(network) {
positions.add(origin)
this.axis = axis
}

override fun addBack(position: BlockKey) {
val data = getBlockDataSafe(manager.world, getX(position), getY(position), getZ(position)) as? Directional ?: return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ abstract class LinearNode<T: NodeManager, A: LinearNode<T, B, A>, B: LinearNode<
}

override fun ofPositions(positions: Set<BlockKey>): B {
val new = super.ofPositions(positions)
new.axis = axis
return new
@Suppress("UNCHECKED_CAST")
val newNode = type.newInstance(manager) as B

// Need to set the axis before the rebuild, hence the override
newNode.axis = axis

positions.forEach {
newNode.addPosition(it)
newNode.buildRelations(it)
}

return newNode
}

fun setAxis(axis: Axis): LinearNode<T, *, *> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ import net.horizonsend.ion.server.miscellaneous.utils.coordinates.getX
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.getY
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.getZ
import net.horizonsend.ion.server.miscellaneous.utils.getBlockDataSafe
import org.bukkit.Axis
import org.bukkit.block.data.Directional

class EndRodNode(network: PowerNodeManager) : LinearNode<PowerNodeManager, EndRodNode, EndRodNode>(network) {
override val type: NodeType = NodeType.END_ROD_NODE

constructor(network: PowerNodeManager, origin: Long, axis: Axis) : this(network) {
positions.add(origin)
this.axis = axis
}

override fun addBack(position: BlockKey) {
val data = getBlockDataSafe(manager.world, getX(position), getY(position), getZ(position)) as? Directional ?: return

Expand Down

0 comments on commit 9ac2120

Please sign in to comment.