forked from FabricMC/fabric
additional hardening for registry desync issues
This commit is contained in:
parent
2c3cdd20a8
commit
aa63df6e1f
4 changed files with 52 additions and 19 deletions
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* 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.impl;
|
||||||
|
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.fabricmc.fabric.networking.CustomPayloadPacketRegistry;
|
||||||
|
import net.fabricmc.fabric.registry.RegistrySyncManager;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.server.integrated.IntegratedServer;
|
||||||
|
|
||||||
|
public class FabricAPIClientInitiailizer implements ClientModInitializer {
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
CustomPayloadPacketRegistry.CLIENT.register(RegistrySyncManager.ID, (ctx, buf) -> {
|
||||||
|
// if not hosting server, apply packet
|
||||||
|
RegistrySyncManager.receivePacket(ctx, buf, !MinecraftClient.getInstance().method_1496());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,8 +52,5 @@ public class MixinBootstrap {
|
||||||
((ListenableRegistry<Block>) Registry.BLOCK).registerListener(new BootstrapBlockRegistryListener());
|
((ListenableRegistry<Block>) Registry.BLOCK).registerListener(new BootstrapBlockRegistryListener());
|
||||||
((ListenableRegistry<Fluid>) Registry.FLUID).registerListener(new BootstrapFluidRegistryListener());
|
((ListenableRegistry<Fluid>) Registry.FLUID).registerListener(new BootstrapFluidRegistryListener());
|
||||||
((ListenableRegistry<Item>) Registry.ITEM).registerListener(new BootstrapItemRegistryListener());
|
((ListenableRegistry<Item>) Registry.ITEM).registerListener(new BootstrapItemRegistryListener());
|
||||||
|
|
||||||
// The packet code is not side-specific, so this is fine!
|
|
||||||
CustomPayloadPacketRegistry.CLIENT.register(RegistrySyncManager.ID, RegistrySyncManager::receivePacket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -51,23 +51,25 @@ public final class RegistrySyncManager {
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void receivePacket(PacketContext context, PacketByteBuf buf) {
|
public static void receivePacket(PacketContext context, PacketByteBuf buf, boolean accept) {
|
||||||
CompoundTag compound = buf.readCompoundTag();
|
CompoundTag compound = buf.readCompoundTag();
|
||||||
|
|
||||||
try {
|
if (accept) {
|
||||||
context.getTaskQueue().executeFuture(() -> {
|
try {
|
||||||
try {
|
context.getTaskQueue().executeFuture(() -> {
|
||||||
apply(compound, false);
|
try {
|
||||||
} catch (RemapException e) {
|
apply(compound, false);
|
||||||
// TODO: log error properly
|
} catch (RemapException e) {
|
||||||
e.printStackTrace();
|
// TODO: log error properly
|
||||||
}
|
e.printStackTrace();
|
||||||
}).get(30, TimeUnit.SECONDS);
|
}
|
||||||
} catch (ExecutionException e) {
|
}).get(30, TimeUnit.SECONDS);
|
||||||
e.printStackTrace();
|
} catch (ExecutionException e) {
|
||||||
} catch (InterruptedException | TimeoutException e) {
|
e.printStackTrace();
|
||||||
// TODO: better error handling
|
} catch (InterruptedException | TimeoutException e) {
|
||||||
new Exception("Failed to apply received packets in time!", e).printStackTrace();
|
// TODO: better error handling
|
||||||
|
new Exception("Failed to apply received packets in time!", e).printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
"description": "Core API module providing key hooks and intercompatibility features.",
|
"description": "Core API module providing key hooks and intercompatibility features.",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"initializers": [
|
"initializers": [
|
||||||
"net.fabricmc.fabric.impl.FabricAPIInitializer"
|
"net.fabricmc.fabric.impl.FabricAPIInitializer",
|
||||||
|
"net.fabricmc.fabric.impl.FabricAPIClientInitializer"
|
||||||
],
|
],
|
||||||
"mixins": {
|
"mixins": {
|
||||||
"client": "net.fabricmc.fabric.mixins.client.json",
|
"client": "net.fabricmc.fabric.mixins.client.json",
|
||||||
|
|
Loading…
Reference in a new issue