2014-09-03 02:51:00 +02:00
|
|
|
package mekanism.common.tile;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import mekanism.api.gas.Gas;
|
|
|
|
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;
|
2014-09-05 05:20:12 +02:00
|
|
|
import mekanism.common.recipe.inputs.IntegerInput;
|
|
|
|
import mekanism.common.recipe.machines.AmbientGasRecipe;
|
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;
|
2014-09-05 05:20:12 +02:00
|
|
|
public AmbientGasRecipe cachedRecipe;
|
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-05 05:20:12 +02:00
|
|
|
if(cachedRecipe == null || worldObj.provider.dimensionId != cachedDimensionId)
|
2014-09-04 05:26:55 +02:00
|
|
|
{
|
|
|
|
cachedDimensionId = worldObj.provider.dimensionId;
|
2014-09-05 05:20:12 +02:00
|
|
|
cachedRecipe = RecipeHandler.getDimensionGas(new IntegerInput(cachedDimensionId));
|
2014-09-04 05:26:55 +02:00
|
|
|
}
|
2014-09-03 02:51:00 +02:00
|
|
|
|
2015-02-18 03:27:35 +01:00
|
|
|
if(cachedRecipe != null && gasRand.nextDouble() < 0.05 && cachedRecipe.getOutput().applyOutputs(collectedGas, false, 1))
|
2014-09-03 02:51:00 +02:00
|
|
|
{
|
2015-02-18 03:27:35 +01:00
|
|
|
cachedRecipe.getOutput().applyOutputs(collectedGas, true, 1);
|
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());
|
2015-02-25 17:11:30 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-09-03 02:51:00 +02:00
|
|
|
data.add(-1);
|
|
|
|
data.add(0);
|
|
|
|
}
|
2015-02-25 17:11:30 +01:00
|
|
|
|
2014-09-03 02:51:00 +02:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handlePacketData(ByteBuf data)
|
|
|
|
{
|
|
|
|
int gasID = data.readInt();
|
2015-02-25 17:11:30 +01:00
|
|
|
|
2014-09-03 02:51:00 +02:00
|
|
|
if(gasID < 0)
|
|
|
|
{
|
|
|
|
collectedGas.setGas(null);
|
2015-02-25 17:11:30 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-09-03 02:51:00 +02:00
|
|
|
collectedGas.setGas(new GasStack(gasID, data.readInt()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|