mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -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)
|
val container = createChest(connection)
|
||||||
container.invokeAction(FastMoveContainerAction(0))
|
container.invokeAction(FastMoveContainerAction(0))
|
||||||
assertNull(container.floatingItem)
|
assertNull(container.floatingItem)
|
||||||
assertEquals(container.slots.size, 0)
|
assertEquals(container.slots, slotsOf())
|
||||||
connection.assertNoPacket()
|
connection.assertNoPacket()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,9 +46,8 @@ class FastMoveContainerActionTest {
|
|||||||
container[54] = ItemStack(AppleTestO.item, 9)
|
container[54] = ItemStack(AppleTestO.item, 9)
|
||||||
container.invokeAction(FastMoveContainerAction(54))
|
container.invokeAction(FastMoveContainerAction(54))
|
||||||
assertNull(container.floatingItem)
|
assertNull(container.floatingItem)
|
||||||
assertNull(container[54])
|
assertEquals(container.slots, slotsOf(0 to ItemStack(AppleTestO.item, 9)))
|
||||||
assertEquals(container[0], 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))
|
||||||
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 53, 1, 0, 0, slotsOf(54 to null, 0 to ItemStack(AppleTestO.item, count = 9)), null))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun chestToHotbar() {
|
fun chestToHotbar() {
|
||||||
|
@ -17,6 +17,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
|||||||
import org.testng.Assert.assertEquals
|
import org.testng.Assert.assertEquals
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
|
@Test(groups = ["version"])
|
||||||
internal class VersionsIT {
|
internal class VersionsIT {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -18,45 +18,39 @@ import org.objenesis.ObjenesisStd
|
|||||||
import org.testng.Assert.assertEquals
|
import org.testng.Assert.assertEquals
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
|
@Test(groups = ["biome"])
|
||||||
class NoiseBiomeAccessorTest {
|
class NoiseBiomeAccessorTest {
|
||||||
private val OBJENESIS = ObjenesisStd()
|
private val OBJENESIS = ObjenesisStd()
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testBiomeNoise1() {
|
fun testBiomeNoise1() {
|
||||||
assertEquals(calculate(129, 3274, 91, 1823123L), Vec3i(32, 818, 22))
|
assertEquals(calculate(129, 3274, 91, 1823123L), Vec3i(32, 818, 22))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testBiomeNoise2() {
|
fun testBiomeNoise2() {
|
||||||
assertEquals(calculate(129, 3274, 91, -123213L), Vec3i(32, 818, 22))
|
assertEquals(calculate(129, 3274, 91, -123213L), Vec3i(32, 818, 22))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testBiomeNoise3() {
|
fun testBiomeNoise3() {
|
||||||
assertEquals(calculate(-17, 3274, 91, -123213L), Vec3i(-5, 818, 22))
|
assertEquals(calculate(-17, 3274, 91, -123213L), Vec3i(-5, 818, 22))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testBiomeNoise4() {
|
fun testBiomeNoise4() {
|
||||||
assertEquals(calculate(-1123, 3, 1, -18209371253621313), Vec3i(-281, 0, 0))
|
assertEquals(calculate(-1123, 3, 1, -18209371253621313), Vec3i(-281, 0, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testBiomeNoise5() {
|
fun testBiomeNoise5() {
|
||||||
assertEquals(calculate(0, 3, 1, -33135639), Vec3i(0, 0, 0))
|
assertEquals(calculate(0, 3, 1, -33135639), Vec3i(0, 0, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testBiomeNoise6() {
|
fun testBiomeNoise6() {
|
||||||
assertEquals(calculate(16, 15, -16, 561363374), Vec3i(4, 3, -4))
|
assertEquals(calculate(16, 15, -16, 561363374), Vec3i(4, 3, -4))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testBiomeNoise7() {
|
fun testBiomeNoise7() {
|
||||||
assertEquals(calculate(16, -15, -16, 79707367), Vec3i(4, -4, -5))
|
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)
|
val accessor = OBJENESIS.newInstance(NoiseBiomeAccessor::class.java)
|
||||||
return accessor.getBiomePosition(seed, x, y, z)
|
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
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
|
||||||
|
|
||||||
open class Container(
|
open class Container(
|
||||||
protected val connection: PlayConnection,
|
val connection: PlayConnection,
|
||||||
val type: ContainerType,
|
val type: ContainerType,
|
||||||
val title: ChatComponent? = null,
|
val title: ChatComponent? = null,
|
||||||
) : Iterable<Map.Entry<Int, ItemStack>> {
|
) : Iterable<Map.Entry<Int, ItemStack>> {
|
||||||
|
@ -27,7 +27,6 @@ class FastMoveContainerAction(
|
|||||||
override fun invoke(connection: PlayConnection, containerId: Int, container: Container) {
|
override fun invoke(connection: PlayConnection, containerId: Int, container: Container) {
|
||||||
// ToDo: minecraft always sends a packet
|
// ToDo: minecraft always sends a packet
|
||||||
val source = container.slots[slot] ?: return
|
val source = container.slots[slot] ?: return
|
||||||
val previous = source.copy()
|
|
||||||
container.lock.lock()
|
container.lock.lock()
|
||||||
try {
|
try {
|
||||||
val sourceSection = container.getSection(slot) ?: Int.MAX_VALUE
|
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 {
|
} finally {
|
||||||
container.commit()
|
container.commit()
|
||||||
container._validate()
|
container._validate()
|
||||||
|
@ -27,7 +27,7 @@ object FuelSlotType : SlotType {
|
|||||||
if (item is BucketItem && item.fluid is LavaFluid) {
|
if (item is BucketItem && item.fluid is LavaFluid) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// ToDo: get from registries (misc/fuel_time)
|
val fuelTime = container.connection.registries.misc.getFuelTime(item)
|
||||||
return super.canPut(container, slot, stack)
|
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.ItemRegistry
|
||||||
import de.bixilon.minosoft.data.registries.item.items.Item
|
import de.bixilon.minosoft.data.registries.item.items.Item
|
||||||
import de.bixilon.minosoft.data.registries.materials.Material
|
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.other.containers.ContainerType
|
||||||
import de.bixilon.minosoft.data.registries.particle.ParticleType
|
import de.bixilon.minosoft.data.registries.particle.ParticleType
|
||||||
import de.bixilon.minosoft.data.registries.registries.registry.*
|
import de.bixilon.minosoft.data.registries.registries.registry.*
|
||||||
@ -120,6 +121,8 @@ class Registries {
|
|||||||
val argumentTypeRegistry: ResourceLocationRegistry = ResourceLocationRegistry()
|
val argumentTypeRegistry: ResourceLocationRegistry = ResourceLocationRegistry()
|
||||||
val messageTypeRegistry: Registry<ChatMessageType> = register("chat_type", Registry(codec = ChatMessageType))
|
val messageTypeRegistry: Registry<ChatMessageType> = register("chat_type", Registry(codec = ChatMessageType))
|
||||||
|
|
||||||
|
val misc = MiscData()
|
||||||
|
|
||||||
var isFullyLoaded = false
|
var isFullyLoaded = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@ -198,6 +201,7 @@ class Registries {
|
|||||||
worker += WorkerTask(this::frogVariants) { frogVariants.rawUpdate(pixlyzerData["variant/frog"]?.toJsonObject(), this) }
|
worker += WorkerTask(this::frogVariants) { frogVariants.rawUpdate(pixlyzerData["variant/frog"]?.toJsonObject(), this) }
|
||||||
|
|
||||||
worker += WorkerTask(this::statisticRegistry) { statisticRegistry.rawUpdate(pixlyzerData["statistics"]?.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)
|
val inner = CountUpAndDownLatch(1, latch)
|
||||||
worker.work(inner)
|
worker.work(inner)
|
||||||
|
@ -30,8 +30,8 @@ data class ContainerClickC2SP(
|
|||||||
val mode: Int,
|
val mode: Int,
|
||||||
val button: Int,
|
val button: Int,
|
||||||
val actionId: Int,
|
val actionId: Int,
|
||||||
val next: Int2ObjectMap<ItemStack?>,
|
val changes: Int2ObjectMap<ItemStack?>,
|
||||||
val clickedItem: ItemStack?,
|
val floating: ItemStack?,
|
||||||
) : PlayC2SPacket {
|
) : PlayC2SPacket {
|
||||||
|
|
||||||
override fun write(buffer: PlayOutByteBuffer) {
|
override fun write(buffer: PlayOutByteBuffer) {
|
||||||
@ -47,16 +47,16 @@ data class ContainerClickC2SP(
|
|||||||
}
|
}
|
||||||
buffer.writeVarInt(mode) // was byte in protocol
|
buffer.writeVarInt(mode) // was byte in protocol
|
||||||
if (buffer.versionId >= V_1_17_1_PRE1) { // ToDo
|
if (buffer.versionId >= V_1_17_1_PRE1) { // ToDo
|
||||||
buffer.writeVarInt(next.size)
|
buffer.writeVarInt(changes.size)
|
||||||
for ((slot, value) in next) {
|
for ((slot, value) in changes) {
|
||||||
buffer.writeShort(slot)
|
buffer.writeShort(slot)
|
||||||
buffer.writeItemStack(value)
|
buffer.writeItemStack(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer.writeItemStack(clickedItem)
|
buffer.writeItemStack(floating)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun log(reducedLog: Boolean) {
|
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