Search in sources :

Example 1 with RailcraftInputStream

use of mods.railcraft.common.util.network.RailcraftInputStream in project Railcraft by Railcraft.

the class ContainerTank method createGauge.

public FluidGaugeWidget createGauge(StandardTank tank, int x, int y, int u, int v, int w, int h) {
    if (logicContainer.getLogic(WaterGeneratorLogic.class).isPresent())
        return new FluidGaugeWidget(tank, x, y, u, v, w, h) {

            GeneratorStatus status = new GeneratorStatus();

            ToolTip toolTip = new ToolTip() {

                @Override
                public void refresh() {
                    clear();
                    ToolTip tankToolTip = tank.getToolTip();
                    tankToolTip.refresh();
                    addAll(tankToolTip);
                    get(0).format = TextFormatting.BLUE;
                    newline();
                    add(new ToolTipLine(LocalizationPlugin.format("gui.railcraft.tank.sky", status.canSeeSky), TextFormatting.DARK_GRAY));
                    add(new ToolTipLine(LocalizationPlugin.format("gui.railcraft.tank.base", status.baseRate() * status.canSeeSky), TextFormatting.DARK_GRAY));
                    add(new ToolTipLine(LocalizationPlugin.format("gui.railcraft.tank.humidity", status.humidityMultiplier), TextFormatting.DARK_GRAY));
                    add(new ToolTipLine(LocalizationPlugin.format("gui.railcraft.tank.precipitation", status.precipitationMultiplier), TextFormatting.DARK_GRAY));
                    add(new ToolTipLine(LocalizationPlugin.format("gui.railcraft.tank.temp", -status.tempPenalty), TextFormatting.DARK_GRAY));
                    add(new ToolTipLine(LocalizationPlugin.format("gui.railcraft.tank.final", (status.baseRate() * status.canSeeSky * status.humidityMultiplier * status.precipitationMultiplier) - status.tempPenalty), TextFormatting.DARK_GRAY));
                }
            };

            @Override
            public void writeServerSyncData(IContainerListener listener, RailcraftOutputStream data) throws IOException {
                super.writeServerSyncData(listener, data);
                GeneratorStatus temp = new GeneratorStatus();
                temp.precipitationMultiplier = 0.0;
                temp.humidityMultiplier = 0.0;
                logicContainer.getLogic(StructureLogic.class).ifPresent(struct -> {
                    struct.getComponents().stream().map(t -> t.getLogic(WaterGeneratorLogic.class)).flatMap(Streams.unwrap()).map(l -> l.status).forEach(s -> {
                        temp.canSeeSky += s.canSeeSky;
                        if (s.canSeeSky > 0) {
                            temp.humidityMultiplier += s.humidityMultiplier;
                            temp.precipitationMultiplier += s.precipitationMultiplier;
                            temp.tempPenalty += s.tempPenalty;
                        }
                    });
                });
                if (temp.canSeeSky > 0) {
                    temp.humidityMultiplier /= temp.canSeeSky;
                    temp.precipitationMultiplier /= temp.canSeeSky;
                }
                temp.writeData(data);
            }

            @Override
            public void readServerSyncData(RailcraftInputStream data) throws IOException {
                super.readServerSyncData(data);
                status.readData(data);
            }

            @Override
            public ToolTip getToolTip() {
                return toolTip;
            }
        };
    return new FluidGaugeWidget(tank, x, y, u, v, w, h);
}
Also used : ToolTip(mods.railcraft.common.gui.tooltips.ToolTip) ToolTipLine(mods.railcraft.common.gui.tooltips.ToolTipLine) ILogicContainer(mods.railcraft.common.blocks.logic.ILogicContainer) ToolTip(mods.railcraft.common.gui.tooltips.ToolTip) FluidGaugeWidget(mods.railcraft.common.gui.widgets.FluidGaugeWidget) TextFormatting(net.minecraft.util.text.TextFormatting) Streams(mods.railcraft.common.util.collections.Streams) IInventoryImplementor(mods.railcraft.common.util.inventory.IInventoryImplementor) IOException(java.io.IOException) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) StructureLogic(mods.railcraft.common.blocks.logic.StructureLogic) GeneratorStatus(mods.railcraft.common.blocks.logic.WaterGeneratorLogic.GeneratorStatus) RailcraftInputStream(mods.railcraft.common.util.network.RailcraftInputStream) LocalizationPlugin(mods.railcraft.common.plugins.forge.LocalizationPlugin) RailcraftOutputStream(mods.railcraft.common.util.network.RailcraftOutputStream) IContainerListener(net.minecraft.inventory.IContainerListener) WaterGeneratorLogic(mods.railcraft.common.blocks.logic.WaterGeneratorLogic) SlotOutput(mods.railcraft.common.gui.slots.SlotOutput) FluidLogic(mods.railcraft.common.blocks.logic.FluidLogic) StandardTank(mods.railcraft.common.fluids.tanks.StandardTank) SlotRailcraft(mods.railcraft.common.gui.slots.SlotRailcraft) RailcraftInputStream(mods.railcraft.common.util.network.RailcraftInputStream) GeneratorStatus(mods.railcraft.common.blocks.logic.WaterGeneratorLogic.GeneratorStatus) ToolTipLine(mods.railcraft.common.gui.tooltips.ToolTipLine) WaterGeneratorLogic(mods.railcraft.common.blocks.logic.WaterGeneratorLogic) RailcraftOutputStream(mods.railcraft.common.util.network.RailcraftOutputStream) FluidGaugeWidget(mods.railcraft.common.gui.widgets.FluidGaugeWidget) IContainerListener(net.minecraft.inventory.IContainerListener) IOException(java.io.IOException)

Example 2 with RailcraftInputStream

use of mods.railcraft.common.util.network.RailcraftInputStream in project Railcraft by Railcraft.

the class TrackKitLocomotive method readPacketData.

@Override
public void readPacketData(DataInputStream data) throws IOException {
    super.readPacketData(data);
    RailcraftInputStream inputStream = new RailcraftInputStream(data);
    mode = inputStream.readEnum(LocoMode.VALUES);
    markBlockNeedsUpdate();
}
Also used : RailcraftInputStream(mods.railcraft.common.util.network.RailcraftInputStream)

Aggregations

RailcraftInputStream (mods.railcraft.common.util.network.RailcraftInputStream)2 IOException (java.io.IOException)1 FluidLogic (mods.railcraft.common.blocks.logic.FluidLogic)1 ILogicContainer (mods.railcraft.common.blocks.logic.ILogicContainer)1 StructureLogic (mods.railcraft.common.blocks.logic.StructureLogic)1 WaterGeneratorLogic (mods.railcraft.common.blocks.logic.WaterGeneratorLogic)1 GeneratorStatus (mods.railcraft.common.blocks.logic.WaterGeneratorLogic.GeneratorStatus)1 StandardTank (mods.railcraft.common.fluids.tanks.StandardTank)1 SlotOutput (mods.railcraft.common.gui.slots.SlotOutput)1 SlotRailcraft (mods.railcraft.common.gui.slots.SlotRailcraft)1 ToolTip (mods.railcraft.common.gui.tooltips.ToolTip)1 ToolTipLine (mods.railcraft.common.gui.tooltips.ToolTipLine)1 FluidGaugeWidget (mods.railcraft.common.gui.widgets.FluidGaugeWidget)1 LocalizationPlugin (mods.railcraft.common.plugins.forge.LocalizationPlugin)1 Streams (mods.railcraft.common.util.collections.Streams)1 IInventoryImplementor (mods.railcraft.common.util.inventory.IInventoryImplementor)1 RailcraftOutputStream (mods.railcraft.common.util.network.RailcraftOutputStream)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 IContainerListener (net.minecraft.inventory.IContainerListener)1 TextFormatting (net.minecraft.util.text.TextFormatting)1