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

CyclopsMC / IntegratedDynamics / 22823084981

08 Mar 2026 02:30PM UTC coverage: 53.736% (+1.9%) from 51.814%
22823084981

push

github

web-flow
Fix 3 failing game tests: update serialized value format in advancement JSON files for MC 1.21.11 (#1626)

* Initial plan

* Fix 3 failing game tests by updating serialized value format in advancement JSON files

Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>

3060 of 8909 branches covered (34.35%)

Branch coverage included in aggregate %.

18682 of 31552 relevant lines covered (59.21%)

3.06 hits per line

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

54.92
/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntitySqueezer.java
1
package org.cyclops.integrateddynamics.blockentity;
2

3
import com.google.common.collect.Lists;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.world.Containers;
7
import net.minecraft.world.item.ItemStack;
8
import net.minecraft.world.item.crafting.CraftingInput;
9
import net.minecraft.world.item.crafting.RecipeHolder;
10
import net.minecraft.world.item.crafting.RecipeType;
11
import net.minecraft.world.level.Level;
12
import net.minecraft.world.level.block.entity.BlockEntityType;
13
import net.minecraft.world.level.block.state.BlockState;
14
import net.minecraft.world.level.storage.ValueInput;
15
import net.minecraft.world.level.storage.ValueOutput;
16
import net.neoforged.neoforge.capabilities.Capabilities;
17
import net.neoforged.neoforge.fluids.FluidStack;
18
import net.neoforged.neoforge.transfer.ResourceHandler;
19
import net.neoforged.neoforge.transfer.ResourceHandlerUtil;
20
import net.neoforged.neoforge.transfer.fluid.FluidResource;
21
import net.neoforged.neoforge.transfer.item.ItemResource;
22
import net.neoforged.neoforge.transfer.item.VanillaContainerWrapper;
23
import net.neoforged.neoforge.transfer.transaction.Transaction;
24
import org.cyclops.cyclopscore.blockentity.BlockEntityTickerDelayed;
25
import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntity;
26
import org.cyclops.cyclopscore.capability.registrar.BlockEntityCapabilityRegistrar;
27
import org.cyclops.cyclopscore.datastructure.SingleCache;
28
import org.cyclops.cyclopscore.fluid.SingleUseTank;
29
import org.cyclops.cyclopscore.helper.IModHelpers;
30
import org.cyclops.cyclopscore.helper.IModHelpersNeoForge;
31
import org.cyclops.cyclopscore.inventory.SimpleInventory;
32
import org.cyclops.cyclopscore.inventory.SimpleInventoryState;
33
import org.cyclops.cyclopscore.persist.nbt.NBTPersist;
34
import org.cyclops.integrateddynamics.RegistryEntries;
35
import org.cyclops.integrateddynamics.block.BlockSqueezer;
36
import org.cyclops.integrateddynamics.core.recipe.handler.RecipeHandlerSqueezer;
37
import org.cyclops.integrateddynamics.core.recipe.type.RecipeSqueezer;
38

39
import java.util.Arrays;
40
import java.util.Optional;
41
import java.util.function.Supplier;
42

43
/**
44
 * A part entity for squeezing stuff.
45
 * @author rubensworks
46
 */
47
public class BlockEntitySqueezer extends CyclopsBlockEntity {
48

49
    private final SimpleInventory inventory;
50
    private final SingleUseTank tank;
51

52
    @NBTPersist
3✔
53
    private int itemHeight = 1;
54

55
    private SingleCache<ItemStack, Optional<RecipeHolder<RecipeSqueezer>>> recipeCache;
56

57
    public int getItemHeight() {
58
        return itemHeight;
3✔
59
    }
60

61
    public BlockEntitySqueezer(BlockPos blockPos, BlockState blockState) {
62
        super(RegistryEntries.BLOCK_ENTITY_SQUEEZER.get(), blockPos, blockState);
7✔
63

64
        // Create inventory and tank
65
        this.inventory = new SimpleInventory(1, 1) {
16✔
66
            @Override
67
            public boolean canPlaceItem(int slot, ItemStack itemStack) {
68
                return getLevel().getBlockState(getBlockPos()).getValue(BlockSqueezer.HEIGHT) == 1
×
69
                        && getItem(0).isEmpty() && super.canPlaceItem(slot, itemStack);
×
70
            }
71

72
            @Override
73
            public void setItem(int slotId, ItemStack itemstack) {
74
                super.setItem(slotId, itemstack);
4✔
75
                itemHeight = 1;
4✔
76
                sendUpdate();
3✔
77
            }
1✔
78
        };
79
        this.tank = new SingleUseTank(IModHelpersNeoForge.get().getFluidHelpers().getBucketVolume());
8✔
80

81
        // Add dirty mark listeners to inventory and tank
82
        this.inventory.addDirtyMarkListener(this::sendUpdate);
5✔
83
        this.tank.addDirtyMarkListener(this.inventory::setChanged);
9✔
84

85
        // Efficient cache to retrieve the current craftable recipe.
86
        recipeCache = new SingleCache<>(
9✔
87
                new SingleCache.ICacheUpdater<ItemStack, Optional<RecipeHolder<RecipeSqueezer>>>() {
6✔
88
                    @Override
89
                    public Optional<RecipeHolder<RecipeSqueezer>> getNewValue(ItemStack key) {
90
                        return IModHelpers.get().getCraftingHelpers().findRecipe(getRegistry(), CraftingInput.of(1, 1, Lists.newArrayList(key)), getLevel());
20✔
91
                    }
92

93
                    @Override
94
                    public boolean isKeyEqual(ItemStack cacheKey, ItemStack newKey) {
95
                        return ItemStack.matches(cacheKey, newKey);
×
96
                    }
97
                });
98
    }
1✔
99

100
    public static class CapabilityRegistrar extends BlockEntityCapabilityRegistrar<BlockEntitySqueezer> {
101
        public CapabilityRegistrar(Supplier<BlockEntityType<? extends BlockEntitySqueezer>> blockEntityType) {
102
            super(blockEntityType);
3✔
103
        }
1✔
104

105
        @Override
106
        public void populate() {
107
            add(
4✔
108
                    net.neoforged.neoforge.capabilities.Capabilities.Item.BLOCK,
109
                    (blockEntity, direction) -> VanillaContainerWrapper.of(blockEntity.getInventory())
×
110
            );
111
            add(
4✔
112
                    org.cyclops.commoncapabilities.api.capability.Capabilities.InventoryState.BLOCK,
113
                    (blockEntity, direction) -> new SimpleInventoryState(blockEntity.getInventory())
×
114
            );
115
            add(
4✔
116
                    net.neoforged.neoforge.capabilities.Capabilities.Fluid.BLOCK,
117
                    (blockEntity, direction) -> blockEntity.getTank()
×
118
            );
119
            add(
4✔
120
                    org.cyclops.commoncapabilities.api.capability.Capabilities.RecipeHandler.BLOCK,
121
                    (blockEntity, direction) -> new RecipeHandlerSqueezer<>(blockEntity::getLevel, RegistryEntries.RECIPETYPE_SQUEEZER.get())
×
122
            );
123
        }
1✔
124
    }
125

126
    public SimpleInventory getInventory() {
127
        return inventory;
3✔
128
    }
129

130
    public SingleUseTank getTank() {
131
        return tank;
3✔
132
    }
133

134
    @Override
135
    public void read(ValueInput input) {
136
        inventory.readFromNBT(input, "inventory");
×
137
        tank.deserialize(input, "tank");
×
138
        super.read(input);
×
139
    }
×
140

141
    @Override
142
    public void saveAdditional(ValueOutput output) {
143
        inventory.writeToNBT(output, "inventory");
5✔
144
        tank.serialize(output, "tank");
5✔
145
        super.saveAdditional(output);
3✔
146
    }
1✔
147

148
    protected RecipeType<RecipeSqueezer> getRegistry() {
149
        return RegistryEntries.RECIPETYPE_SQUEEZER.get();
4✔
150
    }
151

152
    public Optional<RecipeHolder<RecipeSqueezer>> getCurrentRecipe() {
153
        return recipeCache.get(getInventory().getItem(0).copy());
10✔
154
    }
155

156
    public void setItemHeight(int itemHeight) {
157
        this.itemHeight = itemHeight;
3✔
158
        sendUpdate();
2✔
159
        getInventory().setChanged();
3✔
160
    }
1✔
161

162
    @Override
163
    public void preRemoveSideEffects(BlockPos pos, BlockState state) {
164
        super.preRemoveSideEffects(pos, state);
×
165
        Containers.dropContents(level, pos, this.getInventory());
×
166
    }
×
167

168
    public static class Ticker extends BlockEntityTickerDelayed<BlockEntitySqueezer> {
3✔
169
        @Override
170
        protected void update(Level level, BlockPos pos, BlockState blockState, BlockEntitySqueezer blockEntity) {
171
            super.update(level, pos, blockState, blockEntity);
6✔
172

173
            if(!blockEntity.getTank().isEmpty()) {
4✔
174
                Direction.Axis axis = blockState.getValue(BlockSqueezer.AXIS);
5✔
175
                Arrays.stream(Direction.AxisDirection.values())
4✔
176
                        .map(axisDirection -> Direction.get(axisDirection, axis))
9✔
177
                        .forEach(side -> {
1✔
178
                            if (!blockEntity.getTank().isEmpty()) {
4!
179
                                IModHelpersNeoForge.get().getCapabilityHelpers().getCapability(level, pos.relative(side), side.getOpposite(), net.neoforged.neoforge.capabilities.Capabilities.Fluid.BLOCK)
12✔
180
                                        .ifPresent(handler -> {
1✔
181
                                            FluidStack fluidStack = new FluidStack(blockEntity.getTank().getFluid().getFluid(),
×
182
                                                    Math.min(100, blockEntity.getTank().getFluidAmount()));
×
183
                                            ResourceHandlerUtil.move(blockEntity.getTank(), handler, f -> f.matches(fluidStack), fluidStack.getAmount(), null);
×
184
                                        });
×
185
                            }
186
                        });
1✔
187
            } else {
1✔
188
                if (blockEntity.itemHeight == 7) {
4✔
189
                    Optional<RecipeHolder<RecipeSqueezer>> recipeOptional = blockEntity.getCurrentRecipe();
3✔
190
                    if (recipeOptional.isPresent()) {
3!
191
                        RecipeSqueezer recipe = recipeOptional.get().value();
6✔
192
                        ItemStack oldItem = blockEntity.getInventory().getItem(0);
5✔
193
                        blockEntity.getInventory().setItem(0, ItemStack.EMPTY);
5✔
194
                        for (RecipeSqueezer.IngredientChance itemStackChance : recipe.assemble(oldItem)) {
8!
195
                            if (itemStackChance.getChance() == 1.0F || itemStackChance.getChance() >= level.random.nextFloat()) {
×
196
                                ItemStack resultStack = itemStackChance.getIngredientFirst().copy();
×
197
                                for (Direction side : Direction.values()) {
×
198
                                    if (!resultStack.isEmpty() && side != Direction.UP) {
×
199
                                        ResourceHandler<ItemResource> itemHandler = IModHelpersNeoForge.get().getCapabilityHelpers().getCapability(level, pos.relative(side), side.getOpposite(), Capabilities.Item.BLOCK).orElse(null);
×
200
                                        if (itemHandler != null) {
×
201
                                            try (var tx = Transaction.openRoot()) {
×
202
                                                int inserted = itemHandler.insert(ItemResource.of(resultStack), resultStack.getCount(), tx);
×
203
                                                tx.commit();
×
204
                                                resultStack.shrink(inserted);
×
205
                                            }
206
                                        }
207
                                    }
208
                                }
209
                                if (!resultStack.isEmpty()) {
×
210
                                    IModHelpers.get().getItemStackHelpers().spawnItemStack(level, pos, resultStack);
×
211
                                }
212
                            }
213
                        }
×
214
                        if (recipe.getOutputFluid().isPresent()) {
4!
215
                            try (var tx = Transaction.openRoot()) {
2✔
216
                                FluidStack fluidStack = recipe.getOutputFluid().get();
5✔
217
                                blockEntity.getTank().insert(FluidResource.of(fluidStack), fluidStack.getAmount(), tx);
9✔
218
                                tx.commit();
2✔
219
                            }
220
                        }
221
                    }
222
                }
223
            }
224
        }
1✔
225
    }
226
}
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