Search in sources :

Example 1 with IGasTank

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;
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) IGasTank(mekanism.api.chemical.gas.IGasTank) ArrayList(java.util.ArrayList) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ListNBT(net.minecraft.nbt.ListNBT) TileEntityChemicalTank(mekanism.common.tile.TileEntityChemicalTank) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 2 with IGasTank

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);
}
Also used : Gas(mekanism.api.chemical.gas.Gas) IGasHandler(mekanism.api.chemical.gas.IGasHandler) MethodsReturnNonnullByDefault(mcp.MethodsReturnNonnullByDefault) MekanismRecipeType(mekanism.common.recipe.MekanismRecipeType) Predicate(java.util.function.Predicate) IMekanismInventory(mekanism.api.inventory.IMekanismInventory) World(net.minecraft.world.World) IChemicalHandler(mekanism.api.chemical.IChemicalHandler) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) BooleanSupplier(java.util.function.BooleanSupplier) Objects(java.util.Objects) IContentsListener(mekanism.api.IContentsListener) ItemStack(net.minecraft.item.ItemStack) FieldsAreNonnullByDefault(mekanism.api.annotations.FieldsAreNonnullByDefault) IGasTank(mekanism.api.chemical.gas.IGasTank) Capabilities(mekanism.common.capabilities.Capabilities) GasStack(mekanism.api.chemical.gas.GasStack) NonNull(mekanism.api.annotations.NonNull) Nullable(javax.annotation.Nullable) ItemStackToGasRecipe(mekanism.api.recipes.ItemStackToGasRecipe) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IGasTank

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;
}
Also used : IInventorySlot(mekanism.api.inventory.IInventorySlot) IPigmentTank(mekanism.api.chemical.pigment.IPigmentTank) IInfusionTank(mekanism.api.chemical.infuse.IInfusionTank) IGasTank(mekanism.api.chemical.gas.IGasTank) DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) ISlurryTank(mekanism.api.chemical.slurry.ISlurryTank) Nullable(javax.annotation.Nullable)

Example 4 with IGasTank

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));
                }
            }
        }
    }
}
Also used : IHeatHandler(mekanism.api.heat.IHeatHandler) IGasTile(mekanism.common.tile.interfaces.chemical.IGasTile) SecurityMode(mekanism.common.lib.security.SecurityMode) IHeatCapacitorHolder(mekanism.common.capabilities.holder.heat.IHeatCapacitorHolder) ComputerMethodMapper(mekanism.common.integration.computer.ComputerMethodMapper) ITileHeatHandler(mekanism.common.capabilities.heat.ITileHeatHandler) IEnergyContainerHolder(mekanism.common.capabilities.holder.energy.IEnergyContainerHolder) GasHandlerManager(mekanism.common.capabilities.resolver.manager.ChemicalHandlerManager.GasHandlerManager) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) CompoundNBT(net.minecraft.nbt.CompoundNBT) ITierUpgradable(mekanism.common.tile.interfaces.ITierUpgradable) Direction(net.minecraft.util.Direction) SlurryHandlerManager(mekanism.common.capabilities.resolver.manager.ChemicalHandlerManager.SlurryHandlerManager) ITileRadioactive(mekanism.common.tile.interfaces.ITileRadioactive) IComputerTile(mekanism.common.integration.computer.IComputerTile) Block(net.minecraft.block.Block) Capabilities(mekanism.common.capabilities.Capabilities) Map(java.util.Map) InfusionHandlerManager(mekanism.common.capabilities.resolver.manager.ChemicalHandlerManager.InfusionHandlerManager) BoundComputerMethod(mekanism.common.integration.computer.BoundComputerMethod) SyncMapper(mekanism.common.inventory.container.sync.dynamic.SyncMapper) ISound(net.minecraft.client.audio.ISound) ISustainedInventory(mekanism.common.tile.interfaces.ISustainedInventory) ListNBT(net.minecraft.nbt.ListNBT) IChunkLoader(mekanism.common.lib.chunkloading.IChunkLoader) ITileRedstone(mekanism.common.tile.interfaces.ITileRedstone) Attribute(mekanism.common.block.attribute.Attribute) NBTUtils(mekanism.common.util.NBTUtils) EnergyHandlerManager(mekanism.common.capabilities.resolver.manager.EnergyHandlerManager) Set(java.util.Set) IBlockProvider(mekanism.api.providers.IBlockProvider) IMekanismFluidHandler(mekanism.api.fluid.IMekanismFluidHandler) ISecurityTile(mekanism.common.lib.security.ISecurityTile) ITrackableContainer(mekanism.common.inventory.container.ITrackableContainer) MekanismUtils(mekanism.common.util.MekanismUtils) FluidHandlerManager(mekanism.common.capabilities.resolver.manager.FluidHandlerManager) MethodRestriction(mekanism.common.integration.computer.ComputerMethodMapper.MethodRestriction) ComputerException(mekanism.common.integration.computer.ComputerException) ComputerCapabilityHelper(mekanism.common.integration.computer.ComputerCapabilityHelper) IGasTank(mekanism.api.chemical.gas.IGasTank) ITileSound(mekanism.common.tile.interfaces.ITileSound) SyncablePigmentStack(mekanism.common.inventory.container.sync.chemical.SyncablePigmentStack) TileComponentSecurity(mekanism.common.tile.component.TileComponentSecurity) ActionResultType(net.minecraft.util.ActionResultType) SyncableFloatingLong(mekanism.common.inventory.container.sync.SyncableFloatingLong) Util(net.minecraft.util.Util) IInfusionTile(mekanism.common.tile.interfaces.chemical.IInfusionTile) IHeatCapacitor(mekanism.api.heat.IHeatCapacitor) AttributeUpgradeable(mekanism.common.block.attribute.AttributeUpgradeable) IPigmentTank(mekanism.api.chemical.pigment.IPigmentTank) ISlurryTank(mekanism.api.chemical.slurry.ISlurryTank) AttributeComparator(mekanism.common.block.attribute.Attributes.AttributeComparator) ArrayList(java.util.ArrayList) ItemConfigurationCard(mekanism.common.item.ItemConfigurationCard) ItemStack(net.minecraft.item.ItemStack) ItemConfigurator(mekanism.common.item.ItemConfigurator) NetworkHooks(net.minecraftforge.fml.network.NetworkHooks) IMekanismStrictEnergyHandler(mekanism.api.energy.IMekanismStrictEnergyHandler) AttributeStateFacing(mekanism.common.block.attribute.AttributeStateFacing) IEnergyContainer(mekanism.api.energy.IEnergyContainer) ICapabilityHandlerManager(mekanism.common.capabilities.resolver.manager.ICapabilityHandlerManager) Nullable(javax.annotation.Nullable) EnumUtils(mekanism.common.util.EnumUtils) SyncableEnum(mekanism.common.inventory.container.sync.SyncableEnum) PigmentHandlerManager(mekanism.common.capabilities.resolver.manager.ChemicalHandlerManager.PigmentHandlerManager) IComparatorSupport(mekanism.common.tile.interfaces.IComparatorSupport) BlockPos(net.minecraft.util.math.BlockPos) SecurityUtils(mekanism.common.util.SecurityUtils) IUpgradeData(mekanism.common.upgrade.IUpgradeData) AttributeSecurity(mekanism.common.block.attribute.Attributes.AttributeSecurity) BasicHeatCapacitor(mekanism.common.capabilities.heat.BasicHeatCapacitor) IFrequencyHandler(mekanism.common.lib.frequency.IFrequencyHandler) TileEntity(net.minecraft.tileentity.TileEntity) TextComponentUtil(mekanism.api.text.TextComponentUtil) IInventorySlotHolder(mekanism.common.capabilities.holder.slot.IInventorySlotHolder) Action(mekanism.api.Action) SoundEvent(net.minecraft.util.SoundEvent) MekanismAPI(mekanism.api.MekanismAPI) IMekanismInventory(mekanism.api.inventory.IMekanismInventory) SyncableGasStack(mekanism.common.inventory.container.sync.chemical.SyncableGasStack) AutomationType(mekanism.api.inventory.AutomationType) ITileUpgradable(mekanism.common.tile.interfaces.ITileUpgradable) AttributeComputerIntegration(mekanism.common.block.attribute.Attributes.AttributeComputerIntegration) TileComponentUpgrade(mekanism.common.tile.component.TileComponentUpgrade) IInfusionTank(mekanism.api.chemical.infuse.IInfusionTank) AttributeStateActive(mekanism.common.block.attribute.AttributeStateActive) TileEntityType(net.minecraft.tileentity.TileEntityType) BlockState(net.minecraft.block.BlockState) AttributeRedstone(mekanism.common.block.attribute.Attributes.AttributeRedstone) AttributeGui(mekanism.common.block.attribute.AttributeGui) PlayerEntity(net.minecraft.entity.player.PlayerEntity) MachineEnergyContainer(mekanism.common.capabilities.energy.MachineEnergyContainer) SyncableInfusionStack(mekanism.common.inventory.container.sync.chemical.SyncableInfusionStack) SyncableSlurryStack(mekanism.common.inventory.container.sync.chemical.SyncableSlurryStack) DataHandlerUtils(mekanism.api.DataHandlerUtils) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) ITileActive(mekanism.common.tile.interfaces.ITileActive) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Objects(java.util.Objects) IConfigCardAccess(mekanism.api.IConfigCardAccess) List(java.util.List) AttributeSound(mekanism.common.block.attribute.AttributeSound) NBTConstants(mekanism.api.NBTConstants) ItemHandlerManager(mekanism.common.capabilities.resolver.manager.ItemHandlerManager) CachedAmbientTemperature(mekanism.common.capabilities.heat.CachedAmbientTemperature) ITickableTileEntity(net.minecraft.tileentity.ITickableTileEntity) MekanismContainer(mekanism.common.inventory.container.MekanismContainer) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Upgrade(mekanism.api.Upgrade) IPigmentTile(mekanism.common.tile.interfaces.chemical.IPigmentTile) CapabilityUtils(mekanism.common.util.CapabilityUtils) IFluidTankHolder(mekanism.common.capabilities.holder.fluid.IFluidTankHolder) SyncableDouble(mekanism.common.inventory.container.sync.SyncableDouble) Function(java.util.function.Function) ITextComponent(net.minecraft.util.text.ITextComponent) Minecraft(net.minecraft.client.Minecraft) FloatingLong(mekanism.api.math.FloatingLong) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod) ISlurryTile(mekanism.common.tile.interfaces.chemical.ISlurryTile) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) Hand(net.minecraft.util.Hand) Nonnull(javax.annotation.Nonnull) IntSupplier(java.util.function.IntSupplier) AttributeUpgradeSupport(mekanism.common.block.attribute.AttributeUpgradeSupport) Mekanism(mekanism.common.Mekanism) SoundHandler(mekanism.client.sound.SoundHandler) ITileComponent(mekanism.common.tile.component.ITileComponent) HeatHandlerManager(mekanism.common.capabilities.resolver.manager.HeatHandlerManager) ITileDirectional(mekanism.common.tile.interfaces.ITileDirectional) ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) NBT(net.minecraftforge.common.util.Constants.NBT) TileComponentFrequency(mekanism.common.lib.frequency.TileComponentFrequency) IInventorySlot(mekanism.api.inventory.IInventorySlot) WorldUtils(mekanism.common.util.WorldUtils) Collections(java.util.Collections) MekanismConfig(mekanism.common.config.MekanismConfig) SyncableFluidStack(mekanism.common.inventory.container.sync.SyncableFluidStack) BasicHeatCapacitor(mekanism.common.capabilities.heat.BasicHeatCapacitor) IGasTank(mekanism.api.chemical.gas.IGasTank) ITileComponent(mekanism.common.tile.component.ITileComponent) IPigmentTank(mekanism.api.chemical.pigment.IPigmentTank) IEnergyContainer(mekanism.api.energy.IEnergyContainer) IInfusionTank(mekanism.api.chemical.infuse.IInfusionTank) IHeatCapacitor(mekanism.api.heat.IHeatCapacitor) MachineEnergyContainer(mekanism.common.capabilities.energy.MachineEnergyContainer) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) ISlurryTank(mekanism.api.chemical.slurry.ISlurryTank)

Aggregations

IGasTank (mekanism.api.chemical.gas.IGasTank)4 Nullable (javax.annotation.Nullable)3 ArrayList (java.util.ArrayList)2 Objects (java.util.Objects)2 Function (java.util.function.Function)2 Nonnull (javax.annotation.Nonnull)2 IInfusionTank (mekanism.api.chemical.infuse.IInfusionTank)2 IPigmentTank (mekanism.api.chemical.pigment.IPigmentTank)2 ISlurryTank (mekanism.api.chemical.slurry.ISlurryTank)2 IExtendedFluidTank (mekanism.api.fluid.IExtendedFluidTank)2 IInventorySlot (mekanism.api.inventory.IInventorySlot)2 IMekanismInventory (mekanism.api.inventory.IMekanismInventory)2 ItemStack (net.minecraft.item.ItemStack)2 ObjectOpenHashSet (it.unimi.dsi.fastutil.objects.ObjectOpenHashSet)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 BooleanSupplier (java.util.function.BooleanSupplier)1 IntSupplier (java.util.function.IntSupplier)1