Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into nova-0.18
Browse files Browse the repository at this point in the history
# Conflicts:
#	settings.gradle.kts
  • Loading branch information
NichtStudioCode committed Nov 22, 2024
2 parents 25df775 + dce512b commit ccb52fb
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 32 deletions.
2 changes: 1 addition & 1 deletion logistics/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.2.9-alpha.3"
version = "0.2.9-alpha.7"

dependencies {
implementation(project(":simple-upgrades"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract class ContainerCableConfigMenu<H : ContainerEndPointDataHolder<*>>(
*
* Should only be called from the main thread.
*/
open fun updateGui() {
fun updateGui() {
updatableItems.notifyWindows()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion machines/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.4.6-alpha.12"
version = "0.4.6-alpha.15"

dependencies {
implementation(project(":simple-upgrades"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,6 +45,7 @@ private val BREED_LIMIT by BREEDER.config.entry<Int>("breed_limit")
private val MIN_RANGE = BREEDER.config.entry<Int>("range", "min")
private val MAX_RANGE = BREEDER.config.entry<Int>("range", "max")
private val DEFAULT_RANGE by BREEDER.config.entry<Int>("range", "default")
private val FEED_BABIES by BREEDER.config.entry<Boolean>("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,
Expand Down Expand Up @@ -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<Animals>()

// TODO: protection check?

var breedsLeft = min((energyHolder.energy / energyPerBreed).toInt(), BREED_LIMIT)
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mob>()
.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions machines/src/main/resources/configs/breeder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ energy_per_tick: 10
energy_per_breed: 100
idle_time: 200
breed_limit: 5
feed_babies: false

range:
min: 1
Expand Down

0 comments on commit ccb52fb

Please sign in to comment.