Search in sources :

Example 6 with DataType

use of mekanism.common.tile.component.config.DataType in project Mekanism by mekanism.

the class TileComponentConfig method read.

@Override
public void read(CompoundNBT nbtTags) {
    if (nbtTags.contains(NBTConstants.COMPONENT_CONFIG, NBT.TAG_COMPOUND)) {
        CompoundNBT configNBT = nbtTags.getCompound(NBTConstants.COMPONENT_CONFIG);
        Set<Direction> directionsToUpdate = EnumSet.noneOf(Direction.class);
        for (Entry<TransmissionType, ConfigInfo> entry : configInfo.entrySet()) {
            TransmissionType type = entry.getKey();
            ConfigInfo info = entry.getValue();
            info.setEjecting(configNBT.getBoolean(NBTConstants.EJECT + type.ordinal()));
            CompoundNBT sideConfig = configNBT.getCompound(NBTConstants.CONFIG + type.ordinal());
            for (RelativeSide side : EnumUtils.SIDES) {
                NBTUtils.setEnumIfPresent(sideConfig, NBTConstants.SIDE + side.ordinal(), DataType::byIndexStatic, dataType -> {
                    if (info.getDataType(side) != dataType) {
                        info.setDataType(dataType, side);
                        if (tile.hasLevel()) {
                            // If we aren't already loaded yet don't do any updates
                            Direction direction = side.getDirection(tile.getDirection());
                            sideChangedBasic(type, direction);
                            directionsToUpdate.add(direction);
                        }
                    }
                });
            }
        }
        WorldUtils.notifyNeighborsOfChange(tile.getLevel(), tile.getBlockPos(), directionsToUpdate);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) RelativeSide(mekanism.api.RelativeSide) DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) Direction(net.minecraft.util.Direction)

Example 7 with DataType

use of mekanism.common.tile.component.config.DataType in project Mekanism by mekanism.

the class TileComponentConfig method readFromUpdateTag.

@Override
public void readFromUpdateTag(CompoundNBT updateTag) {
    if (updateTag.contains(NBTConstants.COMPONENT_CONFIG, NBT.TAG_COMPOUND)) {
        CompoundNBT configNBT = updateTag.getCompound(NBTConstants.COMPONENT_CONFIG);
        for (Entry<TransmissionType, ConfigInfo> entry : configInfo.entrySet()) {
            TransmissionType type = entry.getKey();
            ConfigInfo info = entry.getValue();
            CompoundNBT sideConfig = configNBT.getCompound(NBTConstants.CONFIG + type.ordinal());
            for (RelativeSide side : EnumUtils.SIDES) {
                NBTUtils.setEnumIfPresent(sideConfig, NBTConstants.SIDE + side.ordinal(), DataType::byIndexStatic, dataType -> info.setDataType(dataType, side));
            }
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) RelativeSide(mekanism.api.RelativeSide) DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo)

Example 8 with DataType

use of mekanism.common.tile.component.config.DataType 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());
            }
        }
    }
}
Also used : ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) LongSupplier(java.util.function.LongSupplier) SyncableInt(mekanism.common.inventory.container.sync.SyncableInt) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) CompoundNBT(net.minecraft.nbt.CompoundNBT) Direction(net.minecraft.util.Direction) FluidSlotInfo(mekanism.common.tile.component.config.slot.FluidSlotInfo) TileTransitRequest(mekanism.common.lib.inventory.TileTransitRequest) Map(java.util.Map) EnumSet(java.util.EnumSet) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase) EnumMap(java.util.EnumMap) NBTUtils(mekanism.common.util.NBTUtils) Predicate(java.util.function.Predicate) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) Set(java.util.Set) List(java.util.List) ComputerException(mekanism.common.integration.computer.ComputerException) InventoryUtils(mekanism.common.util.InventoryUtils) RelativeSide(mekanism.api.RelativeSide) ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) NBTConstants(mekanism.api.NBTConstants) ChemicalUtil(mekanism.common.util.ChemicalUtil) EnumColor(mekanism.api.text.EnumColor) CableUtils(mekanism.common.util.CableUtils) SyncableBoolean(mekanism.common.inventory.container.sync.SyncableBoolean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ISpecificContainerTracker(mekanism.common.inventory.container.MekanismContainer.ISpecificContainerTracker) ChemicalSlotInfo(mekanism.common.tile.component.config.slot.ChemicalSlotInfo) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod) IEnergyContainer(mekanism.api.energy.IEnergyContainer) Nonnull(javax.annotation.Nonnull) IntSupplier(java.util.function.IntSupplier) Nullable(javax.annotation.Nullable) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) EnumUtils(mekanism.common.util.EnumUtils) DataType(mekanism.common.tile.component.config.DataType) InventorySlotInfo(mekanism.common.tile.component.config.slot.InventorySlotInfo) TransporterUtils(mekanism.common.util.TransporterUtils) FluidUtils(mekanism.common.util.FluidUtils) NBT(net.minecraftforge.common.util.Constants.NBT) EnergySlotInfo(mekanism.common.tile.component.config.slot.EnergySlotInfo) WorldUtils(mekanism.common.util.WorldUtils) TileEntity(net.minecraft.tileentity.TileEntity) IChemicalTank(mekanism.api.chemical.IChemicalTank) MekanismConfig(mekanism.common.config.MekanismConfig) FloatingLongSupplier(mekanism.api.math.FloatingLongSupplier) ISyncableData(mekanism.common.inventory.container.sync.ISyncableData) FluidSlotInfo(mekanism.common.tile.component.config.slot.FluidSlotInfo) EnumSet(java.util.EnumSet) Set(java.util.Set) EnergySlotInfo(mekanism.common.tile.component.config.slot.EnergySlotInfo) Direction(net.minecraft.util.Direction) ChemicalSlotInfo(mekanism.common.tile.component.config.slot.ChemicalSlotInfo) IEnergyContainer(mekanism.api.energy.IEnergyContainer) DataType(mekanism.common.tile.component.config.DataType) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap)

Example 9 with DataType

use of mekanism.common.tile.component.config.DataType in project Mekanism by mekanism.

the class SideDataButton method drawBackground.

@Override
public void drawBackground(@Nonnull MatrixStack matrix, int mouseX, int mouseY, float partialTicks) {
    DataType dataType = getDataType();
    EnumColor color = dataType == null ? null : getColor();
    boolean doColor = color != null && color != EnumColor.GRAY;
    if (doColor) {
        Color c = Color.rgbi(color.getRgbCode()[0], color.getRgbCode()[1], color.getRgbCode()[2]);
        double[] hsv = c.hsvArray();
        hsv[1] = Math.max(0, hsv[1] - 0.25F);
        hsv[2] = Math.min(1, hsv[2] + 0.4F);
        MekanismRenderer.color(Color.hsv(hsv[0], hsv[1], hsv[2]));
    } else {
        MekanismRenderer.resetColor();
    }
    super.drawBackground(matrix, mouseX, mouseY, partialTicks);
    if (doColor) {
        MekanismRenderer.resetColor();
    }
}
Also used : EnumColor(mekanism.api.text.EnumColor) EnumColor(mekanism.api.text.EnumColor) Color(mekanism.common.lib.Color) DataType(mekanism.common.tile.component.config.DataType)

Example 10 with DataType

use of mekanism.common.tile.component.config.DataType in project Mekanism by mekanism.

the class TileComponentConfig method setMode.

@ComputerMethod
private void setMode(TransmissionType type, RelativeSide side, DataType mode) throws ComputerException {
    tile.validateSecurityIsPublic();
    validateSupportedTransmissionType(type);
    ConfigInfo config = configInfo.get(type);
    if (!config.getSupportedDataTypes().contains(mode)) {
        throw new ComputerException("This machine does not support mode '%s' for transmission type '%s'.", mode, type);
    }
    DataType currentMode = config.getDataType(side);
    if (mode != currentMode) {
        config.setDataType(mode, side);
        sideChanged(type, side);
    }
}
Also used : DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) ComputerException(mekanism.common.integration.computer.ComputerException) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod)

Aggregations

DataType (mekanism.common.tile.component.config.DataType)15 ConfigInfo (mekanism.common.tile.component.config.ConfigInfo)9 RelativeSide (mekanism.api.RelativeSide)6 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)6 TransmissionType (mekanism.common.lib.transmitter.TransmissionType)5 TileEntity (net.minecraft.tileentity.TileEntity)5 Direction (net.minecraft.util.Direction)5 IInventorySlot (mekanism.api.inventory.IInventorySlot)4 EnumColor (mekanism.api.text.EnumColor)4 ItemStack (net.minecraft.item.ItemStack)4 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 ItemConfigurator (mekanism.common.item.ItemConfigurator)3 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)3 TileComponentConfig (mekanism.common.tile.component.TileComponentConfig)3 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 IEnergyContainer (mekanism.api.energy.IEnergyContainer)2 IExtendedFluidTank (mekanism.api.fluid.IExtendedFluidTank)2 InventoryContainerSlot (mekanism.common.inventory.container.slot.InventoryContainerSlot)2