Search in sources :

Example 1 with IHeatHandler

use of mekanism.api.heat.IHeatHandler in project Mekanism by mekanism.

the class ItemNetworkReader method useOn.

@Nonnull
@Override
public ActionResultType useOn(ItemUseContext context) {
    PlayerEntity player = context.getPlayer();
    World world = context.getLevel();
    if (!world.isClientSide && player != null) {
        BlockPos pos = context.getClickedPos();
        TileEntity tile = WorldUtils.getTileEntity(world, pos);
        if (tile != null) {
            if (!player.isCreative()) {
                FloatingLong energyPerUse = MekanismConfig.gear.networkReaderEnergyUsage.get();
                IEnergyContainer energyContainer = StorageUtils.getEnergyContainer(context.getItemInHand(), 0);
                if (energyContainer == null || energyContainer.extract(energyPerUse, Action.SIMULATE, AutomationType.MANUAL).smallerThan(energyPerUse)) {
                    return ActionResultType.FAIL;
                }
                energyContainer.extract(energyPerUse, Action.EXECUTE, AutomationType.MANUAL);
            }
            Direction opposite = context.getClickedFace().getOpposite();
            if (tile instanceof TileEntityTransmitter) {
                displayTransmitterInfo(player, ((TileEntityTransmitter) tile).getTransmitter(), tile, opposite);
            } else {
                Optional<IHeatHandler> heatHandler = CapabilityUtils.getCapability(tile, Capabilities.HEAT_HANDLER_CAPABILITY, opposite).resolve();
                if (heatHandler.isPresent()) {
                    IHeatHandler transfer = heatHandler.get();
                    displayBorder(player, MekanismLang.MEKANISM, true);
                    sendTemperature(player, transfer);
                    displayEndBorder(player);
                } else {
                    displayConnectedNetworks(player, world, pos);
                }
            }
            return ActionResultType.SUCCESS;
        } else if (player.isShiftKeyDown() && MekanismAPI.debug) {
            displayBorder(player, MekanismLang.DEBUG_TITLE, true);
            for (ITextComponent component : TransmitterNetworkRegistry.getInstance().toComponents()) {
                player.sendMessage(TextComponentUtil.build(EnumColor.DARK_GRAY, component), Util.NIL_UUID);
            }
            displayEndBorder(player);
        }
    }
    return ActionResultType.PASS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FloatingLong(mekanism.api.math.FloatingLong) IEnergyContainer(mekanism.api.energy.IEnergyContainer) ITextComponent(net.minecraft.util.text.ITextComponent) BlockPos(net.minecraft.util.math.BlockPos) TileEntityTransmitter(mekanism.common.tile.transmitter.TileEntityTransmitter) World(net.minecraft.world.World) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IHeatHandler(mekanism.api.heat.IHeatHandler) Nonnull(javax.annotation.Nonnull)

Example 2 with IHeatHandler

use of mekanism.api.heat.IHeatHandler in project Mekanism by mekanism.

the class ITileHeatHandler method simulateAdjacent.

default double simulateAdjacent() {
    double adjacentTransfer = 0;
    for (Direction side : EnumUtils.DIRECTIONS) {
        IHeatHandler sink = getAdjacent(side);
        if (sink != null) {
            double heatCapacity = getTotalHeatCapacity(side);
            double invConduction = sink.getTotalInverseConduction() + getTotalInverseConductionCoefficient(side);
            double tempToTransfer = (getTotalTemperature(side) - getAmbientTemperature(side)) / invConduction;
            // TODO - 1.18: Try and figure out how to do this properly/I believe the below is correct
            // but it seems to nerf the heat system quite a bit so needs more review than being able
            // to be done just before a release is made
            /*double temp = getTotalTemperature(side);
                double sinkTemp = sink.getTotalTemperature();
                if (temp <= sinkTemp) {
                    //If our temperature is lower than the sink, we skip calculating what the adjacent loss to the sink
                    // is as if the sink is able to have heat transferred away from it (which is a bit of a weird concept
                    // in relation to thermodynamics, but makes some sense with our implementation), it will be handled by
                    // the sink when the sink simulates adjacent heat transfers. This also prevents us from having heat
                    // transfers effectively happen "twice" per tick rather than just once
                    // Note: We also skip if our temp is equal to the sink's temperature so that we can short circuit
                    // past the following logic
                    continue;
                }
                double heatCapacity = getTotalHeatCapacity(side);
                double sinkHeatCapacity = sink.getTotalHeatCapacity();
                //Calculate the target temperature using calorimetry
                double finalTemp = (temp * heatCapacity + sinkTemp * sinkHeatCapacity) / (heatCapacity + sinkHeatCapacity);
                double invConduction = sink.getTotalInverseConduction() + getTotalInverseConductionCoefficient(side);
                double tempToTransfer = (temp - finalTemp) / invConduction;*/
            double heatToTransfer = tempToTransfer * heatCapacity;
            handleHeat(-heatToTransfer, side);
            // Note: Our sinks in mek are "lazy" but they will update the next tick if needed
            sink.handleHeat(heatToTransfer);
            adjacentTransfer = incrementAdjacentTransfer(adjacentTransfer, tempToTransfer, side);
        }
    }
    return adjacentTransfer;
}
Also used : Direction(net.minecraft.util.Direction) IHeatHandler(mekanism.api.heat.IHeatHandler)

Aggregations

IHeatHandler (mekanism.api.heat.IHeatHandler)2 Direction (net.minecraft.util.Direction)2 Nonnull (javax.annotation.Nonnull)1 IEnergyContainer (mekanism.api.energy.IEnergyContainer)1 FloatingLong (mekanism.api.math.FloatingLong)1 TileEntityTransmitter (mekanism.common.tile.transmitter.TileEntityTransmitter)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 World (net.minecraft.world.World)1