Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,30 @@ internal object MultiblockCache : Listener {
private fun loadedMultiblocksWithComponentsInChunk(chunkPosition: ChunkPosition): Set<BlockPosition>
= multiblocksWithComponentsInChunk[chunkPosition] ?: emptySet()

@EventHandler
private fun handle(event: PylonBlockLoadEvent) {
if (event.pylonBlock is PylonMultiblock) {
onMultiblockAdded(event.pylonBlock)
}
}

@EventHandler
private fun handle(event: PylonChunkBlocksLoadEvent) {
// Refresh existing multiblocks with a component in the chunk that was just loaded
for (multiblockPosition in loadedMultiblocksWithComponentsInChunk(event.chunk.position)) {
BlockStorage.getAs<PylonMultiblock>(multiblockPosition)?.let { refreshFullyLoaded(it) }
}
}

// Add new multiblocks
for (pylonBlock in event.pylonBlocks) {
if (pylonBlock is PylonMultiblock) {
onMultiblockAdded(pylonBlock)
}
@EventHandler
private fun handle(event: PylonBlockUnloadEvent) {
if (event.pylonBlock is PylonMultiblock) {
onMultiblockRemoved(event.pylonBlock)
}
}

@EventHandler
private fun handle(event: PylonChunkBlocksUnloadEvent) {
// Remove multiblocks that were just unloaded
for (pylonBlock in event.pylonBlocks) {
if (pylonBlock is PylonMultiblock) {
onMultiblockRemoved(pylonBlock)
}
}

// Mark existing multiblocks with components as not formed and not fully loaded
for (multiblockPosition in loadedMultiblocksWithComponentsInChunk(event.chunk.position)) {
val multiblock = BlockStorage.getAs<PylonMultiblock>(multiblockPosition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ interface PylonCargoBlock : PylonLogisticBlock, PylonEntityHolderBlock {
continue
}


tickCargoFace(sourceGroup, targetGroup)
}
}
Expand All @@ -166,7 +167,7 @@ interface PylonCargoBlock : PylonLogisticBlock, PylonEntityHolderBlock {
val targetAmount = targetSlot.getAmount()
val targetMaxAmount = targetSlot.getMaxAmount(sourceStack)

if (targetAmount == targetMaxAmount || !sourceStack.isSimilar(targetStack)) {
if (targetAmount == targetMaxAmount || (targetStack != null && !sourceStack.isSimilar(targetStack))) {
continue
}

Expand Down Expand Up @@ -242,7 +243,7 @@ interface PylonCargoBlock : PylonLogisticBlock, PylonEntityHolderBlock {
// Disconnect adjacent cargo ducts
for ((face, _) in block.cargoBlockData.groups) {
BlockStorage.getAs<CargoDuct>(block.block.getRelative(face))?.let { duct ->
if (face in duct.connectedFaces) {
if (face.oppositeFace in duct.connectedFaces) {
duct.connectedFaces.remove(face.oppositeFace)
duct.updateConnectedFaces()
PylonCargoDisconnectEvent(duct, block).callEvent()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.pylonmc.pylon.core.block.base

import io.github.pylonmc.pylon.core.block.MultiblockCache
import io.github.pylonmc.pylon.core.util.position.BlockPosition
import io.github.pylonmc.pylon.core.util.position.ChunkPosition
import org.bukkit.block.Block
import org.jetbrains.annotations.ApiStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import net.kyori.adventure.bossbar.BossBar
import net.kyori.adventure.text.Component
import org.bukkit.Bukkit
import org.bukkit.attribute.Attribute
import org.bukkit.block.Block
import org.bukkit.entity.Entity
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
Expand Down Expand Up @@ -256,6 +256,19 @@ class Waila private constructor(private val player: Player, playerConfig: Player
blockOverrides[position] = provider
}

/**
* Adds a WAILA override for the given position. This will always show the
* provided WAILA config when a WAILA-enabled player looks at the block at
* the given position, regardless of the block type or even if the block is
* not a Pylon block.
*
* If an override is added for a position that already has an override, the
* old override will be replaced.
*/
@JvmStatic
fun addWailaOverride(block: Block, provider: (Player) -> WailaDisplay?)
= addWailaOverride(block.position, provider)

/**
* Adds a WAILA override for the given entity. This will always show the
* provided WAILA config when a WAILA-enabled player looks at the entity
Expand All @@ -277,6 +290,13 @@ class Waila private constructor(private val player: Player, playerConfig: Player
blockOverrides.remove(position)
}

/**
* Removes any existing WAILA override for the given position.
*/
@JvmStatic
fun removeWailaOverride(block: Block)
= removeWailaOverride(block.position)

/**
* Removes any existing WAILA override for the given entity.
*/
Expand All @@ -288,12 +308,6 @@ class Waila private constructor(private val player: Player, playerConfig: Player
@EventHandler(priority = EventPriority.MONITOR)
private fun onPlayerJoin(event: PlayerJoinEvent) {
val player = event.player

// TODO: Remove this migration code in a future version
if (player.persistentDataContainer.has(wailaKey, PylonSerializers.BOOLEAN)) {
player.persistentDataContainer.remove(wailaKey)
}

if (player.wailaConfig.enabled) {
addPlayer(player)
}
Expand Down