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 @@ -179,7 +179,8 @@ class Atlas : JavaPlugin() {
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.LavaGenerator.descriptor
com.coderjoe.atlas.power.block.LavaGenerator.descriptor,
com.coderjoe.atlas.power.block.AutoSmelter.descriptor
).associateBy { it.baseBlockId }
}

Expand Down
17 changes: 15 additions & 2 deletions src/main/kotlin/com/coderjoe/atlas/guide/GuideBook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ object GuideBook {
private const val FLUID_PIPE = "\uE106"
private const val FLUID_CONTAINER = "\uE107"
private const val CONVEYOR_BELT = "\uE108"
private const val AUTO_SMELTER = "\uE109"

fun create(): ItemStack {
val book = ItemStack(Material.WRITTEN_BOOK)
Expand Down Expand Up @@ -208,14 +209,26 @@ object GuideBook {
.append(Component.text("place after a drill\nto auto-collect mined\nblocks.", darkGray))
.build(),

// Page 13: Tips
// Page 13: Auto Smelter
Component.text()
.append(Component.text("Auto Smelter\n", Style.style(TextDecoration.BOLD).color(darkGreen)))
.append(Component.text("\n"))
.append(Component.text(AUTO_SMELTER))
.append(Component.text(" "))
.append(Component.text("Auto Smelter\n", Style.style(TextDecoration.BOLD).color(darkGreen)))
.append(Component.text("\nSmelts items passing\nthrough it. Conveyor\nbelt on the bottom,\nfire chamber on top.\n\n", darkGray))
.append(Component.text("Power cost: ", bold))
.append(Component.text("2 per item", darkGray))
.build(),

// Page 14: Tips
Component.text()
.append(Component.text("Tips & Tricks\n", Style.style(TextDecoration.BOLD).color(darkRed)))
.append(Component.text("\n"))
.append(Component.text("Lava power pipeline:\n", bold))
.append(Component.text("Pump > Pipe >\nContainer > Lava Gen\n\n", darkGray))
.append(Component.text("Auto-mining:\n", bold))
.append(Component.text("Drill + Conveyor Belt\ncollects drops for you\n\n", darkGray))
.append(Component.text("Drill + Conveyor Belt\n+ Auto Smelter for\nauto ore processing\n\n", darkGray))
.append(Component.text("Placement:\n", bold))
.append(Component.text("blocks face where you\nlook. The pull direction\nis always from behind.", darkGray))
.build()
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.AutoSmelter
import com.coderjoe.atlas.power.block.LavaGenerator
import com.coderjoe.atlas.power.block.PowerCable
import com.coderjoe.atlas.power.block.SmallBattery
Expand Down Expand Up @@ -125,6 +126,7 @@ object PowerBlockDialog {
is SmallDrill -> "Small Drill"
is PowerCable -> "Power Cable (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})"
is LavaGenerator -> "Lava Generator"
is AutoSmelter -> "Auto Smelter (${powerBlock.facing.name.lowercase().replaceFirstChar { it.uppercase() }})"
else -> "Power Block"
}

Expand Down Expand Up @@ -169,6 +171,8 @@ object PowerBlockDialog {
.color(NamedTextColor.GRAY)
is LavaGenerator -> Component.text("Generator - produces ${LavaGenerator.POWER_PER_LAVA} power per lava unit")
.color(NamedTextColor.GRAY)
is AutoSmelter -> Component.text("Machine - smelts items passing through, consumes ${AutoSmelter.POWER_PER_SMELT} power/item")
.color(NamedTextColor.GRAY)
else -> Component.text("Power block")
.color(NamedTextColor.GRAY)
}
Expand Down
126 changes: 126 additions & 0 deletions src/main/kotlin/com/coderjoe/atlas/power/block/AutoSmelter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.coderjoe.atlas.power.block

import com.coderjoe.atlas.core.BlockDescriptor
import com.coderjoe.atlas.core.PlacementType
import com.coderjoe.atlas.power.PowerBlock
import com.coderjoe.atlas.power.PowerBlockRegistry
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.block.BlockFace
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) {

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 = "auto_smelter"
const val POWER_PER_SMELT = 2
private const val MOVE_DISTANCE = 1.0

val DIRECTIONAL_IDS = mapOf(
BlockFace.NORTH to "auto_smelter_north",
BlockFace.SOUTH to "auto_smelter_south",
BlockFace.EAST to "auto_smelter_east",
BlockFace.WEST to "auto_smelter_west"
)

val POWERED_IDS = mapOf(
BlockFace.NORTH to "auto_smelter_north_on",
BlockFace.SOUTH to "auto_smelter_south_on",
BlockFace.EAST to "auto_smelter_east_on",
BlockFace.WEST to "auto_smelter_west_on"
)

val ID_TO_FACING: Map<String, BlockFace> = buildMap {
DIRECTIONAL_IDS.forEach { (face, id) -> put(id, face) }
POWERED_IDS.forEach { (face, id) -> put(id, face) }
}

val ALL_VARIANT_IDS: List<String> = DIRECTIONAL_IDS.values.toList() + POWERED_IDS.values.toList()

fun facingFromBlockId(blockId: String): BlockFace? = ID_TO_FACING[blockId]

val descriptor = BlockDescriptor(
baseBlockId = BLOCK_ID,
displayName = "Auto Smelter",
description = "Smelts items passing through, consumes 2 power per item",
placementType = PlacementType.DIRECTIONAL,
directionalVariants = DIRECTIONAL_IDS,
allRegistrableIds = ALL_VARIANT_IDS,
constructor = { loc, face -> AutoSmelter(loc, face) }
)

fun getSmeltingResult(input: ItemStack): ItemStack? {
return try {
Bukkit.recipeIterator().asSequence()
.filterIsInstance<FurnaceRecipe>()
.find { it.inputChoice.test(input) }
?.result
} catch (_: Exception) {
null
}
}
}

override fun getVisualStateBlockId(): String {
return if (hasPower()) {
POWERED_IDS[direction]!!
} else {
DIRECTIONAL_IDS[direction]!!
}
}

override fun powerUpdate() {
// Pull power from adjacent blocks
if (canAcceptPower()) {
val registry = PowerBlockRegistry.instance ?: return
val neighbors = registry.getAdjacentPowerBlocks(location)
for (neighbor in neighbors) {
if (!canAcceptPower()) break
if (neighbor.hasPower()) {
val pulled = neighbor.removePower(1)
if (pulled > 0) {
addPower(pulled)
}
}
}
}

val world = location.world ?: return

// Scan for items on the belt surface (same as conveyor belt)
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) {
// Try to smelt the item if we have power
if (currentPower >= POWER_PER_SMELT) {
val result = getSmeltingResult(item.itemStack)
if (result != null) {
removePower(POWER_PER_SMELT)
val smeltedStack = result.clone()
smeltedStack.amount = item.itemStack.amount
item.itemStack = smeltedStack
}
}

// Always move items forward (conveyor belt behavior)
item.teleportAsync(item.location.add(dx, 0.0, dz))
}
}
}
Loading
Loading