mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-27 23:45:55 +00:00
Implement Mekanism v8 gas API, in the process move mek API to src/api
This commit is contained in:
1 parent
e05b3c2f75
commit
752342d15d
67 files changed
+2279
-94
No files matched your search
@@ -29,6 +29,7 @@ import crazypants.enderio.conduit.TileConduitBundle;
|
||||
import crazypants.enderio.conduit.facade.FacadeRenderer;
|
||||
import crazypants.enderio.conduit.gas.GasConduit;
|
||||
import crazypants.enderio.conduit.gas.GasConduitRenderer;
|
||||
import crazypants.enderio.conduit.gas.GasUtil;
|
||||
import crazypants.enderio.conduit.item.ItemConduit;
|
||||
import crazypants.enderio.conduit.liquid.AdvancedLiquidConduit;
|
||||
import crazypants.enderio.conduit.liquid.AdvancedLiquidConduitRenderer;
|
||||
@@ -37,6 +38,7 @@ import crazypants.enderio.conduit.liquid.EnderLiquidConduitRenderer;
|
||||
import crazypants.enderio.conduit.liquid.LiquidConduit;
|
||||
import crazypants.enderio.conduit.liquid.LiquidConduitRenderer;
|
||||
import crazypants.enderio.conduit.me.MEConduit;
|
||||
import crazypants.enderio.conduit.me.MEUtil;
|
||||
import crazypants.enderio.conduit.power.PowerConduit;
|
||||
import crazypants.enderio.conduit.power.PowerConduitRenderer;
|
||||
import crazypants.enderio.conduit.redstone.InsulatedRedstoneConduit;
|
||||
@@ -159,8 +161,12 @@ public class ClientProxy extends CommonProxy {
|
||||
AdvancedLiquidConduit.initIcons();
|
||||
EnderLiquidConduit.initIcons();
|
||||
ItemConduit.initIcons();
|
||||
GasConduit.initIcons();
|
||||
MEConduit.initIcons();
|
||||
if(GasUtil.isGasConduitEnabled()) {
|
||||
GasConduit.initIcons();
|
||||
}
|
||||
if(MEUtil.isMEEnabled()) {
|
||||
MEConduit.initIcons();
|
||||
}
|
||||
}
|
||||
|
||||
private final List<ConduitRenderer> conduitRenderers = new ArrayList<ConduitRenderer>();
|
||||
@@ -364,7 +370,9 @@ public class ClientProxy extends CommonProxy {
|
||||
conduitRenderers.add(new InsulatedRedstoneConduitRenderer());
|
||||
conduitRenderers.add(new EnderLiquidConduitRenderer());
|
||||
conduitRenderers.add(new crazypants.enderio.conduit.item.ItemConduitRenderer());
|
||||
conduitRenderers.add(new GasConduitRenderer());
|
||||
if(GasUtil.isGasConduitEnabled()) {
|
||||
conduitRenderers.add(new GasConduitRenderer());
|
||||
}
|
||||
|
||||
EnderIoRenderer eior = new EnderIoRenderer();
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEnderIO.class, eior);
|
||||
|
||||
@@ -790,24 +790,39 @@ public class TileConduitBundle extends TileEntityEio implements IConduitBundle {
|
||||
// ---- Mekanism Gas Tubes
|
||||
|
||||
@Override
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public int receiveGas(ForgeDirection side, GasStack stack) {
|
||||
return receiveGas(side, stack, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public int receiveGas(ForgeDirection side, GasStack stack, boolean doTransfer) {
|
||||
IGasConduit gc = getConduit(IGasConduit.class);
|
||||
if(gc != null) {
|
||||
return gc.receiveGas(side, stack);
|
||||
return gc.receiveGas(side, stack, doTransfer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public GasStack drawGas(ForgeDirection side, int amount) {
|
||||
return drawGas(side, amount, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public GasStack drawGas(ForgeDirection side, int amount, boolean doTransfer) {
|
||||
IGasConduit gc = getConduit(IGasConduit.class);
|
||||
if(gc != null) {
|
||||
return gc.drawGas(side, amount);
|
||||
return gc.drawGas(side, amount, doTransfer);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public boolean canReceiveGas(ForgeDirection side, Gas type) {
|
||||
IGasConduit gc = getConduit(IGasConduit.class);
|
||||
if(gc != null) {
|
||||
@@ -817,6 +832,7 @@ public class TileConduitBundle extends TileEntityEio implements IConduitBundle {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public boolean canDrawGas(ForgeDirection side, Gas type) {
|
||||
IGasConduit gc = getConduit(IGasConduit.class);
|
||||
if(gc != null) {
|
||||
|
||||
@@ -221,19 +221,31 @@ public class GasConduit extends AbstractGasTankConduit {
|
||||
// ------------------------------------------- Gas API
|
||||
|
||||
@Override
|
||||
public int receiveGas(ForgeDirection from, GasStack resource) {
|
||||
if(network == null || !getConnectionMode(from).acceptsInput()) {
|
||||
return 0;
|
||||
}
|
||||
return network.fill(from, resource, true);
|
||||
@Deprecated
|
||||
public int receiveGas(ForgeDirection side, GasStack stack) {
|
||||
return receiveGas(side, stack, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GasStack drawGas(ForgeDirection from, int maxDrain) {
|
||||
if(network == null || !getConnectionMode(from).acceptsOutput()) {
|
||||
public int receiveGas(ForgeDirection side, GasStack stack, boolean doTransfer) {
|
||||
if(network == null || !getConnectionMode(side).acceptsInput()) {
|
||||
return 0;
|
||||
}
|
||||
return network.fill(side, stack, doTransfer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public GasStack drawGas(ForgeDirection side, int amount) {
|
||||
return drawGas(side, amount, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GasStack drawGas(ForgeDirection side, int amount, boolean doTransfer) {
|
||||
if(network == null || !getConnectionMode(side).acceptsOutput()) {
|
||||
return null;
|
||||
}
|
||||
return network.drain(from, maxDrain, true);
|
||||
return network.drain(side, amount, doTransfer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -261,5 +273,4 @@ public class GasConduit extends AbstractGasTankConduit {
|
||||
public AbstractGasTankConduitNetwork<? extends AbstractGasTankConduit> getTankNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import mekanism.api.gas.IGasHandler;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
import crazypants.enderio.conduit.IConduitBundle;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.util.BlockCoord;
|
||||
@@ -16,11 +17,8 @@ public final class GasUtil {
|
||||
|
||||
public static boolean isGasConduitEnabled() {
|
||||
if(!useCheckPerformed) {
|
||||
String configOption = Config.isGasConduitEnabled;
|
||||
if(configOption.equalsIgnoreCase("auto")) {
|
||||
isGasConduitEnabled = Loader.isModLoaded("Mekanism");
|
||||
} else if(configOption.equalsIgnoreCase("true")) {
|
||||
isGasConduitEnabled = true;
|
||||
if(Config.isGasConduitEnabled) {
|
||||
isGasConduitEnabled = Loader.isModLoaded("MekanismAPI|gas");
|
||||
} else {
|
||||
isGasConduitEnabled = false;
|
||||
}
|
||||
@@ -29,20 +27,24 @@ public final class GasUtil {
|
||||
return isGasConduitEnabled;
|
||||
}
|
||||
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public static IGasHandler getExternalGasHandler(IBlockAccess world, BlockCoord bc) {
|
||||
IGasHandler con = getGasHandler(world, bc);
|
||||
return (con != null && !(con instanceof IConduitBundle)) ? con : null;
|
||||
}
|
||||
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public static IGasHandler getGasHandler(IBlockAccess world, BlockCoord bc) {
|
||||
return getGasHandler(world, bc.x, bc.y, bc.z);
|
||||
}
|
||||
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public static IGasHandler getGasHandler(IBlockAccess world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
return getGasHandler(te);
|
||||
}
|
||||
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public static IGasHandler getGasHandler(TileEntity te) {
|
||||
if(te instanceof IGasHandler) {
|
||||
return (IGasHandler) te;
|
||||
@@ -50,6 +52,7 @@ public final class GasUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Method(modid = "MekanismAPI|gas")
|
||||
public static boolean isGasValid(GasStack gas) {
|
||||
if(gas != null) {
|
||||
String name = gas.getGas().getLocalizedName();
|
||||
|
||||
@@ -354,7 +354,7 @@ public final class Config {
|
||||
|
||||
public static boolean allowTileEntitiesAsPaintSource = true;
|
||||
|
||||
public static String isGasConduitEnabled = "auto";
|
||||
public static boolean isGasConduitEnabled = true;
|
||||
public static boolean enableMEConduits = true;
|
||||
|
||||
public static String[] soulVesselBlackList = new String[0];
|
||||
@@ -1049,10 +1049,11 @@ public final class Config {
|
||||
|
||||
killerJoeMustSee = config.get(sectionKiller.name, "killerJoeMustSee", killerJoeMustSee, "Set whether the Killer Joe can attack through blocks.").getBoolean();
|
||||
|
||||
isGasConduitEnabled = config.getString("isGasConduitEnabled", sectionItems.name, isGasConduitEnabled,
|
||||
"Can be set to 'auto', 'true' or 'false'. When set to auto the gas conduit will only be enabled when Mekanism is installed.");
|
||||
enableMEConduits = config.getBoolean("enableMEConduits", sectionItems.name, enableMEConduits,
|
||||
"Allows ME conduits. Only has an effect with AE2 installed.");
|
||||
// Add deprecated comment
|
||||
config.getString("isGasConduitEnabled", sectionItems.name, "auto", "Deprecated option. Use boolean \"gasConduitsEnabled\" below.");
|
||||
isGasConduitEnabled = config.getBoolean("gasConduitEnabled", sectionItems.name, isGasConduitEnabled,
|
||||
"If true, gas conduits will be enabled if the Mekanism Gas API is found. False to forcibly disable.");
|
||||
enableMEConduits = config.getBoolean("enableMEConduits", sectionItems.name, enableMEConduits, "Allows ME conduits. Only has an effect with AE2 installed.");
|
||||
|
||||
soulVesselBlackList = config.getStringList("soulVesselBlackList", sectionSoulBinder.name, soulVesselBlackList,
|
||||
"Entities listed here will can not be captured in a Soul Vial");
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
package mekanism.api;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
/**
|
||||
* Chunk3D - an integer-based way to keep track of and perform operations on chunks in a Minecraft-based environment. This also takes
|
||||
* in account the dimension the chunk is in.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class Chunk3D
|
||||
{
|
||||
public int dimensionId;
|
||||
|
||||
public int xCoord;
|
||||
public int zCoord;
|
||||
|
||||
/**
|
||||
* Creates a Chunk3D object from the given x and z coordinates, as well as a dimension.
|
||||
* @param x - chunk x location
|
||||
* @param z - chunk z location
|
||||
* @param dimension - the dimension this Chunk3D is in
|
||||
*/
|
||||
public Chunk3D(int x, int z, int dimension)
|
||||
{
|
||||
xCoord = x;
|
||||
zCoord = z;
|
||||
|
||||
dimensionId = dimension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Chunk3D from an entity based on it's location and dimension.
|
||||
* @param entity - the entity to get the Chunk3D object from
|
||||
*/
|
||||
public Chunk3D(Entity entity)
|
||||
{
|
||||
xCoord = ((int)entity.posX) >> 4;
|
||||
zCoord = ((int)entity.posZ) >> 4;
|
||||
|
||||
dimensionId = entity.dimension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Chunk3D from a Coord4D based on it's coordinates and dimension.
|
||||
* @param coord - the Coord4D object to get this Chunk3D from
|
||||
*/
|
||||
public Chunk3D(Coord4D coord)
|
||||
{
|
||||
xCoord = coord.xCoord >> 4;
|
||||
zCoord = coord.zCoord >> 4;
|
||||
|
||||
dimensionId = coord.dimensionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this chunk exists in the given world.
|
||||
* @param world - the world to check in
|
||||
* @return if the chunk exists
|
||||
*/
|
||||
public boolean exists(World world)
|
||||
{
|
||||
return world.getChunkProvider().chunkExists(xCoord, zCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Chunk object corresponding to this Chunk3D's coordinates.
|
||||
* @param world - the world to get the Chunk object from
|
||||
* @return the corresponding Chunk object
|
||||
*/
|
||||
public Chunk getChunk(World world)
|
||||
{
|
||||
return world.getChunkFromChunkCoords(xCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coord4D clone()
|
||||
{
|
||||
return new Coord4D(xCoord, zCoord, dimensionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[Chunk3D: " + xCoord + ", " + zCoord + ", dim=" + dimensionId + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Chunk3D &&
|
||||
((Chunk3D)obj).xCoord == xCoord &&
|
||||
((Chunk3D)obj).zCoord == zCoord &&
|
||||
((Chunk3D)obj).dimensionId == dimensionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int code = 1;
|
||||
code = 31 * code + xCoord;
|
||||
code = 31 * code + zCoord;
|
||||
code = 31 * code + dimensionId;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -1,358 +0,0 @@
|
||||
package mekanism.api;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
|
||||
/**
|
||||
* Coord4D - an integer-based way to keep track of and perform operations on blocks in a Minecraft-based environment. This also takes
|
||||
* in account the dimension the coordinate is in.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class Coord4D
|
||||
{
|
||||
public int xCoord;
|
||||
public int yCoord;
|
||||
public int zCoord;
|
||||
|
||||
public int dimensionId;
|
||||
|
||||
/**
|
||||
* Creates a Coord4D WITHOUT a dimensionId. Don't use unless absolutely necessary.
|
||||
* @param x - x coordinate
|
||||
* @param y - y coordinate
|
||||
* @param z - z coordinate
|
||||
*/
|
||||
public Coord4D(int x, int y, int z)
|
||||
{
|
||||
xCoord = x;
|
||||
yCoord = y;
|
||||
zCoord = z;
|
||||
|
||||
dimensionId = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Coord4D from the defined x, y, z, and dimension values.
|
||||
* @param x - x coordinate
|
||||
* @param y - y coordinate
|
||||
* @param z - z coordinate
|
||||
* @param dimension - dimension ID
|
||||
*/
|
||||
public Coord4D(int x, int y, int z, int dimension)
|
||||
{
|
||||
xCoord = x;
|
||||
yCoord = y;
|
||||
zCoord = z;
|
||||
|
||||
dimensionId = dimension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the metadata of the block representing this Coord4D.
|
||||
* @param world - world this Coord4D is in
|
||||
* @return the metadata of this Coord4D's block
|
||||
*/
|
||||
public int getMetadata(IBlockAccess world)
|
||||
{
|
||||
return world.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the TileEntity of the block representing this Coord4D.
|
||||
* @param world - world this Coord4D is in
|
||||
* @return the TileEntity of this Coord4D's block
|
||||
*/
|
||||
public TileEntity getTileEntity(IBlockAccess world)
|
||||
{
|
||||
if(world instanceof World && !exists((World)world))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return world.getTileEntity(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Block value of the block representing this Coord4D.
|
||||
* @param world - world this Coord4D is in
|
||||
* @return the Block value of this Coord4D's block
|
||||
*/
|
||||
public Block getBlock(IBlockAccess world)
|
||||
{
|
||||
if(world instanceof World && !exists((World)world))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return world.getBlock(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes this Coord4D's data to an NBTTagCompound.
|
||||
* @param nbtTags - tag compound to write to
|
||||
* @return the tag compound with this Coord4D's data
|
||||
*/
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
nbtTags.setInteger("x", xCoord);
|
||||
nbtTags.setInteger("y", yCoord);
|
||||
nbtTags.setInteger("z", zCoord);
|
||||
nbtTags.setInteger("dimensionId", dimensionId);
|
||||
|
||||
return nbtTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes this Coord4D's data to an ArrayList for packet transfer.
|
||||
* @param data - the ArrayList to add the data to
|
||||
*/
|
||||
public void write(ArrayList data)
|
||||
{
|
||||
data.add(xCoord);
|
||||
data.add(yCoord);
|
||||
data.add(zCoord);
|
||||
data.add(dimensionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes this Coord4D's data to a ByteBuf for packet transfer.
|
||||
* @param dataStream - the ByteBuf to add the data to
|
||||
*/
|
||||
public void write(ByteBuf dataStream)
|
||||
{
|
||||
dataStream.writeInt(xCoord);
|
||||
dataStream.writeInt(yCoord);
|
||||
dataStream.writeInt(zCoord);
|
||||
dataStream.writeInt(dimensionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates this Coord4D by the defined x, y, and z values.
|
||||
* @param x - x value to translate
|
||||
* @param y - y value to translate
|
||||
* @param z - z value to translate
|
||||
* @return translated Coord4D
|
||||
*/
|
||||
public Coord4D translate(int x, int y, int z)
|
||||
{
|
||||
xCoord += x;
|
||||
yCoord += y;
|
||||
zCoord += z;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new Coord4D translated to the defined offsets of the side.
|
||||
* @param side - side to translate this Coord4D to
|
||||
* @return translated Coord4D
|
||||
*/
|
||||
public Coord4D getFromSide(ForgeDirection side)
|
||||
{
|
||||
return getFromSide(side, 1);
|
||||
}
|
||||
|
||||
public Coord4D getFromSide(ForgeDirection side, int amount)
|
||||
{
|
||||
return new Coord4D(xCoord+(side.offsetX*amount), yCoord+(side.offsetY*amount), zCoord+(side.offsetZ*amount), dimensionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new Coord4D from a defined TileEntity's xCoord, yCoord and zCoord values.
|
||||
* @param tileEntity - TileEntity at the location that will represent this Coord4D
|
||||
* @return the Coord4D object from the TileEntity
|
||||
*/
|
||||
public static Coord4D get(TileEntity tileEntity)
|
||||
{
|
||||
return new Coord4D(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, tileEntity.getWorldObj().provider.dimensionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new Coord4D from a tag compound.
|
||||
* @param data - tag compound to read from
|
||||
* @return the Coord4D from the tag compound
|
||||
*/
|
||||
public static Coord4D read(NBTTagCompound tag)
|
||||
{
|
||||
return new Coord4D(tag.getInteger("x"), tag.getInteger("y"), tag.getInteger("z"), tag.getInteger("id"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new Coord4D from a ByteBuf.
|
||||
* @param dataStream - data input to read from
|
||||
* @return the Coord4D from the data input
|
||||
*/
|
||||
public static Coord4D read(ByteBuf dataStream)
|
||||
{
|
||||
return new Coord4D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new Coord4D with values representing the difference between the defined Coord4D
|
||||
* @param other - the Coord4D to subtract from this
|
||||
* @return a Coord4D representing the distance between the defined Coord4D
|
||||
*/
|
||||
public Coord4D difference(Coord4D other)
|
||||
{
|
||||
return new Coord4D(xCoord-other.xCoord, yCoord-other.yCoord, zCoord-other.zCoord, dimensionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method used to find the ForgeDirection represented by the distance of the defined Coord4D. Most likely won't have many
|
||||
* applicable uses.
|
||||
* @param other - Coord4D to find the side difference of
|
||||
* @return ForgeDirection representing the side the defined relative Coord4D is on to this
|
||||
*/
|
||||
public ForgeDirection sideDifference(Coord4D other)
|
||||
{
|
||||
Coord4D diff = difference(other);
|
||||
|
||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if(side.offsetX == diff.xCoord && side.offsetY == diff.yCoord && side.offsetZ == diff.zCoord)
|
||||
{
|
||||
return side;
|
||||
}
|
||||
}
|
||||
|
||||
return ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance to a defined Coord4D.
|
||||
* @param obj - the Coord4D to find the distance to
|
||||
* @return the distance to the defined Coord4D
|
||||
*/
|
||||
public int distanceTo(Coord4D obj)
|
||||
{
|
||||
int subX = xCoord - obj.xCoord;
|
||||
int subY = yCoord - obj.yCoord;
|
||||
int subZ = zCoord - obj.zCoord;
|
||||
return (int)MathHelper.sqrt_double(subX * subX + subY * subY + subZ * subZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the defined side of this Coord4D is visible.
|
||||
* @param side - side to check
|
||||
* @param world - world this Coord4D is in
|
||||
* @return
|
||||
*/
|
||||
public boolean sideVisible(ForgeDirection side, IBlockAccess world)
|
||||
{
|
||||
return world.isAirBlock(xCoord+side.offsetX, yCoord+side.offsetY, zCoord+side.offsetZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a TargetPoint with the defined range from this Coord4D with the appropriate coordinates and dimension ID.
|
||||
* @param range - the range the packet can be sent in of this Coord4D
|
||||
* @return TargetPoint relative to this Coord4D
|
||||
*/
|
||||
public TargetPoint getTargetPoint(double range)
|
||||
{
|
||||
return new TargetPoint(dimensionId, xCoord, yCoord, zCoord, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Steps this Coord4D in the defined side's offset without creating a new value.
|
||||
* @param side - side to step towards
|
||||
* @return this Coord4D
|
||||
*/
|
||||
public Coord4D step(ForgeDirection side)
|
||||
{
|
||||
return translate(side.offsetX, side.offsetY, side.offsetZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the chunk this Coord4D is in exists and is loaded.
|
||||
* @param world - world this Coord4D is in
|
||||
* @return the chunk of this Coord4D
|
||||
*/
|
||||
public boolean exists(World world)
|
||||
{
|
||||
return world.getChunkProvider().chunkExists(xCoord >> 4, zCoord >> 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk this Coord4D is in.
|
||||
* @param world - world this Coord4D is in
|
||||
* @return the chunk of this Coord4D
|
||||
*/
|
||||
public Chunk getChunk(World world)
|
||||
{
|
||||
return world.getChunkFromBlockCoords(xCoord, zCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Chunk3D object with chunk coordinates correlating to this Coord4D's location
|
||||
* @return Chunk3D with correlating chunk coordinates.
|
||||
*/
|
||||
public Chunk3D getChunk3D()
|
||||
{
|
||||
return new Chunk3D(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the block this Coord4D represents is an air block.
|
||||
* @param world - world this Coord4D is in
|
||||
* @return if this Coord4D is an air block
|
||||
*/
|
||||
public boolean isAirBlock(IBlockAccess world)
|
||||
{
|
||||
return world.isAirBlock(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a bounding box that contains the area this Coord4D would take up in a world.
|
||||
* @return this Coord4D's bounding box
|
||||
*/
|
||||
public AxisAlignedBB getBoundingBox()
|
||||
{
|
||||
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coord4D clone()
|
||||
{
|
||||
return new Coord4D(xCoord, yCoord, zCoord, dimensionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[Coord4D: " + xCoord + ", " + yCoord + ", " + zCoord + ", dim=" + dimensionId + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Coord4D &&
|
||||
((Coord4D)obj).xCoord == xCoord &&
|
||||
((Coord4D)obj).yCoord == yCoord &&
|
||||
((Coord4D)obj).zCoord == zCoord &&
|
||||
((Coord4D)obj).dimensionId == dimensionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int code = 1;
|
||||
code = 31 * code + xCoord;
|
||||
code = 31 * code + yCoord;
|
||||
code = 31 * code + zCoord;
|
||||
code = 31 * code + dimensionId;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package mekanism.api;
|
||||
|
||||
public interface IClientTicker
|
||||
{
|
||||
public void clientTick();
|
||||
|
||||
public boolean needsTicks();
|
||||
}
|
||||
@@ -1,282 +0,0 @@
|
||||
package mekanism.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ListUtils
|
||||
{
|
||||
public static <V> List<V> inverse(List<V> list)
|
||||
{
|
||||
List<V> toReturn = new ArrayList<V>();
|
||||
|
||||
for(int i = list.size() - 1; i >= 0; i--)
|
||||
{
|
||||
toReturn.add(list.get(i));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static <V> List<V> cap(List<V> list, int cap)
|
||||
{
|
||||
List<V> toReturn = new ArrayList<V>();
|
||||
|
||||
if(list.size() <= cap)
|
||||
{
|
||||
toReturn = copy(list);
|
||||
}
|
||||
else {
|
||||
int count = 0;
|
||||
|
||||
for(V obj : list)
|
||||
{
|
||||
count++;
|
||||
|
||||
toReturn.add(obj);
|
||||
|
||||
if(count == cap)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static <V> List<V> copy(List<V> list)
|
||||
{
|
||||
List<V> toReturn = new ArrayList<V>();
|
||||
|
||||
for(V obj : list)
|
||||
{
|
||||
toReturn.add(obj);
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static <V> List<V> merge(List<V> listOne, List<V> listTwo)
|
||||
{
|
||||
List<V> newList = new ArrayList<V>();
|
||||
|
||||
for(V obj : listOne)
|
||||
{
|
||||
newList.add(obj);
|
||||
}
|
||||
|
||||
for(V obj : listTwo)
|
||||
{
|
||||
newList.add(obj);
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
public static <V> List<V> capRemains(List<V> list, int cap)
|
||||
{
|
||||
List<V> toReturn = new ArrayList<V>();
|
||||
|
||||
if(list.size() <= cap)
|
||||
{
|
||||
return toReturn;
|
||||
}
|
||||
else {
|
||||
List<V> inverse = inverse(list);
|
||||
|
||||
int iterNeeded = list.size() - cap;
|
||||
int count = 0;
|
||||
|
||||
for(V obj : list)
|
||||
{
|
||||
count++;
|
||||
|
||||
toReturn.add(obj);
|
||||
|
||||
if(count == iterNeeded)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
public static <V> ArrayList<List<V>> split(List<V> list, int divide)
|
||||
{
|
||||
int remain = list.size() % divide;
|
||||
int size = (list.size() - remain) / divide;
|
||||
|
||||
ArrayList<List<V>> toReturn = new ArrayList<List<V>>();
|
||||
|
||||
for(int i = 0; i < divide; i++)
|
||||
{
|
||||
toReturn.add(i, new ArrayList<V>());
|
||||
}
|
||||
|
||||
for(List<V> iterSet : toReturn)
|
||||
{
|
||||
List<V> removed = new ArrayList<V>();
|
||||
|
||||
int toAdd = size;
|
||||
|
||||
if(remain > 0)
|
||||
{
|
||||
remain--;
|
||||
toAdd++;
|
||||
}
|
||||
|
||||
for(V obj : list)
|
||||
{
|
||||
if(toAdd == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
iterSet.add(obj);
|
||||
removed.add(obj);
|
||||
toAdd--;
|
||||
}
|
||||
|
||||
for(V obj : removed)
|
||||
{
|
||||
list.remove(obj);
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static <V> V getTop(List<V> list)
|
||||
{
|
||||
for(V obj : list)
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <V> List<V> asList(Set<V> set)
|
||||
{
|
||||
return (List<V>)Arrays.asList(set.toArray());
|
||||
}
|
||||
|
||||
public static <V> List<V> asList(V... values)
|
||||
{
|
||||
return (List<V>)Arrays.asList(values);
|
||||
}
|
||||
|
||||
public static double[] splitDouble(int size, double num)
|
||||
{
|
||||
double[] split = new double[size];
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
double remain = num%size;
|
||||
double ret = (num-remain)/size;
|
||||
ret += remain;
|
||||
|
||||
split[i] = ret;
|
||||
num -= remain;
|
||||
}
|
||||
|
||||
return split;
|
||||
}
|
||||
|
||||
public static double[] percent(double[] values)
|
||||
{
|
||||
double[] ret = new double[values.length];
|
||||
double total = 0;
|
||||
|
||||
for(double d : values) total += d;
|
||||
|
||||
for(int i = 0; i < values.length; i++)
|
||||
{
|
||||
ret[i] = values[i]/total;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int[] calcPercentInt(double[] percent, int val)
|
||||
{
|
||||
int[] ret = new int[percent.length];
|
||||
|
||||
for(int i = 0; i < percent.length; i++)
|
||||
{
|
||||
ret[i] = (int)Math.round(val*percent[i]);
|
||||
}
|
||||
|
||||
int newTotal = 0;
|
||||
for(int i : ret) newTotal += i;
|
||||
|
||||
int diff = val-newTotal;
|
||||
|
||||
if(diff != val)
|
||||
{
|
||||
for(int i = 0; i < ret.length; i++)
|
||||
{
|
||||
int num = ret[i];
|
||||
|
||||
if(diff < 0 && num == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(diff > 0)
|
||||
{
|
||||
ret[i]++;
|
||||
diff--;
|
||||
}
|
||||
else if(diff < 0)
|
||||
{
|
||||
ret[i]--;
|
||||
diff++;
|
||||
}
|
||||
|
||||
if(diff == 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int[] splitInt(int size, int num)
|
||||
{
|
||||
int[] split = new int[size];
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
int remain = num%size;
|
||||
int ret = (num-remain)/size;
|
||||
ret += remain;
|
||||
|
||||
split[i] = ret;
|
||||
num -= remain;
|
||||
}
|
||||
|
||||
return split;
|
||||
}
|
||||
|
||||
public static double[] percent(int[] values)
|
||||
{
|
||||
double[] ret = new double[values.length];
|
||||
double total = 0;
|
||||
|
||||
for(double d : values) total += d;
|
||||
|
||||
for(int i = 0; i < values.length; i++)
|
||||
{
|
||||
ret[i] = values[i]/total;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
package mekanism.api;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
/**
|
||||
* Pos3D - a way of performing operations on objects in a three dimensional environment.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class Pos3D
|
||||
{
|
||||
public double xPos;
|
||||
public double yPos;
|
||||
public double zPos;
|
||||
|
||||
public Pos3D()
|
||||
{
|
||||
this(0, 0, 0);
|
||||
}
|
||||
|
||||
public Pos3D(double x, double y, double z)
|
||||
{
|
||||
xPos = x;
|
||||
yPos = y;
|
||||
zPos = z;
|
||||
}
|
||||
|
||||
public Pos3D(Coord4D coord)
|
||||
{
|
||||
xPos = coord.xCoord;
|
||||
yPos = coord.yCoord;
|
||||
zPos = coord.zCoord;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Pos3D with an entity's posX, posY, and posZ values.
|
||||
* @param entity - entity to create the Pos3D from
|
||||
*/
|
||||
public Pos3D(Entity entity)
|
||||
{
|
||||
this(entity.posX, entity.posY, entity.posZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Pos3D with a TileEntity's xCoord, yCoord and zCoord values.
|
||||
* @param tileEntity - TileEntity to create the Pos3D from
|
||||
*/
|
||||
public Pos3D(TileEntity tileEntity)
|
||||
{
|
||||
this(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a Pos3D with values representing the difference between this and the Pos3D in the parameters.
|
||||
* @param pos - Pos3D to subtract
|
||||
* @return difference of the two Pos3Ds
|
||||
*/
|
||||
public Pos3D diff(Pos3D pos)
|
||||
{
|
||||
return new Pos3D(xPos-pos.xPos, yPos-pos.yPos, zPos-pos.zPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Pos3D from the motion of an entity.
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static Pos3D fromMotion(Entity entity)
|
||||
{
|
||||
return new Pos3D(entity.motionX, entity.motionY, entity.motionZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates this Pos3D by the defined values.
|
||||
* @param x - amount to translate on the x axis
|
||||
* @param y - amount to translate on the y axis
|
||||
* @param z - amount to translate on the z axis
|
||||
* @return the translated Pos3D
|
||||
*/
|
||||
public Pos3D translate(double x, double y, double z)
|
||||
{
|
||||
xPos += x;
|
||||
yPos += y;
|
||||
zPos += z;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the same operation as translate(x, y, z), but with a Pos3D value instead.
|
||||
* @param pos - Pos3D value to translate by
|
||||
* @return translated Pos3D
|
||||
*/
|
||||
public Pos3D translate(Pos3D pos)
|
||||
{
|
||||
return translate(pos.xPos, pos.yPos, pos.zPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the distance between this and the defined Pos3D.
|
||||
* @param pos - the Pos3D to find the distance to
|
||||
* @return the distance between this and the defined Pos3D
|
||||
*/
|
||||
public double distance(Pos3D pos)
|
||||
{
|
||||
double subX = xPos - pos.xPos;
|
||||
double subY = yPos - pos.yPos;
|
||||
double subZ = zPos - pos.zPos;
|
||||
return MathHelper.sqrt_double(subX * subX + subY * subY + subZ * subZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates this Pos3D by the defined yaw value.
|
||||
* @param yaw - yaw to rotate by
|
||||
* @return rotated Pos3D
|
||||
*/
|
||||
public Pos3D rotateYaw(double yaw)
|
||||
{
|
||||
double yawRadians = Math.toRadians(yaw);
|
||||
|
||||
double x = xPos;
|
||||
double z = zPos;
|
||||
|
||||
if(yaw != 0)
|
||||
{
|
||||
xPos = x * Math.cos(yawRadians) - z * Math.sin(yawRadians);
|
||||
zPos = x * Math.sin(yawRadians) + z * Math.cos(yawRadians);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales this Pos3D by the defined x, y, an z values.
|
||||
* @param x - x value to scale by
|
||||
* @param y - y value to scale by
|
||||
* @param z - z value to scale by
|
||||
* @return scaled Pos3D
|
||||
*/
|
||||
public Pos3D scale(double x, double y, double z)
|
||||
{
|
||||
xPos *= x;
|
||||
yPos *= y;
|
||||
zPos *= z;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the same operation as scale(x, y, z), but with a value representing all three dimensions.
|
||||
* @param scale - value to scale by
|
||||
* @return scaled Pos3D
|
||||
*/
|
||||
public Pos3D scale(double scale)
|
||||
{
|
||||
return scale(scale, scale, scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos3D clone()
|
||||
{
|
||||
return new Pos3D(xPos, yPos, zPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[Pos3D: " + xPos + ", " + yPos + ", " + zPos + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Pos3D &&
|
||||
((Pos3D)obj).xPos == xPos &&
|
||||
((Pos3D)obj).yPos == yPos &&
|
||||
((Pos3D)obj).zPos == zPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int code = 1;
|
||||
code = 31 * code + new Double(xPos).hashCode();
|
||||
code = 31 * code + new Double(yPos).hashCode();
|
||||
code = 31 * code + new Double(zPos).hashCode();
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
package mekanism.api;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
public class Range4D
|
||||
{
|
||||
public int dimensionId;
|
||||
|
||||
public int xMin;
|
||||
public int yMin;
|
||||
public int zMin;
|
||||
public int xMax;
|
||||
public int yMax;
|
||||
public int zMax;
|
||||
|
||||
public Range4D(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int dimension)
|
||||
{
|
||||
xMin = minX;
|
||||
yMin = minY;
|
||||
zMin = minZ;
|
||||
xMax = maxX;
|
||||
yMax = maxY;
|
||||
zMax = maxZ;
|
||||
|
||||
dimensionId = dimension;
|
||||
}
|
||||
|
||||
public Range4D(Chunk3D chunk)
|
||||
{
|
||||
xMin = chunk.xCoord*16;
|
||||
yMin = 0;
|
||||
zMin = chunk.zCoord*16;
|
||||
xMax = xMin+16;
|
||||
yMax = 255;
|
||||
zMax = zMin+16;
|
||||
}
|
||||
|
||||
public Range4D(Coord4D coord)
|
||||
{
|
||||
xMin = coord.xCoord;
|
||||
yMin = coord.yCoord;
|
||||
zMin = coord.zCoord;
|
||||
|
||||
xMax = coord.xCoord+1;
|
||||
yMax = coord.yCoord+1;
|
||||
zMax = coord.zCoord+1;
|
||||
}
|
||||
|
||||
public static Range4D getChunkRange(EntityPlayer player)
|
||||
{
|
||||
int radius = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().getViewDistance();
|
||||
|
||||
return new Range4D(new Chunk3D(player)).expandChunks(radius);
|
||||
}
|
||||
|
||||
public Range4D expandChunks(int chunks)
|
||||
{
|
||||
xMin -= chunks*16;
|
||||
xMax += chunks*16;
|
||||
zMin -= chunks*16;
|
||||
zMax += chunks*16;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean intersects(Range4D range)
|
||||
{
|
||||
return (xMax+1 - 1.E-05D > range.xMin) && (range.xMax+1 - 1.E-05D > xMin) && (yMax+1 - 1.E-05D > range.yMin) && (range.yMax+1 - 1.E-05D > yMin) && (zMax+1 - 1.E-05D > range.zMin) && (range.zMax+1 - 1.E-05D > zMin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Range4D clone()
|
||||
{
|
||||
return new Range4D(xMin, yMin, zMin, xMax, yMax, zMax, dimensionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[Range4D: " + xMin + ", " + yMin + ", " + zMin + ", " + xMax + ", " + yMax + ", " + zMax + ", dim=" + dimensionId + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Range4D &&
|
||||
((Range4D)obj).xMin == xMin &&
|
||||
((Range4D)obj).yMin == yMin &&
|
||||
((Range4D)obj).zMin == zMin &&
|
||||
((Range4D)obj).xMax == xMax &&
|
||||
((Range4D)obj).yMax == yMax &&
|
||||
((Range4D)obj).zMax == zMax &&
|
||||
((Range4D)obj).dimensionId == dimensionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int code = 1;
|
||||
code = 31 * code + xMin;
|
||||
code = 31 * code + yMin;
|
||||
code = 31 * code + zMin;
|
||||
code = 31 * code + xMax;
|
||||
code = 31 * code + yMax;
|
||||
code = 31 * code + zMax;
|
||||
code = 31 * code + dimensionId;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
|
||||
/**
|
||||
* Gas - a class used to set specific properties of gasses when used or seen in-game.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class Gas
|
||||
{
|
||||
private String name;
|
||||
|
||||
private String unlocalizedName;
|
||||
|
||||
private Fluid fluid;
|
||||
|
||||
private IIcon icon;
|
||||
|
||||
private boolean visible = true;
|
||||
|
||||
private boolean from_fluid = false;
|
||||
|
||||
/**
|
||||
* Creates a new Gas object with a defined name or key value.
|
||||
* @param s - name or key to associate this Gas with
|
||||
*/
|
||||
public Gas(String s)
|
||||
{
|
||||
unlocalizedName = name = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Gas object that corresponds to the given Fluid
|
||||
*/
|
||||
public Gas(Fluid f)
|
||||
{
|
||||
unlocalizedName = name = f.getName();
|
||||
icon = f.getStillIcon();
|
||||
fluid = f;
|
||||
from_fluid = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name (key) of this Gas. This is NOT a translated or localized display name.
|
||||
* @return this Gas's name or key
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this is a visible gas.
|
||||
* @return if this gas is visible
|
||||
*/
|
||||
public boolean isVisible()
|
||||
{
|
||||
return visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this gas's "visible" state to a new value. Setting it to 'false' will treat this gas as an internal gas, and it will not be displayed or accessed by other mods.
|
||||
* @param v - new visible state
|
||||
* @return this Gas object
|
||||
*/
|
||||
public Gas setVisible(boolean v)
|
||||
{
|
||||
visible = v;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unlocalized name of this Gas.
|
||||
* @return this Gas's unlocalized name
|
||||
*/
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
return "gas." + unlocalizedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates this Gas's unlocalized name and returns it as localized.
|
||||
* @return this Gas's localized name
|
||||
*/
|
||||
public String getLocalizedName()
|
||||
{
|
||||
return StatCollector.translateToLocal(getUnlocalizedName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the unlocalized name of this Gas.
|
||||
* @param s - unlocalized name to set
|
||||
* @return this Gas object
|
||||
*/
|
||||
public Gas setUnlocalizedName(String s)
|
||||
{
|
||||
unlocalizedName = s;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the IIcon associated with this Gas.
|
||||
* @return associated IIcon
|
||||
*/
|
||||
public IIcon getIcon()
|
||||
{
|
||||
if(from_fluid)
|
||||
{
|
||||
return this.getFluid().getIcon();
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this gas's icon.
|
||||
* @param i - IIcon to associate with this Gas
|
||||
* @return this Gas object
|
||||
*/
|
||||
public Gas setIcon(IIcon i)
|
||||
{
|
||||
icon = i;
|
||||
|
||||
if(hasFluid())
|
||||
{
|
||||
fluid.setIcons(getIcon());
|
||||
}
|
||||
|
||||
from_fluid = false;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID associated with this gas.
|
||||
* @return the associated gas ID
|
||||
*/
|
||||
public int getID()
|
||||
{
|
||||
return GasRegistry.getGasID(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes this Gas to a defined tag compound.
|
||||
* @param nbtTags - tag compound to write this Gas to
|
||||
* @return the tag compound this gas was written to
|
||||
*/
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
nbtTags.setString("gasName", getName());
|
||||
|
||||
return nbtTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Gas stored in the defined tag compound.
|
||||
* @param nbtTags - tag compound to get the Gas from
|
||||
* @return Gas stored in the tag compound
|
||||
*/
|
||||
public static Gas readFromNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(nbtTags == null || nbtTags.hasNoTags())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return GasRegistry.getGas(nbtTags.getString("gasName"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this Gas has an associated fluid.
|
||||
* @return if this gas has a fluid
|
||||
*/
|
||||
public boolean hasFluid()
|
||||
{
|
||||
return fluid != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fluid associated with this Gas.
|
||||
* @return fluid associated with this gas
|
||||
*/
|
||||
public Fluid getFluid()
|
||||
{
|
||||
return fluid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new fluid out of this Gas or gets one from the FluidRegistry.
|
||||
* @return this Gas object
|
||||
*/
|
||||
public Gas registerFluid()
|
||||
{
|
||||
if(fluid == null)
|
||||
{
|
||||
if(FluidRegistry.getFluid(getName()) == null)
|
||||
{
|
||||
fluid = new Fluid(getName()).setGaseous(true);
|
||||
FluidRegistry.registerFluid(fluid);
|
||||
}
|
||||
else {
|
||||
fluid = FluidRegistry.getFluid(getName());
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -1,474 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.ListUtils;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import mekanism.api.transmitters.ITransmitterNetwork;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
/**
|
||||
* A DynamicNetwork extension created specifically for the transfer of Gasses. By default this is server-only, but if ticked on
|
||||
* the client side and if it's posted events are handled properly, it has the capability to visually display gasses network-wide.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
||||
{
|
||||
public int transferDelay = 0;
|
||||
|
||||
public boolean didTransfer;
|
||||
public boolean prevTransfer;
|
||||
|
||||
public float gasScale;
|
||||
|
||||
public Gas refGas;
|
||||
|
||||
public GasStack gasStored;
|
||||
public int prevStored;
|
||||
|
||||
public int prevTransferAmount = 0;
|
||||
|
||||
public GasNetwork(IGridTransmitter<GasNetwork>... varPipes)
|
||||
{
|
||||
transmitters.addAll(Arrays.asList(varPipes));
|
||||
register();
|
||||
}
|
||||
|
||||
public GasNetwork(Collection<IGridTransmitter<GasNetwork>> collection)
|
||||
{
|
||||
transmitters.addAll(collection);
|
||||
register();
|
||||
}
|
||||
|
||||
public GasNetwork(Set<GasNetwork> networks)
|
||||
{
|
||||
for(GasNetwork net : networks)
|
||||
{
|
||||
if(net != null)
|
||||
{
|
||||
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||
{
|
||||
if(net.refGas != null && net.gasScale > gasScale)
|
||||
{
|
||||
gasScale = net.gasScale;
|
||||
refGas = net.refGas;
|
||||
gasStored = net.gasStored;
|
||||
|
||||
net.gasScale = 0;
|
||||
net.refGas = null;
|
||||
net.gasStored = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(net.gasStored != null)
|
||||
{
|
||||
if(gasStored == null)
|
||||
{
|
||||
gasStored = net.gasStored;
|
||||
}
|
||||
else {
|
||||
gasStored.amount += net.gasStored.amount;
|
||||
}
|
||||
|
||||
net.gasStored = null;
|
||||
}
|
||||
}
|
||||
|
||||
addAllTransmitters(net.transmitters);
|
||||
net.deregister();
|
||||
}
|
||||
}
|
||||
|
||||
gasScale = getScale();
|
||||
|
||||
register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetworksCreated(List<GasNetwork> networks)
|
||||
{
|
||||
if(gasStored != null && FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
int[] caps = new int[networks.size()];
|
||||
int cap = 0;
|
||||
|
||||
for(GasNetwork network : networks)
|
||||
{
|
||||
caps[networks.indexOf(network)] = network.getCapacity();
|
||||
cap += network.getCapacity();
|
||||
}
|
||||
|
||||
gasStored.amount = Math.min(cap, gasStored.amount);
|
||||
|
||||
int[] values = ListUtils.calcPercentInt(ListUtils.percent(caps), gasStored.amount);
|
||||
|
||||
for(GasNetwork network : networks)
|
||||
{
|
||||
int index = networks.indexOf(network);
|
||||
|
||||
if(values[index] > 0)
|
||||
{
|
||||
network.gasStored = new GasStack(gasStored.getGas(), values[index]);
|
||||
network.refGas = gasStored.getGas();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gasScale = 0;
|
||||
refGas = null;
|
||||
gasStored = null;
|
||||
}
|
||||
|
||||
public synchronized int getGasNeeded()
|
||||
{
|
||||
return getCapacity()-(gasStored != null ? gasStored.amount : 0);
|
||||
}
|
||||
|
||||
public synchronized int tickEmit(GasStack stack)
|
||||
{
|
||||
List availableAcceptors = Arrays.asList(getAcceptors(stack.getGas()).toArray());
|
||||
|
||||
Collections.shuffle(availableAcceptors);
|
||||
|
||||
int toSend = stack.amount;
|
||||
int prevSending = toSend;
|
||||
|
||||
if(!availableAcceptors.isEmpty())
|
||||
{
|
||||
int divider = availableAcceptors.size();
|
||||
int remaining = toSend % divider;
|
||||
int sending = (toSend-remaining)/divider;
|
||||
|
||||
for(Object obj : availableAcceptors)
|
||||
{
|
||||
if(obj instanceof IGasHandler)
|
||||
{
|
||||
IGasHandler acceptor = (IGasHandler)obj;
|
||||
|
||||
int currentSending = sending;
|
||||
|
||||
if(remaining > 0)
|
||||
{
|
||||
currentSending++;
|
||||
remaining--;
|
||||
}
|
||||
|
||||
toSend -= acceptor.receiveGas(acceptorDirections.get(acceptor).getOpposite(), new GasStack(stack.getGas(), currentSending));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int sent = prevSending-toSend;
|
||||
|
||||
if(sent > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
didTransfer = true;
|
||||
transferDelay = 2;
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
public synchronized int emit(GasStack stack)
|
||||
{
|
||||
if(gasStored != null && gasStored.getGas() != stack.getGas())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int toUse = Math.min(getGasNeeded(), stack.amount);
|
||||
|
||||
if(gasStored == null)
|
||||
{
|
||||
gasStored = stack.copy();
|
||||
gasStored.amount = toUse;
|
||||
}
|
||||
else {
|
||||
gasStored.amount += toUse;
|
||||
}
|
||||
|
||||
return toUse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
super.onUpdate();
|
||||
|
||||
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
prevTransferAmount = 0;
|
||||
|
||||
if(transferDelay == 0)
|
||||
{
|
||||
didTransfer = false;
|
||||
}
|
||||
else {
|
||||
transferDelay--;
|
||||
}
|
||||
|
||||
int stored = gasStored != null ? gasStored.amount : 0;
|
||||
|
||||
if(stored != prevStored)
|
||||
{
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
prevStored = stored;
|
||||
|
||||
if(didTransfer != prevTransfer || needsUpdate)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new GasTransferEvent(this, gasStored, didTransfer));
|
||||
needsUpdate = false;
|
||||
}
|
||||
|
||||
prevTransfer = didTransfer;
|
||||
|
||||
if(gasStored != null)
|
||||
{
|
||||
prevTransferAmount = tickEmit(gasStored);
|
||||
gasStored.amount -= prevTransferAmount;
|
||||
|
||||
if(gasStored.amount <= 0)
|
||||
{
|
||||
gasStored = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientTick()
|
||||
{
|
||||
super.clientTick();
|
||||
|
||||
gasScale = Math.max(gasScale, getScale());
|
||||
|
||||
if(didTransfer && gasScale < 1)
|
||||
{
|
||||
gasScale = Math.max(getScale(), Math.min(1, gasScale+0.02F));
|
||||
}
|
||||
else if(!didTransfer && gasScale > 0)
|
||||
{
|
||||
gasScale = Math.max(getScale(), Math.max(0, gasScale-0.02F));
|
||||
|
||||
if(gasScale == 0)
|
||||
{
|
||||
gasStored = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Set<IGasHandler> getAcceptors(Object... data)
|
||||
{
|
||||
Gas type = (Gas)data[0];
|
||||
Set<IGasHandler> toReturn = new HashSet<IGasHandler>();
|
||||
|
||||
for(IGasHandler acceptor : ((Map<Coord4D, IGasHandler>)possibleAcceptors.clone()).values())
|
||||
{
|
||||
if(acceptorDirections.get(acceptor) == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(acceptor.canReceiveGas(acceptorDirections.get(acceptor).getOpposite(), type))
|
||||
{
|
||||
toReturn.add(acceptor);
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void refresh()
|
||||
{
|
||||
Set<IGridTransmitter<GasNetwork>> iterTubes = (Set<IGridTransmitter<GasNetwork>>)transmitters.clone();
|
||||
Iterator<IGridTransmitter<GasNetwork>> it = iterTubes.iterator();
|
||||
boolean networkChanged = false;
|
||||
|
||||
while(it.hasNext())
|
||||
{
|
||||
IGridTransmitter<GasNetwork> conductor = (IGridTransmitter<GasNetwork>)it.next();
|
||||
|
||||
if(conductor == null || conductor.getTile().isInvalid())
|
||||
{
|
||||
it.remove();
|
||||
networkChanged = true;
|
||||
transmitters.remove(conductor);
|
||||
}
|
||||
else {
|
||||
conductor.setTransmitterNetwork(this);
|
||||
}
|
||||
}
|
||||
|
||||
if(networkChanged)
|
||||
{
|
||||
updateCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void refresh(IGridTransmitter<GasNetwork> transmitter)
|
||||
{
|
||||
IGasHandler[] acceptors = GasTransmission.getConnectedAcceptors(transmitter.getTile());
|
||||
|
||||
clearAround(transmitter);
|
||||
|
||||
for(IGasHandler acceptor : acceptors)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
|
||||
|
||||
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
|
||||
{
|
||||
possibleAcceptors.put(Coord4D.get((TileEntity)acceptor), acceptor);
|
||||
acceptorDirections.put(acceptor, ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class GasTransferEvent extends Event
|
||||
{
|
||||
public final GasNetwork gasNetwork;
|
||||
|
||||
public final GasStack transferType;
|
||||
public final boolean didTransfer;
|
||||
|
||||
public GasTransferEvent(GasNetwork network, GasStack type, boolean did)
|
||||
{
|
||||
gasNetwork = network;
|
||||
transferType = type;
|
||||
didTransfer = did;
|
||||
}
|
||||
}
|
||||
|
||||
public float getScale()
|
||||
{
|
||||
return Math.min(1, (gasStored == null || getCapacity() == 0 ? 0 : (float)gasStored.amount/getCapacity()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[GasNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size() + " acceptors.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMerge(List<ITransmitterNetwork<?, ?>> networks)
|
||||
{
|
||||
Gas found = null;
|
||||
|
||||
for(ITransmitterNetwork<?, ?> network : networks)
|
||||
{
|
||||
if(network instanceof GasNetwork)
|
||||
{
|
||||
GasNetwork net = (GasNetwork)network;
|
||||
|
||||
if(net.gasStored != null)
|
||||
{
|
||||
if(found != null && found != net.gasStored.getGas())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
found = net.gasStored.getGas();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GasNetwork create(IGridTransmitter<GasNetwork>... varTransmitters)
|
||||
{
|
||||
GasNetwork network = new GasNetwork(varTransmitters);
|
||||
network.refGas = refGas;
|
||||
|
||||
if(gasStored != null)
|
||||
{
|
||||
if(network.gasStored == null)
|
||||
{
|
||||
network.gasStored = gasStored;
|
||||
}
|
||||
else {
|
||||
network.gasStored.amount += gasStored.amount;
|
||||
}
|
||||
}
|
||||
|
||||
network.gasScale = network.getScale();
|
||||
gasScale = 0;
|
||||
refGas = null;
|
||||
gasStored = null;
|
||||
|
||||
return network;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GasNetwork create(Collection<IGridTransmitter<GasNetwork>> collection)
|
||||
{
|
||||
GasNetwork network = new GasNetwork(collection);
|
||||
network.refGas = refGas;
|
||||
|
||||
if(gasStored != null)
|
||||
{
|
||||
if(network.gasStored == null)
|
||||
{
|
||||
network.gasStored = gasStored;
|
||||
}
|
||||
else {
|
||||
network.gasStored.amount += gasStored.amount;
|
||||
}
|
||||
}
|
||||
|
||||
network.gasScale = network.getScale();
|
||||
network.updateCapacity();
|
||||
return network;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GasNetwork create(Set<GasNetwork> networks)
|
||||
{
|
||||
return new GasNetwork(networks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransmissionType getTransmissionType()
|
||||
{
|
||||
return TransmissionType.GAS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNeededInfo()
|
||||
{
|
||||
return Integer.toString(getGasNeeded());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStoredInfo()
|
||||
{
|
||||
return gasStored != null ? gasStored.getGas().getLocalizedName() + " (" + gasStored.amount + ")" : "None";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlowInfo()
|
||||
{
|
||||
return Integer.toString(prevTransferAmount) + "/t";
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
public class GasRegistry
|
||||
{
|
||||
private static ArrayList<Gas> registeredGasses = new ArrayList<Gas>();
|
||||
|
||||
/**
|
||||
* Register a new gas into GasRegistry.
|
||||
* @param gas - Gas to register
|
||||
* @return the gas that has been registered, pulled right out of GasRegistry
|
||||
*/
|
||||
public static Gas register(Gas gas)
|
||||
{
|
||||
if(gas == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
registeredGasses.add(gas);
|
||||
|
||||
return getGas(gas.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gas associated with the defined ID.
|
||||
* @param id - ID to check
|
||||
* @return gas associated with defined ID
|
||||
*/
|
||||
public static Gas getGas(int id)
|
||||
{
|
||||
if(id == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return registeredGasses.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gas associated with the defined fluid.
|
||||
* @param f - fluid to check
|
||||
* @return the gas associated with the fluid
|
||||
*/
|
||||
public static Gas getGas(Fluid f)
|
||||
{
|
||||
for(Gas gas : getRegisteredGasses())
|
||||
{
|
||||
if(gas.hasFluid() && gas.getFluid() == f)
|
||||
{
|
||||
return gas;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not GasRegistry contains a gas with the specified name
|
||||
* @param name - name to check
|
||||
* @return if GasRegistry contains a gas with the defined name
|
||||
*/
|
||||
public static boolean containsGas(String name)
|
||||
{
|
||||
return getGas(name) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of all gasses registered in GasRegistry.
|
||||
* @return a cloned list of all registered gasses
|
||||
*/
|
||||
public static List<Gas> getRegisteredGasses()
|
||||
{
|
||||
return (List<Gas>)registeredGasses.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gas associated with the specified name.
|
||||
* @param name - name of the gas to get
|
||||
* @return gas associated with the name
|
||||
*/
|
||||
public static Gas getGas(String name)
|
||||
{
|
||||
for(Gas gas : registeredGasses)
|
||||
{
|
||||
if(gas.getName().toLowerCase().equals(name.toLowerCase()))
|
||||
{
|
||||
return gas;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gas ID of a specified gas.
|
||||
* @param gas - gas to get the ID from
|
||||
* @return gas ID
|
||||
*/
|
||||
public static int getGasID(Gas gas)
|
||||
{
|
||||
if(gas == null || !containsGas(gas.getName()))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return registeredGasses.indexOf(gas);
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* GasStack - a specified amount of a defined Gas with certain properties.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class GasStack
|
||||
{
|
||||
private Gas type;
|
||||
|
||||
public int amount;
|
||||
|
||||
/**
|
||||
* Creates a new GasStack with a defined gas ID and quantity.
|
||||
* @param id - gas ID to associate this GasStack to, will perform a GasRegistry lookup in the constructor
|
||||
* @param quantity - amount of gas to be referenced in this GasStack
|
||||
*/
|
||||
public GasStack(int id, int quantity)
|
||||
{
|
||||
type = GasRegistry.getGas(id);
|
||||
amount = quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new GasStack with a defined Gas type and quantity.
|
||||
* @param gas - gas type of the stack
|
||||
* @param quantity - amount of gas to be referenced in this GasStack
|
||||
*/
|
||||
public GasStack(Gas gas, int quantity)
|
||||
{
|
||||
type = gas;
|
||||
amount = quantity;
|
||||
}
|
||||
|
||||
private GasStack() {}
|
||||
|
||||
/**
|
||||
* Gets the Gas type of this GasStack.
|
||||
* @return this GasStack's Gas type
|
||||
*/
|
||||
public Gas getGas()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes this GasStack to a defined tag compound.
|
||||
* @param nbtTags - tag compound to write to
|
||||
* @return tag compound with this GasStack's data
|
||||
*/
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
type.write(nbtTags);
|
||||
nbtTags.setInteger("amount", amount);
|
||||
|
||||
return nbtTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads this GasStack's data from a defined tag compound.
|
||||
* @param nbtTags - tag compound to read from
|
||||
*/
|
||||
public void read(NBTTagCompound nbtTags)
|
||||
{
|
||||
type = Gas.readFromNBT(nbtTags);
|
||||
amount = nbtTags.getInteger("amount");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GasStack stored in the defined tag compound, or null if it doesn't exist.
|
||||
* @param nbtTags - tag compound to read from
|
||||
* @return GasStack stored in the tag compound
|
||||
*/
|
||||
public static GasStack readFromNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(nbtTags == null || nbtTags.hasNoTags())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
GasStack stack = new GasStack();
|
||||
stack.read(nbtTags);
|
||||
|
||||
if(stack.getGas() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copied form of this GasStack.
|
||||
* @return copied GasStack
|
||||
*/
|
||||
public GasStack copy()
|
||||
{
|
||||
return new GasStack(type, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this GasStack's gas type is equal to the other defined GasStack.
|
||||
* @param stack - GasStack to check
|
||||
* @return if the GasStacks contain the same gas type
|
||||
*/
|
||||
public boolean isGasEqual(GasStack stack)
|
||||
{
|
||||
return stack != null && getGas() == stack.getGas();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[" + type + ", " + amount + "]";
|
||||
}
|
||||
}
|
||||
@@ -1,241 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* An optional way of managing and/or storing gasses. Would be very useful in TileEntity and Entity gas storage.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class GasTank
|
||||
{
|
||||
public GasStack stored;
|
||||
|
||||
private int maxGas;
|
||||
|
||||
private GasTank() {}
|
||||
|
||||
/**
|
||||
* Creates a tank with a defined capacity.
|
||||
* @param max - the maximum amount of gas this GasTank can hold
|
||||
*/
|
||||
public GasTank(int max)
|
||||
{
|
||||
maxGas = max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this tank's GasStack value to a new value. Will cap the amount to this GasTank's capacity.
|
||||
* @param stack - value to set this tank's GasStack value to
|
||||
*/
|
||||
public void setGas(GasStack stack)
|
||||
{
|
||||
stored = stack;
|
||||
|
||||
if(stored != null)
|
||||
{
|
||||
stored.amount = Math.min(getMaxGas(), stored.amount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a specified amount of gas out of this tank.
|
||||
* @param amount - amount to draw
|
||||
* @param doDraw - if the gas should actually be removed from this tank
|
||||
* @return gas taken from this GasTank as a GasStack value
|
||||
*/
|
||||
public GasStack draw(int amount, boolean doDraw)
|
||||
{
|
||||
if(stored == null || amount <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
GasStack ret = new GasStack(getGas().getGas(), Math.min(getStored(), amount));
|
||||
|
||||
if(ret.amount > 0)
|
||||
{
|
||||
if(doDraw)
|
||||
{
|
||||
stored.amount -= ret.amount;
|
||||
|
||||
if(stored.amount <= 0)
|
||||
{
|
||||
stored = null;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a specified amount of gas to this tank.
|
||||
* @param amount - the GasStack for this tank to receive
|
||||
* @param doReceive - if the gas should actually be added to this tank
|
||||
* @return the amount of gas accepted by this tank
|
||||
*/
|
||||
public int receive(GasStack amount, boolean doReceive)
|
||||
{
|
||||
if(amount == null || (stored != null && stored.amount == getMaxGas()))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int toFill = Math.min(getMaxGas()-getStored(), amount.amount);
|
||||
|
||||
if(doReceive)
|
||||
{
|
||||
if(stored == null)
|
||||
{
|
||||
stored = amount.copy();
|
||||
}
|
||||
else {
|
||||
stored.amount = Math.min(getMaxGas(), getStored()+amount.amount);
|
||||
}
|
||||
}
|
||||
|
||||
return toFill;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this GasTank can receive the specified type of gas. Will return false if this tank does not need anymore gas.
|
||||
* @param gas - gas to check
|
||||
* @return if this GasTank can accept the defined gas
|
||||
*/
|
||||
public boolean canReceive(Gas gas)
|
||||
{
|
||||
if(getNeeded() == 0 || stored != null && (gas != null && gas != stored.getGas()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this GasTank can receive the specified type of gas. Will return TRUE if this tank does not need anymore gas.
|
||||
* @param gas - gas to check
|
||||
* @return if this GasTank can accept the defined gas
|
||||
*/
|
||||
public boolean canReceiveType(Gas gas)
|
||||
{
|
||||
if(stored != null && (gas != null && gas != stored.getGas()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this GasTank can be drawn of the specified type of gas. Will return false if this tank does not contain any gas.
|
||||
* @param gas - gas to check
|
||||
* @return if this GasTank can be drawn of the defined gas
|
||||
*/
|
||||
public boolean canDraw(Gas gas)
|
||||
{
|
||||
if(stored == null || (gas != null && gas != stored.getGas()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of gas needed by this GasTank.
|
||||
* @return
|
||||
*/
|
||||
public int getNeeded()
|
||||
{
|
||||
return getMaxGas()-getStored();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum amount of gas this tank can hold.
|
||||
* @return - max gas
|
||||
*/
|
||||
public int getMaxGas()
|
||||
{
|
||||
return maxGas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the GasStack held by this GasTank.
|
||||
* @return - GasStakc held by this tank
|
||||
*/
|
||||
public GasStack getGas()
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of gas currently stored in this GasTank.
|
||||
* @return gas type contained
|
||||
*/
|
||||
public Gas getGasType()
|
||||
{
|
||||
return stored != null ? stored.getGas() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of gas stored by this GasTank.
|
||||
* @return amount of gas stored
|
||||
*/
|
||||
public int getStored()
|
||||
{
|
||||
return stored != null ? stored.amount : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes this tank to a defined tag compound.
|
||||
* @param nbtTags - tag compound to write to
|
||||
* @return tag compound with this tank's data
|
||||
*/
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(stored != null)
|
||||
{
|
||||
nbtTags.setTag("stored", stored.write(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
nbtTags.setInteger("maxGas", maxGas);
|
||||
|
||||
return nbtTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads this tank's data from a defined tag compound.
|
||||
* @param nbtTags - tag compound to read from
|
||||
*/
|
||||
public void read(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(nbtTags.hasKey("stored"))
|
||||
{
|
||||
stored = GasStack.readFromNBT(nbtTags.getCompoundTag("stored"));
|
||||
}
|
||||
|
||||
maxGas = nbtTags.getInteger("maxGas");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tank stored in the defined tag compound, or null if it doesn't exist.
|
||||
* @param nbtTags - tag compound to read from
|
||||
* @return tank stored in the tag compound
|
||||
*/
|
||||
public static GasTank readFromNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(nbtTags == null || nbtTags.hasNoTags())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
GasTank tank = new GasTank();
|
||||
tank.read(nbtTags);
|
||||
|
||||
return tank;
|
||||
}
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* A handy class containing several utilities for efficient gas transfer.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public final class GasTransmission
|
||||
{
|
||||
/**
|
||||
* Gets all the tubes around a tile entity.
|
||||
* @param tileEntity - center tile entity
|
||||
* @return array of TileEntities
|
||||
*/
|
||||
public static TileEntity[] getConnectedTubes(TileEntity tileEntity)
|
||||
{
|
||||
TileEntity[] tubes = new TileEntity[] {null, null, null, null, null, null};
|
||||
|
||||
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tube = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
|
||||
|
||||
if(TransmissionType.checkTransmissionType(tube, TransmissionType.GAS, tileEntity))
|
||||
{
|
||||
tubes[orientation.ordinal()] = tube;
|
||||
}
|
||||
}
|
||||
|
||||
return tubes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the acceptors around a tile entity.
|
||||
* @param tileEntity - center tile entity
|
||||
* @return array of IGasAcceptors
|
||||
*/
|
||||
public static IGasHandler[] getConnectedAcceptors(TileEntity tileEntity)
|
||||
{
|
||||
IGasHandler[] acceptors = new IGasHandler[] {null, null, null, null, null, null};
|
||||
|
||||
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity acceptor = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
|
||||
|
||||
if(acceptor instanceof IGasHandler)
|
||||
{
|
||||
acceptors[orientation.ordinal()] = (IGasHandler)acceptor;
|
||||
}
|
||||
}
|
||||
|
||||
return acceptors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the tube connections around a tile entity.
|
||||
* @param tileEntity - center tile entity
|
||||
* @return array of ITubeConnections
|
||||
*/
|
||||
public static ITubeConnection[] getConnections(TileEntity tileEntity)
|
||||
{
|
||||
ITubeConnection[] connections = new ITubeConnection[] {null, null, null, null, null, null};
|
||||
|
||||
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity connection = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
|
||||
|
||||
if(canConnect(connection, orientation))
|
||||
{
|
||||
connections[orientation.ordinal()] = (ITubeConnection)connection;
|
||||
}
|
||||
}
|
||||
|
||||
return connections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not a TileEntity can connect to a specified tile on a specified side.
|
||||
* @param tileEntity - TileEntity to attempt connection to
|
||||
* @param side - side to attempt connection on
|
||||
* @return if this tile and side are connectable
|
||||
*/
|
||||
public static boolean canConnect(TileEntity tileEntity, ForgeDirection side)
|
||||
{
|
||||
if(tileEntity instanceof ITubeConnection && (!(tileEntity instanceof IGasTransmitter) || TransmissionType.checkTransmissionType(tileEntity, TransmissionType.GAS, tileEntity)))
|
||||
{
|
||||
if(((ITubeConnection)tileEntity).canTubeConnect(side.getOpposite()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a specified amount of gas from an IGasItem.
|
||||
* @param itemStack - ItemStack of the IGasItem
|
||||
* @param type - type of gas to remove from the IGasItem, null if it doesn't matter
|
||||
* @param amount - amount of gas to remove from the ItemStack
|
||||
* @return the GasStack removed by the IGasItem
|
||||
*/
|
||||
public static GasStack removeGas(ItemStack itemStack, Gas type, int amount)
|
||||
{
|
||||
if(itemStack != null && itemStack.getItem() instanceof IGasItem)
|
||||
{
|
||||
IGasItem item = (IGasItem)itemStack.getItem();
|
||||
|
||||
if(type != null && item.getGas(itemStack) != null && item.getGas(itemStack).getGas() != type || !item.canProvideGas(itemStack, type))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return item.removeGas(itemStack, amount);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a specified amount of gas to an IGasItem.
|
||||
* @param itemStack - ItemStack of the IGasItem
|
||||
* @param stack - stack to add to the IGasItem
|
||||
* @return amount of gas accepted by the IGasItem
|
||||
*/
|
||||
public static int addGas(ItemStack itemStack, GasStack stack)
|
||||
{
|
||||
if(itemStack != null && itemStack.getItem() instanceof IGasItem && ((IGasItem)itemStack.getItem()).canReceiveGas(itemStack, stack.getGas()))
|
||||
{
|
||||
return ((IGasItem)itemStack.getItem()).addGas(itemStack, stack.copy());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this if your tile entity accepts gas from an external source.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public interface IGasHandler
|
||||
{
|
||||
/**
|
||||
* Transfer a certain amount of gas to this block.
|
||||
* @param stack - gas to add
|
||||
* @return gas added
|
||||
*/
|
||||
public int receiveGas(ForgeDirection side, GasStack stack);
|
||||
|
||||
/**
|
||||
* Draws a certain amount of gas from this block.
|
||||
* @param amount - amount to draw
|
||||
* @return gas drawn
|
||||
*/
|
||||
public GasStack drawGas(ForgeDirection side, int amount);
|
||||
|
||||
/**
|
||||
* Whether or not this block can accept gas from a certain side.
|
||||
* @param side - side to check
|
||||
* @param type - type of gas to check
|
||||
* @return if block accepts gas
|
||||
*/
|
||||
public boolean canReceiveGas(ForgeDirection side, Gas type);
|
||||
|
||||
/**
|
||||
* Whether or not this block can be drawn of gas from a certain side.
|
||||
* @param side - side to check
|
||||
* @param type - type of gas to check
|
||||
* @return if block can be drawn of gas
|
||||
*/
|
||||
public boolean canDrawGas(ForgeDirection side, Gas type);
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this in your item class if it can store or transfer certain gasses.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public interface IGasItem
|
||||
{
|
||||
/**
|
||||
* Gets the rate of transfer this item can handle.
|
||||
* @return
|
||||
*/
|
||||
public int getRate(ItemStack itemstack);
|
||||
|
||||
/**
|
||||
* Adds a defined amount of a certain gas to an item.
|
||||
* @param itemstack - the itemstack to add gas to
|
||||
* @param type - the type of gas to add
|
||||
* @param amount - the amount of gas to add
|
||||
* @return the gas that was accepted by the item
|
||||
*/
|
||||
public int addGas(ItemStack itemstack, GasStack stack);
|
||||
|
||||
/**
|
||||
* Removes the defined amount of a certain gas from the item.
|
||||
* @param itemstack - the itemstack to remove gas from
|
||||
* @param type - the type of gas to remove
|
||||
* @param amount - the amount of gas to remove
|
||||
* @return the gas that was removed by the item
|
||||
*/
|
||||
public GasStack removeGas(ItemStack itemstack, int amount);
|
||||
|
||||
/**
|
||||
* Whether or not this storage tank be given a specific gas.
|
||||
* @param itemstack - the itemstack to check
|
||||
* @param type - the type of gas the tank can possibly receive
|
||||
* @return if the item be charged
|
||||
*/
|
||||
public boolean canReceiveGas(ItemStack itemstack, Gas type);
|
||||
|
||||
/**
|
||||
* Whether or not this item can give a gas receiver a certain type of gas.
|
||||
* @param itemstack - the itemstack to check
|
||||
* @param type - the type of gas the tank can provide
|
||||
* @return if the item can provide gas
|
||||
*/
|
||||
public boolean canProvideGas(ItemStack itemstack, Gas type);
|
||||
|
||||
/**
|
||||
* Get the gas of a declared type.
|
||||
* @param type - type of gas
|
||||
* @param data - ItemStack parameter if necessary
|
||||
* @return gas stored
|
||||
*/
|
||||
public GasStack getGas(ItemStack itemstack);
|
||||
|
||||
/**
|
||||
* Set the gas of a declared type to a new amount;
|
||||
* @param type - type of gas
|
||||
* @param data - ItemStack parameter if necessary
|
||||
* @param amount - amount to store
|
||||
*/
|
||||
public void setGas(ItemStack itemstack, GasStack stack);
|
||||
|
||||
/**
|
||||
* Gets the maximum amount of gas this tile entity can store.
|
||||
* @param type - type of gas
|
||||
* @param data - ItemStack parameter if necessary
|
||||
* @return maximum gas
|
||||
*/
|
||||
public int getMaxGas(ItemStack itemstack);
|
||||
|
||||
/**
|
||||
* Returns whether or not this item contains metadata-specific subtypes instead of using metadata for damage display.
|
||||
* @return if the item contains metadata-specific subtypes
|
||||
*/
|
||||
public boolean isMetadataSpecific(ItemStack itemstack);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public interface IGasTransmitter extends IGridTransmitter<GasNetwork>
|
||||
{
|
||||
public boolean canTransferGasToTube(TileEntity tile);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this if your block can connect to Pressurized Tubes.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public interface ITubeConnection
|
||||
{
|
||||
/**
|
||||
* Whether or not a tube can connect to a certain orientation.
|
||||
* @param side - orientation to check
|
||||
* @return if a tube can connect
|
||||
*/
|
||||
public boolean canTubeConnect(ForgeDirection side);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package mekanism.api.gas;
|
||||
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class OreGas extends Gas
|
||||
{
|
||||
private String oreName;
|
||||
private OreGas cleanGas;
|
||||
|
||||
public OreGas(String s, String name)
|
||||
{
|
||||
super(s);
|
||||
|
||||
oreName = name;
|
||||
}
|
||||
|
||||
public boolean isClean()
|
||||
{
|
||||
return getCleanGas() == null;
|
||||
}
|
||||
|
||||
public OreGas getCleanGas()
|
||||
{
|
||||
return cleanGas;
|
||||
}
|
||||
|
||||
public OreGas setCleanGas(OreGas gas)
|
||||
{
|
||||
cleanGas = gas;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getOreName()
|
||||
{
|
||||
return StatCollector.translateToLocal(oreName);
|
||||
}
|
||||
}
|
||||
@@ -1,537 +0,0 @@
|
||||
package mekanism.api.transmitters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.IClientTicker;
|
||||
import mekanism.api.Range4D;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implements ITransmitterNetwork<A, N>, IClientTicker, INetworkDataHandler
|
||||
{
|
||||
public LinkedHashSet<IGridTransmitter<N>> transmitters = new LinkedHashSet<IGridTransmitter<N>>();
|
||||
|
||||
public HashMap<Coord4D, A> possibleAcceptors = new HashMap<Coord4D, A>();
|
||||
public HashMap<A, ForgeDirection> acceptorDirections = new HashMap<A, ForgeDirection>();
|
||||
|
||||
private List<DelayQueue> updateQueue = new ArrayList<DelayQueue>();
|
||||
|
||||
protected Range4D packetRange = null;
|
||||
|
||||
protected int ticksSinceCreate = 0;
|
||||
|
||||
protected int capacity = 0;
|
||||
protected double meanCapacity = 0;
|
||||
|
||||
protected boolean fixed = false;
|
||||
|
||||
protected boolean needsUpdate = false;
|
||||
|
||||
protected abstract ITransmitterNetwork<A, N> create(IGridTransmitter<N>... varTransmitters);
|
||||
|
||||
protected abstract ITransmitterNetwork<A, N> create(Collection<IGridTransmitter<N>> collection);
|
||||
|
||||
protected abstract ITransmitterNetwork<A, N> create(Set<N> networks);
|
||||
|
||||
protected void clearAround(IGridTransmitter<N> transmitter)
|
||||
{
|
||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
Coord4D coord = Coord4D.get(transmitter.getTile()).getFromSide(side);
|
||||
|
||||
if(possibleAcceptors.containsKey(coord))
|
||||
{
|
||||
clearIfNecessary(coord, transmitter, side.getOpposite());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void clearIfNecessary(Coord4D acceptor, IGridTransmitter<N> transmitter, ForgeDirection side)
|
||||
{
|
||||
if(getWorld() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(acceptor.getTileEntity(getWorld()) == null || acceptor.getTileEntity(getWorld()).isInvalid() || transmitter.canConnectToAcceptor(side, true))
|
||||
{
|
||||
possibleAcceptors.remove(acceptor);
|
||||
acceptorDirections.remove(acceptor.getTileEntity(getWorld()));
|
||||
}
|
||||
}
|
||||
|
||||
public void addAllTransmitters(Set<IGridTransmitter<N>> newTransmitters)
|
||||
{
|
||||
transmitters.addAll(newTransmitters);
|
||||
updateCapacity();
|
||||
}
|
||||
|
||||
public boolean isFirst(IGridTransmitter<N> transmitter)
|
||||
{
|
||||
return transmitters.iterator().next().equals(transmitter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fullRefresh()
|
||||
{
|
||||
possibleAcceptors.clear();
|
||||
acceptorDirections.clear();
|
||||
|
||||
for(IGridTransmitter<N> transmitter : transmitters)
|
||||
{
|
||||
refresh(transmitter);
|
||||
}
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
public Range4D getPacketRange()
|
||||
{
|
||||
if(packetRange == null)
|
||||
{
|
||||
return genPacketRange();
|
||||
}
|
||||
|
||||
return packetRange;
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
if(getSize() == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return transmitters.iterator().next().getTile().getWorldObj();
|
||||
}
|
||||
|
||||
protected Range4D genPacketRange()
|
||||
{
|
||||
if(getSize() == 0)
|
||||
{
|
||||
deregister();
|
||||
return null;
|
||||
}
|
||||
|
||||
Coord4D initCoord = Coord4D.get(transmitters.iterator().next().getTile());
|
||||
|
||||
int minX = initCoord.xCoord;
|
||||
int minY = initCoord.yCoord;
|
||||
int minZ = initCoord.zCoord;
|
||||
int maxX = initCoord.xCoord;
|
||||
int maxY = initCoord.yCoord;
|
||||
int maxZ = initCoord.zCoord;
|
||||
|
||||
for(IGridTransmitter transmitter : transmitters)
|
||||
{
|
||||
Coord4D coord = Coord4D.get(transmitter.getTile());
|
||||
|
||||
if(coord.xCoord < minX) minX = coord.xCoord;
|
||||
if(coord.yCoord < minY) minY = coord.yCoord;
|
||||
if(coord.zCoord < minZ) minZ = coord.zCoord;
|
||||
if(coord.xCoord > maxX) maxX = coord.xCoord;
|
||||
if(coord.yCoord > maxY) maxY = coord.yCoord;
|
||||
if(coord.zCoord > maxZ) maxZ = coord.zCoord;
|
||||
}
|
||||
|
||||
return new Range4D(minX, minY, minZ, maxX, maxY, maxZ, getWorld().provider.dimensionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTransmitter(IGridTransmitter<N> transmitter)
|
||||
{
|
||||
transmitters.remove(transmitter);
|
||||
updateCapacity();
|
||||
|
||||
if(transmitters.size() == 0)
|
||||
{
|
||||
deregister();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register()
|
||||
{
|
||||
try {
|
||||
IGridTransmitter<N> aTransmitter = transmitters.iterator().next();
|
||||
|
||||
if(aTransmitter instanceof TileEntity)
|
||||
{
|
||||
if(!((TileEntity)aTransmitter).getWorldObj().isRemote)
|
||||
{
|
||||
TransmitterNetworkRegistry.getInstance().registerNetwork(this);
|
||||
}
|
||||
else {
|
||||
MinecraftForge.EVENT_BUS.post(new ClientTickUpdate(this, (byte)1));
|
||||
}
|
||||
}
|
||||
} catch(NoSuchElementException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister()
|
||||
{
|
||||
transmitters.clear();
|
||||
|
||||
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
TransmitterNetworkRegistry.getInstance().removeNetwork(this);
|
||||
}
|
||||
else {
|
||||
MinecraftForge.EVENT_BUS.post(new ClientTickUpdate(this, (byte)0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize()
|
||||
{
|
||||
return transmitters.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAcceptorSize()
|
||||
{
|
||||
return possibleAcceptors.size();
|
||||
}
|
||||
|
||||
public synchronized void updateCapacity()
|
||||
{
|
||||
updateMeanCapacity();
|
||||
capacity = (int)meanCapacity * transmitters.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this if things can have variable capacity along the network.
|
||||
* @return An 'average' value of capacity. Calculate it how you will.
|
||||
*/
|
||||
protected synchronized void updateMeanCapacity()
|
||||
{
|
||||
if(transmitters.size() > 0)
|
||||
{
|
||||
meanCapacity = transmitters.iterator().next().getCapacity();
|
||||
}
|
||||
else {
|
||||
meanCapacity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCapacity()
|
||||
{
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public double getMeanCapacity()
|
||||
{
|
||||
return meanCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
boolean didFix = false;
|
||||
|
||||
if(!fixed)
|
||||
{
|
||||
ticksSinceCreate++;
|
||||
|
||||
if(transmitters.size() == 0)
|
||||
{
|
||||
deregister();
|
||||
return;
|
||||
}
|
||||
|
||||
if(ticksSinceCreate > 1200)
|
||||
{
|
||||
ticksSinceCreate = 0;
|
||||
fixMessedUpNetwork(transmitters.iterator().next());
|
||||
didFix = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!didFix)
|
||||
{
|
||||
onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public void onUpdate()
|
||||
{
|
||||
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
Iterator<DelayQueue> i = updateQueue.iterator();
|
||||
|
||||
try {
|
||||
while(i.hasNext())
|
||||
{
|
||||
DelayQueue q = i.next();
|
||||
|
||||
if(q.delay > 0)
|
||||
{
|
||||
q.delay--;
|
||||
}
|
||||
else {
|
||||
needsUpdate = true;
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void fixMessedUpNetwork(IGridTransmitter<N> transmitter)
|
||||
{
|
||||
if(transmitter instanceof TileEntity)
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)transmitter).getWorldObj(), getTransmissionType(), Coord4D.get((TileEntity)transmitter));
|
||||
List<Coord4D> partNetwork = finder.exploreNetwork();
|
||||
Set<IGridTransmitter<N>> newTransporters = new HashSet<IGridTransmitter<N>>();
|
||||
|
||||
for(Coord4D node : partNetwork)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity)transmitter).getWorldObj());
|
||||
|
||||
if(TransmissionType.checkTransmissionType(nodeTile, getTransmissionType(), (TileEntity)transmitter))
|
||||
{
|
||||
((IGridTransmitter<N>)nodeTile).removeFromTransmitterNetwork();
|
||||
newTransporters.add((IGridTransmitter<N>)nodeTile);
|
||||
}
|
||||
}
|
||||
|
||||
ITransmitterNetwork<A, N> newNetwork = create(newTransporters);
|
||||
newNetwork.fullRefresh();
|
||||
newNetwork.setFixed(true);
|
||||
deregister();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void split(IGridTransmitter<N> splitPoint)
|
||||
{
|
||||
if(splitPoint instanceof TileEntity)
|
||||
{
|
||||
removeTransmitter(splitPoint);
|
||||
|
||||
TileEntity[] connectedBlocks = new TileEntity[6];
|
||||
boolean[] dealtWith = {false, false, false, false, false, false};
|
||||
List<ITransmitterNetwork<A, N>> newNetworks = new ArrayList<ITransmitterNetwork<A, N>>();
|
||||
|
||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity sideTile = Coord4D.get((TileEntity)splitPoint).getFromSide(side).getTileEntity(((TileEntity)splitPoint).getWorldObj());
|
||||
|
||||
if(sideTile != null)
|
||||
{
|
||||
connectedBlocks[side.ordinal()] = sideTile;
|
||||
}
|
||||
}
|
||||
|
||||
for(int count = 0; count < connectedBlocks.length; count++)
|
||||
{
|
||||
TileEntity connectedBlockA = connectedBlocks[count];
|
||||
|
||||
if(TransmissionType.checkTransmissionType(connectedBlockA, getTransmissionType()) && !dealtWith[count])
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).getWorldObj(), getTransmissionType(), Coord4D.get(connectedBlockA), Coord4D.get((TileEntity)splitPoint));
|
||||
List<Coord4D> partNetwork = finder.exploreNetwork();
|
||||
|
||||
for(int check = count; check < connectedBlocks.length; check++)
|
||||
{
|
||||
if(check == count)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TileEntity connectedBlockB = connectedBlocks[check];
|
||||
|
||||
if(TransmissionType.checkTransmissionType(connectedBlockB, getTransmissionType()) && !dealtWith[check])
|
||||
{
|
||||
if(partNetwork.contains(Coord4D.get(connectedBlockB)))
|
||||
{
|
||||
dealtWith[check] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set<IGridTransmitter<N>> newNetCables = new HashSet<IGridTransmitter<N>>();
|
||||
|
||||
for(Coord4D node : finder.iterated)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity)splitPoint).getWorldObj());
|
||||
|
||||
if(TransmissionType.checkTransmissionType(nodeTile, getTransmissionType()))
|
||||
{
|
||||
if(nodeTile != splitPoint)
|
||||
{
|
||||
newNetCables.add((IGridTransmitter<N>)nodeTile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newNetworks.add(create(newNetCables));
|
||||
}
|
||||
}
|
||||
|
||||
if(newNetworks.size() > 0)
|
||||
{
|
||||
onNetworksCreated((List)newNetworks);
|
||||
|
||||
for(ITransmitterNetwork<A, N> network : newNetworks)
|
||||
{
|
||||
network.fullRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
deregister();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetworksCreated(List<N> networks) {}
|
||||
|
||||
@Override
|
||||
public void setFixed(boolean value)
|
||||
{
|
||||
fixed = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsTicks()
|
||||
{
|
||||
return getSize() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientTick()
|
||||
{
|
||||
ticksSinceCreate++;
|
||||
|
||||
if(ticksSinceCreate == 5 && getSize() > 0)
|
||||
{
|
||||
TileEntity tile = (TileEntity)transmitters.iterator().next();
|
||||
MinecraftForge.EVENT_BUS.post(new NetworkClientRequest(tile));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMerge(List<ITransmitterNetwork<?, ?>> networks)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class ClientTickUpdate extends Event
|
||||
{
|
||||
public DynamicNetwork network;
|
||||
public byte operation; /*0 remove, 1 add*/
|
||||
|
||||
public ClientTickUpdate(DynamicNetwork net, byte b)
|
||||
{
|
||||
network = net;
|
||||
operation = b;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NetworkClientRequest extends Event
|
||||
{
|
||||
public TileEntity tileEntity;
|
||||
|
||||
public NetworkClientRequest(TileEntity tile)
|
||||
{
|
||||
tileEntity = tile;
|
||||
}
|
||||
}
|
||||
|
||||
public void addUpdate(EntityPlayer player)
|
||||
{
|
||||
updateQueue.add(new DelayQueue(player));
|
||||
}
|
||||
|
||||
public static class NetworkFinder
|
||||
{
|
||||
public TransmissionType transmissionType;
|
||||
|
||||
public World worldObj;
|
||||
public Coord4D start;
|
||||
|
||||
public List<Coord4D> iterated = new ArrayList<Coord4D>();
|
||||
public List<Coord4D> toIgnore = new ArrayList<Coord4D>();
|
||||
|
||||
public NetworkFinder(World world, TransmissionType type, Coord4D location, Coord4D... ignore)
|
||||
{
|
||||
worldObj = world;
|
||||
start = location;
|
||||
|
||||
transmissionType = type;
|
||||
|
||||
if(ignore != null)
|
||||
{
|
||||
for(int i = 0; i < ignore.length; i++)
|
||||
{
|
||||
toIgnore.add(ignore[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loopAll(Coord4D location)
|
||||
{
|
||||
if(TransmissionType.checkTransmissionType(location.getTileEntity(worldObj), transmissionType))
|
||||
{
|
||||
iterated.add(location);
|
||||
}
|
||||
else {
|
||||
toIgnore.add(location);
|
||||
}
|
||||
|
||||
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
Coord4D obj = location.getFromSide(direction);
|
||||
|
||||
if(!iterated.contains(obj) && !toIgnore.contains(obj))
|
||||
{
|
||||
TileEntity tileEntity = obj.getTileEntity(worldObj);
|
||||
|
||||
if(!(tileEntity instanceof IBlockableConnection) || ((IBlockableConnection)tileEntity).canConnectMutual(direction.getOpposite()))
|
||||
{
|
||||
if(TransmissionType.checkTransmissionType(tileEntity, transmissionType, location.getTileEntity(worldObj)))
|
||||
{
|
||||
loopAll(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Coord4D> exploreNetwork()
|
||||
{
|
||||
loopAll(start);
|
||||
|
||||
return iterated;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DelayQueue
|
||||
{
|
||||
public EntityPlayer player;
|
||||
public int delay;
|
||||
|
||||
public DelayQueue(EntityPlayer p)
|
||||
{
|
||||
player = p;
|
||||
delay = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package mekanism.api.transmitters;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IBlockableConnection
|
||||
{
|
||||
public boolean canConnectMutual(ForgeDirection side);
|
||||
|
||||
public boolean canConnect(ForgeDirection side);
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package mekanism.api.transmitters;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IGridTransmitter<N extends DynamicNetwork<?, N>> extends ITransmitter
|
||||
{
|
||||
/**
|
||||
* Gets the network currently in use by this transmitter segment.
|
||||
* @return network this transmitter is using
|
||||
*/
|
||||
public N getTransmitterNetwork();
|
||||
|
||||
/**
|
||||
* Gets the network currently in use by this transmitter segment.
|
||||
* @param createIfNull - If true, the transmitter will try and connect to an
|
||||
* adjacent network, merging several if necessary, or creating a new one
|
||||
* if none is available
|
||||
* @return network this transmitter is using
|
||||
*/
|
||||
public N getTransmitterNetwork(boolean createIfNull);
|
||||
|
||||
/**
|
||||
* Sets this transmitter segment's network to a new value.
|
||||
* @param network - network to set to
|
||||
*/
|
||||
public void setTransmitterNetwork(N network);
|
||||
|
||||
/**
|
||||
* Refreshes the transmitter's network.
|
||||
*/
|
||||
public void refreshTransmitterNetwork();
|
||||
|
||||
/**
|
||||
* Called when the chunk this transmitter is in is loaded.
|
||||
*/
|
||||
public void chunkLoad();
|
||||
|
||||
/**
|
||||
* Remove this transmitter from its network.
|
||||
*/
|
||||
public void removeFromTransmitterNetwork();
|
||||
|
||||
public boolean canConnectToAcceptor(ForgeDirection side, boolean ignoreActive);
|
||||
|
||||
/**
|
||||
* Call this if you're worried a transmitter's network is messed up and you want
|
||||
* it to try and fix itself.
|
||||
*/
|
||||
public void fixTransmitterNetwork();
|
||||
|
||||
public boolean areTransmitterNetworksEqual(TileEntity tileEntity);
|
||||
|
||||
public int getTransmitterNetworkSize();
|
||||
|
||||
public int getTransmitterNetworkAcceptorSize();
|
||||
|
||||
public String getTransmitterNetworkNeeded();
|
||||
|
||||
public String getTransmitterNetworkFlow();
|
||||
|
||||
public int getCapacity();
|
||||
|
||||
public TileEntity getTile();
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package mekanism.api.transmitters;
|
||||
|
||||
public interface INetworkDataHandler
|
||||
{
|
||||
public String getNeededInfo();
|
||||
|
||||
public String getStoredInfo();
|
||||
|
||||
public String getFlowInfo();
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package mekanism.api.transmitters;
|
||||
|
||||
public interface ITransmitter
|
||||
{
|
||||
/**
|
||||
* Get the transmitter's transmission type
|
||||
*
|
||||
* @return TransmissionType this transmitter uses
|
||||
*/
|
||||
public TransmissionType getTransmissionType();
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package mekanism.api.transmitters;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ITransmitterNetwork<A, N extends DynamicNetwork<A, N>>
|
||||
{
|
||||
public void tick();
|
||||
|
||||
public int getSize();
|
||||
|
||||
public int getAcceptorSize();
|
||||
|
||||
public Set<A> getAcceptors(Object... data);
|
||||
|
||||
public void removeTransmitter(IGridTransmitter<N> transmitter);
|
||||
|
||||
public void refresh();
|
||||
|
||||
public void fullRefresh();
|
||||
|
||||
public void refresh(IGridTransmitter<N> transmitter);
|
||||
|
||||
public void split(IGridTransmitter<N> splitPoint);
|
||||
|
||||
public void fixMessedUpNetwork(IGridTransmitter<N> transmitter);
|
||||
|
||||
public void register();
|
||||
|
||||
public void deregister();
|
||||
|
||||
public void setFixed(boolean value);
|
||||
|
||||
public TransmissionType getTransmissionType();
|
||||
|
||||
public boolean canMerge(List<ITransmitterNetwork<?, ?>> networks);
|
||||
|
||||
public void onNetworksCreated(List<N> networks);
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package mekanism.api.transmitters;
|
||||
|
||||
import mekanism.api.gas.IGasTransmitter;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public enum TransmissionType
|
||||
{
|
||||
ENERGY,
|
||||
FLUID,
|
||||
GAS,
|
||||
ITEM;
|
||||
|
||||
public static boolean checkTransmissionType(TileEntity sideTile, TransmissionType type)
|
||||
{
|
||||
return checkTransmissionType(sideTile, type, null);
|
||||
}
|
||||
|
||||
public static boolean checkTransmissionType(TileEntity sideTile, TransmissionType type, TileEntity currentPipe)
|
||||
{
|
||||
return type.checkTransmissionType(sideTile, currentPipe);
|
||||
}
|
||||
|
||||
public boolean checkTransmissionType(TileEntity sideTile, TileEntity currentTile)
|
||||
{
|
||||
if(sideTile instanceof ITransmitter)
|
||||
{
|
||||
if(((ITransmitter)sideTile).getTransmissionType() == this)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(this == GAS && currentTile instanceof IGasTransmitter)
|
||||
{
|
||||
if(((IGasTransmitter)currentTile).canTransferGasToTube(sideTile))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
package mekanism.api.transmitters;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class TransmitterNetworkRegistry
|
||||
{
|
||||
private static TransmitterNetworkRegistry INSTANCE = new TransmitterNetworkRegistry();
|
||||
private static boolean loaderRegistered = false;
|
||||
|
||||
private HashSet<ITransmitterNetwork> networks = new HashSet<ITransmitterNetwork>();
|
||||
|
||||
public static void initiate()
|
||||
{
|
||||
if(!loaderRegistered)
|
||||
{
|
||||
loaderRegistered = true;
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new NetworkLoader());
|
||||
FMLCommonHandler.instance().bus().register(INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
public static TransmitterNetworkRegistry getInstance()
|
||||
{
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void registerNetwork(ITransmitterNetwork network)
|
||||
{
|
||||
networks.add(network);
|
||||
}
|
||||
|
||||
public void removeNetwork(ITransmitterNetwork network)
|
||||
{
|
||||
if(networks.contains(network))
|
||||
{
|
||||
networks.remove(network);
|
||||
}
|
||||
}
|
||||
|
||||
public void pruneEmptyNetworks()
|
||||
{
|
||||
HashSet<ITransmitterNetwork> copySet = new HashSet<ITransmitterNetwork>(networks);
|
||||
|
||||
for(ITransmitterNetwork e : copySet)
|
||||
{
|
||||
if(e.getSize() == 0)
|
||||
{
|
||||
removeNetwork(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(ServerTickEvent event)
|
||||
{
|
||||
if(event.phase == Phase.END && event.side == Side.SERVER)
|
||||
{
|
||||
tickEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public void tickEnd()
|
||||
{
|
||||
Set<ITransmitterNetwork> iterNetworks = (Set<ITransmitterNetwork>)networks.clone();
|
||||
|
||||
for(ITransmitterNetwork net : iterNetworks)
|
||||
{
|
||||
if(networks.contains(net))
|
||||
{
|
||||
net.tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Network Registry:\n" + networks;
|
||||
}
|
||||
|
||||
public String[] toStrings()
|
||||
{
|
||||
String[] strings = new String[networks.size()];
|
||||
int i = 0;
|
||||
|
||||
for(ITransmitterNetwork<?, ?> network : networks)
|
||||
{
|
||||
strings[i] = network.toString();
|
||||
++i;
|
||||
}
|
||||
|
||||
return strings;
|
||||
}
|
||||
|
||||
public static class NetworkLoader
|
||||
{
|
||||
@SubscribeEvent
|
||||
public void onChunkLoad(ChunkEvent.Load event)
|
||||
{
|
||||
if(event.getChunk() != null && !event.world.isRemote)
|
||||
{
|
||||
int x = event.getChunk().xPosition;
|
||||
int z = event.getChunk().zPosition;
|
||||
|
||||
IChunkProvider cProvider = event.getChunk().worldObj.getChunkProvider();
|
||||
Chunk[] neighbors = new Chunk[5];
|
||||
|
||||
neighbors[0] = event.getChunk();
|
||||
|
||||
if(cProvider.chunkExists(x + 1, z)) neighbors[1] = cProvider.provideChunk(x + 1, z);
|
||||
if(cProvider.chunkExists(x - 1, z)) neighbors[2] = cProvider.provideChunk(x - 1, z);
|
||||
if(cProvider.chunkExists(x, z + 1)) neighbors[3] = cProvider.provideChunk(x, z + 1);
|
||||
if(cProvider.chunkExists(x, z - 1)) neighbors[4] = cProvider.provideChunk(x, z - 1);
|
||||
|
||||
for(Chunk c : neighbors)
|
||||
{
|
||||
refreshChunk(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void refreshChunk(Chunk c)
|
||||
{
|
||||
try {
|
||||
if(c != null)
|
||||
{
|
||||
Map copy = (Map)((HashMap)c.chunkTileEntityMap).clone();
|
||||
|
||||
for(Iterator iter = copy.values().iterator(); iter.hasNext();)
|
||||
{
|
||||
Object obj = iter.next();
|
||||
|
||||
if(obj instanceof IGridTransmitter)
|
||||
{
|
||||
((IGridTransmitter)obj).refreshTransmitterNetwork();
|
||||
((IGridTransmitter)obj).chunkLoad();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user