use of mekanism.common.content.gear.IModuleContainerItem 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;
}
}
}
use of mekanism.common.content.gear.IModuleContainerItem 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();
}
use of mekanism.common.content.gear.IModuleContainerItem in project Mekanism by mekanism.
the class TileEntityModificationStation method removeModule.
public void removeModule(PlayerEntity player, ModuleData<?> type) {
ItemStack stack = containerSlot.getStack();
if (!stack.isEmpty()) {
IModuleContainerItem container = (IModuleContainerItem) stack.getItem();
if (container.hasModule(stack, type) && player.inventory.add(type.getItemProvider().getItemStack())) {
container.removeModule(stack, type);
containerSlot.setStack(stack);
}
}
}
Aggregations