mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 19:35:00 -04:00
fix some container tests, misc registry (fuel time)
This commit is contained in:
parent
5a13e181bb
commit
3ca82f202f
@ -36,7 +36,7 @@ class FastMoveContainerActionTest {
|
||||
val container = createChest(connection)
|
||||
container.invokeAction(FastMoveContainerAction(0))
|
||||
assertNull(container.floatingItem)
|
||||
assertEquals(container.slots.size, 0)
|
||||
assertEquals(container.slots, slotsOf())
|
||||
connection.assertNoPacket()
|
||||
}
|
||||
|
||||
@ -46,9 +46,8 @@ class FastMoveContainerActionTest {
|
||||
container[54] = ItemStack(AppleTestO.item, 9)
|
||||
container.invokeAction(FastMoveContainerAction(54))
|
||||
assertNull(container.floatingItem)
|
||||
assertNull(container[54])
|
||||
assertEquals(container[0], ItemStack(AppleTestO.item, 9))
|
||||
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 53, 1, 0, 0, slotsOf(54 to null, 0 to ItemStack(AppleTestO.item, count = 9)), null))
|
||||
assertEquals(container.slots, slotsOf(0 to ItemStack(AppleTestO.item, 9)))
|
||||
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 54, 1, 0, 0, slotsOf(54 to null, 0 to ItemStack(AppleTestO.item, count = 9)), null))
|
||||
}
|
||||
|
||||
fun chestToHotbar() {
|
||||
|
@ -17,6 +17,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
||||
import org.testng.Assert.assertEquals
|
||||
import org.testng.annotations.Test
|
||||
|
||||
@Test(groups = ["version"])
|
||||
internal class VersionsIT {
|
||||
|
||||
@Test
|
||||
|
@ -18,45 +18,39 @@ import org.objenesis.ObjenesisStd
|
||||
import org.testng.Assert.assertEquals
|
||||
import org.testng.annotations.Test
|
||||
|
||||
@Test(groups = ["biome"])
|
||||
class NoiseBiomeAccessorTest {
|
||||
private val OBJENESIS = ObjenesisStd()
|
||||
|
||||
@Test
|
||||
fun testBiomeNoise1() {
|
||||
assertEquals(calculate(129, 3274, 91, 1823123L), Vec3i(32, 818, 22))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBiomeNoise2() {
|
||||
assertEquals(calculate(129, 3274, 91, -123213L), Vec3i(32, 818, 22))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBiomeNoise3() {
|
||||
assertEquals(calculate(-17, 3274, 91, -123213L), Vec3i(-5, 818, 22))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBiomeNoise4() {
|
||||
assertEquals(calculate(-1123, 3, 1, -18209371253621313), Vec3i(-281, 0, 0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBiomeNoise5() {
|
||||
assertEquals(calculate(0, 3, 1, -33135639), Vec3i(0, 0, 0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBiomeNoise6() {
|
||||
assertEquals(calculate(16, 15, -16, 561363374), Vec3i(4, 3, -4))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBiomeNoise7() {
|
||||
assertEquals(calculate(16, -15, -16, 79707367), Vec3i(4, -4, -5))
|
||||
}
|
||||
|
||||
fun calculate(x: Int, y: Int, z: Int, seed: Long): Vec3i {
|
||||
private fun calculate(x: Int, y: Int, z: Int, seed: Long): Vec3i {
|
||||
val accessor = OBJENESIS.newInstance(NoiseBiomeAccessor::class.java)
|
||||
return accessor.getBiomePosition(seed, x, y, z)
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
|
||||
|
||||
open class Container(
|
||||
protected val connection: PlayConnection,
|
||||
val connection: PlayConnection,
|
||||
val type: ContainerType,
|
||||
val title: ChatComponent? = null,
|
||||
) : Iterable<Map.Entry<Int, ItemStack>> {
|
||||
|
@ -27,7 +27,6 @@ class FastMoveContainerAction(
|
||||
override fun invoke(connection: PlayConnection, containerId: Int, container: Container) {
|
||||
// ToDo: minecraft always sends a packet
|
||||
val source = container.slots[slot] ?: return
|
||||
val previous = source.copy()
|
||||
container.lock.lock()
|
||||
try {
|
||||
val sourceSection = container.getSection(slot) ?: Int.MAX_VALUE
|
||||
@ -73,7 +72,7 @@ class FastMoveContainerAction(
|
||||
}
|
||||
}
|
||||
|
||||
connection.sendPacket(ContainerClickC2SP(containerId, container.serverRevision, this.slot, 1, 0, container.createAction(this), changes, previous))
|
||||
connection.sendPacket(ContainerClickC2SP(containerId, container.serverRevision, this.slot, 1, 0, container.createAction(this), changes, null))
|
||||
} finally {
|
||||
container.commit()
|
||||
container._validate()
|
||||
|
@ -27,7 +27,7 @@ object FuelSlotType : SlotType {
|
||||
if (item is BucketItem && item.fluid is LavaFluid) {
|
||||
return true
|
||||
}
|
||||
// ToDo: get from registries (misc/fuel_time)
|
||||
return super.canPut(container, slot, stack)
|
||||
val fuelTime = container.connection.registries.misc.getFuelTime(item)
|
||||
return fuelTime > 0
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.data.registries.misc
|
||||
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.json.JsonObject
|
||||
import de.bixilon.kutil.primitive.IntUtil.toInt
|
||||
import de.bixilon.minosoft.data.registries.item.items.Item
|
||||
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.Parentable
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
|
||||
|
||||
class MiscData(override var parent: MiscData? = null) : Parentable<MiscData> {
|
||||
private val fuelTime = Object2IntOpenHashMap<Item>()
|
||||
|
||||
init {
|
||||
fuelTime.defaultReturnValue(-1)
|
||||
}
|
||||
|
||||
fun getFuelTime(item: Item): Int {
|
||||
val time = fuelTime.getInt(item)
|
||||
if (time < 0) {
|
||||
return parent?.getFuelTime(item) ?: -1
|
||||
}
|
||||
return time
|
||||
}
|
||||
|
||||
fun rawUpdate(data: JsonObject?, registries: Registries) {
|
||||
if (data == null) {
|
||||
return
|
||||
}
|
||||
data["fuel_time"]?.let { rawUpdateFuelTime(it.unsafeCast(), registries) }
|
||||
|
||||
}
|
||||
|
||||
private fun rawUpdateFuelTime(data: Map<Any, Any>, registries: Registries) {
|
||||
for ((itemId, time) in data) {
|
||||
val item = registries.itemRegistry[itemId] ?: continue
|
||||
fuelTime[item] = time.toInt()
|
||||
}
|
||||
}
|
||||
}
|
@ -44,6 +44,7 @@ import de.bixilon.minosoft.data.registries.fluid.Fluid
|
||||
import de.bixilon.minosoft.data.registries.item.ItemRegistry
|
||||
import de.bixilon.minosoft.data.registries.item.items.Item
|
||||
import de.bixilon.minosoft.data.registries.materials.Material
|
||||
import de.bixilon.minosoft.data.registries.misc.MiscData
|
||||
import de.bixilon.minosoft.data.registries.other.containers.ContainerType
|
||||
import de.bixilon.minosoft.data.registries.particle.ParticleType
|
||||
import de.bixilon.minosoft.data.registries.registries.registry.*
|
||||
@ -120,6 +121,8 @@ class Registries {
|
||||
val argumentTypeRegistry: ResourceLocationRegistry = ResourceLocationRegistry()
|
||||
val messageTypeRegistry: Registry<ChatMessageType> = register("chat_type", Registry(codec = ChatMessageType))
|
||||
|
||||
val misc = MiscData()
|
||||
|
||||
var isFullyLoaded = false
|
||||
private set
|
||||
|
||||
@ -198,6 +201,7 @@ class Registries {
|
||||
worker += WorkerTask(this::frogVariants) { frogVariants.rawUpdate(pixlyzerData["variant/frog"]?.toJsonObject(), this) }
|
||||
|
||||
worker += WorkerTask(this::statisticRegistry) { statisticRegistry.rawUpdate(pixlyzerData["statistics"]?.toJsonObject(), this) }
|
||||
worker += WorkerTask(this::misc, dependencies = arrayOf(this::itemRegistry)) { misc.rawUpdate(pixlyzerData["misc"]?.toJsonObject(), this) }
|
||||
|
||||
val inner = CountUpAndDownLatch(1, latch)
|
||||
worker.work(inner)
|
||||
|
@ -30,8 +30,8 @@ data class ContainerClickC2SP(
|
||||
val mode: Int,
|
||||
val button: Int,
|
||||
val actionId: Int,
|
||||
val next: Int2ObjectMap<ItemStack?>,
|
||||
val clickedItem: ItemStack?,
|
||||
val changes: Int2ObjectMap<ItemStack?>,
|
||||
val floating: ItemStack?,
|
||||
) : PlayC2SPacket {
|
||||
|
||||
override fun write(buffer: PlayOutByteBuffer) {
|
||||
@ -47,16 +47,16 @@ data class ContainerClickC2SP(
|
||||
}
|
||||
buffer.writeVarInt(mode) // was byte in protocol
|
||||
if (buffer.versionId >= V_1_17_1_PRE1) { // ToDo
|
||||
buffer.writeVarInt(next.size)
|
||||
for ((slot, value) in next) {
|
||||
buffer.writeVarInt(changes.size)
|
||||
for ((slot, value) in changes) {
|
||||
buffer.writeShort(slot)
|
||||
buffer.writeItemStack(value)
|
||||
}
|
||||
}
|
||||
buffer.writeItemStack(clickedItem)
|
||||
buffer.writeItemStack(floating)
|
||||
}
|
||||
|
||||
override fun log(reducedLog: Boolean) {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_OUT, LogLevels.VERBOSE) { "Container click (containerId=$containerId, revision=$revision, slot=$slot, action=$button, actionId=$actionId, next=$next, clickedItem=$clickedItem)" }
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_OUT, LogLevels.VERBOSE) { "Container click (containerId=$containerId, revision=$revision, slot=$slot, action=$button, actionId=$actionId, changes=$changes, floating=$floating)" }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user