use of mekanism.api.chemical.gas.IGasTank in project Mekanism by mekanism.
the class BlockMekanism method getDrops.
@Nonnull
@Override
@Deprecated
public List<ItemStack> getDrops(@Nonnull BlockState state, @Nonnull LootContext.Builder builder) {
List<ItemStack> drops = super.getDrops(state, builder);
// Check if we need to clear any radioactive materials from the stored tanks as those will be dumped via the tile being removed
if (state.getBlock() instanceof IHasTileEntity) {
TileEntity tile = ((IHasTileEntity<?>) state.getBlock()).getTileType().create();
if (tile instanceof TileEntityMekanism) {
TileEntityMekanism mekTile = (TileEntityMekanism) tile;
// Skip tiles that have no tanks and skip chemical creative tanks
if (!mekTile.getGasTanks(null).isEmpty() && (!(mekTile instanceof TileEntityChemicalTank) || ((TileEntityChemicalTank) mekTile).getTier() != ChemicalTankTier.CREATIVE)) {
for (ItemStack drop : drops) {
ListNBT gasTankList = ItemDataUtils.getList(drop, NBTConstants.GAS_TANKS);
if (!gasTankList.isEmpty()) {
int count = DataHandlerUtils.getMaxId(gasTankList, NBTConstants.TANK);
List<IGasTank> tanks = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
tanks.add(ChemicalTankBuilder.GAS.createDummy(Long.MAX_VALUE));
}
DataHandlerUtils.readContainers(tanks, gasTankList);
boolean hasRadioactive = false;
for (IGasTank tank : tanks) {
if (!tank.isEmpty() && tank.getStack().has(GasAttributes.Radiation.class)) {
// If the tank isn't empty and has a radioactive gas in it, clear the tank and mark we need to update the item
hasRadioactive = true;
tank.setEmpty();
}
}
if (hasRadioactive) {
// If the item has any gas tanks stored, check if any have radioactive substances in them
// and if so clear them out
ListNBT newGasTankList = DataHandlerUtils.writeContainers(tanks);
if (newGasTankList.isEmpty()) {
// If the list is now empty remove it
ItemDataUtils.removeData(drop, NBTConstants.GAS_TANKS);
} else {
// Otherwise, update the list
ItemDataUtils.setList(drop, NBTConstants.GAS_TANKS, newGasTankList);
}
}
}
}
}
}
}
return drops;
}
use of mekanism.api.chemical.gas.IGasTank in project Mekanism by mekanism.
the class GasInventorySlot method fillOrConvert.
/**
* Fills the tank from this item OR converts the given item to a gas
*/
public static GasInventorySlot fillOrConvert(IGasTank gasTank, Supplier<World> worldSupplier, @Nullable IContentsListener listener, int x, int y) {
Objects.requireNonNull(gasTank, "Gas tank cannot be null");
Objects.requireNonNull(worldSupplier, "World supplier cannot be null");
Function<ItemStack, GasStack> potentialConversionSupplier = stack -> getPotentialConversion(worldSupplier.get(), stack);
return new GasInventorySlot(gasTank, worldSupplier, getFillOrConvertExtractPredicate(gasTank, GasInventorySlot::getCapability, potentialConversionSupplier), getFillOrConvertInsertPredicate(gasTank, GasInventorySlot::getCapability, potentialConversionSupplier), stack -> {
if (stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).isPresent()) {
// Note: we mark all gas items as valid and have a more restrictive insert check so that we allow full tanks when they are done being filled
return true;
}
// Allow gas conversion of items that have a gas that is valid
GasStack gasConversion = getPotentialConversion(worldSupplier.get(), stack);
return !gasConversion.isEmpty() && gasTank.isValid(gasConversion);
}, listener, x, y);
}
use of mekanism.api.chemical.gas.IGasTank in project Mekanism by mekanism.
the class ISideConfiguration method getActiveDataType.
@Nullable
default DataType getActiveDataType(Object container) {
ConfigInfo info = null;
TileComponentConfig config = getConfig();
if (container instanceof IGasTank && config.supports(TransmissionType.GAS)) {
info = config.getConfig(TransmissionType.GAS);
} else if (container instanceof IInfusionTank && config.supports(TransmissionType.INFUSION)) {
info = config.getConfig(TransmissionType.INFUSION);
} else if (container instanceof IPigmentTank && config.supports(TransmissionType.PIGMENT)) {
info = config.getConfig(TransmissionType.PIGMENT);
} else if (container instanceof ISlurryTank && config.supports(TransmissionType.SLURRY)) {
info = config.getConfig(TransmissionType.SLURRY);
} else if (container instanceof IExtendedFluidTank && config.supports(TransmissionType.FLUID)) {
info = config.getConfig(TransmissionType.FLUID);
} else if (container instanceof IInventorySlot && config.supports(TransmissionType.ITEM)) {
info = config.getConfig(TransmissionType.ITEM);
}
if (info != null) {
List<DataType> types = info.getDataTypeForContainer(container);
int count = types.size();
// of <= size - 1 to cut down slightly on the calculations
if (count > 0 && count < info.getSupportedDataTypes().size()) {
return types.get(0);
}
}
return null;
}
use of mekanism.api.chemical.gas.IGasTank in project Mekanism by mekanism.
the class TileEntityMekanism method addContainerTrackers.
@Override
public void addContainerTrackers(MekanismContainer container) {
// setup dynamic container syncing
SyncMapper.INSTANCE.setup(container, getClass(), () -> this);
for (ITileComponent component : components) {
component.trackForMainContainer(container);
}
if (supportsRedstone()) {
container.track(SyncableEnum.create(RedstoneControl::byIndexStatic, RedstoneControl.DISABLED, () -> controlType, value -> controlType = value));
}
boolean isClient = isRemote();
if (canHandleGas() && handles(SubstanceType.GAS)) {
List<IGasTank> gasTanks = getGasTanks(null);
for (IGasTank gasTank : gasTanks) {
container.track(SyncableGasStack.create(gasTank, isClient));
}
}
if (canHandleInfusion() && handles(SubstanceType.INFUSION)) {
List<IInfusionTank> infusionTanks = getInfusionTanks(null);
for (IInfusionTank infusionTank : infusionTanks) {
container.track(SyncableInfusionStack.create(infusionTank, isClient));
}
}
if (canHandlePigment() && handles(SubstanceType.PIGMENT)) {
List<IPigmentTank> pigmentTanks = getPigmentTanks(null);
for (IPigmentTank pigmentTank : pigmentTanks) {
container.track(SyncablePigmentStack.create(pigmentTank, isClient));
}
}
if (canHandleSlurry() && handles(SubstanceType.SLURRY)) {
List<ISlurryTank> slurryTanks = getSlurryTanks(null);
for (ISlurryTank slurryTank : slurryTanks) {
container.track(SyncableSlurryStack.create(slurryTank, isClient));
}
}
if (canHandleFluid() && handles(SubstanceType.FLUID)) {
List<IExtendedFluidTank> fluidTanks = getFluidTanks(null);
for (IExtendedFluidTank fluidTank : fluidTanks) {
container.track(SyncableFluidStack.create(fluidTank, isClient));
}
}
if (canHandleHeat() && handles(SubstanceType.HEAT)) {
List<IHeatCapacitor> heatCapacitors = getHeatCapacitors(null);
for (IHeatCapacitor capacitor : heatCapacitors) {
container.track(SyncableDouble.create(capacitor::getHeat, capacitor::setHeat));
if (capacitor instanceof BasicHeatCapacitor) {
container.track(SyncableDouble.create(capacitor::getHeatCapacity, capacity -> ((BasicHeatCapacitor) capacitor).setHeatCapacity(capacity, false)));
}
}
}
if (canHandleEnergy() && handles(SubstanceType.ENERGY)) {
container.track(SyncableFloatingLong.create(this::getInputRate, this::setInputRate));
List<IEnergyContainer> energyContainers = getEnergyContainers(null);
for (IEnergyContainer energyContainer : energyContainers) {
container.track(SyncableFloatingLong.create(energyContainer::getEnergy, energyContainer::setEnergy));
if (energyContainer instanceof MachineEnergyContainer) {
MachineEnergyContainer<?> machineEnergy = (MachineEnergyContainer<?>) energyContainer;
if (supportsUpgrades() || machineEnergy.adjustableRates()) {
container.track(SyncableFloatingLong.create(machineEnergy::getMaxEnergy, machineEnergy::setMaxEnergy));
container.track(SyncableFloatingLong.create(machineEnergy::getEnergyPerTick, machineEnergy::setEnergyPerTick));
}
}
}
}
}
Aggregations