Skip to content

Commit

Permalink
refactor: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jul 26, 2024
1 parent 7a3a0c8 commit 948bf3a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ object ResourcepackGeneration {
.parent(Key.key(parent)).key(Key.key("blocky:block/${material.name.lowercase()}$suffix"))
.build()

resourcePack.model(model)
model.addTo(resourcePack)
}

fun handleBlockState(blockType: SetBlock.BlockType, material: Material, index: Int) {
blockPrefabs.find { it.block.blockType == blockType && it.block.blockId == index + 1 } ?: return
resourcePack.blockState(VanillaBlockstateFiles.vanillaBlockStateFile(blockType, material) ?: return)
VanillaBlockstateFiles.vanillaBlockStateFile(blockType, material)?.addTo(resourcePack)
}

CopperHelpers.BLOCKY_STAIRS.forEachIndexed { index, material ->
Expand All @@ -206,6 +206,7 @@ object ResourcepackGeneration {
handleBlockState(SetBlock.BlockType.SLAB, material, index)
handleModel(SetBlock.BlockType.SLAB, material, index, "block/slab", "")
handleModel(SetBlock.BlockType.SLAB, material, index, "block/slab_top", "_top")
handleModel(SetBlock.BlockType.SLAB, material, index, "block/cube_all", "")
}

CopperHelpers.BLOCKY_DOORS.forEachIndexed { index, material ->
Expand Down
40 changes: 11 additions & 29 deletions src/main/kotlin/com/mineinabyss/blocky/helpers/CopperHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,15 @@ object CopperHelpers {
Material.WEATHERED_COPPER_DOOR, Material.WEATHERED_COPPER_TRAPDOOR, Material.WEATHERED_COPPER_GRATE
)

val BLOCKY_SLABS: Set<Material>
get() = BLOCKY_COPPER.filter { it.name.endsWith("_SLAB") }.toSet()

val BLOCKY_STAIRS: Set<Material>
get() = BLOCKY_COPPER.filter { it.name.endsWith("_STAIRS") }.toSet()

val BLOCKY_DOORS: Set<Material>
get() = BLOCKY_COPPER.filter { it.name.endsWith("_DOOR") }.toSet()

val BLOCKY_TRAPDOORS: Set<Material>
get() = BLOCKY_COPPER.filter { it.name.endsWith("_TRAPDOOR") }.toSet()

val BLOCKY_GRATE: Set<Material>
get() = BLOCKY_COPPER.filter { it.name.endsWith("_GRATE") }.toSet()

val COPPER_SLABS: Set<Material>
get() = VANILLA_COPPER.filter { it.name.endsWith("_SLAB") }.toSet()

val COPPER_STAIRS: Set<Material>
get() = VANILLA_COPPER.filter { it.name.endsWith("_STAIRS") }.toSet()

val COPPER_DOORS: Set<Material>
get() = VANILLA_COPPER.filter { it.name.endsWith("_DOOR") }.toSet()

val COPPER_TRAPDOORS: Set<Material>
get() = VANILLA_COPPER.filter { it.name.endsWith("_TRAPDOOR") }.toSet()

val COPPER_GRATE: Set<Material>
get() = VANILLA_COPPER.filter { it.name.endsWith("_GRATE") }.toSet()
val BLOCKY_SLABS = BLOCKY_COPPER.filter { it.name.endsWith("_SLAB") }.toSet()
val BLOCKY_STAIRS = BLOCKY_COPPER.filter { it.name.endsWith("_STAIRS") }.toSet()
val BLOCKY_DOORS = BLOCKY_COPPER.filter { it.name.endsWith("_DOOR") }.toSet()
val BLOCKY_TRAPDOORS = BLOCKY_COPPER.filter { it.name.endsWith("_TRAPDOOR") }.toSet()
val BLOCKY_GRATE = BLOCKY_COPPER.filter { it.name.endsWith("_GRATE") }.toSet()

val COPPER_SLABS = VANILLA_COPPER.filter { it.name.endsWith("_SLAB") }.toSet()
val COPPER_STAIRS = VANILLA_COPPER.filter { it.name.endsWith("_STAIRS") }.toSet()
val COPPER_DOORS = VANILLA_COPPER.filter { it.name.endsWith("_DOOR") }.toSet()
val COPPER_TRAPDOORS = VANILLA_COPPER.filter { it.name.endsWith("_TRAPDOOR") }.toSet()
val COPPER_GRATE = VANILLA_COPPER.filter { it.name.endsWith("_GRATE") }.toSet()
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ class BlockySoundListener : Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
fun PlayerInteractEvent.onOpenCloseDoor() {
if (action != Action.RIGHT_CLICK_BLOCK || useInteractedBlock() == Event.Result.DENY) return
val block = clickedBlock?.takeIf { (it.type in CopperHelpers.BLOCKY_DOORS || it.type !in CopperHelpers.BLOCKY_TRAPDOORS) } ?: return
val type = if (block.blockData is Door) "_door_" else if (block.blockData is TrapDoor) "_trapdoor_" else return
val block = clickedBlock?.takeIf(CopperHelpers::isBlockyDoor)?.takeIf(CopperHelpers::isBlockyTrapDoor) ?: return
val opening = !(block.blockData as Openable).isOpen
val suffix = if (opening) "open" else "close"
val sound = block.toGearyOrNull()?.get<BlockySound>()?.let { if (opening) it.openSound else it.closeSound } ?: ("blocky:copper_$type$suffix")
val suffix = when (block.blockData) {
is Door -> "_door_"
is TrapDoor -> "_trapdoor_"
else -> return
}.plus(if (opening) "open" else "close")
val sound = block.toGearyOrNull()?.get<BlockySound>()?.let { if (opening) it.openSound else it.closeSound } ?: ("blocky:copper_$suffix")
block.world.playSound(block.location, sound, SoundCategory.BLOCKS, DEFAULT_HIT_VOLUME, DEFAULT_HIT_PITCH)
}

Expand Down

0 comments on commit 948bf3a

Please sign in to comment.