mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 04:52:25 +00:00
* First pass reformatting code to be more readable (common still not done) * Replace google common collect calls with Java calls where possible * Remove a bunch of unnecessary parenthesis leaving clarifying ones * Add some missing @Nonnull annotations * Fix checking wrong type * Remove unnecessary continue/return statements and simplify comparision check * Pass exception instead of directly printing stack trace * Work on cleaning up common, through config so far * Work on cleaning up common, through integration so far * Work on cleaning up common, through network so far * Work on cleaning up common, through tier so far * Remove empty constructors that get created by default anyways * Work on cleaning up common, through transmitters so far * Work on cleaning up common, through utils so far * Finish cleaning up spacing for common
108 lines
3.5 KiB
Java
108 lines
3.5 KiB
Java
package mekanism.common.tile;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
import java.util.Random;
|
|
import javax.annotation.Nonnull;
|
|
import mekanism.api.TileNetworkList;
|
|
import mekanism.api.gas.Gas;
|
|
import mekanism.api.gas.GasStack;
|
|
import mekanism.api.gas.GasTank;
|
|
import mekanism.api.gas.GasTankInfo;
|
|
import mekanism.api.gas.IGasHandler;
|
|
import mekanism.common.capabilities.Capabilities;
|
|
import mekanism.common.recipe.RecipeHandler;
|
|
import mekanism.common.recipe.inputs.IntegerInput;
|
|
import mekanism.common.recipe.machines.AmbientGasRecipe;
|
|
import mekanism.common.tile.prefab.TileEntityContainerBlock;
|
|
import mekanism.common.util.InventoryUtils;
|
|
import mekanism.common.util.TileUtils;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.EnumFacing;
|
|
import net.minecraft.util.NonNullList;
|
|
import net.minecraftforge.common.capabilities.Capability;
|
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
|
|
|
public class TileEntityAmbientAccumulator extends TileEntityContainerBlock implements IGasHandler {
|
|
|
|
public static Random gasRand = new Random();
|
|
public GasTank collectedGas = new GasTank(1000);
|
|
public int cachedDimensionId = 0;
|
|
public AmbientGasRecipe cachedRecipe;
|
|
|
|
public TileEntityAmbientAccumulator() {
|
|
super("AmbientAccumulator");
|
|
inventory = NonNullList.withSize(0, ItemStack.EMPTY);
|
|
}
|
|
|
|
@Override
|
|
public void onUpdate() {
|
|
if (!world.isRemote) {
|
|
if (cachedRecipe == null || world.provider.getDimension() != cachedDimensionId) {
|
|
cachedDimensionId = world.provider.getDimension();
|
|
cachedRecipe = RecipeHandler.getDimensionGas(new IntegerInput(cachedDimensionId));
|
|
}
|
|
if (cachedRecipe != null && gasRand.nextDouble() < 0.05 && cachedRecipe.getOutput().applyOutputs(collectedGas, false, 1)) {
|
|
cachedRecipe.getOutput().applyOutputs(collectedGas, true, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int receiveGas(EnumFacing side, GasStack stack, boolean doTransfer) {
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public GasStack drawGas(EnumFacing side, int amount, boolean doTransfer) {
|
|
return collectedGas.draw(amount, doTransfer);
|
|
}
|
|
|
|
@Override
|
|
public boolean canReceiveGas(EnumFacing side, Gas type) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean canDrawGas(EnumFacing side, Gas type) {
|
|
return type == collectedGas.getGasType();
|
|
}
|
|
|
|
@Override
|
|
@Nonnull
|
|
public GasTankInfo[] getTankInfo() {
|
|
return new GasTankInfo[]{collectedGas};
|
|
}
|
|
|
|
@Override
|
|
public TileNetworkList getNetworkedData(TileNetworkList data) {
|
|
TileUtils.addTankData(data, collectedGas);
|
|
return data;
|
|
}
|
|
|
|
@Override
|
|
public void handlePacketData(ByteBuf data) {
|
|
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
|
TileUtils.readTankData(data, collectedGas);
|
|
}
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public int[] getSlotsForFace(@Nonnull EnumFacing side) {
|
|
return InventoryUtils.EMPTY;
|
|
}
|
|
|
|
//Gas capability is never disabled here
|
|
@Override
|
|
public boolean hasCapability(@Nonnull Capability<?> capability, EnumFacing side) {
|
|
return capability == Capabilities.GAS_HANDLER_CAPABILITY || super.hasCapability(capability, side);
|
|
}
|
|
|
|
@Override
|
|
public <T> T getCapability(@Nonnull Capability<T> capability, EnumFacing side) {
|
|
if (capability == Capabilities.GAS_HANDLER_CAPABILITY) {
|
|
return Capabilities.GAS_HANDLER_CAPABILITY.cast(this);
|
|
}
|
|
return super.getCapability(capability, side);
|
|
}
|
|
} |