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
3 changes: 2 additions & 1 deletion src/main/kotlin/com/coderjoe/atlas/Atlas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class Atlas : JavaPlugin() {
com.coderjoe.atlas.power.block.SmallSolarPanel.descriptor,
com.coderjoe.atlas.power.block.SmallDrill.descriptor,
com.coderjoe.atlas.power.block.SmallBattery.descriptor,
com.coderjoe.atlas.power.block.PowerCable.descriptor
com.coderjoe.atlas.power.block.PowerCable.descriptor,
com.coderjoe.atlas.power.block.LavaGenerator.descriptor
).associateBy { it.baseBlockId }
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/com/coderjoe/atlas/power/PowerBlockDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.coderjoe.atlas.power

import com.coderjoe.atlas.core.AtlasBlockDialog
import com.coderjoe.atlas.core.BlockRegistry
import com.coderjoe.atlas.power.block.LavaGenerator
import com.coderjoe.atlas.power.block.PowerCable
import com.coderjoe.atlas.power.block.SmallBattery
import com.coderjoe.atlas.power.block.SmallDrill
Expand Down Expand Up @@ -123,6 +124,7 @@ object PowerBlockDialog {
is SmallBattery -> "Small Battery"
is SmallDrill -> "Small Drill"
is PowerCable -> "Power Cable (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})"
is LavaGenerator -> "Lava Generator"
else -> "Power Block"
}

Expand Down Expand Up @@ -165,6 +167,8 @@ object PowerBlockDialog {
}
is PowerCable -> Component.text("Cable - transfers power in facing direction")
.color(NamedTextColor.GRAY)
is LavaGenerator -> Component.text("Generator - produces ${LavaGenerator.POWER_PER_LAVA} power per lava unit")
.color(NamedTextColor.GRAY)
else -> Component.text("Power block")
.color(NamedTextColor.GRAY)
}
Expand Down
90 changes: 90 additions & 0 deletions src/main/kotlin/com/coderjoe/atlas/power/block/LavaGenerator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.coderjoe.atlas.power.block

import com.coderjoe.atlas.atlasInfo
import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.fluid.FluidBlockRegistry
import com.coderjoe.atlas.fluid.FluidType
import com.coderjoe.atlas.fluid.block.FluidContainer
import com.coderjoe.atlas.fluid.block.FluidPipe
import com.coderjoe.atlas.fluid.block.FluidPump
import com.coderjoe.atlas.power.PowerBlock
import org.bukkit.Location
import org.bukkit.block.BlockFace

class LavaGenerator(location: Location) : PowerBlock(location, maxStorage = 50) {

override val canReceivePower: Boolean = false
override val updateIntervalTicks: Long = 20L

companion object {
const val BLOCK_ID = "lava_generator"
const val BLOCK_ID_ACTIVE = "lava_generator_active"
const val POWER_PER_LAVA = 5

private val ADJACENT_FACES = listOf(
BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST,
BlockFace.WEST, BlockFace.UP, BlockFace.DOWN
)

val descriptor = BlockDescriptor(
baseBlockId = BLOCK_ID,
displayName = "Lava Generator",
description = "Generator - produces $POWER_PER_LAVA power per lava unit",
placementType = PlacementType.SIMPLE,
directionalVariants = emptyMap(),
allRegistrableIds = listOf(BLOCK_ID, BLOCK_ID_ACTIVE),
constructor = { loc, _ -> LavaGenerator(loc) }
)
}

override val baseBlockId: String = BLOCK_ID

override fun getVisualStateBlockId(): String = when {
currentPower > 0 -> BLOCK_ID_ACTIVE
else -> BLOCK_ID
}

override fun powerUpdate() {
if (currentPower >= maxStorage) return

val fluidRegistry = FluidBlockRegistry.instance ?: return

for (face in ADJACENT_FACES) {
val spaceAvailable = maxStorage - currentPower
if (spaceAvailable < POWER_PER_LAVA) break

val source = fluidRegistry.getAdjacentFluidBlock(location, face) ?: continue

val lava = tryPullLava(source, face)
if (lava) {
val generated = addPower(POWER_PER_LAVA)
plugin.logger.atlasInfo("LavaGenerator at ${location.blockX},${location.blockY},${location.blockZ} consumed 1 lava, generated $generated power (now $currentPower/$maxStorage)")
}
}
}

private fun tryPullLava(source: com.coderjoe.atlas.fluid.FluidBlock, face: BlockFace): Boolean {
when (source) {
is FluidPump -> {
if (source.canRemoveFluidFrom(face.oppositeFace) && source.storedFluid == FluidType.LAVA) {
source.removeFluid()
return true
}
}
is FluidPipe -> {
if (source.hasFluid() && source.storedFluid == FluidType.LAVA) {
source.removeFluid()
return true
}
}
is FluidContainer -> {
if (source.canRemoveFluidFrom(face.oppositeFace) && source.storedFluid == FluidType.LAVA) {
source.removeFluid()
return true
}
}
}
return false
}
}
61 changes: 61 additions & 0 deletions src/main/resources/nexo/items/atlas_blocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2648,3 +2648,64 @@ fluid_container_down_lava_full:
loots:
- nexo_item: fluid_container
probability: 1.0

# ─── Lava Generator ───────────────────────────────────────────────
lava_generator:
itemname: "<gradient:#FF4500:#FF8C00>Lava Generator"
material: paper
Pack:
generate_model: true
parent_model: block/cube
textures:
north: atlas:block/lava_generator_side
south: atlas:block/lava_generator_side
east: atlas:block/lava_generator_side
west: atlas:block/lava_generator_side
up: atlas:block/lava_generator_top
down: atlas:block/lava_generator_bottom
Mechanics:
custom_block:
type: NOTEBLOCK
custom_variation: 152
hardness: 5
block_sounds:
break_sound: block.metal.break
place_sound: block.metal.place
hit_sound: block.metal.hit
step_sound: block.metal.step
fall_sound: block.metal.fall
drop:
silktouch: false
loots:
- nexo_item: lava_generator
probability: 1.0

lava_generator_active:
itemname: "<gradient:#FF4500:#FF8C00>Lava Generator"
material: paper
Pack:
generate_model: true
parent_model: block/cube
textures:
north: atlas:block/lava_generator_side_active
south: atlas:block/lava_generator_side_active
east: atlas:block/lava_generator_side_active
west: atlas:block/lava_generator_side_active
up: atlas:block/lava_generator_top_active
down: atlas:block/lava_generator_bottom
Mechanics:
custom_block:
type: NOTEBLOCK
custom_variation: 153
hardness: 5
block_sounds:
break_sound: block.metal.break
place_sound: block.metal.place
hit_sound: block.metal.hit
step_sound: block.metal.step
fall_sound: block.metal.fall
drop:
silktouch: false
loots:
- nexo_item: lava_generator
probability: 1.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/main/resources/nexo/recipes/shapeless/atlas_recipes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,18 @@ fluid_container_recipe:
C:
amount: 1
minecraft_type: BUCKET

lava_generator_recipe:
result:
nexo_item: lava_generator
amount: 1
ingredients:
A:
amount: 3
minecraft_type: IRON_INGOT
B:
amount: 3
minecraft_type: REDSTONE
C:
amount: 1
minecraft_type: MAGMA_BLOCK
4 changes: 2 additions & 2 deletions src/test/kotlin/com/coderjoe/atlas/AtlasPluginTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class AtlasPluginTest {
}

@Test
fun `power system initializes with 17 block types`() {
fun `power system initializes with 19 block types`() {
TestHelper.initPowerFactory()
assertEquals(17, PowerBlockFactory.getRegisteredBlockIds().size)
assertEquals(19, PowerBlockFactory.getRegisteredBlockIds().size)
}

@Test
Expand Down
4 changes: 3 additions & 1 deletion src/test/kotlin/com/coderjoe/atlas/TestHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.coderjoe.atlas.fluid.block.FluidPump
import com.coderjoe.atlas.power.PowerBlock
import com.coderjoe.atlas.power.PowerBlockFactory
import com.coderjoe.atlas.power.PowerBlockRegistry
import com.coderjoe.atlas.power.block.LavaGenerator
import com.coderjoe.atlas.power.block.PowerCable
import com.coderjoe.atlas.power.block.SmallBattery
import com.coderjoe.atlas.power.block.SmallDrill
Expand Down Expand Up @@ -136,7 +137,8 @@ object TestHelper {
fun initPowerFactory() {
PowerBlockFactory.registerFromDescriptors(listOf(
SmallSolarPanel.descriptor, SmallDrill.descriptor,
SmallBattery.descriptor, PowerCable.descriptor
SmallBattery.descriptor, PowerCable.descriptor,
LavaGenerator.descriptor
))
}

Expand Down
Loading
Loading