Search in sources :

Example 1 with IHeatExchangerLogic

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

the class BlockHeatSink method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
    TileEntity te = world.getTileEntity(pos);
    if (te instanceof TileEntityHeatSink && entity instanceof EntityLivingBase) {
        IHeatExchangerLogic heat = ((TileEntityHeatSink) te).getHeatExchangerLogic(null);
        int temp = (int) ((TileEntityHeatSink) te).getHeatExchangerLogic(null).getTemperature();
        if (temp > 323) {
            // +50C
            entity.attackEntityFrom(DamageSource.HOT_FLOOR, 2);
            if (temp > 373) {
                // +100C
                entity.setFire(3);
            }
        } else if (temp < 243) {
            // -30C
            int durationSec = (243 - (int) heat.getTemperature()) / 10;
            int amplifier = (243 - (int) heat.getTemperature()) / 80;
            ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, durationSec * 20, amplifier));
            if (temp < 213) {
                // -60C
                entity.attackEntityFrom(DamageSourcePneumaticCraft.FREEZING, 2);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) TileEntityHeatSink(me.desht.pneumaticcraft.common.tileentity.TileEntityHeatSink) IHeatExchangerLogic(me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic)

Example 2 with IHeatExchangerLogic

use of me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic 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 3 with IHeatExchangerLogic

use of me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic 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 4 with IHeatExchangerLogic

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

the class WailaHeatHandler method getNBTData.

@Nonnull
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) {
    if (te instanceof IHeatExchanger) {
        Set<IHeatExchangerLogic> heatExchangers = new HashSet<>();
        IHeatExchangerLogic logic = null;
        boolean isMultisided = true;
        for (EnumFacing face : EnumFacing.values()) {
            logic = ((IHeatExchanger) te).getHeatExchangerLogic(face);
            if (logic != null) {
                if (heatExchangers.contains(logic)) {
                    isMultisided = false;
                    break;
                } else {
                    heatExchangers.add(logic);
                }
            }
        }
        if (isMultisided) {
            NBTTagList tagList = new NBTTagList();
            for (EnumFacing face : EnumFacing.values()) {
                logic = ((IHeatExchanger) te).getHeatExchangerLogic(face);
                if (logic != null) {
                    NBTTagCompound heatTag = new NBTTagCompound();
                    heatTag.setByte("side", (byte) face.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(me.desht.pneumaticcraft.api.tileentity.IHeatExchanger) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IHeatExchangerLogic(me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic) HashSet(java.util.HashSet) Nonnull(javax.annotation.Nonnull)

Example 5 with IHeatExchangerLogic

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

the class ItemManometer method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (world.isRemote)
        return EnumActionResult.PASS;
    ItemStack iStack = player.getHeldItem(hand);
    if (((IPressurizable) iStack.getItem()).getPressure(iStack) > 0F) {
        TileEntity te = world.getTileEntity(pos);
        IPneumaticMachine machine = ModInteractionUtils.getInstance().getMachine(te);
        List<ITextComponent> curInfo = new ArrayList<>();
        List<String> info = new ArrayList<>();
        if (machine != null && machine.getAirHandler(side) != null) {
            machine.getAirHandler(side).printManometerMessage(player, info);
        }
        if (te instanceof IManoMeasurable) {
            ((IManoMeasurable) te).printManometerMessage(player, info);
        }
        for (String s : info) curInfo.add(new TextComponentTranslation(s));
        if (te instanceof IHeatExchanger) {
            IHeatExchangerLogic exchanger = ((IHeatExchanger) te).getHeatExchangerLogic(side);
            if (exchanger != null) {
                curInfo.add(new TextComponentTranslation("waila.temperature", (int) exchanger.getTemperature() - 273));
            } else {
                for (EnumFacing d : EnumFacing.VALUES) {
                    exchanger = ((IHeatExchanger) te).getHeatExchangerLogic(d);
                    if (exchanger != null) {
                        curInfo.add(new TextComponentTranslation("waila.temperature." + d.toString().toLowerCase(), (int) exchanger.getTemperature() - 273));
                    }
                }
            }
        }
        if (curInfo.size() > 0) {
            ((IPressurizable) iStack.getItem()).addAir(iStack, -30);
            for (ITextComponent s : curInfo) {
                player.sendStatusMessage(s, false);
            }
            return EnumActionResult.SUCCESS;
        }
    } else {
        player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "The Manometer doesn't have any charge!"), false);
        return EnumActionResult.FAIL;
    }
    return EnumActionResult.PASS;
}
Also used : IPressurizable(me.desht.pneumaticcraft.api.item.IPressurizable) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IManoMeasurable(me.desht.pneumaticcraft.api.tileentity.IManoMeasurable) EnumFacing(net.minecraft.util.EnumFacing) ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) TileEntity(net.minecraft.tileentity.TileEntity) IHeatExchanger(me.desht.pneumaticcraft.api.tileentity.IHeatExchanger) IPneumaticMachine(me.desht.pneumaticcraft.api.tileentity.IPneumaticMachine) ItemStack(net.minecraft.item.ItemStack) IHeatExchangerLogic(me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic)

Aggregations

IHeatExchangerLogic (me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic)6 IHeatExchanger (me.desht.pneumaticcraft.api.tileentity.IHeatExchanger)3 EnumFacing (net.minecraft.util.EnumFacing)3 HeatBehaviour (me.desht.pneumaticcraft.api.heat.HeatBehaviour)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 TileEntity (net.minecraft.tileentity.TileEntity)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 LuaException (dan200.computercraft.api.lua.LuaException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Nonnull (javax.annotation.Nonnull)1 IPressurizable (me.desht.pneumaticcraft.api.item.IPressurizable)1 IManoMeasurable (me.desht.pneumaticcraft.api.tileentity.IManoMeasurable)1 IPneumaticMachine (me.desht.pneumaticcraft.api.tileentity.IPneumaticMachine)1 ILuaMethod (me.desht.pneumaticcraft.common.thirdparty.computercraft.ILuaMethod)1 LuaMethod (me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod)1 TileEntityHeatSink (me.desht.pneumaticcraft.common.tileentity.TileEntityHeatSink)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagList (net.minecraft.nbt.NBTTagList)1