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<Fluid>) Registry.FLUID).registerListener(new BootstrapFluidRegistryListener());
|
||||
((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,9 +51,10 @@ public final class RegistrySyncManager {
|
|||
return packet;
|
||||
}
|
||||
|
||||
public static void receivePacket(PacketContext context, PacketByteBuf buf) {
|
||||
public static void receivePacket(PacketContext context, PacketByteBuf buf, boolean accept) {
|
||||
CompoundTag compound = buf.readCompoundTag();
|
||||
|
||||
if (accept) {
|
||||
try {
|
||||
context.getTaskQueue().executeFuture(() -> {
|
||||
try {
|
||||
|
@ -70,6 +71,7 @@ public final class RegistrySyncManager {
|
|||
new Exception("Failed to apply received packets in time!", e).printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CompoundTag toTag(boolean isClientSync) {
|
||||
CompoundTag mainTag = new CompoundTag();
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
"description": "Core API module providing key hooks and intercompatibility features.",
|
||||
"license": "Apache-2.0",
|
||||
"initializers": [
|
||||
"net.fabricmc.fabric.impl.FabricAPIInitializer"
|
||||
"net.fabricmc.fabric.impl.FabricAPIInitializer",
|
||||
"net.fabricmc.fabric.impl.FabricAPIClientInitializer"
|
||||
],
|
||||
"mixins": {
|
||||
"client": "net.fabricmc.fabric.mixins.client.json",
|
||||
|
|
Loading…
Reference in a new issue