Search in sources :

Example 1 with IModuleItem

use of mekanism.common.content.gear.IModuleItem in project Mekanism by mekanism.

the class TileEntityModificationStation method onUpdateServer.

@Override
protected void onUpdateServer() {
    super.onUpdateServer();
    energySlot.fillContainerOrConvert();
    if (MekanismUtils.canFunction(this)) {
        boolean operated = false;
        if (energyContainer.getEnergy().greaterOrEqual(energyContainer.getEnergyPerTick()) && !moduleSlot.isEmpty() && !containerSlot.isEmpty()) {
            ModuleData<?> data = ((IModuleItem) moduleSlot.getStack().getItem()).getModuleData();
            ItemStack stack = containerSlot.getStack();
            // make sure the container supports this module
            if (MekanismAPI.getModuleHelper().getSupported(stack).contains(data)) {
                // make sure we can still install more of this module
                IModule<?> module = MekanismAPI.getModuleHelper().load(stack, data);
                if (module == null || module.getInstalledCount() < data.getMaxStackSize()) {
                    operated = true;
                    operatingTicks++;
                    energyContainer.extract(energyContainer.getEnergyPerTick(), Action.EXECUTE, AutomationType.INTERNAL);
                    if (operatingTicks == ticksRequired) {
                        operatingTicks = 0;
                        ((IModuleContainerItem) stack.getItem()).addModule(stack, data);
                        containerSlot.setStack(stack);
                        MekanismUtils.logMismatchedStackSize(moduleSlot.shrinkStack(1, Action.EXECUTE), 1);
                    }
                }
            }
        }
        if (!operated) {
            operatingTicks = 0;
        }
    }
}
Also used : IModuleContainerItem(mekanism.common.content.gear.IModuleContainerItem) ItemStack(net.minecraft.item.ItemStack) IModuleItem(mekanism.common.content.gear.IModuleItem)

Example 2 with IModuleItem

use of mekanism.common.content.gear.IModuleItem in project Mekanism by mekanism.

the class TileEntityModificationStation method getInitialInventory.

@Nonnull
@Override
protected IInventorySlotHolder getInitialInventory() {
    InventorySlotHelper builder = InventorySlotHelper.forSide(this::getDirection);
    builder.addSlot(moduleSlot = InputInventorySlot.at(stack -> stack.getItem() instanceof IModuleItem, this, 35, 118));
    builder.addSlot(containerSlot = InputInventorySlot.at(stack -> stack.getItem() instanceof IModuleContainerItem, this, 125, 118));
    moduleSlot.setSlotType(ContainerSlotType.NORMAL);
    moduleSlot.setSlotOverlay(SlotOverlay.MODULE);
    containerSlot.setSlotType(ContainerSlotType.NORMAL);
    builder.addSlot(energySlot = EnergyInventorySlot.fillOrConvert(energyContainer, this::getLevel, this, 149, 21));
    return builder.build();
}
Also used : InventorySlotHelper(mekanism.common.capabilities.holder.slot.InventorySlotHelper) IModuleContainerItem(mekanism.common.content.gear.IModuleContainerItem) IModuleItem(mekanism.common.content.gear.IModuleItem) Nonnull(javax.annotation.Nonnull)

Aggregations

IModuleContainerItem (mekanism.common.content.gear.IModuleContainerItem)2 IModuleItem (mekanism.common.content.gear.IModuleItem)2 Nonnull (javax.annotation.Nonnull)1 InventorySlotHelper (mekanism.common.capabilities.holder.slot.InventorySlotHelper)1 ItemStack (net.minecraft.item.ItemStack)1