Search in sources :

Example 1 with IPowerHandler

use of forestry.core.tiles.IPowerHandler in project ForestryMC by ForestryMC.

the class ContainerTile method onGuiEnergy.

@SideOnly(Side.CLIENT)
public void onGuiEnergy(int energyStored) {
    if (tile instanceof IPowerHandler) {
        EnergyManager energyManager = ((IPowerHandler) tile).getEnergyManager();
        energyManager.setEnergyStored(energyStored);
    }
}
Also used : EnergyManager(forestry.energy.EnergyManager) IPowerHandler(forestry.core.tiles.IPowerHandler) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with IPowerHandler

use of forestry.core.tiles.IPowerHandler in project ForestryMC by ForestryMC.

the class ContainerTile method detectAndSendChanges.

@Override
public void detectAndSendChanges() {
    super.detectAndSendChanges();
    if (tile instanceof IErrorLogicSource) {
        IErrorLogicSource errorLogicSource = (IErrorLogicSource) tile;
        ImmutableSet<IErrorState> errorStates = errorLogicSource.getErrorLogic().getErrorStates();
        if (previousErrorStates == null || !errorStates.equals(previousErrorStates)) {
            PacketErrorUpdate packet = new PacketErrorUpdate(tile, errorLogicSource);
            sendPacketToListeners(packet);
        }
        previousErrorStates = errorStates;
    }
    if (tile instanceof IPowerHandler) {
        EnergyManager energyManager = ((IPowerHandler) tile).getEnergyManager();
        int energyManagerData = energyManager.getEnergyStored();
        if (energyManagerData != previousEnergyManagerData) {
            PacketGuiEnergy packet = new PacketGuiEnergy(windowId, energyManagerData);
            sendPacketToListeners(packet);
            previousEnergyManagerData = energyManagerData;
        }
    }
    if (tile instanceof TilePowered) {
        boolean guiNeedsUpdate = false;
        TilePowered tilePowered = (TilePowered) tile;
        int workCounter = tilePowered.getWorkCounter();
        if (workCounter != previousWorkCounter) {
            guiNeedsUpdate = true;
            previousWorkCounter = workCounter;
        }
        int ticksPerWorkCycle = tilePowered.getTicksPerWorkCycle();
        if (ticksPerWorkCycle != previousTicksPerWorkCycle) {
            guiNeedsUpdate = true;
            previousTicksPerWorkCycle = ticksPerWorkCycle;
        }
        if (guiNeedsUpdate) {
            PacketGuiUpdate packet = new PacketGuiUpdate(tilePowered);
            sendPacketToListeners(packet);
        }
    }
}
Also used : PacketErrorUpdate(forestry.core.network.packets.PacketErrorUpdate) PacketGuiUpdate(forestry.core.network.packets.PacketGuiUpdate) IErrorState(forestry.api.core.IErrorState) EnergyManager(forestry.energy.EnergyManager) IPowerHandler(forestry.core.tiles.IPowerHandler) PacketGuiEnergy(forestry.core.network.packets.PacketGuiEnergy) TilePowered(forestry.core.tiles.TilePowered) IErrorLogicSource(forestry.api.core.IErrorLogicSource)

Aggregations

IPowerHandler (forestry.core.tiles.IPowerHandler)2 EnergyManager (forestry.energy.EnergyManager)2 IErrorLogicSource (forestry.api.core.IErrorLogicSource)1 IErrorState (forestry.api.core.IErrorState)1 PacketErrorUpdate (forestry.core.network.packets.PacketErrorUpdate)1 PacketGuiEnergy (forestry.core.network.packets.PacketGuiEnergy)1 PacketGuiUpdate (forestry.core.network.packets.PacketGuiUpdate)1 TilePowered (forestry.core.tiles.TilePowered)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1