• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CyclopsMC / IntegratedDynamics / 20210191346

14 Dec 2025 03:32PM UTC coverage: 19.514% (-33.5%) from 53.061%
20210191346

push

github

rubensworks
Remove deprecations

663 of 8728 branches covered (7.6%)

Branch coverage included in aggregate %.

6786 of 29445 relevant lines covered (23.05%)

1.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

3.39
/src/main/java/org/cyclops/integrateddynamics/core/item/ItemBlockEnergyContainerAutoSupply.java
1
package org.cyclops.integrateddynamics.core.item;
2

3
import net.minecraft.network.chat.Component;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.world.InteractionHand;
6
import net.minecraft.world.InteractionResult;
7
import net.minecraft.world.entity.Entity;
8
import net.minecraft.world.entity.EquipmentSlot;
9
import net.minecraft.world.entity.player.Player;
10
import net.minecraft.world.item.Item;
11
import net.minecraft.world.item.ItemStack;
12
import net.minecraft.world.item.TooltipFlag;
13
import net.minecraft.world.item.component.TooltipDisplay;
14
import net.minecraft.world.level.Level;
15
import net.minecraft.world.level.block.Block;
16
import net.neoforged.neoforge.capabilities.Capabilities;
17
import net.neoforged.neoforge.transfer.access.ItemAccess;
18
import net.neoforged.neoforge.transfer.energy.EnergyHandler;
19
import net.neoforged.neoforge.transfer.energy.EnergyHandlerUtil;
20
import net.neoforged.neoforge.transfer.transaction.Transaction;
21
import org.cyclops.cyclopscore.helper.IModHelpers;
22
import org.cyclops.integrateddynamics.RegistryEntries;
23

24
import javax.annotation.Nullable;
25
import java.util.function.Consumer;
26

27
/**
28
 * @author rubensworks
29
 */
30
public class ItemBlockEnergyContainerAutoSupply extends ItemBlockEnergyContainer {
31

32
    public ItemBlockEnergyContainerAutoSupply(Block block, Properties builder) {
33
        super(block, builder);
4✔
34
    }
1✔
35

36
    @Override
37
    public void appendHoverText(ItemStack itemStack, Item.TooltipContext context, TooltipDisplay tooltipDisplay, Consumer<Component> tooltipAdder, TooltipFlag flag) {
38
        super.appendHoverText(itemStack, context, tooltipDisplay, tooltipAdder, flag);
×
39
        IModHelpers.get().getL10NHelpers().addStatusInfo(tooltipAdder, isActivated(itemStack), getDescriptionId() + ".info.auto_supply");
×
40
    }
×
41

42
    @Override
43
    public InteractionResult use(Level world, Player player, InteractionHand hand) {
44
        return InteractionResult.SUCCESS.heldItemTransformedTo(toggleActivation(player.getItemInHand(hand), world, player));
×
45
    }
46

47
    public static void autofill(EnergyHandler source, Level world, Entity entity) {
48
        if(entity instanceof Player && !world.isClientSide()) {
×
49
            int tickAmount;
50
            try (var tx = Transaction.openRoot()) {
×
51
                tickAmount = source.extract(Integer.MAX_VALUE, tx);
×
52
            }
53
            if(tickAmount > 0) {
×
54
                Player player = (Player) entity;
×
55
                for (InteractionHand hand : InteractionHand.values()) {
×
56
                    tryFillContainerForPlayer(source, ItemAccess.forPlayerInteraction(player, hand), tickAmount);
×
57
                }
58
            }
59
        }
60
    }
×
61

62
    public static boolean tryFillContainerForPlayer(EnergyHandler source, ItemAccess held, int tickAmount) {
63
        EnergyHandler target = held.getCapability(Capabilities.Energy.ITEM);
×
64
        if (target != null) {
×
65
            int moved;
66
            try (var tx = Transaction.openRoot()) {
×
67
                moved = EnergyHandlerUtil.move(source, target, tickAmount, tx);
×
68
                tx.commit();
×
69
            }
70
            if (moved > 0) {
×
71
                return true;
×
72
            }
73
        }
74
        return false;
×
75
    }
76

77
    @Override
78
    public void inventoryTick(ItemStack itemStack, ServerLevel world, Entity entity, @Nullable EquipmentSlot slot) {
79
        if (isActivated(itemStack)) {
×
80
            EnergyHandler energyStorage = itemStack.getCapability(Capabilities.Energy.ITEM, null);
×
81
            if (energyStorage != null) {
×
82
                autofill(energyStorage, world, entity);
×
83
            }
84
        }
85
        super.inventoryTick(itemStack, world, entity, slot);
×
86
    }
×
87

88
    public ItemStack toggleActivation(ItemStack itemStack, Level world, Player player) {
89
        if(player.isSecondaryUseActive()) {
×
90
            if(!world.isClientSide()) {
×
91
                ItemStack activated = itemStack.copy();
×
92
                activated.set(RegistryEntries.DATACOMPONENT_ACTIVATED, !activated.getOrDefault(RegistryEntries.DATACOMPONENT_ACTIVATED, false));
×
93
                return activated;
×
94
            }
95
            return itemStack;
×
96
        }
97
        return itemStack;
×
98
    }
99

100
    public boolean isActivated(ItemStack itemStack) {
101
        return itemStack.getOrDefault(RegistryEntries.DATACOMPONENT_ACTIVATED, false);
×
102
    }
103

104
    @Override
105
    public boolean isFoil(ItemStack itemStack) {
106
        return isActivated(itemStack);
×
107
    }
108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc