Search in sources :

Example 1 with AutomationType

use of mekanism.api.inventory.AutomationType in project Mekanism by mekanism.

the class MergedChemicalInventorySlot method fill.

public static MergedChemicalInventorySlot<MergedChemicalTank> fill(MergedChemicalTank chemicalTank, @Nullable IContentsListener listener, int x, int y) {
    Objects.requireNonNull(chemicalTank, "Merged chemical tank cannot be null");
    Predicate<@NonNull ItemStack> gasExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(chemicalTank.getGasTank(), GasInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> infusionExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(chemicalTank.getInfusionTank(), InfusionInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> pigmentExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(chemicalTank.getPigmentTank(), PigmentInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> slurryExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(chemicalTank.getSlurryTank(), SlurryInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> gasInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(chemicalTank.getGasTank(), GasInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> infusionInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(chemicalTank.getInfusionTank(), InfusionInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> pigmentInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(chemicalTank.getPigmentTank(), PigmentInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> slurryInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(chemicalTank.getSlurryTank(), SlurryInventorySlot.getCapability(stack));
    return new MergedChemicalInventorySlot<>(chemicalTank, (stack, automationType) -> {
        if (automationType == AutomationType.MANUAL) {
            // Always allow the player to manually extract
            return true;
        }
        Current current = chemicalTank.getCurrent();
        if (current == Current.GAS) {
            return gasExtractPredicate.test(stack);
        } else if (current == Current.INFUSION) {
            return infusionExtractPredicate.test(stack);
        } else if (current == Current.PIGMENT) {
            return pigmentExtractPredicate.test(stack);
        } else if (current == Current.SLURRY) {
            return slurryExtractPredicate.test(stack);
        }
        // Else the tank is empty, check all our extraction predicates
        return gasExtractPredicate.test(stack) && infusionExtractPredicate.test(stack) && pigmentExtractPredicate.test(stack) && slurryExtractPredicate.test(stack);
    }, (stack, automationType) -> {
        Current current = chemicalTank.getCurrent();
        if (current == Current.GAS) {
            return gasInsertPredicate.test(stack);
        } else if (current == Current.INFUSION) {
            return infusionInsertPredicate.test(stack);
        } else if (current == Current.PIGMENT) {
            return pigmentInsertPredicate.test(stack);
        } else if (current == Current.SLURRY) {
            return slurryInsertPredicate.test(stack);
        }
        // Else the tank is empty, only allow it if one of the chemical insert predicates matches
        return gasInsertPredicate.test(stack) || infusionInsertPredicate.test(stack) || pigmentInsertPredicate.test(stack) || slurryInsertPredicate.test(stack);
    }, MergedChemicalInventorySlot::hasCapability, listener, x, y);
}
Also used : CurrentType(mekanism.common.capabilities.merged.MergedTank.CurrentType) Predicate(java.util.function.Predicate) MergedChemicalTank(mekanism.api.chemical.merged.MergedChemicalTank) AutomationType(mekanism.api.inventory.AutomationType) BasicInventorySlot(mekanism.common.inventory.slot.BasicInventorySlot) Objects(java.util.Objects) IContentsListener(mekanism.api.IContentsListener) BiPredicate(java.util.function.BiPredicate) ItemStack(net.minecraft.item.ItemStack) ContainerSlotType(mekanism.common.inventory.container.slot.ContainerSlotType) Capabilities(mekanism.common.capabilities.Capabilities) Current(mekanism.api.chemical.merged.MergedChemicalTank.Current) Nonnull(javax.annotation.Nonnull) NonNull(mekanism.api.annotations.NonNull) Nullable(javax.annotation.Nullable) ItemStack(net.minecraft.item.ItemStack) Current(mekanism.api.chemical.merged.MergedChemicalTank.Current)

Example 2 with AutomationType

use of mekanism.api.inventory.AutomationType in project Mekanism by mekanism.

the class TileEntityDigitalMiner method getInitialInventory.

@Nonnull
@Override
protected IInventorySlotHolder getInitialInventory() {
    mainSlots = new ArrayList<>();
    InventorySlotHelper builder = InventorySlotHelper.forSide(this::getDirection, side -> side == RelativeSide.TOP, side -> side == RelativeSide.BACK);
    // Allow insertion manually or internally, or if it is a replace stack
    BiPredicate<@NonNull ItemStack, @NonNull AutomationType> canInsert = (stack, automationType) -> automationType != AutomationType.EXTERNAL || isReplaceTarget(stack.getItem());
    // Allow extraction if it is manual or if it is a replace stack
    BiPredicate<@NonNull ItemStack, @NonNull AutomationType> canExtract = (stack, automationType) -> automationType == AutomationType.MANUAL || !isReplaceTarget(stack.getItem());
    for (int slotY = 0; slotY < 3; slotY++) {
        for (int slotX = 0; slotX < 9; slotX++) {
            BasicInventorySlot slot = BasicInventorySlot.at(canExtract, canInsert, this, 8 + slotX * 18, 92 + slotY * 18);
            builder.addSlot(slot, RelativeSide.BACK, RelativeSide.TOP);
            mainSlots.add(slot);
        }
    }
    builder.addSlot(energySlot = EnergyInventorySlot.fillOrConvert(energyContainer, this::getLevel, this, 152, 20));
    return builder.build();
}
Also used : SyncableInt(mekanism.common.inventory.container.sync.SyncableInt) IEnergyContainerHolder(mekanism.common.capabilities.holder.energy.IEnergyContainerHolder) IBoundingBlock(mekanism.common.tile.interfaces.IBoundingBlock) CompoundNBT(net.minecraft.nbt.CompoundNBT) WrappingComputerMethod(mekanism.common.integration.computer.annotation.WrappingComputerMethod) Direction(net.minecraft.util.Direction) Block(net.minecraft.block.Block) Capabilities(mekanism.common.capabilities.Capabilities) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) BasicCapabilityResolver(mekanism.common.capabilities.resolver.BasicCapabilityResolver) MekanismBlocks(mekanism.common.registries.MekanismBlocks) ListNBT(net.minecraft.nbt.ListNBT) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase) IChunkLoader(mekanism.common.lib.chunkloading.IChunkLoader) BlockEvent(net.minecraftforge.event.world.BlockEvent) EnergyInventorySlot(mekanism.common.inventory.slot.EnergyInventorySlot) NBTUtils(mekanism.common.util.NBTUtils) MinerEnergyContainer(mekanism.common.capabilities.energy.MinerEnergyContainer) Set(java.util.Set) MekanismUtils(mekanism.common.util.MekanismUtils) State(mekanism.common.content.miner.ThreadMinerSearch.State) ComputerException(mekanism.common.integration.computer.ComputerException) InventoryUtils(mekanism.common.util.InventoryUtils) RelativeSide(mekanism.api.RelativeSide) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) IFilter(mekanism.common.content.filter.IFilter) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) EnergyContainerHelper(mekanism.common.capabilities.holder.energy.EnergyContainerHelper) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SyncableBoolean(mekanism.common.inventory.container.sync.SyncableBoolean) ArrayList(java.util.ArrayList) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) LootContext(net.minecraft.loot.LootContext) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) DigitalMinerConfigContainer(mekanism.common.inventory.container.tile.DigitalMinerConfigContainer) Nullable(javax.annotation.Nullable) Long2ObjectMaps(it.unimi.dsi.fastutil.longs.Long2ObjectMaps) SyncableEnum(mekanism.common.inventory.container.sync.SyncableEnum) ISustainedData(mekanism.common.tile.interfaces.ISustainedData) SyncableItemStack(mekanism.common.inventory.container.sync.SyncableItemStack) BlockPos(net.minecraft.util.math.BlockPos) MinerFilter(mekanism.common.content.miner.MinerFilter) SyncableFilterList(mekanism.common.inventory.container.sync.list.SyncableFilterList) MekFakePlayer(mekanism.common.base.MekFakePlayer) MinecraftForge(net.minecraftforge.common.MinecraftForge) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) MekanismTags(mekanism.common.tags.MekanismTags) TileEntity(net.minecraft.tileentity.TileEntity) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) IInventorySlotHolder(mekanism.common.capabilities.holder.slot.IInventorySlotHolder) Finder(mekanism.common.lib.inventory.Finder) Action(mekanism.api.Action) SyncableRegistryEntry(mekanism.common.inventory.container.sync.SyncableRegistryEntry) ServerWorld(net.minecraft.world.server.ServerWorld) EnergyCompatUtils(mekanism.common.integration.energy.EnergyCompatUtils) Item(net.minecraft.item.Item) ThreadMinerSearch(mekanism.common.content.miner.ThreadMinerSearch) AutomationType(mekanism.api.inventory.AutomationType) ComputerIInventorySlotWrapper(mekanism.common.integration.computer.SpecialComputerMethodWrapper.ComputerIInventorySlotWrapper) InventorySlotHelper(mekanism.common.capabilities.holder.slot.InventorySlotHelper) ItemDataUtils(mekanism.common.util.ItemDataUtils) ITileFilterHolder(mekanism.common.tile.interfaces.ITileFilterHolder) WorldEvents(net.minecraftforge.common.util.Constants.WorldEvents) Enchantments(net.minecraft.enchantment.Enchantments) HashList(mekanism.common.lib.collection.HashList) Region(net.minecraft.world.Region) TileComponentChunkLoader(mekanism.common.tile.component.TileComponentChunkLoader) BlockState(net.minecraft.block.BlockState) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) IHasSortableFilters(mekanism.common.tile.interfaces.IHasSortableFilters) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Predicate(java.util.function.Predicate) StackUtils(mekanism.common.util.StackUtils) LootParameters(net.minecraft.loot.LootParameters) ChunkPos(net.minecraft.util.math.ChunkPos) Capability(net.minecraftforge.common.capabilities.Capability) Objects(java.util.Objects) List(java.util.List) BaseFilter(mekanism.common.content.filter.BaseFilter) Vector3d(net.minecraft.util.math.vector.Vector3d) NBTConstants(mekanism.api.NBTConstants) Optional(java.util.Optional) Vector3i(net.minecraft.util.math.vector.Vector3i) MekanismContainer(mekanism.common.inventory.container.MekanismContainer) Upgrade(mekanism.api.Upgrade) ObjectArraySet(it.unimi.dsi.fastutil.objects.ObjectArraySet) BasicInventorySlot(mekanism.common.inventory.slot.BasicInventorySlot) ITextComponent(net.minecraft.util.text.ITextComponent) BiPredicate(java.util.function.BiPredicate) FloatingLong(mekanism.api.math.FloatingLong) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod) TransitRequest(mekanism.common.lib.inventory.TransitRequest) MekanismItems(mekanism.common.registries.MekanismItems) Nonnull(javax.annotation.Nonnull) NonNull(mekanism.api.annotations.NonNull) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) Items(net.minecraft.item.Items) ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) NBT(net.minecraftforge.common.util.Constants.NBT) IInventorySlot(mekanism.api.inventory.IInventorySlot) WorldUtils(mekanism.common.util.WorldUtils) BitSet(java.util.BitSet) Collections(java.util.Collections) MekanismConfig(mekanism.common.config.MekanismConfig) UpgradeUtils(mekanism.common.util.UpgradeUtils) InventorySlotHelper(mekanism.common.capabilities.holder.slot.InventorySlotHelper) AutomationType(mekanism.api.inventory.AutomationType) BasicInventorySlot(mekanism.common.inventory.slot.BasicInventorySlot) ItemStack(net.minecraft.item.ItemStack) SyncableItemStack(mekanism.common.inventory.container.sync.SyncableItemStack) Nonnull(javax.annotation.Nonnull)

Example 3 with AutomationType

use of mekanism.api.inventory.AutomationType in project Mekanism by mekanism.

the class TileEntityPersonalChest method getInitialInventory.

@Nonnull
@Override
protected IInventorySlotHolder getInitialInventory() {
    InventorySlotHelper builder = InventorySlotHelper.forSide(this::getDirection);
    // Note: We always allow manual interaction (even for insertion), as if a player has the GUI open we treat that as they are allowed to interact with it
    // and if the security mode changes we then boot any players who can't interact with it anymore out of the GUI
    BiPredicate<@NonNull ItemStack, @NonNull AutomationType> canInteract = (stack, automationType) -> automationType == AutomationType.MANUAL || SecurityUtils.getSecurity(this, Dist.DEDICATED_SERVER) == SecurityMode.PUBLIC;
    for (int slotY = 0; slotY < 6; slotY++) {
        for (int slotX = 0; slotX < 9; slotX++) {
            // Note: we allow access to the slots from all sides as long as it is public, unlike in 1.12 where we always denied the bottom face
            // We did that to ensure that things like hoppers that could check IInventory did not bypass any restrictions
            builder.addSlot(BasicInventorySlot.at(canInteract, canInteract, this, 8 + slotX * 18, 26 + slotY * 18));
        }
    }
    return builder.build();
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) SecurityMode(mekanism.common.lib.security.SecurityMode) AutomationType(mekanism.api.inventory.AutomationType) BasicInventorySlot(mekanism.common.inventory.slot.BasicInventorySlot) SecurityUtils(mekanism.common.util.SecurityUtils) SoundEvents(net.minecraft.util.SoundEvents) InventorySlotHelper(mekanism.common.capabilities.holder.slot.InventorySlotHelper) Dist(net.minecraftforge.api.distmarker.Dist) BiPredicate(java.util.function.BiPredicate) ItemStack(net.minecraft.item.ItemStack) IInventorySlotHolder(mekanism.common.capabilities.holder.slot.IInventorySlotHolder) Nonnull(javax.annotation.Nonnull) NonNull(mekanism.api.annotations.NonNull) MekanismBlocks(mekanism.common.registries.MekanismBlocks) SoundCategory(net.minecraft.util.SoundCategory) InventorySlotHelper(mekanism.common.capabilities.holder.slot.InventorySlotHelper) AutomationType(mekanism.api.inventory.AutomationType) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 4 with AutomationType

use of mekanism.api.inventory.AutomationType in project Mekanism by mekanism.

the class HybridInventorySlot method outputOrFill.

public static HybridInventorySlot outputOrFill(MergedTank mergedTank, @Nullable IContentsListener listener, int x, int y) {
    Objects.requireNonNull(mergedTank, "Merged tank cannot be null");
    Predicate<@NonNull ItemStack> gasExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getGasTank(), GasInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> infusionExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getInfusionTank(), InfusionInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> pigmentExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getPigmentTank(), PigmentInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> slurryExtractPredicate = ChemicalInventorySlot.getFillExtractPredicate(mergedTank.getSlurryTank(), SlurryInventorySlot::getCapability);
    Predicate<@NonNull ItemStack> gasInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getGasTank(), GasInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> infusionInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getInfusionTank(), InfusionInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> pigmentInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getPigmentTank(), PigmentInventorySlot.getCapability(stack));
    Predicate<@NonNull ItemStack> slurryInsertPredicate = stack -> ChemicalInventorySlot.fillInsertCheck(mergedTank.getSlurryTank(), SlurryInventorySlot.getCapability(stack));
    return new HybridInventorySlot(mergedTank, (stack, automationType) -> {
        if (automationType == AutomationType.MANUAL) {
            // Always allow the player to manually extract
            return true;
        }
        CurrentType currentType = mergedTank.getCurrentType();
        if (currentType == CurrentType.FLUID) {
            // Always allow extracting from a "fluid output" slot
            return true;
        } else if (currentType == CurrentType.GAS) {
            return gasExtractPredicate.test(stack);
        } else if (currentType == CurrentType.INFUSION) {
            return infusionExtractPredicate.test(stack);
        } else if (currentType == CurrentType.PIGMENT) {
            return pigmentExtractPredicate.test(stack);
        } else if (currentType == CurrentType.SLURRY) {
            return slurryExtractPredicate.test(stack);
        }
        // Else the tank is empty, check all our extraction predicates
        return gasExtractPredicate.test(stack) && infusionExtractPredicate.test(stack) && pigmentExtractPredicate.test(stack) && slurryExtractPredicate.test(stack);
    }, (stack, automationType) -> {
        CurrentType currentType = mergedTank.getCurrentType();
        if (currentType == CurrentType.FLUID) {
            // Only allow inserting internally for "fluid output" slots
            return automationType == AutomationType.INTERNAL;
        } else if (currentType == CurrentType.GAS) {
            return gasInsertPredicate.test(stack);
        } else if (currentType == CurrentType.INFUSION) {
            return infusionInsertPredicate.test(stack);
        } else if (currentType == CurrentType.PIGMENT) {
            return pigmentInsertPredicate.test(stack);
        } else if (currentType == CurrentType.SLURRY) {
            return slurryInsertPredicate.test(stack);
        }
        // Else the tank is empty, if the item is a fluid handler, and it is an internal check allow it
        if (automationType == AutomationType.INTERNAL && FluidUtil.getFluidHandler(stack).isPresent()) {
            return true;
        }
        // otherwise, only allow it if one of the chemical insert predicates matches
        return gasInsertPredicate.test(stack) || infusionInsertPredicate.test(stack) || pigmentInsertPredicate.test(stack) || slurryInsertPredicate.test(stack);
    }, HybridInventorySlot::hasCapability, listener, x, y);
}
Also used : FluidUtil(net.minecraftforge.fluids.FluidUtil) MergedChemicalInventorySlot(mekanism.common.inventory.slot.chemical.MergedChemicalInventorySlot) CurrentType(mekanism.common.capabilities.merged.MergedTank.CurrentType) Predicate(java.util.function.Predicate) InfusionInventorySlot(mekanism.common.inventory.slot.chemical.InfusionInventorySlot) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) AutomationType(mekanism.api.inventory.AutomationType) ChemicalInventorySlot(mekanism.common.inventory.slot.chemical.ChemicalInventorySlot) PigmentInventorySlot(mekanism.common.inventory.slot.chemical.PigmentInventorySlot) SlurryInventorySlot(mekanism.common.inventory.slot.chemical.SlurryInventorySlot) CompoundNBT(net.minecraft.nbt.CompoundNBT) MergedTank(mekanism.common.capabilities.merged.MergedTank) Objects(java.util.Objects) IContentsListener(mekanism.api.IContentsListener) BiPredicate(java.util.function.BiPredicate) ItemStack(net.minecraft.item.ItemStack) GasInventorySlot(mekanism.common.inventory.slot.chemical.GasInventorySlot) Capabilities(mekanism.common.capabilities.Capabilities) NBTConstants(mekanism.api.NBTConstants) Nonnull(javax.annotation.Nonnull) NonNull(mekanism.api.annotations.NonNull) Nullable(javax.annotation.Nullable) SlurryInventorySlot(mekanism.common.inventory.slot.chemical.SlurryInventorySlot) CurrentType(mekanism.common.capabilities.merged.MergedTank.CurrentType) GasInventorySlot(mekanism.common.inventory.slot.chemical.GasInventorySlot) ItemStack(net.minecraft.item.ItemStack) InfusionInventorySlot(mekanism.common.inventory.slot.chemical.InfusionInventorySlot) PigmentInventorySlot(mekanism.common.inventory.slot.chemical.PigmentInventorySlot)

Aggregations

BiPredicate (java.util.function.BiPredicate)4 Nonnull (javax.annotation.Nonnull)4 NonNull (mekanism.api.annotations.NonNull)4 AutomationType (mekanism.api.inventory.AutomationType)4 ItemStack (net.minecraft.item.ItemStack)4 Objects (java.util.Objects)3 Predicate (java.util.function.Predicate)3 Nullable (javax.annotation.Nullable)3 Capabilities (mekanism.common.capabilities.Capabilities)3 BasicInventorySlot (mekanism.common.inventory.slot.BasicInventorySlot)3 IContentsListener (mekanism.api.IContentsListener)2 NBTConstants (mekanism.api.NBTConstants)2 IInventorySlotHolder (mekanism.common.capabilities.holder.slot.IInventorySlotHolder)2 InventorySlotHelper (mekanism.common.capabilities.holder.slot.InventorySlotHelper)2 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)1 Long2ObjectMaps (it.unimi.dsi.fastutil.longs.Long2ObjectMaps)1 Object2ObjectOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)1 ObjectArraySet (it.unimi.dsi.fastutil.objects.ObjectArraySet)1