Search in sources :

Example 1 with IHeatExchangerLogic

use of pneumaticCraft.api.IHeatExchangerLogic in project PneumaticCraft by MineMaarten.

the class HeatExchangerLogic method update.

@Override
public void update() {
    if (getThermalCapacity() < 0.1D) {
        temperature = 295;
        return;
    }
    if (newBehaviours != null) {
        List<HeatBehaviour> oldBehaviours = behaviours;
        behaviours = newBehaviours;
        newBehaviours = null;
        for (HeatBehaviour oldBehaviour : oldBehaviours) {
            // Transfer over equal heat behaviour's info.
            int equalBehaviourIndex = behaviours.indexOf(oldBehaviour);
            if (equalBehaviourIndex >= 0) {
                NBTTagCompound tag = new NBTTagCompound();
                oldBehaviour.writeToNBT(tag);
                behaviours.get(equalBehaviourIndex).readFromNBT(tag);
            }
        }
    }
    Iterator<HeatBehaviour> iterator = behaviours.iterator();
    while (iterator.hasNext()) {
        HeatBehaviour behaviour = iterator.next();
        if (behaviour.getWorld() != null) {
            // upon loading from NBT the world is null. gets initialized once 'initializeAsHull' is invoked.
            if (behaviour.isApplicable()) {
                behaviour.update();
            } else {
                iterator.remove();
            }
        }
    }
    for (IHeatExchangerLogic logic : connectedExchangers) {
        // As the connected logics also will tick, we should prevent dispersing more when more are connected.
        exchange(logic, this, getTickingHeatExchangers());
    }
}
Also used : HeatBehaviour(pneumaticCraft.api.tileentity.HeatBehaviour) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IHeatExchangerLogic(pneumaticCraft.api.IHeatExchangerLogic)

Example 2 with IHeatExchangerLogic

use of pneumaticCraft.api.IHeatExchangerLogic in project PneumaticCraft by MineMaarten.

the class WailaHeatHandler method getNBTData.

@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z) {
    if (te instanceof IHeatExchanger) {
        Set<IHeatExchangerLogic> heatExchangers = new HashSet<IHeatExchangerLogic>();
        IHeatExchangerLogic logic = null;
        boolean isMultisided = true;
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            logic = ((IHeatExchanger) te).getHeatExchangerLogic(d);
            if (logic != null) {
                if (heatExchangers.contains(logic)) {
                    isMultisided = false;
                    break;
                } else {
                    heatExchangers.add(logic);
                }
            }
        }
        if (isMultisided) {
            NBTTagList tagList = new NBTTagList();
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                logic = ((IHeatExchanger) te).getHeatExchangerLogic(d);
                if (logic != null) {
                    NBTTagCompound heatTag = new NBTTagCompound();
                    heatTag.setByte("side", (byte) d.ordinal());
                    heatTag.setInteger("temp", (int) logic.getTemperature());
                    tagList.appendTag(heatTag);
                }
            }
            tag.setTag("heat", tagList);
        } else if (logic != null) {
            tag.setInteger("temp", (int) logic.getTemperature());
        }
    }
    return tag;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IHeatExchanger(pneumaticCraft.api.tileentity.IHeatExchanger) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IHeatExchangerLogic(pneumaticCraft.api.IHeatExchangerLogic) HashSet(java.util.HashSet)

Example 3 with IHeatExchangerLogic

use of pneumaticCraft.api.IHeatExchangerLogic in project PneumaticCraft by MineMaarten.

the class TileEntityBase method addLuaMethods.

/*
     * COMPUTERCRAFT API 
     */
protected void addLuaMethods() {
    if (this instanceof IHeatExchanger) {
        final IHeatExchanger exchanger = (IHeatExchanger) this;
        luaMethods.add(new LuaMethod("getTemperature") {

            @Override
            public Object[] call(Object[] args) throws Exception {
                if (args.length == 0) {
                    return new Object[] { exchanger.getHeatExchangerLogic(ForgeDirection.UNKNOWN).getTemperature() };
                } else if (args.length == 1) {
                    IHeatExchangerLogic logic = exchanger.getHeatExchangerLogic(getDirForString((String) args[0]));
                    return new Object[] { logic != null ? logic.getTemperature() : 0 };
                } else {
                    throw new IllegalArgumentException("getTemperature method requires 0 or 1 argument (direction: up, down, east, west, north, south!");
                }
            }
        });
    }
}
Also used : IHeatExchanger(pneumaticCraft.api.tileentity.IHeatExchanger) ILuaMethod(pneumaticCraft.common.thirdparty.computercraft.ILuaMethod) LuaMethod(pneumaticCraft.common.thirdparty.computercraft.LuaMethod) LuaException(dan200.computercraft.api.lua.LuaException) IHeatExchangerLogic(pneumaticCraft.api.IHeatExchangerLogic)

Example 4 with IHeatExchangerLogic

use of pneumaticCraft.api.IHeatExchangerLogic in project PneumaticCraft by MineMaarten.

the class ItemManometer method onItemUseFirst.

/**
 * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
 * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
 */
@Override
public boolean onItemUseFirst(ItemStack iStack, EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) {
    if (world.isRemote)
        return false;
    if (((IPressurizable) iStack.getItem()).getPressure(iStack) > 0F) {
        TileEntity te = world.getTileEntity(x, y, z);
        IPneumaticMachine machine = ModInteractionUtils.getInstance().getMachine(te);
        List<IChatComponent> curInfo = new ArrayList<IChatComponent>();
        List<String> info = new ArrayList<String>();
        if (te instanceof IManoMeasurable) {
            ((IManoMeasurable) te).printManometerMessage(player, info);
        } else if (machine != null) {
            machine.getAirHandler().printManometerMessage(player, info);
        }
        for (String s : info) curInfo.add(new ChatComponentTranslation(s));
        if (te instanceof IHeatExchanger) {
            IHeatExchangerLogic exchanger = ((IHeatExchanger) te).getHeatExchangerLogic(ForgeDirection.getOrientation(side));
            if (exchanger != null) {
                curInfo.add(new ChatComponentTranslation("waila.temperature", (int) exchanger.getTemperature() - 273));
            } else {
                for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                    exchanger = ((IHeatExchanger) te).getHeatExchangerLogic(d);
                    if (exchanger != null) {
                        curInfo.add(new ChatComponentTranslation("waila.temperature." + d.toString().toLowerCase(), (int) exchanger.getTemperature() - 273));
                    }
                }
            }
        }
        if (curInfo.size() > 0) {
            ((IPressurizable) iStack.getItem()).addAir(iStack, -30);
            for (IChatComponent s : curInfo) {
                player.addChatComponentMessage(s);
            }
            return true;
        }
    } else {
        player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "The Manometer doesn't have any charge!"));
        return false;
    }
    return false;
}
Also used : IPressurizable(pneumaticCraft.api.item.IPressurizable) IManoMeasurable(pneumaticCraft.api.tileentity.IManoMeasurable) ArrayList(java.util.ArrayList) TileEntity(net.minecraft.tileentity.TileEntity) IHeatExchanger(pneumaticCraft.api.tileentity.IHeatExchanger) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) IChatComponent(net.minecraft.util.IChatComponent) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IHeatExchangerLogic(pneumaticCraft.api.IHeatExchangerLogic)

Example 5 with IHeatExchangerLogic

use of pneumaticCraft.api.IHeatExchangerLogic in project PneumaticCraft by MineMaarten.

the class HeatExchangerLogic method initializeAsHull.

@Override
public void initializeAsHull(World world, int x, int y, int z, ForgeDirection... validSides) {
    if (world.isRemote)
        return;
    for (IHeatExchangerLogic logic : hullExchangers) {
        removeConnectedExchanger(logic);
    }
    hullExchangers.clear();
    newBehaviours = new ArrayList<HeatBehaviour>();
    for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
        if (isSideValid(validSides, d)) {
            HeatBehaviourManager.getInstance().addHeatBehaviours(world, x + d.offsetX, y + d.offsetY, z + d.offsetZ, this, newBehaviours);
            IHeatExchangerLogic logic = HeatExchangerManager.getInstance().getLogic(world, x + d.offsetX, y + d.offsetY, z + d.offsetZ, d.getOpposite());
            if (logic != null) {
                hullExchangers.add(logic);
                addConnectedExchanger(logic);
            }
        }
    }
}
Also used : HeatBehaviour(pneumaticCraft.api.tileentity.HeatBehaviour) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IHeatExchangerLogic(pneumaticCraft.api.IHeatExchangerLogic)

Aggregations

IHeatExchangerLogic (pneumaticCraft.api.IHeatExchangerLogic)5 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 IHeatExchanger (pneumaticCraft.api.tileentity.IHeatExchanger)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 HeatBehaviour (pneumaticCraft.api.tileentity.HeatBehaviour)2 LuaException (dan200.computercraft.api.lua.LuaException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1 IChatComponent (net.minecraft.util.IChatComponent)1 IPressurizable (pneumaticCraft.api.item.IPressurizable)1 IManoMeasurable (pneumaticCraft.api.tileentity.IManoMeasurable)1 IPneumaticMachine (pneumaticCraft.api.tileentity.IPneumaticMachine)1 ILuaMethod (pneumaticCraft.common.thirdparty.computercraft.ILuaMethod)1 LuaMethod (pneumaticCraft.common.thirdparty.computercraft.LuaMethod)1