Search in sources :

Example 1 with TileComponentEjector

use of mekanism.common.tile.component.TileComponentEjector in project Mekanism by mekanism.

the class PacketConfigurationUpdate method handle.

@Override
public void handle(NetworkEvent.Context context) {
    PlayerEntity player = context.getSender();
    if (player == null) {
        return;
    }
    TileEntity tile = WorldUtils.getTileEntity(player.level, pos);
    if (tile instanceof ISideConfiguration) {
        ISideConfiguration config = (ISideConfiguration) tile;
        if (packetType == ConfigurationPacket.EJECT) {
            ConfigInfo info = config.getConfig().getConfig(transmission);
            if (info != null) {
                info.setEjecting(!info.isEjecting());
                WorldUtils.saveChunk(tile);
            }
        } else if (packetType == ConfigurationPacket.CLEAR_ALL) {
            TileComponentConfig configComponent = config.getConfig();
            ConfigInfo info = configComponent.getConfig(transmission);
            if (info != null) {
                for (RelativeSide side : EnumUtils.SIDES) {
                    if (info.isSideEnabled(side) && info.getDataType(side) != DataType.NONE) {
                        info.setDataType(DataType.NONE, side);
                        configComponent.sideChanged(transmission, side);
                    }
                }
            }
        } else if (packetType == ConfigurationPacket.SIDE_DATA) {
            TileComponentConfig configComponent = config.getConfig();
            ConfigInfo info = configComponent.getConfig(transmission);
            if (info != null) {
                DataType type = info.getDataType(inputSide);
                boolean changed = false;
                if (clickType == 0) {
                    changed = type != info.incrementDataType(inputSide);
                } else if (clickType == 1) {
                    changed = type != info.decrementDataType(inputSide);
                } else if (clickType == 2 && type != DataType.NONE) {
                    // We only need to update it if we are changing it to none
                    changed = true;
                    info.setDataType(DataType.NONE, inputSide);
                }
                if (changed) {
                    configComponent.sideChanged(transmission, inputSide);
                }
            }
        } else if (packetType == ConfigurationPacket.EJECT_COLOR) {
            TileComponentEjector ejector = config.getEjector();
            if (clickType == 0) {
                ejector.setOutputColor(TransporterUtils.increment(ejector.getOutputColor()));
            } else if (clickType == 1) {
                ejector.setOutputColor(TransporterUtils.decrement(ejector.getOutputColor()));
            } else if (clickType == 2) {
                ejector.setOutputColor(null);
            }
        } else if (packetType == ConfigurationPacket.INPUT_COLOR) {
            TileComponentEjector ejector = config.getEjector();
            if (clickType == 0) {
                ejector.setInputColor(inputSide, TransporterUtils.increment(ejector.getInputColor(inputSide)));
            } else if (clickType == 1) {
                ejector.setInputColor(inputSide, TransporterUtils.decrement(ejector.getInputColor(inputSide)));
            } else if (clickType == 2) {
                ejector.setInputColor(inputSide, null);
            }
        } else if (packetType == ConfigurationPacket.STRICT_INPUT) {
            TileComponentEjector ejector = config.getEjector();
            ejector.setStrictInput(!ejector.hasStrictInput());
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileComponentEjector(mekanism.common.tile.component.TileComponentEjector) RelativeSide(mekanism.api.RelativeSide) DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Aggregations

RelativeSide (mekanism.api.RelativeSide)1 TileComponentConfig (mekanism.common.tile.component.TileComponentConfig)1 TileComponentEjector (mekanism.common.tile.component.TileComponentEjector)1 ConfigInfo (mekanism.common.tile.component.config.ConfigInfo)1 DataType (mekanism.common.tile.component.config.DataType)1 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1