Search in sources :

Example 1 with IInventorySlotHolder

use of mekanism.common.capabilities.holder.slot.IInventorySlotHolder 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 2 with IInventorySlotHolder

use of mekanism.common.capabilities.holder.slot.IInventorySlotHolder 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)

Aggregations

BiPredicate (java.util.function.BiPredicate)2 Nonnull (javax.annotation.Nonnull)2 NonNull (mekanism.api.annotations.NonNull)2 AutomationType (mekanism.api.inventory.AutomationType)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 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)1 ObjectOpenHashSet (it.unimi.dsi.fastutil.objects.ObjectOpenHashSet)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1