diff --git a/logistics/build.gradle.kts b/logistics/build.gradle.kts index 64ba2c5..0cd970c 100644 --- a/logistics/build.gradle.kts +++ b/logistics/build.gradle.kts @@ -1,4 +1,4 @@ -version = "0.2.9-alpha.3" +version = "0.2.9-alpha.7" dependencies { implementation(project(":simple-upgrades")) diff --git a/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/gui/cable/ContainerCableConfigMenu.kt b/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/gui/cable/ContainerCableConfigMenu.kt index a12b57b..a2e9c19 100644 --- a/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/gui/cable/ContainerCableConfigMenu.kt +++ b/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/gui/cable/ContainerCableConfigMenu.kt @@ -56,7 +56,7 @@ abstract class ContainerCableConfigMenu>( * * Should only be called from the main thread. */ - open fun updateGui() { + fun updateGui() { updatableItems.notifyWindows() } diff --git a/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/gui/cable/ItemCableConfigMenu.kt b/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/gui/cable/ItemCableConfigMenu.kt index 81e5e15..42305ff 100644 --- a/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/gui/cable/ItemCableConfigMenu.kt +++ b/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/gui/cable/ItemCableConfigMenu.kt @@ -13,6 +13,7 @@ import xyz.xenondevs.nova.ui.menu.addIngredient import xyz.xenondevs.nova.ui.menu.item.AddNumberItem import xyz.xenondevs.nova.ui.menu.item.DisplayNumberItem import xyz.xenondevs.nova.ui.menu.item.RemoveNumberItem +import xyz.xenondevs.nova.util.runTask import xyz.xenondevs.nova.world.block.tileentity.network.node.NetworkEndPoint import xyz.xenondevs.nova.world.block.tileentity.network.type.item.ItemNetwork import xyz.xenondevs.nova.world.block.tileentity.network.type.item.holder.ItemHolder @@ -63,13 +64,11 @@ class ItemCableConfigMenu( insertFilter = holder.insertFilters[face]?.toItemStack() extractFilter = holder.extractFilters[face]?.toItemStack() - } - - override fun updateGui() { - super.updateGui() - insertFilterInventory.setItemSilently(0, insertFilter) - extractFilterInventory.setItemSilently(0, extractFilter) + runTask { + insertFilterInventory.setItemSilently(0, insertFilter) + extractFilterInventory.setItemSilently(0, extractFilter) + } } override fun writeChanges(): Boolean { diff --git a/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/registry/Blocks.kt b/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/registry/Blocks.kt index 0d44b83..0912ccb 100644 --- a/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/registry/Blocks.kt +++ b/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/registry/Blocks.kt @@ -73,7 +73,7 @@ object Blocks : BlockRegistry, AddonHolder by Logistics { val ULTIMATE_FLUID_TANK = tank("ultimate", ::UltimateFluidTank) val CREATIVE_FLUID_TANK = tank("creative", ::CreativeFluidTank) - val STORAGE_UNIT = interactiveTileEntity("storage_unit", ::StorageUnit) { behaviors(CABLE, BlockSounds(SoundGroup.STONE)) } + val STORAGE_UNIT = interactiveTileEntity("storage_unit", ::StorageUnit) { behaviors(OTHER, BlockSounds(SoundGroup.STONE)) } val FLUID_STORAGE_UNIT = interactiveTileEntity("fluid_storage_unit", ::FluidStorageUnit) { behaviors(Bucketable, OTHER, BlockSounds(SoundGroup.STONE)) } val VACUUM_CHEST = interactiveTileEntity("vacuum_chest", ::VacuumChest) { behaviors(OTHER, BlockSounds(SoundGroup.STONE)) } val TRASH_CAN = interactiveTileEntity("trash_can", ::TrashCan) { diff --git a/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/tileentity/StorageUnit.kt b/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/tileentity/StorageUnit.kt index 17d8f41..8d9c5b6 100644 --- a/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/tileentity/StorageUnit.kt +++ b/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/tileentity/StorageUnit.kt @@ -11,6 +11,7 @@ import xyz.xenondevs.cbf.Compound import xyz.xenondevs.commons.provider.MutableProvider import xyz.xenondevs.invui.gui.Gui import xyz.xenondevs.invui.inventory.VirtualInventory +import xyz.xenondevs.invui.inventory.event.ItemPostUpdateEvent import xyz.xenondevs.invui.inventory.event.ItemPreUpdateEvent import xyz.xenondevs.invui.item.ItemProvider import xyz.xenondevs.invui.item.builder.ItemBuilder @@ -21,7 +22,6 @@ import xyz.xenondevs.nova.config.entry import xyz.xenondevs.nova.ui.menu.sideconfig.OpenSideConfigItem import xyz.xenondevs.nova.ui.menu.sideconfig.SideConfigMenu import xyz.xenondevs.nova.util.item.takeUnlessEmpty -import xyz.xenondevs.nova.util.runTaskLater import xyz.xenondevs.nova.world.BlockPos import xyz.xenondevs.nova.world.block.state.NovaBlockState import xyz.xenondevs.nova.world.block.tileentity.NetworkedTileEntity @@ -36,7 +36,7 @@ class StorageUnit(pos: BlockPos, state: NovaBlockState, data: Compound) : Networ private val inventory = StorageUnitInventory(storedValue("type", true, ItemStack::empty), storedValue("amount", true) { 0 }) private val inputInventory = VirtualInventory(null, 1).apply { setPreUpdateHandler(::handleInputInventoryUpdate) } - private val outputInventory = VirtualInventory(null, 1).apply { setPreUpdateHandler(::handleOutputInventoryUpdate) } + private val outputInventory = VirtualInventory(null, 1).apply { setPreUpdateHandler(::handlePreOutputInventoryUpdate); setPostUpdateHandler(::handlePostOutputInventoryUpdate) } init { storedItemHolder(inventory to NetworkConnectionType.BUFFER) @@ -47,18 +47,23 @@ class StorageUnit(pos: BlockPos, state: NovaBlockState, data: Compound) : Networ event.isCancelled = true } - private fun handleOutputInventoryUpdate(event: ItemPreUpdateEvent) { + private fun handlePreOutputInventoryUpdate(event: ItemPreUpdateEvent) { if (event.updateReason == SELF_UPDATE_REASON) return - if (event.isAdd || event.isSwap) { + if (!event.isRemove) { event.isCancelled = true - } else if (event.isRemove && !inventory.type.isEmpty) { - inventory.take(0, event.removedAmount) - runTaskLater(1) { menuContainer.forEachMenu(StorageUnitMenu::update) } } } + private fun handlePostOutputInventoryUpdate(event: ItemPostUpdateEvent) { + if (event.updateReason == SELF_UPDATE_REASON) + return + + // preUpdateHandler enforces that only remove is possible + inventory.take(0, event.removedAmount) + } + private fun updateOutputSlot() { if (inventory.type.isEmpty) { outputInventory.setItem(SELF_UPDATE_REASON, 0, null) diff --git a/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/tileentity/VacuumChest.kt b/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/tileentity/VacuumChest.kt index dc001d0..9e8dcbe 100644 --- a/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/tileentity/VacuumChest.kt +++ b/logistics/src/main/kotlin/xyz/xenondevs/nova/addon/logistics/tileentity/VacuumChest.kt @@ -80,10 +80,10 @@ class VacuumChest(pos: BlockPos, state: NovaBlockState, data: Compound) : Networ items.clear() if (serverTick % 10 == 0) { - pos.world.entities.forEach { + pos.world.getNearbyEntities(region.toBoundingBox()).forEach { if (it is Item - && it.location in region && filter?.allows(it.itemStack) != false + && inventory.canHold(it.itemStack.clone().apply { amount = 1 }) && runBlocking { ProtectionManager.canInteractWithEntity(this@VacuumChest, it, null) } // TODO: non-blocking ) { items += it diff --git a/machines/build.gradle.kts b/machines/build.gradle.kts index 63819a5..2da7b31 100644 --- a/machines/build.gradle.kts +++ b/machines/build.gradle.kts @@ -1,4 +1,4 @@ -version = "0.4.6-alpha.12" +version = "0.4.6-alpha.15" dependencies { implementation(project(":simple-upgrades")) diff --git a/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/energy/LightningExchanger.kt b/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/energy/LightningExchanger.kt index 038c113..4928abf 100644 --- a/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/energy/LightningExchanger.kt +++ b/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/energy/LightningExchanger.kt @@ -12,7 +12,7 @@ import xyz.xenondevs.commons.collections.enumSetOf import xyz.xenondevs.invui.gui.Gui import xyz.xenondevs.nova.addon.machines.Machines import xyz.xenondevs.nova.addon.machines.registry.Blocks.LIGHTNING_EXCHANGER -import xyz.xenondevs.nova.addon.machines.util.efficiencyDividedValue +import xyz.xenondevs.nova.addon.machines.util.efficiencyMultipliedValue import xyz.xenondevs.nova.addon.simpleupgrades.gui.OpenUpgradesItem import xyz.xenondevs.nova.addon.simpleupgrades.registry.UpgradeTypes import xyz.xenondevs.nova.addon.simpleupgrades.storedEnergyHolder @@ -41,8 +41,8 @@ class LightningExchanger(pos: BlockPos, blockState: NovaBlockState, data: Compou private val upgradeHolder = storedUpgradeHolder(UpgradeTypes.EFFICIENCY, UpgradeTypes.ENERGY) private val energyHolder = storedEnergyHolder(MAX_ENERGY, upgradeHolder, EXTRACT, BLOCKED_FACES) - private val minBurst by efficiencyDividedValue(MIN_BURST, upgradeHolder) - private val maxBurst by efficiencyDividedValue(MAX_BURST, upgradeHolder) + private val minBurst by efficiencyMultipliedValue(MIN_BURST, upgradeHolder) + private val maxBurst by efficiencyMultipliedValue(MAX_BURST, upgradeHolder) private var toCharge = 0L override fun handleTick() { diff --git a/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/energy/SolarPanel.kt b/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/energy/SolarPanel.kt index 811afa6..1fc9b7a 100644 --- a/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/energy/SolarPanel.kt +++ b/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/energy/SolarPanel.kt @@ -7,7 +7,7 @@ import xyz.xenondevs.cbf.Compound import xyz.xenondevs.commons.collections.enumSetOf import xyz.xenondevs.invui.gui.Gui import xyz.xenondevs.nova.addon.machines.registry.Blocks.SOLAR_PANEL -import xyz.xenondevs.nova.addon.machines.util.efficiencyDividedValue +import xyz.xenondevs.nova.addon.machines.util.efficiencyMultipliedValue import xyz.xenondevs.nova.addon.simpleupgrades.gui.OpenUpgradesItem import xyz.xenondevs.nova.addon.simpleupgrades.registry.UpgradeTypes import xyz.xenondevs.nova.addon.simpleupgrades.storedEnergyHolder @@ -35,7 +35,7 @@ class SolarPanel(pos: BlockPos, blockState: NovaBlockState, data: Compound) : Ne private val upgradeHolder = storedUpgradeHolder(UpgradeTypes.EFFICIENCY, UpgradeTypes.ENERGY) private val energyHolder = storedEnergyHolder(MAX_ENERGY, upgradeHolder, EXTRACT, BLOCKED_FACES) - private val peakEnergyOutput by efficiencyDividedValue(ENERGY_PER_TICK, upgradeHolder) + private val peakEnergyOutput by efficiencyMultipliedValue(ENERGY_PER_TICK, upgradeHolder) private lateinit var obstructionTask: BukkitTask private var obstructed = true diff --git a/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/mob/Breeder.kt b/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/mob/Breeder.kt index 355a417..636979c 100644 --- a/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/mob/Breeder.kt +++ b/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/mob/Breeder.kt @@ -24,7 +24,6 @@ import xyz.xenondevs.nova.ui.menu.sideconfig.OpenSideConfigItem import xyz.xenondevs.nova.ui.menu.sideconfig.SideConfigMenu import xyz.xenondevs.nova.util.BlockSide import xyz.xenondevs.nova.util.EntityUtils -import xyz.xenondevs.nova.util.getSurroundingChunks import xyz.xenondevs.nova.util.nmsEntity import xyz.xenondevs.nova.util.unwrap import xyz.xenondevs.nova.world.BlockPos @@ -46,6 +45,7 @@ private val BREED_LIMIT by BREEDER.config.entry("breed_limit") private val MIN_RANGE = BREEDER.config.entry("range", "min") private val MAX_RANGE = BREEDER.config.entry("range", "max") private val DEFAULT_RANGE by BREEDER.config.entry("range", "default") +private val FEED_BABIES by BREEDER.config.entry("feed_babies") private val FOOD_MATERIALS = setOf( Tag.ITEMS_PIGLIN_FOOD, Tag.ITEMS_FOX_FOOD, Tag.ITEMS_COW_FOOD, Tag.ITEMS_GOAT_FOOD, Tag.ITEMS_SHEEP_FOOD, @@ -88,10 +88,10 @@ class Breeder(pos: BlockPos, blockState: NovaBlockState, data: Compound) : Netwo if (idleTime++ >= mxIdleTime) { idleTime = 0 - val breedableEntities = pos.location.chunk - .getSurroundingChunks(1, includeCurrent = true, ignoreUnloaded = true) - .flatMap { it.entities.asList() } + val breedableEntities = pos.location.world + .getNearbyEntities(region.toBoundingBox()) .filterIsInstance() + // TODO: protection check? var breedsLeft = min((energyHolder.energy / energyPerBreed).toInt(), BREED_LIMIT) @@ -112,6 +112,9 @@ class Breeder(pos: BlockPos, blockState: NovaBlockState, data: Compound) : Netwo for ((index, item) in inventory.items.withIndex()) { if (item == null) continue + if (!FEED_BABIES && !animal.isAdult) + continue + fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, item.unwrap()) val result = animal.nmsEntity.interact(fakePlayer, InteractionHand.MAIN_HAND) if (result.consumesAction()) { diff --git a/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/mob/MobKiller.kt b/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/mob/MobKiller.kt index a627ee5..dccbb06 100644 --- a/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/mob/MobKiller.kt +++ b/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/mob/MobKiller.kt @@ -74,10 +74,9 @@ class MobKiller(pos: BlockPos, blockState: NovaBlockState, data: Compound) : Net val killLimit = min((energyHolder.energy / energyPerDamage).toInt(), KILL_LIMIT) - pos.world.entities - .asSequence() + pos.world.getNearbyEntities(region.toBoundingBox()).asSequence() .filterIsInstance() - .filter { it.location in region && runBlocking { ProtectionManager.canHurtEntity(this@MobKiller, it, null) } } // TODO non-blocking + .filter { runBlocking { ProtectionManager.canHurtEntity(this@MobKiller, it, null) } } // TODO non-blocking .take(killLimit) .forEach { entity -> // TODO: custom damage type diff --git a/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/world/ChunkLoader.kt b/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/world/ChunkLoader.kt index 1959845..f6127f1 100644 --- a/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/world/ChunkLoader.kt +++ b/machines/src/main/kotlin/xyz/xenondevs/nova/addon/machines/tileentity/world/ChunkLoader.kt @@ -42,7 +42,10 @@ class ChunkLoader(pos: BlockPos, blockState: NovaBlockState, data: Compound) : N private var active = false private val energyPerTick by combinedProvider(ENERGY_PER_CHUNK, range, upgradeHolder.getValueProvider(UpgradeTypes.EFFICIENCY)) - .map { (energyPerChunk, range, efficiency) -> (energyPerChunk * range * range / efficiency).roundToLong() } + .map { (energyPerChunk, range, efficiency) -> + val diameter = range * 2 + 1 + (energyPerChunk * diameter * diameter / efficiency).roundToLong() + } override fun handleDisable() { super.handleDisable() diff --git a/machines/src/main/resources/configs/breeder.yml b/machines/src/main/resources/configs/breeder.yml index 9cdf115..686b0f9 100644 --- a/machines/src/main/resources/configs/breeder.yml +++ b/machines/src/main/resources/configs/breeder.yml @@ -3,6 +3,7 @@ energy_per_tick: 10 energy_per_breed: 100 idle_time: 200 breed_limit: 5 +feed_babies: false range: min: 1