Skip to content

Commit

Permalink
node factory simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
Gutin1 committed Sep 22, 2024
1 parent 14ecbff commit 5716200
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ object PrePackaged {
val type = itemStack.type
if (!type.isBlock) return false

//TODO something with double slabs
return requirement.checkBlockData(type.createBlockData())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package net.horizonsend.ion.server.features.transport.node

import com.manya.pdc.base.EnumDataType
import net.horizonsend.ion.server.features.transport.node.manager.NodeManager
import net.horizonsend.ion.server.features.transport.node.type.fluid.LightningRodNode
import net.horizonsend.ion.server.features.transport.node.type.fluid.FluidLinearNode
import net.horizonsend.ion.server.features.transport.node.type.power.EndRodNode
import net.horizonsend.ion.server.features.transport.node.type.power.InvertedDirectionalNode
import net.horizonsend.ion.server.features.transport.node.type.power.PowerDirectionalNode
import net.horizonsend.ion.server.features.transport.node.type.power.PowerEqualSplitterNode
import net.horizonsend.ion.server.features.transport.node.type.power.PowerExtractorNode
import net.horizonsend.ion.server.features.transport.node.type.power.PowerFlowMeter
import net.horizonsend.ion.server.features.transport.node.type.power.PowerInputNode
Expand All @@ -23,12 +22,11 @@ enum class NodeType(val clazz: Class<out TransportNode>) {
POWER_FLOW_METER(PowerFlowMeter::class.java),
POWER_DIRECTIONAL_NODE(PowerDirectionalNode::class.java),
POWER_INVERSE_DIRECTIONAL_NODE(InvertedDirectionalNode::class.java),
POWER_EQUAL_SPLITTER(PowerEqualSplitterNode::class.java),

//FLUID
FLUID_INPUT(net.horizonsend.ion.server.features.transport.node.type.fluid.FluidInputNode::class.java),
FLUID_JUNCTION(net.horizonsend.ion.server.features.transport.node.type.fluid.FluidJunctionNode::class.java),
LIGHTNING_ROD(LightningRodNode::class.java),
LIGHTNING_ROD(FluidLinearNode::class.java),

//ITEM
;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.horizonsend.ion.server.features.transport.node.type.fluid

class GasDirectionalNode {
class FluidDirectionalNode {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.horizonsend.ion.server.features.transport.node.type.fluid

class GasValveNode {
class FluidFilterNode {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.horizonsend.ion.server.features.transport.node.type.fluid

class GasFilterNode {
class FluidFlowMeter {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.horizonsend.ion.server.features.transport.node.type.fluid

class GasInvertedDirectionalNode {
class FluidInvertedDirectionalNode {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FluidJunctionNode(network: FluidNodeManager) : JunctionNode<FluidNodeManag
}

override fun addBack(position: BlockKey) {
manager.nodeFactory.addJunction(position, handleRelationships = false)
manager.nodeFactory.addJunctionNode<FluidJunctionNode>(position, type, handleRelationships = false)
}

override fun toString(): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.horizonsend.ion.server.features.transport.node.type.fluid

import net.horizonsend.ion.server.features.transport.node.NodeType
import net.horizonsend.ion.server.features.transport.node.NodeType.LIGHTNING_ROD
import net.horizonsend.ion.server.features.transport.node.manager.FluidNodeManager
import net.horizonsend.ion.server.features.transport.node.type.general.LinearNode
import net.horizonsend.ion.server.miscellaneous.utils.axis
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.BlockKey
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.getX
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.getY
Expand All @@ -11,8 +13,9 @@ import net.horizonsend.ion.server.miscellaneous.utils.getBlockDataSafe
import org.bukkit.Axis
import org.bukkit.block.data.Directional

class LightningRodNode(network: FluidNodeManager) : LinearNode<FluidNodeManager, LightningRodNode, LightningRodNode>(network) {
override val type: NodeType = NodeType.LIGHTNING_ROD
// 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)
Expand All @@ -22,10 +25,6 @@ class LightningRodNode(network: FluidNodeManager) : LinearNode<FluidNodeManager,
override fun addBack(position: BlockKey) {
val data = getBlockDataSafe(manager.world, getX(position), getY(position), getZ(position)) as? Directional ?: return

manager.nodeFactory.addLightningRod(
data,
position,
handleRelationships = false
)
manager.nodeFactory.addLinearNode<FluidLinearNode>(position, data.facing.axis, type, handleRelationships = false)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package net.horizonsend.ion.server.features.transport.node.type.fluid

import net.horizonsend.ion.server.features.custom.blocks.CustomBlocks
import net.horizonsend.ion.server.features.transport.node.NodeType.FLUID_INPUT
import net.horizonsend.ion.server.features.transport.node.NodeType.FLUID_JUNCTION
import net.horizonsend.ion.server.features.transport.node.NodeType.LIGHTNING_ROD
import net.horizonsend.ion.server.features.transport.node.manager.FluidNodeManager
import net.horizonsend.ion.server.features.transport.node.type.power.SpongeNode
import net.horizonsend.ion.server.features.transport.node.util.NodeFactory
import net.horizonsend.ion.server.features.transport.node.util.getNeighborNodes
import net.horizonsend.ion.server.features.transport.node.util.handleMerges
import net.horizonsend.ion.server.miscellaneous.utils.axis
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.BlockKey
import net.horizonsend.ion.server.miscellaneous.utils.faces
import net.horizonsend.ion.server.miscellaneous.utils.isChiseledCopper
import net.horizonsend.ion.server.miscellaneous.utils.isCopperBlock
import net.horizonsend.ion.server.miscellaneous.utils.isCopperBulb
Expand All @@ -21,84 +19,25 @@ class FluidNodeFactory(network: FluidNodeManager) : NodeFactory<FluidNodeManager
if (network.nodes.contains(key)) return false

when {
// Straight wires
data.material == Material.LIGHTNING_ROD -> addLightningRod(data as Directional, key)
data.material == Material.LIGHTNING_ROD -> addLinearNode<FluidLinearNode>(key, (data as Directional).facing.axis, LIGHTNING_ROD)
data.material.isCopperBlock -> addJunctionNode<FluidJunctionNode>(key, FLUID_JUNCTION)

// Omnidirectional wires
data.material.isCopperBlock -> addJunction(key)
// data.material == Material.CRAFTING_TABLE -> addSimpleSingleNode(key, FLUID_EXTRACOTR_NODE)
data.material == Material.FLETCHING_TABLE -> addSimpleSingleNode(key, FLUID_INPUT)

// Extractor
data.material == Material.CRAFTING_TABLE -> println("TODO")

// Input
data.material == Material.FLETCHING_TABLE -> println("TODO")

// Flow meter
data.material == Material.OBSERVER -> println("TODO")

// Merge
data.material == Material.REDSTONE_BLOCK -> println("TODO")
data.material == Material.IRON_BLOCK -> println("TODO")
// data.material == Material.LAPIS_BLOCK -> addSimpleSingleNode(key, FLUID_INVERTED_DIRECTIONAL_NODE)

// Inverted Merge
data.material == Material.LAPIS_BLOCK -> println("TODO")

// Splitter
CustomBlocks.getByBlockData(data) == CustomBlocks.ALUMINUM_BLOCK -> println("TODO")

// Valve
data.material.isChiseledCopper -> println("TODO")

// Filter
data.material.isCopperBulb -> println("TODO")

else -> return false
}

return true
}

fun addLightningRod(data: Directional, position: Long, handleRelationships: Boolean = true) {
val axis = data.facing.axis

// The neighbors in the direction of the wire's facing, that are also facing that direction
val neighbors = getNeighborNodes(position, network.nodes, axis.faces.toList())
.values
.filterIsInstance<LightningRodNode>()
.filterTo(mutableListOf()) { it.axis == axis }

val finalNode = when (neighbors.size) {
// Disconnected
0 -> LightningRodNode(network, position, data.facing.axis).apply { loadIntoNetwork() }

// Consolidate into neighbor
1 -> neighbors.firstOrNull()?.addPosition(position) ?: throw ConcurrentModificationException("Node removed during processing")

// Should be a max of 2
2 -> handleMerges(neighbors).addPosition(position)

else -> throw IllegalArgumentException("Linear node had more than 2 neighbors")
}

if (handleRelationships) finalNode.rebuildRelations()
}

fun addJunction(position: BlockKey, handleRelationships: Boolean = true) {
val neighbors = getNeighborNodes(position, network.nodes).values.filterIsInstanceTo<SpongeNode, MutableList<SpongeNode>>(mutableListOf())

val finalNode = when (neighbors.size) {
// New sponge node
0 -> net.horizonsend.ion.server.features.transport.node.type.fluid.FluidJunctionNode(network, position).apply { loadIntoNetwork() }

// Consolidate into neighbor
1 -> neighbors.firstOrNull()?.addPosition(position) ?: throw ConcurrentModificationException("Node removed during processing")

// Join multiple neighbors together
in 2..6 -> handleMerges(neighbors).addPosition(position)

else -> throw NotImplementedError()
}

if (handleRelationships) finalNode.rebuildRelations()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.horizonsend.ion.server.features.transport.node.type.fluid

class GasFlowMeter {
class FluidValveNode {
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ abstract class LinearNode<T: NodeManager, A: LinearNode<T, B, A>, B: LinearNode<
return new
}

fun setAxis(axis: Axis): LinearNode<T, *, *> {
this.axis = axis
return this
}

override fun toString(): String = "(END ROD NODE: Axis: $axis; ${positions.size} positions; ${relationships.size} relations, Transferable to: ${getTransferableNodes().joinToString { it.javaClass.simpleName }} nodes)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.horizonsend.ion.server.features.transport.node.type.power
import net.horizonsend.ion.server.features.transport.node.NodeType
import net.horizonsend.ion.server.features.transport.node.manager.PowerNodeManager
import net.horizonsend.ion.server.features.transport.node.type.general.LinearNode
import net.horizonsend.ion.server.miscellaneous.utils.axis
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.BlockKey
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.getX
import net.horizonsend.ion.server.miscellaneous.utils.coordinates.getY
Expand All @@ -22,10 +23,6 @@ class EndRodNode(network: PowerNodeManager) : LinearNode<PowerNodeManager, EndRo
override fun addBack(position: BlockKey) {
val data = getBlockDataSafe(manager.world, getX(position), getY(position), getZ(position)) as? Directional ?: return

manager.nodeFactory.addEndRod(
data,
position,
handleRelationships = false
)
manager.nodeFactory.addLinearNode<EndRodNode>(position, data.facing.axis, type, handleRelationships = false)
}
}

This file was deleted.

Loading

0 comments on commit 5716200

Please sign in to comment.