Skip to content
4 changes: 4 additions & 0 deletions src/main/kotlin/com/coderjoe/atlas/Atlas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import com.coderjoe.atlas.transport.TransportBlockRegistry
import com.coderjoe.atlas.transport.block.ConveyorBelt
import com.coderjoe.atlas.utility.block.AutoSmelter
import com.coderjoe.atlas.utility.block.CobblestoneFactory
import com.coderjoe.atlas.utility.block.Crusher
import com.coderjoe.atlas.utility.block.ObsidianFactory
import com.coderjoe.atlas.utility.block.SmallDrill
import com.coderjoe.atlas.utility.block.SoftTouchDrill
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.scheduler.BukkitTask

Expand Down Expand Up @@ -209,7 +211,9 @@ class Atlas : JavaPlugin() {
PowerSplitter.descriptor,
CobblestoneFactory.descriptor,
ObsidianFactory.descriptor,
Crusher.descriptor,
PowerMerger.descriptor,
SoftTouchDrill.descriptor,
).associateBy { it.baseBlockId }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid

companion object {
const val BLOCK_ID = "atlas:fluid_container"
const val MAX_CAPACITY = 10
const val MAX_CAPACITY = 20

val descriptor =
BlockDescriptor(
Expand Down Expand Up @@ -62,8 +62,8 @@ class FluidContainer(location: Location, override val facing: BlockFace) : Fluid
fun getFillLevel(): Int =
when (storedAmount) {
0 -> 0
in 1..3 -> 1
in 4..7 -> 2
in 1..6 -> 1
in 7..13 -> 2
else -> 3
}

Expand Down
15 changes: 14 additions & 1 deletion src/main/kotlin/com/coderjoe/atlas/power/PowerBlockDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import com.coderjoe.atlas.power.block.SmallBattery
import com.coderjoe.atlas.power.block.SmallSolarPanel
import com.coderjoe.atlas.utility.block.AutoSmelter
import com.coderjoe.atlas.utility.block.CobblestoneFactory
import com.coderjoe.atlas.utility.block.Crusher
import com.coderjoe.atlas.utility.block.ObsidianFactory
import com.coderjoe.atlas.utility.block.SmallDrill
import com.coderjoe.atlas.utility.block.SoftTouchDrill
import io.papermc.paper.dialog.Dialog
import io.papermc.paper.registry.data.dialog.ActionButton
import io.papermc.paper.registry.data.dialog.DialogBase
Expand Down Expand Up @@ -74,7 +76,7 @@ object PowerBlockDialog {
drill: SmallDrill,
onClose: (Player) -> Unit,
) {
val title = Component.text("Small Drill")
val title = Component.text(getBlockDisplayName(drill))
val bodyText = buildPowerInfo(drill)
val body = DialogBody.plainMessage(bodyText)

Expand Down Expand Up @@ -124,13 +126,15 @@ object PowerBlockDialog {
when (powerBlock) {
is SmallSolarPanel -> "Small Solar Panel"
is SmallBattery -> "Small Battery"
is SoftTouchDrill -> "Soft Touch Drill"
is SmallDrill -> "Small Drill"
is PowerCable -> "Power Cable (${powerBlock.facing.displayName()})"
is LavaGenerator -> "Lava Generator"
is AutoSmelter -> "Auto Smelter (${powerBlock.facing.displayName()})"
is PowerSplitter -> "Power Splitter (${powerBlock.facing.displayName()})"
is CobblestoneFactory -> "Cobblestone Factory"
is ObsidianFactory -> "Obsidian Factory"
is Crusher -> "Crusher (${powerBlock.facing.displayName()})"
is PowerMerger -> "Power Merger (${powerBlock.facing.displayName()})"
else -> "Power Block"
}
Expand Down Expand Up @@ -175,6 +179,12 @@ object PowerBlockDialog {
is SmallBattery ->
Component.text("Storage - holds up to 10 power")
.color(NamedTextColor.GRAY)
is SoftTouchDrill -> {
val directionName = powerBlock.miningDirection.displayName()
val status = if (powerBlock.enabled) "ON" else "OFF"
Component.text("Machine - mining $directionName, $status, consumes 50 power/s (silk touch)")
.color(NamedTextColor.GRAY)
}
is SmallDrill -> {
val directionName = powerBlock.miningDirection.displayName()
val status = if (powerBlock.enabled) "ON" else "OFF"
Expand All @@ -199,6 +209,9 @@ object PowerBlockDialog {
is ObsidianFactory ->
Component.text("Machine - consumes ${ObsidianFactory.POWER_COST} power + water + lava → obsidian")
.color(NamedTextColor.GRAY)
is Crusher ->
Component.text("Machine - crushes ore blocks into 2x ores, consumes ${Crusher.POWER_PER_CRUSH} power/item")
.color(NamedTextColor.GRAY)
is PowerMerger ->
Component.text("Cable - merges power from all sides, outputs in facing direction")
.color(NamedTextColor.GRAY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.coderjoe.atlas.power.PowerBlock
import org.bukkit.Location
import org.bukkit.block.BlockFace

class LavaGenerator(location: Location) : PowerBlock(location, maxStorage = 50) {
class LavaGenerator(location: Location) : PowerBlock(location, maxStorage = 20) {
override val canReceivePower: Boolean = false
override val updateIntervalTicks: Long = 20L

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.coderjoe.atlas.power.PowerBlockRegistry
import org.bukkit.Location
import org.bukkit.block.BlockFace

class SmallBattery(location: Location, facing: BlockFace) : PowerBlock(location, maxStorage = 10) {
class SmallBattery(location: Location, facing: BlockFace) : PowerBlock(location, maxStorage = 50) {
override val facing: BlockFace = if (facing == BlockFace.SELF) BlockFace.DOWN else facing

override val canReceivePower: Boolean = true
Expand All @@ -25,7 +25,7 @@ class SmallBattery(location: Location, facing: BlockFace) : PowerBlock(location,
BlockDescriptor(
baseBlockId = BLOCK_ID,
displayName = "Small Battery",
description = "Storage - holds up to 10 power",
description = "Storage - holds up to 50 power",
placementType = PlacementType.SIMPLE,
additionalBlockIds = listOf(BLOCK_ID_LOW, BLOCK_ID_MEDIUM, BLOCK_ID_FULL),
constructor = { loc, facing -> SmallBattery(loc, facing) },
Expand All @@ -37,8 +37,8 @@ class SmallBattery(location: Location, facing: BlockFace) : PowerBlock(location,
private fun chargeLevel(): Int =
when (currentPower) {
0 -> 0
in 1..3 -> 1
in 4..7 -> 2
in 1..16 -> 1
in 17..33 -> 2
else -> 3
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.power.PowerBlock
import org.bukkit.Location

class SmallSolarPanel(location: Location) : PowerBlock(location, maxStorage = 1) {
class SmallSolarPanel(location: Location) : PowerBlock(location, maxStorage = 4) {
override val canReceivePower: Boolean = false
override val updateIntervalTicks: Long = 1200L
override val updateIntervalTicks: Long = 200L

companion object {
const val BLOCK_ID = "atlas:small_solar_panel"
Expand All @@ -19,7 +19,7 @@ class SmallSolarPanel(location: Location) : PowerBlock(location, maxStorage = 1)
BlockDescriptor(
baseBlockId = BLOCK_ID,
displayName = "Small Solar Panel",
description = "Generator - produces 1 power/min during daytime",
description = "Generator - produces 2 power/10s during daytime",
placementType = PlacementType.SIMPLE,
additionalBlockIds = listOf(BLOCK_ID_FULL),
constructor = { loc, _ -> SmallSolarPanel(loc) },
Expand All @@ -39,7 +39,7 @@ class SmallSolarPanel(location: Location) : PowerBlock(location, maxStorage = 1)
val isDaytime = world.time in 0..12000

if (isDaytime) {
val generated = addPower(1)
val generated = addPower(2)
if (generated > 0) {
plugin.logger.atlasInfo(
"SmallSolarPanel at ${location.coordinates} " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.bukkit.entity.Item
import org.bukkit.inventory.FurnaceRecipe
import org.bukkit.inventory.ItemStack

class AutoSmelter(location: Location, facing: BlockFace = BlockFace.NORTH) : PowerBlock(location, maxStorage = 2) {
class AutoSmelter(location: Location, facing: BlockFace = BlockFace.NORTH) : PowerBlock(location, maxStorage = 4) {
override val canReceivePower: Boolean = true
override val updateIntervalTicks: Long = 20L
override val baseBlockId: String = BLOCK_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.coderjoe.atlas.core.PlacementType
import org.bukkit.Location
import org.bukkit.Material

class CobblestoneFactory(location: Location) : MaterialFactory(location, maxStorage = 2) {
class CobblestoneFactory(location: Location) : MaterialFactory(location, maxStorage = 4) {
companion object {
const val BLOCK_ID = "atlas:cobblestone_factory"
const val BLOCK_ID_ACTIVE = "atlas:cobblestone_factory_active"
Expand Down
89 changes: 89 additions & 0 deletions src/main/kotlin/com/coderjoe/atlas/utility/block/Crusher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.coderjoe.atlas.utility.block

import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.power.PowerBlock
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.block.BlockFace
import org.bukkit.entity.Item
import org.bukkit.inventory.ItemStack

class Crusher(location: Location, facing: BlockFace = BlockFace.NORTH) : PowerBlock(location, maxStorage = 8) {
override val canReceivePower: Boolean = true
override val updateIntervalTicks: Long = 20L
override val baseBlockId: String = BLOCK_ID

var direction: BlockFace = if (facing == BlockFace.SELF) BlockFace.NORTH else facing

override val facing: BlockFace get() = direction

companion object {
const val BLOCK_ID = "atlas:crusher"
const val POWER_PER_CRUSH = 4
private const val MOVE_DISTANCE = 1.0
private const val DROP_AMOUNT = 2

val ORE_TO_DROP: Map<Material, Material> =
mapOf(
Material.IRON_ORE to Material.RAW_IRON,
Material.GOLD_ORE to Material.RAW_GOLD,
Material.COPPER_ORE to Material.RAW_COPPER,
Material.COAL_ORE to Material.COAL,
Material.DIAMOND_ORE to Material.DIAMOND,
Material.EMERALD_ORE to Material.EMERALD,
Material.LAPIS_ORE to Material.LAPIS_LAZULI,
Material.REDSTONE_ORE to Material.REDSTONE,
Material.DEEPSLATE_IRON_ORE to Material.RAW_IRON,
Material.DEEPSLATE_GOLD_ORE to Material.RAW_GOLD,
Material.DEEPSLATE_COPPER_ORE to Material.RAW_COPPER,
Material.DEEPSLATE_COAL_ORE to Material.COAL,
Material.DEEPSLATE_DIAMOND_ORE to Material.DIAMOND,
Material.DEEPSLATE_EMERALD_ORE to Material.EMERALD,
Material.DEEPSLATE_LAPIS_ORE to Material.LAPIS_LAZULI,
Material.DEEPSLATE_REDSTONE_ORE to Material.REDSTONE,
)

val descriptor =
BlockDescriptor(
baseBlockId = BLOCK_ID,
displayName = "Crusher",
description = "Crushes ore blocks into double the ores, consumes $POWER_PER_CRUSH power per item",
placementType = PlacementType.DIRECTIONAL,
constructor = { loc, face -> Crusher(loc, face) },
)
}

override fun getVisualStateBlockId(): String = BLOCK_ID

override fun powerUpdate() {
pullPowerFromNeighbors()

val world = location.world ?: return

val scanCenter = location.clone().add(0.5, 0.75, 0.5)
val nearbyItems =
world.getNearbyEntities(scanCenter, 0.5, 0.75, 0.5)
.filterIsInstance<Item>()

if (nearbyItems.isEmpty()) return

val dx = direction.direction.x * MOVE_DISTANCE
val dz = direction.direction.z * MOVE_DISTANCE

for (item in nearbyItems) {
if (currentPower >= POWER_PER_CRUSH) {
val dropMaterial = ORE_TO_DROP[item.itemStack.type]
if (dropMaterial != null) {
removePower(POWER_PER_CRUSH)
val crushedStack = ItemStack(dropMaterial, item.itemStack.amount * DROP_AMOUNT)
item.itemStack = crushedStack
}
}

item.teleportAsync(item.location.add(dx, 0.0, dz))
}

updatePoweredState()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import com.coderjoe.atlas.core.PlacementType
import org.bukkit.Location
import org.bukkit.Material

class ObsidianFactory(location: Location) : MaterialFactory(location, maxStorage = 100) {
class ObsidianFactory(location: Location) : MaterialFactory(location, maxStorage = 50) {
companion object {
const val BLOCK_ID = "atlas:obsidian_factory"
const val BLOCK_ID_ACTIVE = "atlas:obsidian_factory_active"
const val POWER_COST = 100
const val POWER_COST = 25

val descriptor =
BlockDescriptor(
Expand Down
17 changes: 12 additions & 5 deletions src/main/kotlin/com/coderjoe/atlas/utility/block/SmallDrill.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import com.coderjoe.atlas.power.PowerBlock
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.block.BlockFace
import org.bukkit.inventory.ItemStack

class SmallDrill(location: Location, facing: BlockFace? = null) : PowerBlock(location, maxStorage = 10) {
open class SmallDrill(location: Location, facing: BlockFace? = null, maxStorage: Int = 16) : PowerBlock(location, maxStorage) {
override val canReceivePower: Boolean = true
override val updateIntervalTicks: Long = 20L

var miningDirection: BlockFace = if (facing == null || facing == BlockFace.SELF) BlockFace.DOWN else facing
var enabled: Boolean = true
internal open val powerCost: Int = 8

companion object {
const val BLOCK_ID = "atlas:small_drill"
Expand All @@ -22,7 +24,7 @@ class SmallDrill(location: Location, facing: BlockFace? = null) : PowerBlock(loc
BlockDescriptor(
baseBlockId = BLOCK_ID,
displayName = "Small Drill",
description = "Machine - consumes 10 power/s",
description = "Machine - consumes 8 power/s",
placementType = PlacementType.DIRECTIONAL_OPPOSITE,
constructor = { loc, facing -> SmallDrill(loc, facing) },
)
Expand All @@ -42,7 +44,7 @@ class SmallDrill(location: Location, facing: BlockFace? = null) : PowerBlock(loc

pullPowerFromNeighbors()

if (currentPower < 10) return
if (currentPower < powerCost) return

val world = location.world ?: return

Expand Down Expand Up @@ -83,10 +85,15 @@ class SmallDrill(location: Location, facing: BlockFace? = null) : PowerBlock(loc
}
}

internal open fun getBlockDrops(block: org.bukkit.block.Block): Collection<ItemStack> {
val tool = ItemStack(Material.DIAMOND_PICKAXE)
return block.getDrops(tool)
}

private fun mineBlock(block: org.bukkit.block.Block) {
val world = location.world ?: return
removePower(10)
val drops = block.getDrops()
removePower(powerCost)
val drops = getBlockDrops(block)
block.setType(Material.AIR, false)

val dropLocation = location.clone().add(0.5, 1.0, 0.5)
Expand Down
32 changes: 32 additions & 0 deletions src/main/kotlin/com/coderjoe/atlas/utility/block/SoftTouchDrill.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.coderjoe.atlas.utility.block

import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import org.bukkit.Location
import org.bukkit.block.BlockFace
import org.bukkit.inventory.ItemStack

class SoftTouchDrill(location: Location, facing: BlockFace? = null) : SmallDrill(location, facing, maxStorage = 40) {
override val powerCost: Int = 20

companion object {
const val BLOCK_ID = "atlas:soft_touch_drill"

val descriptor =
BlockDescriptor(
baseBlockId = BLOCK_ID,
displayName = "Soft Touch Drill",
description = "Machine - consumes 20 power/s, drops blocks in original form",
placementType = PlacementType.DIRECTIONAL_OPPOSITE,
constructor = { loc, facing -> SoftTouchDrill(loc, facing) },
)
}

override val baseBlockId: String = BLOCK_ID

override fun getVisualStateBlockId(): String = BLOCK_ID

override fun getBlockDrops(block: org.bukkit.block.Block): Collection<ItemStack> {
return listOf(ItemStack(block.type))
}
}
Loading
Loading