mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-20 19:04:44 -04:00
improve synchronization for network packet parsing, add NbtType class
This commit is contained in:
parent
19bc18104d
commit
2c3cdd20a8
4 changed files with 76 additions and 10 deletions
|
@ -38,8 +38,8 @@ minecraft {
|
|||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:$mcVersion"
|
||||
mappings "net.fabricmc:yarn:$mcVersion.21"
|
||||
modCompile "net.fabricmc:fabric-loader:0.2.0.68"
|
||||
mappings "net.fabricmc:yarn:$mcVersion.34"
|
||||
modCompile "net.fabricmc:fabric-loader:0.2.0.70"
|
||||
}
|
||||
|
||||
curseforge {
|
||||
|
|
55
src/main/java/net/fabricmc/fabric/api/util/NbtType.java
Normal file
55
src/main/java/net/fabricmc/fabric/api/util/NbtType.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.api.util;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
/**
|
||||
* NBT type ID constants. Useful for filtering by value type in a few cases.
|
||||
*
|
||||
* @see CompoundTag#containsKey(String, int)
|
||||
* @see Tag#idToString(int)
|
||||
*
|
||||
* For the current list of types, check with {@link Tag#TYPES}.
|
||||
*/
|
||||
public final class NbtType {
|
||||
public static final int END = 0;
|
||||
public static final int BYTE = 1;
|
||||
public static final int SHORT = 2;
|
||||
public static final int INT = 3;
|
||||
public static final int LONG = 4;
|
||||
public static final int FLOAT = 5;
|
||||
public static final int DOUBLE = 6;
|
||||
public static final int BYTE_ARRAY = 7;
|
||||
public static final int STRING = 8;
|
||||
public static final int LIST = 9;
|
||||
public static final int COMPOUND = 10;
|
||||
public static final int INT_ARRAY = 11;
|
||||
public static final int LONG_ARRAY = 12;
|
||||
|
||||
/**
|
||||
* Any numeric value: byte, short, int, long, float, double.
|
||||
*
|
||||
* @see CompoundTag#containsKey(String, int)
|
||||
*/
|
||||
public static final int NUMBER = 99;
|
||||
|
||||
private NbtType() {
|
||||
|
||||
}
|
||||
}
|
|
@ -36,6 +36,7 @@ public abstract class MixinServerPlayNetworkHandler {
|
|||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
public void init(MinecraftServer server, ClientConnection connection, ServerPlayerEntity player, CallbackInfo info) {
|
||||
//if (server.isDedicated()) {
|
||||
// TODO: If integrated and local, don't send the packet
|
||||
sendPacket(RegistrySyncManager.createPacket());
|
||||
//}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@ import net.minecraft.util.registry.ModifiableRegistry;
|
|||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public final class RegistrySyncManager {
|
||||
public static final Identifier ID = new Identifier("fabric", "registry/sync");
|
||||
|
@ -51,14 +54,21 @@ public final class RegistrySyncManager {
|
|||
public static void receivePacket(PacketContext context, PacketByteBuf buf) {
|
||||
CompoundTag compound = buf.readCompoundTag();
|
||||
|
||||
context.getTaskQueue().execute(() -> {
|
||||
try {
|
||||
apply(compound, false);
|
||||
} catch (RemapException e) {
|
||||
// TODO: log error properly
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
try {
|
||||
context.getTaskQueue().executeFuture(() -> {
|
||||
try {
|
||||
apply(compound, false);
|
||||
} catch (RemapException e) {
|
||||
// TODO: log error properly
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).get(30, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException | TimeoutException e) {
|
||||
// TODO: better error handling
|
||||
new Exception("Failed to apply received packets in time!", e).printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static CompoundTag toTag(boolean isClientSync) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue