You shouldn't be creating FluidStacks from unregistered Fluids. Warn clearly on failed registrations, and make a useful log message for failed fluidstack

creations. Should help a lot with tracking down broken mods that are doing this wrongly.
This commit is contained in:
cpw 2015-04-05 22:37:40 -04:00
parent f7395f517b
commit 4f0e2fb9c4
2 changed files with 10 additions and 0 deletions

View file

@ -13,6 +13,7 @@ import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.eventhandler.Event;
/**
@ -75,6 +76,7 @@ public abstract class FluidRegistry
{
if (fluidIDs.containsKey(fluid.getName()))
{
FMLLog.bigWarning("Duplicate registration attempt for fluid %s (type %s) has occurred. This is not a problem itself, but subsequent failed FluidStacks might be a result if not handled properly", fluid.getName(), fluid.getClass().getName());
return false;
}
fluids.put(fluid.getName(), fluid);

View file

@ -2,7 +2,10 @@
package net.minecraftforge.fluids;
import java.util.Locale;
import com.google.common.base.Strings;
import cpw.mods.fml.common.FMLLog;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -24,6 +27,11 @@ public class FluidStack
public FluidStack(Fluid fluid, int amount)
{
if (!FluidRegistry.isFluidRegistered(fluid))
{
FMLLog.bigWarning("Failed attempt to create a FluidStack for an unregistered Fluid %s (type %s)", fluid.getName(), fluid.getClass().getName());
throw new IllegalArgumentException("Cannot create a fluidstack from an unregistered fluid");
}
this.fluid = fluid;
this.amount = amount;
}