Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expand NoteBlock BlockTracking to support up-to 1149 states #25

Merged
merged 1 commit into from
Mar 28, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.bukkit.block.data.BlockData
import org.bukkit.block.data.type.CaveVines
import org.bukkit.block.data.type.NoteBlock
import org.bukkit.block.data.type.Tripwire
import kotlin.math.min

class Block2Prefab {
val blockMap = createBlockMap()
Expand Down Expand Up @@ -54,25 +55,16 @@ class Block2Prefab {
arrayListOf<BlockData>().apply {
// Make the default blockstate the 0'th entry in the array
add(0, Material.NOTE_BLOCK.createBlockData() as NoteBlock)
// Start at 50 to skip PIANO, which is the default Instrument
for (j in 50..799) {
val noteBlockData = Material.NOTE_BLOCK.createBlockData() as NoteBlock
noteBlockData.instrument = Instrument.getByType((j / 50 % 400).toByte()) ?: continue

noteBlockData.note = Note((j % 25))
noteBlockData.isPowered = j / 25 % 2 == 1
add(j - 49, noteBlockData)
}

// Adds the piano states to the end of the blockMap, excluding Note:0 due to it being the default
// Since the order is not really relevant and some plugins might want to use the default states,
// them being at the end makes it easier to skip them
for (j in 1..49) {
// Max size is set to total -1 to reserve 1 state (0) for the default vanilla noteblock
val maxSize = Instrument.entries.size * 50 - 1
for (j in 1..<maxSize) {
val noteBlockData = Material.NOTE_BLOCK.createBlockData() as NoteBlock
noteBlockData.instrument = Instrument.PIANO
noteBlockData.instrument = Instrument.getByType(min(Instrument.entries.size, j / 50).toByte()) ?: continue

noteBlockData.note = Note((j % 25))
noteBlockData.isPowered = j / 25 % 2 == 1
add(j + 750, noteBlockData)
noteBlockData.isPowered = j % 50 >= 25
add(j, noteBlockData)
}
}.toTypedArray().let { putIfAbsent(SetBlock.BlockType.NOTEBLOCK, it) }

Expand Down
Loading