-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store data components in bytebuf form for mcpl
- Loading branch information
1 parent
7eae4e6
commit 371787a
Showing
8 changed files
with
11,659 additions
and
19,577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
server/src/main/java/com/soulfiremc/server/data/ByteDataComponents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* SoulFire | ||
* Copyright (C) 2024 AlexProgrammerDE | ||
* | ||
* 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/>. | ||
*/ | ||
package com.soulfiremc.server.data; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.TypeAdapter; | ||
import com.google.gson.stream.JsonReader; | ||
import com.google.gson.stream.JsonWriter; | ||
import com.soulfiremc.server.util.structs.GsonInstance; | ||
import io.netty.buffer.Unpooled; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; | ||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponent; | ||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType; | ||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemCodecHelper; | ||
|
||
import java.util.Base64; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
public record ByteDataComponents(Map<DataComponentType<?>, DataComponent<?, ?>> components) { | ||
public static final TypeAdapter<ByteDataComponents> SERIALIZER = new TypeAdapter<>() { | ||
@Override | ||
public void write(JsonWriter out, ByteDataComponents value) { | ||
throw new UnsupportedOperationException("ByteDataComponents serialization is not supported"); | ||
} | ||
|
||
@Override | ||
public ByteDataComponents read(JsonReader in) { | ||
var parsedJson = GsonInstance.GSON.<JsonObject>fromJson(in, JsonObject.class); | ||
var map = new HashMap<DataComponentType<?>, DataComponent<?, ?>>(); | ||
for (var entry : parsedJson.entrySet()) { | ||
var value = entry.getValue().getAsString(); | ||
var bytes = Base64.getDecoder().decode(value); | ||
var buf = Unpooled.wrappedBuffer(bytes); | ||
var helper = new MinecraftCodecHelper(); | ||
var dataComponentType = DataComponentType.from(helper.readVarInt(buf)); | ||
var dataComponent = dataComponentType.readDataComponent(ItemCodecHelper.INSTANCE, buf); | ||
map.put(dataComponentType, dataComponent); | ||
} | ||
|
||
return new ByteDataComponents(map); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
server/src/main/java/com/soulfiremc/server/data/JsonDataComponents.java
This file was deleted.
Oops, something went wrong.
127 changes: 0 additions & 127 deletions
127
server/src/main/java/com/soulfiremc/server/data/JsonToMCPLCodecs.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.