Deprecate int IDs in FluidRegistry. Modders should only ever use the String name. Also add a 'friendly' exception when attempting to get an ID for a unregistered fluid. Closes #1374
This commit is contained in:
parent
2302963a9f
commit
dcda451a0a
3 changed files with 14 additions and 12 deletions
|
@ -48,10 +48,11 @@ public abstract class ForgeMessage {
|
||||||
public static class FluidIdMapMessage extends ForgeMessage {
|
public static class FluidIdMapMessage extends ForgeMessage {
|
||||||
BiMap<Fluid, Integer> fluidIds = HashBiMap.create();
|
BiMap<Fluid, Integer> fluidIds = HashBiMap.create();
|
||||||
Set<String> defaultFluids = Sets.newHashSet();
|
Set<String> defaultFluids = Sets.newHashSet();
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
void toBytes(ByteBuf bytes)
|
void toBytes(ByteBuf bytes)
|
||||||
{
|
{
|
||||||
Map<Fluid, Integer> ids = FluidRegistry.getRegisteredFluidIDsByFluid();
|
Map<Fluid, Integer> ids = FluidRegistry.getRegisteredFluidIDs();
|
||||||
bytes.writeInt(ids.size());
|
bytes.writeInt(ids.size());
|
||||||
for (Map.Entry<Fluid, Integer> entry : ids.entrySet())
|
for (Map.Entry<Fluid, Integer> entry : ids.entrySet())
|
||||||
{
|
{
|
||||||
|
|
|
@ -165,6 +165,7 @@ public class Fluid
|
||||||
return this.fluidName;
|
return this.fluidName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated // Modders should never actually use int ID, use String
|
||||||
public final int getID()
|
public final int getID()
|
||||||
{
|
{
|
||||||
return FluidRegistry.getFluidID(this.fluidName);
|
return FluidRegistry.getFluidID(this.fluidName);
|
||||||
|
|
|
@ -188,19 +188,26 @@ public abstract class FluidRegistry
|
||||||
return fluids.get(fluidName);
|
return fluids.get(fluidName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated // Modders should never actually use int ID, use String
|
||||||
public static Fluid getFluid(int fluidID)
|
public static Fluid getFluid(int fluidID)
|
||||||
{
|
{
|
||||||
return fluidIDs.inverse().get(fluidID);
|
return fluidIDs.inverse().get(fluidID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated // Modders should never actually use int ID, use String
|
||||||
public static int getFluidID(Fluid fluid)
|
public static int getFluidID(Fluid fluid)
|
||||||
{
|
{
|
||||||
return fluidIDs.get(fluid);
|
Integer ret = fluidIDs.get(fluid);
|
||||||
|
if (ret == null) throw new RuntimeException("Attempted to access ID for unregistered fluid, Stop using this method modder!");
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated // Modders should never actually use int ID, use String
|
||||||
public static int getFluidID(String fluidName)
|
public static int getFluidID(String fluidName)
|
||||||
{
|
{
|
||||||
return fluidIDs.get(getFluid(fluidName));
|
Integer ret = fluidIDs.get(getFluid(fluidName));
|
||||||
|
if (ret == null) throw new RuntimeException("Attempted to access ID for unregistered fluid, Stop using this method modder!");
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFluidName(Fluid fluid)
|
public static String getFluidName(Fluid fluid)
|
||||||
|
@ -232,21 +239,14 @@ public abstract class FluidRegistry
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a read-only map containing Fluid Names and their associated IDs.
|
* Returns a read-only map containing Fluid Names and their associated IDs.
|
||||||
|
* Modders should never actually use this, use the String names.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static Map<Fluid, Integer> getRegisteredFluidIDs()
|
public static Map<Fluid, Integer> getRegisteredFluidIDs()
|
||||||
{
|
{
|
||||||
return ImmutableMap.copyOf(fluidIDs);
|
return ImmutableMap.copyOf(fluidIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a read-only map containing Fluid IDs and their associated Fluids.
|
|
||||||
* In 1.8.3, this will change to just 'getRegisteredFluidIDs'
|
|
||||||
*/
|
|
||||||
public static Map<Fluid, Integer> getRegisteredFluidIDsByFluid()
|
|
||||||
{
|
|
||||||
return ImmutableMap.copyOf(fluidIDs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Fluid lookupFluidForBlock(Block block)
|
public static Fluid lookupFluidForBlock(Block block)
|
||||||
{
|
{
|
||||||
if (fluidBlocks == null)
|
if (fluidBlocks == null)
|
||||||
|
|
Loading…
Reference in a new issue