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

CyclopsMC / IntegratedDynamics / 22777205265

06 Mar 2026 06:45PM UTC coverage: 51.814% (+0.04%) from 51.772%
22777205265

push

github

web-flow
Fix crash when drying rotten flesh (no fluid input) in drying basin (#1625)

Closes #1624

2913 of 8887 branches covered (32.78%)

Branch coverage included in aggregate %.

17721 of 30936 relevant lines covered (57.28%)

2.97 hits per line

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

58.71
/src/main/java/org/cyclops/integrateddynamics/blockentity/BlockEntityDryingBasin.java
1
package org.cyclops.integrateddynamics.blockentity;
2

3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Direction;
5
import net.minecraft.core.NonNullList;
6
import net.minecraft.core.particles.BlockParticleOption;
7
import net.minecraft.core.particles.ItemParticleOption;
8
import net.minecraft.core.particles.ParticleTypes;
9
import net.minecraft.world.Containers;
10
import net.minecraft.world.item.ItemStack;
11
import net.minecraft.world.item.crafting.RecipeHolder;
12
import net.minecraft.world.item.crafting.RecipeType;
13
import net.minecraft.world.level.Level;
14
import net.minecraft.world.level.block.Blocks;
15
import net.minecraft.world.level.block.entity.BlockEntityTicker;
16
import net.minecraft.world.level.block.entity.BlockEntityType;
17
import net.minecraft.world.level.block.state.BlockState;
18
import net.minecraft.world.level.storage.ValueInput;
19
import net.minecraft.world.level.storage.ValueOutput;
20
import net.neoforged.neoforge.capabilities.Capabilities;
21
import net.neoforged.neoforge.fluids.FluidStack;
22
import net.neoforged.neoforge.transfer.fluid.FluidResource;
23
import net.neoforged.neoforge.transfer.item.VanillaContainerWrapper;
24
import net.neoforged.neoforge.transfer.transaction.Transaction;
25
import org.apache.commons.lang3.tuple.Pair;
26
import org.cyclops.cyclopscore.blockentity.BlockEntityTickerDelayed;
27
import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntity;
28
import org.cyclops.cyclopscore.capability.registrar.BlockEntityCapabilityRegistrar;
29
import org.cyclops.cyclopscore.datastructure.SingleCache;
30
import org.cyclops.cyclopscore.fluid.SingleUseTank;
31
import org.cyclops.cyclopscore.helper.IModHelpers;
32
import org.cyclops.cyclopscore.helper.IModHelpersNeoForge;
33
import org.cyclops.cyclopscore.inventory.SimpleInventory;
34
import org.cyclops.cyclopscore.inventory.SimpleInventoryState;
35
import org.cyclops.cyclopscore.persist.nbt.NBTPersist;
36
import org.cyclops.cyclopscore.recipe.type.IInventoryFluid;
37
import org.cyclops.cyclopscore.recipe.type.InventoryFluid;
38
import org.cyclops.integrateddynamics.IntegratedDynamics;
39
import org.cyclops.integrateddynamics.RegistryEntries;
40
import org.cyclops.integrateddynamics.core.recipe.handler.RecipeHandlerDryingBasin;
41
import org.cyclops.integrateddynamics.core.recipe.type.RecipeDryingBasin;
42

43
import java.util.Optional;
44
import java.util.function.Supplier;
45

46
/**
47
 * A part entity for drying stuff.
48
 * @author rubensworks
49
 */
50
public class BlockEntityDryingBasin extends CyclopsBlockEntity {
51

52
    private static final int WOOD_IGNITION_TEMPERATURE = 573; // 300 degrees celcius
53

54
    private final SimpleInventory inventory;
55
    private final SingleUseTank tank;
56

57
    @NBTPersist
2✔
58
    private Float randomRotation = 0F;
2✔
59
    @NBTPersist
3✔
60
    private int progress = 0;
61
    @NBTPersist
3✔
62
    private int fire = 0;
63

64
    private SingleCache<Pair<ItemStack, FluidStack>, Optional<RecipeHolder<RecipeDryingBasin>>> recipeCache;
65

66
    public BlockEntityDryingBasin(BlockPos blockPos, BlockState blockState) {
67
        super(RegistryEntries.BLOCK_ENTITY_DRYING_BASIN.get(), blockPos, blockState);
7✔
68

69
        // Create inventory and tank
70
        this.inventory = new SimpleInventory(1, 1) {
16✔
71
            @Override
72
            public boolean canPlaceItem(int i, ItemStack itemstack) {
73
                return getItem(0).isEmpty();
×
74
            }
75

76
            @Override
77
            public void setItem(int slotId, ItemStack itemstack) {
78
                super.setItem(slotId, itemstack);
4✔
79
                BlockEntityDryingBasin.this.randomRotation = level.random.nextFloat() * 360;
11✔
80
                sendUpdate();
3✔
81
            }
1✔
82
        };
83
        this.tank = new SingleUseTank(IModHelpersNeoForge.get().getFluidHelpers().getBucketVolume());
8✔
84

85
        // Add dirty mark listeners to inventory and tank
86
        this.inventory.addDirtyMarkListener(this::sendUpdate);
5✔
87
        this.tank.addDirtyMarkListener(this.inventory::setChanged);
9✔
88

89
        // Efficient cache to retrieve the current craftable recipe.
90
        recipeCache = new SingleCache<>(new SingleCache.ICacheUpdater<Pair<ItemStack, FluidStack>, Optional<RecipeHolder<RecipeDryingBasin>>>() {
15✔
91
            @Override
92
            public Optional<RecipeHolder<RecipeDryingBasin>> getNewValue(Pair<ItemStack, FluidStack> key) {
93
                IInventoryFluid recipeInput = new InventoryFluid(
8✔
94
                        NonNullList.of(ItemStack.EMPTY, key.getLeft()),
10✔
95
                        NonNullList.of(FluidStack.EMPTY, key.getRight()));
6✔
96
                return IModHelpers.get().getCraftingHelpers().findRecipe(getRegistry(), recipeInput, getLevel());
11✔
97
            }
98

99
            @Override
100
            public boolean isKeyEqual(Pair<ItemStack, FluidStack> cacheKey, Pair<ItemStack, FluidStack> newKey) {
101
                return cacheKey == null || newKey == null ||
6!
102
                        (ItemStack.matches(cacheKey.getLeft(), newKey.getLeft()) &&
8✔
103
                                FluidStack.matches(cacheKey.getRight(), newKey.getRight()));
10!
104
            }
105
        });
106
    }
1✔
107

108
    public static class CapabilityRegistrar extends BlockEntityCapabilityRegistrar<BlockEntityDryingBasin> {
109
        public CapabilityRegistrar(Supplier<BlockEntityType<? extends BlockEntityDryingBasin>> blockEntityType) {
110
            super(blockEntityType);
3✔
111
        }
1✔
112

113
        @Override
114
        public void populate() {
115
            add(
4✔
116
                    net.neoforged.neoforge.capabilities.Capabilities.Item.BLOCK,
117
                    (blockEntity, direction) -> VanillaContainerWrapper.of(blockEntity.getInventory())
×
118
            );
119
            add(
4✔
120
                    org.cyclops.commoncapabilities.api.capability.Capabilities.InventoryState.BLOCK,
121
                    (blockEntity, direction) -> new SimpleInventoryState(blockEntity.getInventory())
×
122
            );
123
            add(
4✔
124
                    Capabilities.Fluid.BLOCK,
125
                    (blockEntity, direction) -> blockEntity.getTank()
3✔
126
            );
127
            add(
4✔
128
                    org.cyclops.commoncapabilities.api.capability.Capabilities.RecipeHandler.BLOCK,
129
                    (blockEntity, direction) -> new RecipeHandlerDryingBasin<>(blockEntity::getLevel, RegistryEntries.RECIPETYPE_DRYING_BASIN.get())
×
130
            );
131
        }
1✔
132
    }
133

134
    public int getProgress() {
135
        return progress;
3✔
136
    }
137

138
    public void setProgress(int progress) {
139
        this.progress = progress;
3✔
140
    }
1✔
141

142
    public int getFire() {
143
        return fire;
3✔
144
    }
145

146
    public void setFire(int fire) {
147
        this.fire = fire;
3✔
148
    }
1✔
149

150
    public SimpleInventory getInventory() {
151
        return inventory;
3✔
152
    }
153

154
    public SingleUseTank getTank() {
155
        return tank;
3✔
156
    }
157

158
    @Override
159
    public void read(ValueInput input) {
160
        inventory.readFromNBT(input, "inventory");
5✔
161
        tank.deserialize(input, "tank");
5✔
162
        super.read(input);
3✔
163
    }
1✔
164

165
    @Override
166
    public void saveAdditional(ValueOutput output) {
167
        inventory.writeToNBT(output, "inventory");
5✔
168
        tank.serialize(output, "tank");
5✔
169
        super.saveAdditional(output);
3✔
170
    }
1✔
171

172
    protected RecipeType<RecipeDryingBasin> getRegistry() {
173
        return RegistryEntries.RECIPETYPE_DRYING_BASIN.get();
4✔
174
    }
175

176
    public Optional<RecipeHolder<RecipeDryingBasin>> getCurrentRecipe() {
177
        return recipeCache.get(Pair.of(getInventory().getItem(0).copy(), IModHelpersNeoForge.get().getFluidHelpers().copy(getTank().getFluid())));
17✔
178
    }
179

180
    /**
181
     * Get the random rotation for displaying the item.
182
     * @return The random rotation.
183
     */
184
    public float getRandomRotation() {
185
        return randomRotation;
×
186
    }
187

188
    @Override
189
    public void preRemoveSideEffects(BlockPos pos, BlockState state) {
190
        super.preRemoveSideEffects(pos, state);
×
191
        Containers.dropContents(level, pos, this.getInventory());
×
192
    }
×
193

194
    public static class TickerServer extends BlockEntityTickerDelayed<BlockEntityDryingBasin> {
3✔
195
        @Override
196
        protected void update(Level level, BlockPos pos, BlockState blockState, BlockEntityDryingBasin blockEntity) {
197
            super.update(level, pos, blockState, blockEntity);
6✔
198

199
            Optional<RecipeHolder<RecipeDryingBasin>> currentRecipe = blockEntity.getCurrentRecipe();
3✔
200
            if (!blockEntity.getTank().isEmpty() && blockEntity.getTank().getFluid().getFluid().getFluidType().getTemperature(blockEntity.getTank().getFluid()) >= WOOD_IGNITION_TEMPERATURE) {
15!
201
                blockEntity.setFire(blockEntity.getFire() + 1);
×
202
                if (blockEntity.getFire() >= 100) {
×
203
                    level.setBlockAndUpdate(pos, Blocks.FIRE.defaultBlockState());
×
204
                } else if (level.isEmptyBlock(pos.relative(Direction.UP)) && level.random.nextInt(10) == 0) {
×
205
                    level.setBlockAndUpdate(pos.relative(Direction.UP), Blocks.FIRE.defaultBlockState());
×
206
                }
207

208
            } else if (currentRecipe.isPresent()) {
3✔
209
                RecipeDryingBasin recipe = currentRecipe.get().value();
6✔
210
                if (blockEntity.getProgress() >= recipe.getDuration()) {
5✔
211
                    // Consume input fluid
212
                    if (recipe.getInputFluid().isPresent()) {
4✔
213
                        int amount = IModHelpersNeoForge.get().getFluidHelpers().getAmount(recipe.getInputFluid().get());
8✔
214
                        try (var tx = Transaction.openRoot()) {
2✔
215
                            blockEntity.getTank().extract(FluidResource.of(recipe.getInputFluid().get()), amount, tx);
11✔
216
                            tx.commit();
2✔
217
                        }
218
                    }
219

220
                    // Produce output item
221
                    ItemStack output = recipe.getOutputItemFirst().orElse(ItemStack.EMPTY);
6✔
222
                    if (!output.isEmpty()) {
3!
223
                        output = output.copy();
3✔
224
                        blockEntity.getInventory().setItem(0, output);
6✔
225
                    } else {
226
                        blockEntity.getInventory().setItem(0, ItemStack.EMPTY);
×
227
                    }
228

229
                    // Produce output fluid
230
                    if (recipe.getOutputFluid().isPresent()) {
4!
231
                        int inserted;
232
                        try (var tx = Transaction.openRoot()) {
×
233
                            FluidStack fluidStack = recipe.getOutputFluid().get();
×
234
                            inserted = blockEntity.getTank().insert(FluidResource.of(fluidStack), fluidStack.getAmount(), tx);
×
235
                            tx.commit();
×
236
                        }
237
                        if (inserted == 0) {
×
238
                            IntegratedDynamics.clog(org.apache.logging.log4j.Level.ERROR, "Encountered an invalid recipe: " + currentRecipe.get().id());
×
239
                        }
240
                    }
241

242
                    blockEntity.setProgress(0);
3✔
243
                } else {
1✔
244
                    blockEntity.setProgress(blockEntity.getProgress() + 1);
6✔
245
                    blockEntity.setChanged();
2✔
246
                }
247
                blockEntity.setFire(0);
3✔
248
            } else {
1✔
249
                if ((blockEntity.getProgress() > 0) || (blockEntity.getFire() > 0)) {
6!
250
                    blockEntity.setProgress(0);
×
251
                    blockEntity.setFire(0);
×
252
                    blockEntity.setChanged();
×
253
                }
254
            }
255
        }
1✔
256
    }
257

258
    public static class TickerClient implements BlockEntityTicker<BlockEntityDryingBasin> {
×
259
        @Override
260
        public void tick(Level level, BlockPos pos, BlockState blockState, BlockEntityDryingBasin blockEntity) {
261
            if(blockEntity.getProgress() > 0 && level.random.nextInt(5) == 0) {
×
262
                if(!blockEntity.getTank().isEmpty()) {
×
263
                    BlockState blockStateFluid = blockEntity.getTank().getFluid().getFluid().getFluidType().getBlockForFluidState(level, pos,
×
264
                            blockEntity.getTank().getFluid().getFluid().defaultFluidState());
×
265
                    if(blockStateFluid != null) {
×
266
                        level.addParticle(new BlockParticleOption(ParticleTypes.FALLING_DUST, blockStateFluid),
×
267
                                pos.getX() + Math.random() * 0.8D + 0.1D, pos.getY() + Math.random() * 0.1D + 0.9D,
×
268
                                pos.getZ() + Math.random() * 0.8D + 0.1D, 0, 0.1D, 0);
×
269
                    }
270
                }
271
                if(!blockEntity.getInventory().getItem(0).isEmpty()) {
×
272
                    ItemStack itemStack = blockEntity.getInventory().getItem(0);
×
273
                    level.addParticle(new ItemParticleOption(ParticleTypes.ITEM, itemStack),
×
274
                            pos.getX() + Math.random() * 0.8D + 0.1D, pos.getY() + Math.random() * 0.1D + 0.9D,
×
275
                            pos.getZ() + Math.random() * 0.8D + 0.1D, 0, 0.1D, 0);
×
276
                }
277
            }
278
        }
×
279
    }
280
}
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