|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package net.brokenmoon.redcontrol.util
|
|
|
|
|
|
|
|
|
|
import net.brokenmoon.redcontrol.RedControl
|
|
|
|
|
import net.brokenmoon.redcontrol.api.RCWorldBus
|
|
|
|
|
import net.brokenmoon.redcontrol.blocks.NetworkCarrier
|
|
|
|
|
import net.minecraft.particle.ParticleTypes
|
|
|
|
|
import net.minecraft.server.world.ServerWorld
|
|
|
|
|
import net.minecraft.util.math.BlockPos
|
|
|
|
@ -10,16 +12,57 @@ object FloodFill {
|
|
|
|
|
fun blockFloodFiller(world: ServerWorld, seed: BlockPos) {
|
|
|
|
|
val checkable = mutableListOf(seed)
|
|
|
|
|
val seen = mutableListOf<BlockPos>()
|
|
|
|
|
var bus: RCWorldBus? = null
|
|
|
|
|
while (checkable.isNotEmpty()) {
|
|
|
|
|
val pos = checkable.removeFirst()
|
|
|
|
|
if (pos in seen) {continue}
|
|
|
|
|
if (!world.getBlockState(pos).isIn(RedControl.TAG_BUSABLE)){continue}
|
|
|
|
|
val cpos = pos.toCenterPos()
|
|
|
|
|
world.spawnParticles(ParticleTypes.CHERRY_LEAVES,cpos.x,cpos.y,cpos.z,20,0.2,0.2,0.2,0.2)
|
|
|
|
|
val state = world.getBlockState(pos)
|
|
|
|
|
if (!state.isIn(RedControl.TAG_BUSABLE)){continue}
|
|
|
|
|
val net = state.block as? NetworkCarrier
|
|
|
|
|
if (net != null) {
|
|
|
|
|
val cpos = pos.toCenterPos()
|
|
|
|
|
world.spawnParticles(ParticleTypes.WAX_ON,cpos.x,cpos.y,cpos.z,20,0.6,0.6,0.6,0.2)
|
|
|
|
|
if (bus == null) {
|
|
|
|
|
bus = net.getBus(world,pos)
|
|
|
|
|
} else {
|
|
|
|
|
net.setBus(world,pos,bus)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//val cpos = pos.toCenterPos()
|
|
|
|
|
//world.spawnParticles(ParticleTypes.WAX_ON,cpos.x,cpos.y,cpos.z,20,0.2,0.2,0.2,0.2)
|
|
|
|
|
Direction.entries.forEach {
|
|
|
|
|
checkable.add(pos.add(it.offsetX,it.offsetY,it.offsetZ))
|
|
|
|
|
}
|
|
|
|
|
seen.add(pos)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fun blockBreakFloodFiller(world: ServerWorld, seed: BlockPos) {
|
|
|
|
|
val checkable = mutableListOf<BlockPos>()
|
|
|
|
|
Direction.entries.forEach {
|
|
|
|
|
checkable.add(seed.add(it.offsetX,it.offsetY,it.offsetZ))
|
|
|
|
|
}
|
|
|
|
|
val seen = mutableListOf<BlockPos>()
|
|
|
|
|
while (checkable.isNotEmpty()) {
|
|
|
|
|
val pos = checkable.removeFirst()
|
|
|
|
|
if (pos in seen) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
val state = world.getBlockState(pos)
|
|
|
|
|
if (!state.isIn(RedControl.TAG_BUSABLE)) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
Direction.entries.forEach {
|
|
|
|
|
checkable.add(pos.add(it.offsetX, it.offsetY, it.offsetZ))
|
|
|
|
|
}
|
|
|
|
|
seen.add(pos)
|
|
|
|
|
val nc = (state.block as? NetworkCarrier)
|
|
|
|
|
if (nc != null) {
|
|
|
|
|
nc.getBus(world,pos).valid = false
|
|
|
|
|
val cpos = pos.toCenterPos()
|
|
|
|
|
world.spawnParticles(ParticleTypes.WAX_OFF,cpos.x,cpos.y,cpos.z,20,0.6,0.6,0.6,0.2)
|
|
|
|
|
}
|
|
|
|
|
//val cpos = pos.toCenterPos()
|
|
|
|
|
//world.spawnParticles(ParticleTypes.WAX_OFF, cpos.x, cpos.y, cpos.z, 20, 0.2, 0.2, 0.2, 0.2)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|