• 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

4.61
/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
×
58
    private Float randomRotation = 0F;
×
59
    @NBTPersist
×
60
    private int progress = 0;
61
    @NBTPersist
×
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);
×
68

69
        // Create inventory and tank
70
        this.inventory = new SimpleInventory(1, 1) {
×
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);
×
79
                BlockEntityDryingBasin.this.randomRotation = level.random.nextFloat() * 360;
×
80
                sendUpdate();
×
81
            }
×
82
        };
83
        this.tank = new SingleUseTank(IModHelpersNeoForge.get().getFluidHelpers().getBucketVolume());
×
84

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

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

99
            @Override
100
            public boolean isKeyEqual(Pair<ItemStack, FluidStack> cacheKey, Pair<ItemStack, FluidStack> newKey) {
101
                return cacheKey == null || newKey == null ||
×
102
                        (ItemStack.matches(cacheKey.getLeft(), newKey.getLeft()) &&
×
103
                                FluidStack.matches(cacheKey.getRight(), newKey.getRight()));
×
104
            }
105
        });
106
    }
×
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()
×
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;
×
136
    }
137

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

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

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

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

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

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

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

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

176
    public Optional<RecipeHolder<RecipeDryingBasin>> getCurrentRecipe() {
177
        return recipeCache.get(Pair.of(getInventory().getItem(0).copy(), IModHelpersNeoForge.get().getFluidHelpers().copy(getTank().getFluid())));
×
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> {
×
195
        @Override
196
        protected void update(Level level, BlockPos pos, BlockState blockState, BlockEntityDryingBasin blockEntity) {
197
            super.update(level, pos, blockState, blockEntity);
×
198

199
            Optional<RecipeHolder<RecipeDryingBasin>> currentRecipe = blockEntity.getCurrentRecipe();
×
200
            if (!blockEntity.getTank().isEmpty() && blockEntity.getTank().getFluid().getFluid().getFluidType().getTemperature(blockEntity.getTank().getFluid()) >= WOOD_IGNITION_TEMPERATURE) {
×
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()) {
×
209
                RecipeDryingBasin recipe = currentRecipe.get().value();
×
210
                if (blockEntity.getProgress() >= recipe.getDuration()) {
×
211
                    // Consume input fluid
212
                    int amount = IModHelpersNeoForge.get().getFluidHelpers().getAmount(recipe.getInputFluid().orElse(FluidStack.EMPTY));
×
213
                    try (var tx = Transaction.openRoot()) {
×
214
                        blockEntity.getTank().extract(FluidResource.of(recipe.getInputFluid().get()), amount, tx);
×
215
                        tx.commit();
×
216
                    }
217

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

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

240
                    blockEntity.setProgress(0);
×
241
                } else {
×
242
                    blockEntity.setProgress(blockEntity.getProgress() + 1);
×
243
                    blockEntity.setChanged();
×
244
                }
245
                blockEntity.setFire(0);
×
246
            } else {
×
247
                if ((blockEntity.getProgress() > 0) || (blockEntity.getFire() > 0)) {
×
248
                    blockEntity.setProgress(0);
×
249
                    blockEntity.setFire(0);
×
250
                    blockEntity.setChanged();
×
251
                }
252
            }
253
        }
×
254
    }
255

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