2014-09-03 02:51:00 +02:00
|
|
|
package mekanism.common.tile;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import mekanism.api.gas.Gas;
|
|
|
|
import mekanism.api.gas.GasRegistry;
|
|
|
|
import mekanism.api.gas.GasStack;
|
|
|
|
import mekanism.api.gas.GasTank;
|
|
|
|
import mekanism.api.gas.IGasHandler;
|
|
|
|
import mekanism.api.gas.ITubeConnection;
|
2014-09-04 05:26:55 +02:00
|
|
|
import mekanism.common.recipe.RecipeHandler;
|
|
|
|
import mekanism.common.recipe.RecipeHandler.Recipe;
|
2014-09-03 02:51:00 +02:00
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
|
|
|
public class TileEntityAmbientAccumulator extends TileEntityContainerBlock implements IGasHandler, ITubeConnection
|
|
|
|
{
|
|
|
|
public GasTank collectedGas = new GasTank(1000);
|
|
|
|
|
2014-09-04 05:26:55 +02:00
|
|
|
public int cachedDimensionId = 0;
|
|
|
|
public GasStack cachedGas;
|
2014-09-03 02:51:00 +02:00
|
|
|
|
|
|
|
public static Random gasRand = new Random();
|
|
|
|
|
|
|
|
public TileEntityAmbientAccumulator()
|
|
|
|
{
|
|
|
|
super("AmbientAccumulator");
|
|
|
|
inventory = new ItemStack[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
|
|
|
if(!worldObj.isRemote)
|
|
|
|
{
|
2014-09-04 05:26:55 +02:00
|
|
|
if(cachedGas == null || worldObj.provider.dimensionId != cachedDimensionId)
|
|
|
|
{
|
|
|
|
cachedDimensionId = worldObj.provider.dimensionId;
|
|
|
|
cachedGas = RecipeHandler.getDimensionGas(cachedDimensionId);
|
|
|
|
}
|
2014-09-03 02:51:00 +02:00
|
|
|
|
2014-09-04 05:26:55 +02:00
|
|
|
if(cachedGas != null && gasRand.nextDouble() < 0.05)
|
2014-09-03 02:51:00 +02:00
|
|
|
{
|
2014-09-04 05:26:55 +02:00
|
|
|
collectedGas.receive(cachedGas, true);
|
2014-09-03 02:51:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int receiveGas(ForgeDirection side, GasStack stack, boolean doTransfer)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public GasStack drawGas(ForgeDirection side, int amount, boolean doTransfer)
|
|
|
|
{
|
|
|
|
return collectedGas.draw(amount, doTransfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canReceiveGas(ForgeDirection side, Gas type)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrawGas(ForgeDirection side, Gas type)
|
|
|
|
{
|
|
|
|
return type == collectedGas.getGasType();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canTubeConnect(ForgeDirection side)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList getNetworkedData(ArrayList data)
|
|
|
|
{
|
|
|
|
if(collectedGas.getGasType() != null)
|
|
|
|
{
|
|
|
|
data.add(collectedGas.getGasType().getID());
|
|
|
|
data.add(collectedGas.getStored());
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
data.add(-1);
|
|
|
|
data.add(0);
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handlePacketData(ByteBuf data)
|
|
|
|
{
|
|
|
|
int gasID = data.readInt();
|
|
|
|
if(gasID < 0)
|
|
|
|
{
|
|
|
|
collectedGas.setGas(null);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
collectedGas.setGas(new GasStack(gasID, data.readInt()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|