8000 Remove ContainerDataDelegate and change ContainerDataLongDelegate to … · object-Object/HexDebug@33216e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 33216e5

Browse files
committed
Remove ContainerDataDelegate and change ContainerDataLongDelegate to use 4 values instead of 2 (fix #23)
1 parent db5a56d commit 33216e5

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

Common/src/main/kotlin/gay/object/hexdebug/blocks/base/ContainerDataDelegate.kt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@ package gay.`object`.hexdebug.blocks.base
33
import net.minecraft.world.inventory.ContainerData
44
import kotlin.reflect.KProperty
55

6-
data class ContainerDataDelegate(val data: ContainerData, val index: Int) {
7-
operator fun getValue(thisRef: Any, property: KProperty<*>) = data.get(index)
8-
9-
operator fun setValue(thisRef: Any, property: KProperty<*>, value: Int) {
10-
data.set(index, value)
11-
}
12-
}
13-
14-
data class ContainerDataLongDelegate(val data: ContainerData, val lowIndex: Int, val highIndex: Int) {
6+
// DataSlot stores ints but serializes them as shorts??????????????????????????????????????????????
7+
// TODO: idk if this works for negative values but i don't need it to be negative so idc
8+
data class ContainerDataLongDelegate(
9+
val data: ContainerData,
10+
val index0: Int,
11+
val index1: Int,
12+
val index2: Int,
13+
val index3: Int,
14+
) {
1515
operator fun getValue(thisRef: Any, property: KProperty<*>): Long {
16-
val low = data.get(lowIndex).toLong()
17-
val high = data.get(highIndex).toLong() shl 32
18-
return low + high
16+
return (
17+
data.get(index0).toUShort().toLong()
18+
+ (data.get(index1).toUShort().toLong() shl 16)
19+
+ (data.get(index2).toUShort().toLong() shl 32)
20+
+ (data.get(index3).toUShort().toLong() shl 48)
21+
)
1922
}
2023

2124
operator fun setValue(thisRef: Any, property: KProperty<*>, value: Long) {
22-
data.set(lowIndex, value.toInt())
23-
data.set(highIndex, (value shr 32).toInt())
25+
data.set(index0, value.toInt())
26+
data.set(index1, (value shr 16).toInt())
27+
data.set(index2, (value shr 32).toInt())
28+
data.set(index3, (value shr 48).toInt())
2429
}
2530
}

Common/src/main/kotlin/gay/object/hexdebug/blocks/splicing/SplicingTableBlockEntity.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ class SplicingTableBlockEntity(pos: BlockPos, state: BlockState) : BlockEntity(
4444

4545
private var media by ContainerDataLongDelegate(
4646
containerData,
47-
lowIndex = SplicingTableDataSlot.MEDIA_LOW.index,
48-
highIndex = SplicingTableDataSlot.MEDIA_HIGH.index,
47+
index0 = SplicingTableDataSlot.MEDIA_0.index,
48+
index1 = SplicingTableDataSlot.MEDIA_1.index,
49+
index2 = SplicingTableDataSlot.MEDIA_2.index,
50+
index3 = SplicingTableDataSlot.MEDIA_3.index,
4951
)
5052

5153
val analogOutputSignal get() = if (!listStack.isEmpty) 15 else 0

Common/src/main/kotlin/gay/object/hexdebug/blocks/splicing/SplicingTableDataSlot.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package gay.`object`.hexdebug.blocks.splicing
22

3-
import gay.`object`.hexdebug.blocks.base.ContainerDataDelegate
4-
import net.minecraft.world.inventory.ContainerData
5-
63
enum class SplicingTableDataSlot {
74
// media is a long but ContainerData stores ints :/
8-
MEDIA_LOW,
9-
MEDIA_HIGH;
5+
// and also DataSlot serializes ints as shorts for some reason
6+
MEDIA_0,
7+
MEDIA_1,
8+
MEDIA_2,
9+
MEDIA_3;
1010

1111
val index = ordinal
1212

13-
fun delegate(data: ContainerData) = ContainerDataDelegate(data, index)
14-
1513
companion object {
1614
val size = entries.size
1715
}

Common/src/main/kotlin/gay/object/hexdebug/gui/splicing/SplicingTableMenu.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ class SplicingTableMenu(
4343

4444
val media by ContainerDataLongDelegate(
4545
data,
46-
lowIndex = SplicingTableDataSlot.MEDIA_LOW.index,
47-
highIndex = SplicingTableDataSlot.MEDIA_HIGH.index,
46+
index0 = SplicingTableDataSlot.MEDIA_0.index,
47+
index1 = SplicingTableDataSlot.MEDIA_1.index,
48+
index2 = SplicingTableDataSlot.MEDIA_2.index,
49+
index3 = SplicingTableDataSlot.MEDIA_3.index,
4850
)
4951

5052
var clientView = SplicingTableClientView.empty()

0 commit comments

Comments
 (0)
0