fix chunk reading on custom servers, fixes GH-4

This commit is contained in:
Bixilon 2022-05-09 13:07:15 +02:00
parent 7a9ee5779d
commit 29550d9788
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 22 additions and 7 deletions

View File

@ -51,6 +51,8 @@ class SimpleContainerAction(
val target = container.slots[slot]
try {
if (slot == null) {
// slot id is null, we are not targeting anything
// -> drop item into the void
if (count == ContainerCounts.ALL) {
floatingItem.item._count = 0
} else {
@ -62,6 +64,7 @@ class SimpleContainerAction(
val matches = floatingItem.matches(target)
if (target != null && matches) {
// we can remove or merge the item
if (slotType?.canPut(container, slot, floatingItem) == true) {
// merge
val subtract = if (count == ContainerCounts.ALL) minOf(target.item.item.maxStackSize - target.item._count, floatingItem.item._count) else 1
@ -85,9 +88,12 @@ class SimpleContainerAction(
return
}
if (target != null && slotType?.canRemove(container, slot, target) != true) {
// we can not remove the item from the slot, cancelling
return
}
if (slotType?.canPut(container, slot, floatingItem) != true) {
// when can not put any item in there, cancel
return
}
// swap

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -21,15 +21,23 @@ class ArrayPaletteData(
val elementBits: Int,
override val size: Int,
) : PaletteData {
private lateinit var data: LongArray
init {
check(elementBits in 0..32)
}
private lateinit var data: LongArray
override fun read(buffer: PlayInByteBuffer) {
data = buffer.readLongArray()
buffer.readVarInt() // minecraft ignores the length prefix
val longs: Int = if (versionId < V_1_16) { // ToDo: When did this changed? is just a guess
val bits = size * elementBits
(bits + (Long.SIZE_BITS - 1)) / Long.SIZE_BITS // divide up
} else {
val elementsPerLong = Long.SIZE_BITS / elementBits
(size + elementsPerLong - 1) / elementsPerLong
}
data = buffer.readLongArray(longs)
}
override operator fun get(index: Int): Int {

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -21,6 +21,7 @@ class ArrayPalette<T>(private val registry: AbstractRegistry<T>, override val bi
override fun read(buffer: PlayInByteBuffer) {
array = arrayOfNulls(buffer.readVarInt())
for (i in array.indices) {
array[i] = registry[buffer.readVarInt()]
}

View File

@ -125,7 +125,7 @@ class ItemElement(
return true
}
override fun onDragMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions, count: Int, draggable: Dragged): Element? {
override fun onDragMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions, count: Int, draggable: Dragged): Element {
if (action != MouseActions.PRESS) {
return this
}