use of mekanism.common.tile.component.config.slot.ISlotInfo in project Mekanism by mekanism.
the class ModelEnergyCube method renderSidesBatched.
public void renderSidesBatched(@Nonnull TileEntityEnergyCube tile, @Nonnull MatrixStack matrix, @Nonnull IRenderTypeBuffer renderer, int light, int overlayLight) {
Set<RelativeSide> enabledSides = EnumSet.noneOf(RelativeSide.class);
Set<RelativeSide> outputSides = EnumSet.noneOf(RelativeSide.class);
ConfigInfo config = tile.getConfig().getConfig(TransmissionType.ENERGY);
if (config != null) {
for (RelativeSide side : EnumUtils.SIDES) {
ISlotInfo slotInfo = config.getSlotInfo(side);
if (slotInfo != null) {
if (slotInfo.canInput()) {
enabledSides.add(side);
} else if (slotInfo.canOutput()) {
enabledSides.add(side);
outputSides.add(side);
}
}
}
}
renderSidesBatched(matrix, renderer, light, overlayLight, enabledSides, outputSides, false);
}
use of mekanism.common.tile.component.config.slot.ISlotInfo in project Mekanism by mekanism.
the class TileComponentEjector method eject.
/**
* @apiNote Ensure that it can eject before calling this method.
*/
private void eject(TransmissionType type, ConfigInfo info) {
// Used to keep track of tanks to what sides they output to
Map<Object, Set<Direction>> outputData = null;
for (DataType dataType : info.getSupportedDataTypes()) {
if (dataType.canOutput()) {
ISlotInfo slotInfo = info.getSlotInfo(dataType);
if (slotInfo != null) {
Set<Direction> outputSides = info.getSidesForData(dataType);
if (!outputSides.isEmpty()) {
if (outputData == null) {
// Lazy init outputData
outputData = new HashMap<>();
}
if (type.isChemical() && slotInfo instanceof ChemicalSlotInfo) {
for (IChemicalTank<?, ?> tank : ((ChemicalSlotInfo<?, ?, ?>) slotInfo).getTanks()) {
if (!tank.isEmpty() && (canTankEject == null || canTankEject.test(tank))) {
outputData.computeIfAbsent(tank, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
}
}
} else if (type == TransmissionType.FLUID && slotInfo instanceof FluidSlotInfo) {
for (IExtendedFluidTank tank : ((FluidSlotInfo) slotInfo).getTanks()) {
if (!tank.isEmpty()) {
outputData.computeIfAbsent(tank, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
}
}
} else if (type == TransmissionType.ENERGY && slotInfo instanceof EnergySlotInfo) {
for (IEnergyContainer container : ((EnergySlotInfo) slotInfo).getContainers()) {
if (!container.isEmpty()) {
outputData.computeIfAbsent(container, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
}
}
}
}
}
}
}
if (outputData != null && !outputData.isEmpty()) {
for (Map.Entry<Object, Set<Direction>> entry : outputData.entrySet()) {
if (type.isChemical()) {
ChemicalUtil.emit(entry.getValue(), (IChemicalTank<?, ?>) entry.getKey(), tile, chemicalEjectRate.getAsLong());
} else if (type == TransmissionType.FLUID) {
FluidUtils.emit(entry.getValue(), (IExtendedFluidTank) entry.getKey(), tile, fluidEjectRate.getAsInt());
} else if (type == TransmissionType.ENERGY) {
IEnergyContainer container = (IEnergyContainer) entry.getKey();
CableUtils.emit(entry.getValue(), container, tile, energyEjectRate == null ? container.getMaxEnergy() : energyEjectRate.get());
}
}
}
}
use of mekanism.common.tile.component.config.slot.ISlotInfo in project Mekanism by mekanism.
the class ConfigHolder method getSlotInfo.
@Nullable
private ISlotInfo getSlotInfo(Direction side) {
Direction direction = facingSupplier.get();
if (direction != lastDirection) {
// Invalid entire cache and update what direction we had as last if our last direction doesn't match the one we currently are facing
cachedSlotInfo.clear();
lastDirection = direction;
} else if (cachedSlotInfo.containsKey(side)) {
return cachedSlotInfo.get(side);
}
ISlotInfo slotInfo;
TileComponentConfig config = configSupplier.get();
if (config == null) {
slotInfo = NO_CONFIG;
} else {
TransmissionType transmissionType = getTransmissionType();
ConfigInfo configInfo = config.getConfig(transmissionType);
if (configInfo == null) {
slotInfo = NO_CONFIG;
} else {
if (!listenerAdded) {
// If we haven't added a listener to our config yet add one to remove the cached info we have for that side
listenerAdded = true;
config.addConfigChangeListener(transmissionType, cachedSlotInfo::remove);
}
slotInfo = configInfo.getSlotInfo(RelativeSide.fromDirections(direction, side));
if (slotInfo != null && !slotInfo.isEnabled()) {
// If we have a slot info, but it is not actually enabled, just store it as null to avoid having to recheck if it is enabled later
slotInfo = null;
}
}
}
cachedSlotInfo.put(side, slotInfo);
return slotInfo;
}
use of mekanism.common.tile.component.config.slot.ISlotInfo in project Mekanism by mekanism.
the class TileComponentEjector method outputItems.
/**
* @apiNote Ensure that it can eject before calling this method.
*/
private void outputItems(ConfigInfo info) {
for (DataType dataType : info.getSupportedDataTypes()) {
if (!dataType.canOutput()) {
continue;
}
ISlotInfo slotInfo = info.getSlotInfo(dataType);
if (slotInfo instanceof InventorySlotInfo) {
// Validate the slot info is of the correct type
Set<Direction> outputs = info.getSidesForData(dataType);
if (!outputs.isEmpty()) {
EjectTransitRequest ejectMap = InventoryUtils.getEjectItemMap(new EjectTransitRequest(tile, outputs.iterator().next()), ((InventorySlotInfo) slotInfo).getSlots());
if (!ejectMap.isEmpty()) {
for (Direction side : outputs) {
TileEntity target = WorldUtils.getTileEntity(tile.getLevel(), tile.getBlockPos().relative(side));
if (target != null) {
// Update the side so that if/when the response uses it, it makes sure it is grabbing from the correct side
ejectMap.side = side;
// If the spot is not loaded just skip trying to eject to it
TransitResponse response;
if (target instanceof TileEntityLogisticalTransporterBase) {
response = ((TileEntityLogisticalTransporterBase) target).getTransmitter().insert(tile, ejectMap, outputColor, true, 0);
} else {
response = ejectMap.addToInventory(target, side, 0, false);
}
if (!response.isEmpty()) {
// use the items returned by the TransitResponse; will be visible next loop
response.useAll();
if (ejectMap.isEmpty()) {
// If we are out of items to eject, break
break;
}
}
}
}
}
}
}
}
tickDelay = 10;
}
use of mekanism.common.tile.component.config.slot.ISlotInfo in project Mekanism by mekanism.
the class GuiMekanismTile method getFromSlot.
private DataType getFromSlot(Slot slot) {
if (slot.index < tile.getSlots() && slot instanceof InventoryContainerSlot) {
ISideConfiguration config = (ISideConfiguration) tile;
ConfigInfo info = config.getConfig().getConfig(TransmissionType.ITEM);
if (info != null) {
Set<DataType> supportedDataTypes = info.getSupportedDataTypes();
IInventorySlot inventorySlot = ((InventoryContainerSlot) slot).getInventorySlot();
for (DataType type : supportedDataTypes) {
ISlotInfo slotInfo = info.getSlotInfo(type);
if (slotInfo instanceof InventorySlotInfo && ((InventorySlotInfo) slotInfo).hasSlot(inventorySlot)) {
return type;
}
}
}
}
return null;
}
Aggregations