Search in sources :

Example 1 with HeatBehaviour

use of pneumaticCraft.api.tileentity.HeatBehaviour 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 HeatBehaviour

use of pneumaticCraft.api.tileentity.HeatBehaviour in project PneumaticCraft by MineMaarten.

the class HeatBehaviourManager method registerBehaviour.

public void registerBehaviour(Class<? extends HeatBehaviour> behaviour) {
    if (behaviour == null)
        throw new IllegalArgumentException("Can't register a null behaviour!");
    try {
        HeatBehaviour ins = behaviour.newInstance();
        HeatBehaviour overridenBehaviour = behaviours.put(ins.getId(), ins);
        if (overridenBehaviour != null)
            Log.warning("Registered a heat behaviour that has the same id as an already registered one. The old one will be discarded. Old behaviour class: " + overridenBehaviour.getClass() + ". New class: " + behaviour.getClass());
    } catch (InstantiationException e) {
        throw new IllegalArgumentException("The behaviour class doesn't have a nullary constructor, or is abstract! Class: " + behaviour);
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException("Doesn't have access to the class (is it private?) Class: " + behaviour);
    }
}
Also used : HeatBehaviour(pneumaticCraft.api.tileentity.HeatBehaviour)

Example 3 with HeatBehaviour

use of pneumaticCraft.api.tileentity.HeatBehaviour in project PneumaticCraft by MineMaarten.

the class HeatBehaviourManager method addHeatBehaviours.

public void addHeatBehaviours(World world, int x, int y, int z, IHeatExchangerLogic logic, List<HeatBehaviour> list) {
    for (HeatBehaviour behaviour : behaviours.values()) {
        behaviour.initialize(logic, world, x, y, z);
        if (behaviour.isApplicable()) {
            try {
                behaviour = behaviour.getClass().newInstance();
                behaviour.initialize(logic, world, x, y, z);
                list.add(behaviour);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : HeatBehaviour(pneumaticCraft.api.tileentity.HeatBehaviour)

Example 4 with HeatBehaviour

use of pneumaticCraft.api.tileentity.HeatBehaviour in project PneumaticCraft by MineMaarten.

the class HeatExchangerLogic method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound tag) {
    temperature = tag.getDouble("temperature");
    behaviours.clear();
    NBTTagList tagList = tag.getTagList("behaviours", 10);
    for (int i = 0; i < tagList.tagCount(); i++) {
        NBTTagCompound t = tagList.getCompoundTagAt(i);
        HeatBehaviour behaviour = HeatBehaviourManager.getInstance().getBehaviourForId(t.getString("id"));
        if (behaviour != null) {
            behaviour.readFromNBT(t);
            behaviours.add(behaviour);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) HeatBehaviour(pneumaticCraft.api.tileentity.HeatBehaviour) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 5 with HeatBehaviour

use of pneumaticCraft.api.tileentity.HeatBehaviour 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

HeatBehaviour (pneumaticCraft.api.tileentity.HeatBehaviour)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)2 IHeatExchangerLogic (pneumaticCraft.api.IHeatExchangerLogic)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1