Search in sources :

Example 1 with RelativeSide

use of mekanism.api.RelativeSide 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);
}
Also used : ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) RelativeSide(mekanism.api.RelativeSide) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo)

Example 2 with RelativeSide

use of mekanism.api.RelativeSide in project Mekanism by mekanism.

the class ModelEnergyCube method renderSidesBatched.

public void renderSidesBatched(@Nonnull ItemStack stack, EnergyCubeTier tier, @Nonnull MatrixStack matrix, @Nonnull IRenderTypeBuffer renderer, int light, int overlayLight, boolean hasEffect) {
    Set<RelativeSide> enabledSides;
    Set<RelativeSide> outputSides;
    CompoundNBT configData = ItemDataUtils.getDataMapIfPresent(stack);
    if (configData != null && configData.contains(NBTConstants.COMPONENT_CONFIG, NBT.TAG_COMPOUND)) {
        enabledSides = EnumSet.noneOf(RelativeSide.class);
        outputSides = EnumSet.noneOf(RelativeSide.class);
        CompoundNBT sideConfig = configData.getCompound(NBTConstants.COMPONENT_CONFIG).getCompound(NBTConstants.CONFIG + TransmissionType.ENERGY.ordinal());
        // TODO: Maybe improve on this, but for now this is a decent way of making it not have disabled sides show
        for (RelativeSide side : EnumUtils.SIDES) {
            DataType dataType = DataType.byIndexStatic(sideConfig.getInt(NBTConstants.SIDE + side.ordinal()));
            if (dataType.equals(DataType.INPUT)) {
                enabledSides.add(side);
            } else if (dataType.equals(DataType.OUTPUT)) {
                enabledSides.add(side);
                outputSides.add(side);
            }
        }
    } else {
        enabledSides = EnumSet.allOf(RelativeSide.class);
        if (tier == EnergyCubeTier.CREATIVE) {
            outputSides = EnumSet.allOf(RelativeSide.class);
        } else {
            outputSides = Collections.singleton(RelativeSide.FRONT);
        }
    }
    renderSidesBatched(matrix, renderer, light, overlayLight, enabledSides, outputSides, hasEffect);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) RelativeSide(mekanism.api.RelativeSide) DataType(mekanism.common.tile.component.config.DataType)

Example 3 with RelativeSide

use of mekanism.api.RelativeSide in project Mekanism by mekanism.

the class TileEntityGenerator method onUpdateServer.

@Override
protected void onUpdateServer() {
    super.onUpdateServer();
    if (MekanismUtils.canFunction(this)) {
        // TODO: Cache the directions or maybe even make some generators have a side config/ejector component and move this to the ejector component?
        Set<Direction> emitDirections = EnumSet.noneOf(Direction.class);
        Direction direction = getDirection();
        for (RelativeSide energySide : getEnergySides()) {
            emitDirections.add(energySide.getDirection(direction));
        }
        CableUtils.emit(emitDirections, energyContainer, this, getMaxOutput());
    }
}
Also used : RelativeSide(mekanism.api.RelativeSide) Direction(net.minecraft.util.Direction)

Example 4 with RelativeSide

use of mekanism.api.RelativeSide 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 5 with RelativeSide

use of mekanism.api.RelativeSide 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)

Aggregations

RelativeSide (mekanism.api.RelativeSide)14 ConfigInfo (mekanism.common.tile.component.config.ConfigInfo)7 TransmissionType (mekanism.common.lib.transmitter.TransmissionType)6 DataType (mekanism.common.tile.component.config.DataType)5 CompoundNBT (net.minecraft.nbt.CompoundNBT)5 Direction (net.minecraft.util.Direction)4 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 IVertexBuilder (com.mojang.blaze3d.vertex.IVertexBuilder)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1 IConfigurable (mekanism.api.IConfigurable)1 IEnergyContainer (mekanism.api.energy.IEnergyContainer)1 IInventorySlot (mekanism.api.inventory.IInventorySlot)1 IMekanismInventory (mekanism.api.inventory.IMekanismInventory)1 FloatingLong (mekanism.api.math.FloatingLong)1