From 4f0e2fb9c4359ecdcffea30e673d026dfa97ba14 Mon Sep 17 00:00:00 2001 From: cpw Date: Sun, 5 Apr 2015 22:37:40 -0400 Subject: [PATCH] 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. --- .../java/net/minecraftforge/fluids/FluidRegistry.java | 2 ++ src/main/java/net/minecraftforge/fluids/FluidStack.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/net/minecraftforge/fluids/FluidRegistry.java b/src/main/java/net/minecraftforge/fluids/FluidRegistry.java index bff900767..866f0dbf6 100644 --- a/src/main/java/net/minecraftforge/fluids/FluidRegistry.java +++ b/src/main/java/net/minecraftforge/fluids/FluidRegistry.java @@ -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); diff --git a/src/main/java/net/minecraftforge/fluids/FluidStack.java b/src/main/java/net/minecraftforge/fluids/FluidStack.java index 16e386863..b485170e9 100644 --- a/src/main/java/net/minecraftforge/fluids/FluidStack.java +++ b/src/main/java/net/minecraftforge/fluids/FluidStack.java @@ -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; }