mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 19:05:02 -04:00
remove gson
This commit is contained in:
parent
8508442b35
commit
0971a7a1dc
5
pom.xml
5
pom.xml
@ -286,11 +286,6 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.36</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
|
@ -13,8 +13,8 @@
|
||||
|
||||
package de.bixilon.minosoft.data.entities.data.types
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import de.bixilon.kutil.cast.CastUtil.nullCast
|
||||
import de.bixilon.kutil.json.JsonObject
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
|
||||
object NbtEntityDataType : EntityDataType<JsonObject> {
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
package de.bixilon.minosoft.data.registries
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import de.bixilon.kotlinglm.vec3.Vec3
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
@ -33,8 +32,6 @@ class AABB {
|
||||
val min: Vec3d
|
||||
val max: Vec3d
|
||||
|
||||
constructor(jsonData: JsonObject) : this(jsonData["from"].toVec3(Vec3.EMPTY), jsonData["to"].toVec3(Vec3.ONE))
|
||||
|
||||
constructor(jsonData: Map<String, Any>) : this(jsonData["from"]!!.toVec3(Vec3.EMPTY), jsonData["to"]!!.toVec3(Vec3.ONE))
|
||||
|
||||
constructor(aabb: AABB) : this(aabb.min, aabb.max)
|
||||
|
@ -13,8 +13,6 @@
|
||||
|
||||
package de.bixilon.minosoft.data.registries
|
||||
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonPrimitive
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kotlinglm.vec3.Vec3t
|
||||
import de.bixilon.kutil.primitive.IntUtil.toInt
|
||||
@ -29,14 +27,6 @@ class VoxelShape(private val aabbs: MutableList<AABB> = mutableListOf()) : Itera
|
||||
|
||||
constructor(data: Any, aabbs: List<AABB>) : this() {
|
||||
when (data) {
|
||||
is JsonArray -> {
|
||||
for (index in data) {
|
||||
this.aabbs.add(aabbs[index.asInt])
|
||||
}
|
||||
}
|
||||
is JsonPrimitive -> {
|
||||
this.aabbs.add(aabbs[data.asInt])
|
||||
}
|
||||
is Collection<*> -> {
|
||||
for (index in data) {
|
||||
this.aabbs.add(aabbs[index?.toInt()!!])
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
package de.bixilon.minosoft.data.registries.registries.registry
|
||||
|
||||
import com.google.gson.JsonPrimitive
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.enums.ValuesEnum
|
||||
import de.bixilon.kutil.primitive.IntUtil.toInt
|
||||
@ -44,12 +43,6 @@ class EnumRegistry<T : Enum<*>>(
|
||||
return when (data) {
|
||||
is Int -> values[data]
|
||||
is String -> values.NAME_MAP[data.lowercase(Locale.getDefault())] ?: error("Can not find enum: $data")
|
||||
is JsonPrimitive -> {
|
||||
if (data.isNumber) {
|
||||
return getEnum(data.asInt)
|
||||
}
|
||||
return getEnum(data.asString)
|
||||
}
|
||||
else -> throw IllegalArgumentException("Unknown enum value: $data")
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,6 @@
|
||||
|
||||
package de.bixilon.minosoft.data.registries.registries.registry
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonPrimitive
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.json.JsonObject
|
||||
import de.bixilon.kutil.json.JsonUtil.toJsonObject
|
||||
@ -47,25 +45,10 @@ open class Registry<T : RegistryItem>(
|
||||
return value
|
||||
}
|
||||
|
||||
open operator fun get(json: JsonElement?): T? {
|
||||
return when (json) {
|
||||
null -> return null
|
||||
is JsonPrimitive -> {
|
||||
when {
|
||||
json.isString -> get(json.asString.toResourceLocation())
|
||||
json.isNumber -> getOrNull(json.asInt)
|
||||
else -> TODO()
|
||||
}
|
||||
}
|
||||
else -> TODO()
|
||||
}
|
||||
}
|
||||
|
||||
override operator fun get(any: Any?): T? {
|
||||
return when (any) {
|
||||
null -> null
|
||||
is Number -> getOrNull(any.toInt())
|
||||
is JsonElement -> get(any)
|
||||
is ResourceLocation -> get(any)
|
||||
is String -> get(any)
|
||||
is ResourceLocationAble -> get(any.resourceLocation)
|
||||
|
@ -12,14 +12,12 @@
|
||||
*/
|
||||
package de.bixilon.minosoft.protocol.protocol
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import com.sun.javafx.geom.Vec3f
|
||||
import de.bixilon.kotlinglm.vec3.Vec3
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.util.Util
|
||||
import de.bixilon.minosoft.util.collections.bytes.HeapArrayByteList
|
||||
import de.bixilon.minosoft.util.nbt.tag.NBTTagTypes
|
||||
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.nbtType
|
||||
@ -66,10 +64,6 @@ open class OutByteBuffer() {
|
||||
writeString(chatComponent.legacyText)
|
||||
}
|
||||
|
||||
fun writeJSON(json: JsonObject) {
|
||||
writeString(Util.GSON.toJson(json))
|
||||
}
|
||||
|
||||
fun writeString(string: String) {
|
||||
check(string.length <= ProtocolDefinition.STRING_MAX_LENGTH) { "String max string length exceeded ${string.length} > ${ProtocolDefinition.STRING_MAX_LENGTH}" }
|
||||
val bytes = string.toByteArray(StandardCharsets.UTF_8)
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public final class Util {
|
||||
public static final Gson GSON = new Gson();
|
||||
private static final Field JSON_READER_POS_FIELD;
|
||||
private static final Field JSON_READER_LINE_START_FIELD;
|
||||
|
||||
static {
|
||||
new JsonReader(new StringReader(""));
|
||||
Class<?> jsonReadClass = JsonReader.class;
|
||||
try {
|
||||
JSON_READER_POS_FIELD = jsonReadClass.getDeclaredField("pos");
|
||||
JSON_READER_POS_FIELD.setAccessible(true);
|
||||
JSON_READER_LINE_START_FIELD = jsonReadClass.getDeclaredField("lineStart");
|
||||
JSON_READER_LINE_START_FIELD.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getJsonReaderPosition(JsonReader jsonReader) {
|
||||
try {
|
||||
return JSON_READER_POS_FIELD.getInt(jsonReader) - JSON_READER_LINE_START_FIELD.getInt(jsonReader) + 1;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
*
|
||||
@ -13,24 +13,11 @@
|
||||
|
||||
package de.bixilon.minosoft.util.json
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
|
||||
object ResourceLocationJsonMap {
|
||||
|
||||
fun JsonObject.toResourceLocationMap(): Map<ResourceLocation, JsonObject> {
|
||||
val ret: MutableMap<ResourceLocation, JsonObject> = mutableMapOf()
|
||||
|
||||
for ((key, value) in entrySet()) {
|
||||
check(value is JsonObject)
|
||||
|
||||
ret[ResourceLocation(key)] = value
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
fun Map<*, *>.toResourceLocationMap(): Map<ResourceLocation, Any> {
|
||||
val ret: MutableMap<ResourceLocation, Any> = mutableMapOf()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user