additional hardening for registry desync issues

This commit is contained in:
asie 2018-12-18 01:11:05 +01:00
parent 2c3cdd20a8
commit aa63df6e1f
4 changed files with 52 additions and 19 deletions

View file

@ -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());
});
}
}

View file

@ -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);
} }
} }

View file

@ -51,9 +51,10 @@ 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();
if (accept) {
try { try {
context.getTaskQueue().executeFuture(() -> { context.getTaskQueue().executeFuture(() -> {
try { try {
@ -70,6 +71,7 @@ public final class RegistrySyncManager {
new Exception("Failed to apply received packets in time!", e).printStackTrace(); new Exception("Failed to apply received packets in time!", e).printStackTrace();
} }
} }
}
public static CompoundTag toTag(boolean isClientSync) { public static CompoundTag toTag(boolean isClientSync) {
CompoundTag mainTag = new CompoundTag(); CompoundTag mainTag = new CompoundTag();

View file

@ -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",