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

CyclopsMC / IntegratedCrafting / #479011800

31 Aug 2025 01:00PM UTC coverage: 24.876% (-0.3%) from 25.162%
#479011800

push

github

rubensworks
Add Attuned Crafting Interface

1 of 277 new or added lines in 7 files covered. (0.36%)

113 existing lines in 4 files now uncovered.

750 of 3015 relevant lines covered (24.88%)

0.25 hits per line

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

0.0
/src/main/java/org/cyclops/integratedcrafting/part/PartTypeInterfaceCraftingAttuned.java
1
package org.cyclops.integratedcrafting.part;
2

3
import net.minecraft.ChatFormatting;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.nbt.CompoundTag;
7
import net.minecraft.network.FriendlyByteBuf;
8
import net.minecraft.network.chat.Component;
9
import net.minecraft.network.chat.MutableComponent;
10
import net.minecraft.server.level.ServerPlayer;
11
import net.minecraft.world.MenuProvider;
12
import net.minecraft.world.SimpleContainer;
13
import net.minecraft.world.entity.player.Inventory;
14
import net.minecraft.world.entity.player.Player;
15
import net.minecraft.world.inventory.AbstractContainerMenu;
16
import net.minecraft.world.level.BlockGetter;
17
import net.minecraft.world.level.block.Block;
18
import net.minecraft.world.level.block.state.BlockState;
19
import net.minecraftforge.common.util.LazyOptional;
20
import org.apache.commons.lang3.tuple.Triple;
21
import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeDefinition;
22
import org.cyclops.commoncapabilities.api.capability.recipehandler.IRecipeHandler;
23
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig;
24
import org.cyclops.cyclopscore.helper.BlockHelpers;
25
import org.cyclops.cyclopscore.modcompat.commoncapabilities.BlockCapabilitiesHelpers;
26
import org.cyclops.integratedcrafting.GeneralConfig;
27
import org.cyclops.integratedcrafting.api.network.ICraftingNetwork;
28
import org.cyclops.integratedcrafting.core.part.PartTypeInterfaceCraftingBase;
29
import org.cyclops.integratedcrafting.inventory.container.ContainerPartInterfaceCraftingSettings;
30
import org.cyclops.integrateddynamics.Capabilities;
31
import org.cyclops.integrateddynamics.api.evaluate.variable.ValueDeseralizationContext;
32
import org.cyclops.integrateddynamics.api.network.INetwork;
33
import org.cyclops.integrateddynamics.api.network.IPartNetwork;
34
import org.cyclops.integrateddynamics.api.part.IPartContainer;
35
import org.cyclops.integrateddynamics.api.part.PartPos;
36
import org.cyclops.integrateddynamics.api.part.PartTarget;
37
import org.cyclops.integrateddynamics.core.block.IgnoredBlockStatus;
38
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
39
import org.cyclops.integrateddynamics.core.part.PartTypeBase;
40

41
import javax.annotation.Nullable;
42
import java.util.Collection;
43
import java.util.Collections;
44
import java.util.List;
45
import java.util.Optional;
46

47
/**
48
 * Interface for auto crafting that reads out all available target machine recipes.
49
 * @author rubensworks
50
 */
51
public class PartTypeInterfaceCraftingAttuned extends PartTypeInterfaceCraftingBase<PartTypeInterfaceCraftingAttuned, PartTypeInterfaceCraftingAttuned.State> {
52

53
    public PartTypeInterfaceCraftingAttuned(String name) {
NEW
54
        super(name);
×
NEW
55
    }
×
56

57
    @Override
58
    public int getConsumptionRate(PartTypeInterfaceCraftingAttuned.State state) {
NEW
59
        return state.getCraftingJobHandler().getProcessingCraftingJobs().size() * GeneralConfig.interfaceCraftingAttunedBaseConsumption;
×
60
    }
61

62
    @Override
63
    public Optional<MenuProvider> getContainerProvider(PartPos pos) {
NEW
64
        return Optional.of(new MenuProvider() {
×
65

66
            @Override
67
            public MutableComponent getDisplayName() {
NEW
68
                return Component.translatable(getTranslationKey());
×
69
            }
70

71
            @Override
72
            public AbstractContainerMenu createMenu(int id, Inventory playerInventory, Player playerEntity) {
NEW
73
                Triple<IPartContainer, PartTypeBase, PartTarget> data = PartHelpers.getContainerPartConstructionData(pos);
×
NEW
74
                return new ContainerPartInterfaceCraftingSettings(id, playerInventory, new SimpleContainer(0),
×
NEW
75
                        data.getRight(), Optional.of(data.getLeft()), data.getMiddle());
×
76
            }
77
        });
78
    }
79

80
    @Override
81
    public void writeExtraGuiData(FriendlyByteBuf packetBuffer, PartPos pos, ServerPlayer player) {
NEW
82
        super.writeExtraGuiDataSettings(packetBuffer, pos, player); // We show the settings directly.
×
NEW
83
    }
×
84

85
    @Override
86
    public Optional<MenuProvider> getContainerProviderSettings(PartPos pos) {
NEW
87
        return Optional.empty();
×
88
    }
89

90
    @Override
91
    protected PartTypeInterfaceCraftingAttuned.State constructDefaultState() {
NEW
92
        return new PartTypeInterfaceCraftingAttuned.State();
×
93
    }
94

95
    @Override
96
    protected Block createBlock(BlockConfig blockConfig) {
NEW
97
        return new IgnoredBlockStatus();
×
98
    }
99

100
    protected IgnoredBlockStatus.Status getStatus(State state) {
NEW
101
        IgnoredBlockStatus.Status status = IgnoredBlockStatus.Status.INACTIVE;
×
NEW
102
        if (state != null) {
×
NEW
103
            if (state.hasValidTarget()) {
×
NEW
104
                status = IgnoredBlockStatus.Status.ACTIVE;
×
105
            } else {
NEW
106
                status = IgnoredBlockStatus.Status.ERROR;
×
107
            }
108
        }
109

NEW
110
        return status;
×
111
    }
112

113
    @Override
114
    public BlockState getBlockState(IPartContainer partContainer, Direction side) {
NEW
115
        IgnoredBlockStatus.Status status = this.getStatus(partContainer != null ? (State)partContainer.getPartState(side) : null);
×
NEW
116
        return super.getBlockState(partContainer, side)
×
NEW
117
                .setValue(IgnoredBlockStatus.STATUS, status);
×
118
    }
119

120
    @Override
121
    public void loadTooltip(State state, List<Component> lines) {
NEW
122
        super.loadTooltip(state, lines);
×
123

NEW
124
        if (!state.hasValidTarget()) {
×
NEW
125
            lines.add(Component.translatable("parttype.integratedcrafting.interface_crafting_attuned.unsupported").withStyle(ChatFormatting.RED));
×
126
        }
NEW
127
    }
×
128

129
    @Override
130
    public boolean shouldTriggerBlockRenderUpdate(@Nullable State oldPartState, @Nullable State newPartState) {
NEW
131
        return super.shouldTriggerBlockRenderUpdate(oldPartState, newPartState) || this.getStatus(oldPartState) != this.getStatus(newPartState);
×
132
    }
133

134
    @Override
135
    public void onBlockNeighborChange(INetwork network, IPartNetwork partNetwork, PartTarget target, State state, BlockGetter world, Block neighbourBlock, BlockPos neighbourBlockPos) {
NEW
136
        boolean hadValidTarget = state.hasValidTarget();
×
NEW
137
        removeTargetFromNetwork(network, target.getTarget(), state);
×
138

NEW
139
        super.onBlockNeighborChange(network, partNetwork, target, state, world, neighbourBlock, neighbourBlockPos);
×
140

NEW
141
        addTargetToNetwork(network, target, state, false);
×
NEW
142
        if (hadValidTarget != state.hasValidTarget()) {
×
NEW
143
            BlockHelpers.markForUpdate(target.getCenter().getPos().getLevel(true), target.getCenter().getPos().getBlockPos());
×
144
        }
NEW
145
    }
×
146

NEW
147
    public static class State extends PartTypeInterfaceCraftingBase.State<PartTypeInterfaceCraftingAttuned, PartTypeInterfaceCraftingAttuned.State> {
×
148

NEW
149
        protected boolean hasValidTarget = false;
×
150
        private Collection<IRecipeDefinition> recipes;
151

152
        protected LazyOptional<IRecipeHandler> getTargetRecipeHandler() {
NEW
153
            PartPos target = getTarget().getTarget();
×
NEW
154
            return BlockCapabilitiesHelpers.getTileOrBlockCapability(target.getPos(), target.getSide(), Capabilities.RECIPE_HANDLER);
×
155
        }
156

157
        @Override
158
        public void setNetworks(@org.jetbrains.annotations.Nullable INetwork network, @org.jetbrains.annotations.Nullable ICraftingNetwork craftingNetwork, @org.jetbrains.annotations.Nullable IPartNetwork partNetwork, int channel, @org.jetbrains.annotations.Nullable ValueDeseralizationContext valueDeseralizationContext, boolean initialize) {
NEW
159
            super.setNetworks(network, craftingNetwork, partNetwork, channel, valueDeseralizationContext, initialize);
×
160

NEW
161
            this.hasValidTarget = getTargetRecipeHandler().isPresent();
×
NEW
162
            this.recipes = getTargetRecipeHandler()
×
NEW
163
                    .map(IRecipeHandler::getRecipes)
×
NEW
164
                    .orElse(Collections.emptyList());
×
NEW
165
            markDirty();
×
NEW
166
        }
×
167

168
        public boolean hasValidTarget() {
NEW
169
            return this.hasValidTarget;
×
170
        }
171

172
        @Override
173
        public void writeToNBT(CompoundTag tag) {
NEW
174
            super.writeToNBT(tag);
×
NEW
175
            tag.putBoolean("hasValidTarget", hasValidTarget);
×
NEW
176
        }
×
177

178
        @Override
179
        public void readFromNBT(ValueDeseralizationContext valueDeseralizationContext, CompoundTag tag) {
NEW
180
            super.readFromNBT(valueDeseralizationContext, tag);
×
NEW
181
            this.hasValidTarget = tag.getBoolean("hasValidTarget");
×
NEW
182
        }
×
183

184
        @Override
185
        public Collection<IRecipeDefinition> getRecipes() {
NEW
186
            return this.recipes;
×
187
        }
188
    }
189

190
}
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

© 2025 Coveralls, Inc