Fluids are now tracked internally by mod. This allows for the server and the world to specify a "default"

in the case of a possible alternative fluid implementation. If you always called registerFluid, things
should work pretty seamlessly, but if you didn't (gating with an isFluidRegistered check for example)
you should change to register anyway. This way, even if you're not default in the overall instance, you may
become default if you're the only mod present on a server, for example, or in a world save.

This should radically decrease the mixups caused by mod load ordering problems, and other issues around fluid
tracking.
This commit is contained in:
cpw committed 2015-04-11 17:18:53 -04:00
1 parent eb12936a52
commit 9671179453
5 files changed
+145 -12

No files matched your search

@@ -26,6 +26,7 @@ import net.minecraftforge.classloading.FMLForgePlugin;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.common.network.ForgeNetworkHandler;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.RecipeSorter;
import net.minecraftforge.server.command.ForgeCommand;
@@ -309,6 +310,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
NBTTagCompound forgeData = new NBTTagCompound();
NBTTagCompound dimData = DimensionManager.saveDimensionDataMap();
forgeData.setTag("DimensionData", dimData);
FluidRegistry.writeDefaultFluidList(forgeData);
return forgeData;
}
@@ -316,6 +318,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> propertyMap, NBTTagCompound tag)
{
DimensionManager.loadDimensionDataMap(tag.hasKey("DimensionData") ? tag.getCompoundTag("DimensionData") : null);
FluidRegistry.loadFluidDefaults(tag);
}
@Subscribe
@@ -12,7 +12,7 @@ public class FluidIdRegistryMessageHandler extends SimpleChannelInboundHandler<F
@Override
protected void channelRead0(ChannelHandlerContext ctx, ForgeMessage.FluidIdMapMessage msg) throws Exception
{
FluidRegistry.initFluidIDs(msg.fluidIds);
FluidRegistry.initFluidIDs(msg.fluidIds, msg.defaultFluids);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
@@ -1,10 +1,18 @@
package net.minecraftforge.common.network;
import java.util.Map;
import java.util.Set;
import org.apache.logging.log4j.Level;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Sets;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBuf;
@@ -39,6 +47,7 @@ public abstract class ForgeMessage {
public static class FluidIdMapMessage extends ForgeMessage {
BiMap<Fluid, Integer> fluidIds = HashBiMap.create();
Set<String> defaultFluids = Sets.newHashSet();
@Override
void toBytes(ByteBuf bytes)
{
@@ -49,6 +58,11 @@ public abstract class ForgeMessage {
ByteBufUtils.writeUTF8String(bytes,entry.getKey().getName());
bytes.writeInt(entry.getValue());
}
for (Map.Entry<Fluid, Integer> entry : ids.entrySet())
{
String defaultName = FluidRegistry.getDefaultFluidName(entry.getKey());
ByteBufUtils.writeUTF8String(bytes, defaultName);
}
}
@Override
@@ -60,6 +74,20 @@ public abstract class ForgeMessage {
int fluidId = bytes.readInt();
fluidIds.put(FluidRegistry.getFluid(fluidName), fluidId);
}
// do we have a defaults list?
if (bytes.isReadable())
{
for (int i = 0; i < listSize; i++)
{
defaultFluids.add(ByteBufUtils.readUTF8String(bytes));
}
}
else
{
FMLLog.getLogger().log(Level.INFO, "Legacy server message contains no default fluid list - there may be problems with fluids");
defaultFluids.clear();
}
}
}