From 63f230079473702953173dbf7e4b54276532bca1 Mon Sep 17 00:00:00 2001 From: cpw Date: Wed, 3 Jun 2015 19:26:53 -0400 Subject: [PATCH] Fix up the client/server fluid race condition that could cause the game to bail when an SSP game connects. There's still a teeny gap, but it's MUCH less prominent than it was before. --- .../minecraftforge/fluids/FluidRegistry.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/minecraftforge/fluids/FluidRegistry.java b/src/main/java/net/minecraftforge/fluids/FluidRegistry.java index 77ce2b887..bc01a9848 100644 --- a/src/main/java/net/minecraftforge/fluids/FluidRegistry.java +++ b/src/main/java/net/minecraftforge/fluids/FluidRegistry.java @@ -79,25 +79,21 @@ public abstract class FluidRegistry public static void initFluidIDs(BiMap newfluidIDs, Set defaultNames) { maxID = newfluidIDs.size(); - fluidIDs.clear(); - fluidIDs.putAll(newfluidIDs); - fluidNames.clear(); - for (Entry e : fluidIDs.entrySet()) { - fluidNames.put(e.getValue(), e.getKey().getName()); - } - loadFluidDefaults(defaultNames); + loadFluidDefaults(newfluidIDs, defaultNames); } /** * Called by forge to load default fluid IDs from the world or from server -> client for syncing * DO NOT call this and expect useful behaviour. + * @param newfluidIDs */ - private static void loadFluidDefaults(Set defaultNames) + private static void loadFluidDefaults(BiMap localFluidIDs, Set defaultNames) { // If there's an empty set of default names, use the defaults as defined locally if (defaultNames.isEmpty()) { defaultNames.addAll(defaultFluidName.values()); } + BiMap localFluids = HashBiMap.create(fluids); for (String defaultName : defaultNames) { Fluid fluid = masterFluidReference.get(defaultName); @@ -112,10 +108,17 @@ public abstract class FluidRegistry FMLLog.getLogger().log(Level.ERROR, "The fluid {} specified as default is not present - it will be reverted to default {}", defaultName, localDefault); } FMLLog.getLogger().log(Level.DEBUG, "The fluid {} has been selected as the default fluid for {}", defaultName, fluid.getName()); - Fluid oldFluid = fluids.put(fluid.getName(), fluid); - Integer id = fluidIDs.remove(oldFluid); - fluidIDs.put(fluid, id); + Fluid oldFluid = localFluids.put(fluid.getName(), fluid); + Integer id = localFluidIDs.remove(oldFluid); + localFluidIDs.put(fluid, id); } + BiMap localFluidNames = fluidNames; + for (Entry e : localFluidIDs.entrySet()) { + localFluidNames.put(e.getValue(), e.getKey().getName()); + } + fluidIDs = localFluidIDs; + fluids = localFluids; + fluidNames = localFluidNames; fluidBlocks = null; for (FluidDelegate fd : delegates.values()) { @@ -188,17 +191,17 @@ public abstract class FluidRegistry public static Fluid getFluid(int fluidID) { - return fluidIDs.inverse().get(fluidID); + return fluidIDs.inverse().get(fluidID); } public static int getFluidID(Fluid fluid) { - return fluidIDs.get(fluid); + return fluidIDs.get(fluid); } public static int getFluidID(String fluidName) { - return fluidIDs.get(getFluid(fluidName)); + return fluidIDs.get(getFluid(fluidName)); } @Deprecated //Remove in 1.8.3 @@ -312,7 +315,7 @@ public abstract class FluidRegistry { FMLLog.getLogger().log(Level.DEBUG, "World is missing persistent fluid defaults - using local defaults"); } - loadFluidDefaults(defaults); + loadFluidDefaults(HashBiMap.create(fluidIDs), defaults); } public static void writeDefaultFluidList(NBTTagCompound forgeData)