Search in sources :

Example 1 with HeatBehaviour

use of me.desht.pneumaticcraft.api.heat.HeatBehaviour in project pnc-repressurized by TeamPneumatic.

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(me.desht.pneumaticcraft.api.heat.HeatBehaviour)

Example 2 with HeatBehaviour

use of me.desht.pneumaticcraft.api.heat.HeatBehaviour in project pnc-repressurized by TeamPneumatic.

the class HeatExchangerLogic method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound tag) {
    tag.setDouble("temperature", temperature);
    NBTTagList tagList = new NBTTagList();
    for (HeatBehaviour behaviour : behaviours) {
        NBTTagCompound t = new NBTTagCompound();
        t.setString("id", behaviour.getId());
        behaviour.writeToNBT(t);
        tagList.appendTag(t);
    }
    tag.setTag("behaviours", tagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) HeatBehaviour(me.desht.pneumaticcraft.api.heat.HeatBehaviour) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 3 with HeatBehaviour

use of me.desht.pneumaticcraft.api.heat.HeatBehaviour in project pnc-repressurized by TeamPneumatic.

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(me.desht.pneumaticcraft.api.heat.HeatBehaviour) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IHeatExchangerLogic(me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic)

Example 4 with HeatBehaviour

use of me.desht.pneumaticcraft.api.heat.HeatBehaviour in project pnc-repressurized by TeamPneumatic.

the class HeatExchangerLogic method initializeAsHull.

@Override
public void initializeAsHull(World world, BlockPos pos, EnumFacing... validSides) {
    if (world.isRemote)
        return;
    for (IHeatExchangerLogic logic : hullExchangers) {
        removeConnectedExchanger(logic);
    }
    hullExchangers.clear();
    newBehaviours = new ArrayList<HeatBehaviour>();
    for (EnumFacing d : EnumFacing.VALUES) {
        if (isSideValid(validSides, d)) {
            HeatBehaviourManager.getInstance().addHeatBehaviours(world, pos.offset(d), this, newBehaviours);
            IHeatExchangerLogic logic = HeatExchangerManager.getInstance().getLogic(world, pos.offset(d), d.getOpposite());
            if (logic != null) {
                hullExchangers.add(logic);
                addConnectedExchanger(logic);
            }
        }
    }
}
Also used : HeatBehaviour(me.desht.pneumaticcraft.api.heat.HeatBehaviour) EnumFacing(net.minecraft.util.EnumFacing) IHeatExchangerLogic(me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic)

Example 5 with HeatBehaviour

use of me.desht.pneumaticcraft.api.heat.HeatBehaviour in project pnc-repressurized by TeamPneumatic.

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(me.desht.pneumaticcraft.api.heat.HeatBehaviour) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

HeatBehaviour (me.desht.pneumaticcraft.api.heat.HeatBehaviour)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 IHeatExchangerLogic (me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 EnumFacing (net.minecraft.util.EnumFacing)1