Add universal bucket

This commit is contained in:
Bernhard Bonigl committed 2016-02-16 00:49:01 +01:00
1 parent 06130912c5
commit 1055206ba8
16 files changed
+1560 -28

No files matched your search

@@ -4,6 +4,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.minecraftforge.fml.common.LoaderState;
import org.apache.logging.log4j.Level;
import net.minecraft.block.Block;
@@ -19,6 +20,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@@ -48,6 +50,9 @@ public abstract class FluidRegistry
static BiMap<String,String> defaultFluidName = HashBiMap.create();
static Map<Fluid,FluidDelegate> delegates = Maps.newHashMap();
static boolean universalBucketEnabled = false;
static Set<Fluid> bucketFluids = Sets.newHashSet();
public static final Fluid WATER = new Fluid("water", new ResourceLocation("blocks/water_still"), new ResourceLocation("blocks/water_flow")) {
@Override
public String getLocalizedName(FluidStack fs) {
@@ -247,6 +252,57 @@ public abstract class FluidRegistry
return ImmutableMap.copyOf(fluidIDs);
}
/**
* Enables the universal bucket in forge.
* Has to be called before pre-initialization.
* Actually just call it statically in your mod class.
*/
public static void enableUniversalBucket()
{
if (Loader.instance().hasReachedState(LoaderState.PREINITIALIZATION))
{
FMLLog.getLogger().log(Level.ERROR, "Trying to activate the universal filled bucket too late. Call it statically in your Mods class. Mod: {}", Loader.instance().activeModContainer().getName());
}
else
{
universalBucketEnabled = true;
}
}
public static boolean isUniversalBucketEnabled()
{
return universalBucketEnabled;
}
/**
* Registers a fluid with the universal bucket.
* This only has an effect if the universal bucket is enabled.
* @param fluid The fluid that the bucket shall be able to hold
* @return True if the fluid was added successfully, false if it already was registered or couldn't be registered with the bucket.
*/
public static boolean addBucketForFluid(Fluid fluid)
{
if(fluid == null) {
return false;
}
// register unregistered fluids
if (!isFluidRegistered(fluid))
{
registerFluid(fluid);
}
return bucketFluids.add(fluid);
}
/**
* All fluids registered with the universal bucket
* @return An immutable set containing the fluids
*/
public static Set<Fluid> getBucketFluids()
{
return ImmutableSet.copyOf(bucketFluids);
}
public static Fluid lookupFluidForBlock(Block block)
{
if (fluidBlocks == null)