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);
}
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();
}
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();
}
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);
}
Aggregations