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