diff --git a/src/main/java/com/petrolpark/destroy/block/entity/VatControllerBlockEntity.java b/src/main/java/com/petrolpark/destroy/block/entity/VatControllerBlockEntity.java index fb3ad4997..34f5f0585 100644 --- a/src/main/java/com/petrolpark/destroy/block/entity/VatControllerBlockEntity.java +++ b/src/main/java/com/petrolpark/destroy/block/entity/VatControllerBlockEntity.java @@ -193,7 +193,7 @@ public void tick() { boolean shouldUpdateFluidMixture = false; Vat vat = getVatOptional().get(); if (tankBehaviour.isEmpty()) return; - double fluidAmount = getCapacity() / Constants.MILLIBUCKETS_PER_LITER; // Converts getFluidAmount() in mB to Buckets + double fluidAmount = getCapacity() / Constants.MILLIBUCKETS_PER_LITER; // Converts getFluidAmount() in mB to liters int cyclesPerTick = getSimulationLevel(); diff --git a/src/main/java/com/petrolpark/destroy/block/movementchecks/DestroyMovementChecks.java b/src/main/java/com/petrolpark/destroy/block/movementchecks/DestroyMovementChecks.java index 488538182..bbe42b382 100644 --- a/src/main/java/com/petrolpark/destroy/block/movementchecks/DestroyMovementChecks.java +++ b/src/main/java/com/petrolpark/destroy/block/movementchecks/DestroyMovementChecks.java @@ -2,6 +2,8 @@ import java.util.Optional; +import com.petrolpark.destroy.block.ArcFurnaceLidBlock; +import com.petrolpark.destroy.block.DynamoBlock; import com.petrolpark.destroy.block.VatControllerBlock; import com.petrolpark.destroy.block.VatSideBlock; import com.petrolpark.destroy.block.entity.DestroyBlockEntityTypes; @@ -57,7 +59,14 @@ private static BlockMovementChecks.CheckResult attachedCheckVats(BlockState stat return BlockMovementChecks.CheckResult.PASS; }; + public static BlockMovementChecks.CheckResult attachedCheckArcFurnace(BlockState state, Level level, BlockPos pos, Direction attached) { + if (state.getBlock() instanceof DynamoBlock && state.getValue(DynamoBlock.ARC_FURNACE) && attached == Direction.DOWN) return BlockMovementChecks.CheckResult.SUCCESS; + if (state.getBlock() instanceof ArcFurnaceLidBlock && attached == Direction.UP) return BlockMovementChecks.CheckResult.SUCCESS; + return BlockMovementChecks.CheckResult.PASS; + }; + public static void register() { BlockMovementChecks.registerAttachedCheck(DestroyMovementChecks::attachedCheckVats); + BlockMovementChecks.registerAttachedCheck(DestroyMovementChecks::attachedCheckArcFurnace); }; }; diff --git a/src/main/java/com/petrolpark/destroy/chemistry/legacy/LegacyMixture.java b/src/main/java/com/petrolpark/destroy/chemistry/legacy/LegacyMixture.java index 3aeea2f9a..c496c831b 100644 --- a/src/main/java/com/petrolpark/destroy/chemistry/legacy/LegacyMixture.java +++ b/src/main/java/com/petrolpark/destroy/chemistry/legacy/LegacyMixture.java @@ -568,28 +568,28 @@ public List dissolveItems(ReactionContext context, double volume) { @Deprecated public int recalculateVolume(int initialVolume) { if (contents.isEmpty()) return 0; - double initialVolumeInBuckets = (double)initialVolume / 1000d; - double newVolumeInBuckets = 0d; + double initialVolumeInLiters = (double)initialVolume / Constants.MILLIBUCKETS_PER_LITER; + double newVolumeInLiters = 0d; // Molecules Map molesOfMolecules = new HashMap<>(); for (Entry entry : contents.entrySet()) { LegacySpecies molecule = entry.getKey(); - double molesOfMolecule = entry.getValue() * initialVolumeInBuckets; + double molesOfMolecule = entry.getValue() * initialVolumeInLiters; molesOfMolecules.put(molecule, molesOfMolecule); - newVolumeInBuckets += molesOfMolecule / molecule.getPureConcentration(); + newVolumeInLiters += molesOfMolecule / molecule.getPureConcentration(); }; for (Entry entry : molesOfMolecules.entrySet()) { - contents.replace(entry.getKey(), (float)(entry.getValue() / newVolumeInBuckets)); + contents.replace(entry.getKey(), (float)(entry.getValue() / newVolumeInLiters)); }; // Results Map resultsCopy = new HashMap<>(reactionResults); for (Entry entry : resultsCopy.entrySet()) { - reactionResults.replace(entry.getKey(), (float)(entry.getValue() * initialVolumeInBuckets / newVolumeInBuckets)); + reactionResults.replace(entry.getKey(), (float)(entry.getValue() * initialVolumeInLiters / newVolumeInLiters)); }; - return (int)((newVolumeInBuckets * 1000)); + return (int)((newVolumeInLiters * Constants.MILLIBUCKETS_PER_LITER)); }; /** @@ -718,7 +718,7 @@ protected void incrementReactionResults(LegacyReaction reaction, float molesPerB * {@link LegacyMixture#reactForTick React} this Mixture until it reaches {@link LegacyMixture#equilibrium equilibrium}. This is mutative. * @return A {@link com.petrolpark.destroy.recipe.ReactionInBasinRecipe.ReactionInBasinResult ReactionInBasinResult} containing * the number of ticks it took to reach equilibrium, the {@link ReactionResult Reaction Results} and the new volume of Mixture. - * @param volume (in mB) of this Reaction + * @param volume (in liters) of this Reaction * @param availableStacks Item Stacks available for reacting. This List and its contents will be modified. * @param heatingPower The power being supplied to this Basin by the {@link com.petrolpark.destroy.util.vat.IVatHeaterBlock heater} below it. * @param outsideTemperature The {@link com.petrolpark.destroy.capability.Pollution#getLocalTemperature temperature} outside the Basin. @@ -743,7 +743,7 @@ public ReactionInBasinResult reactInBasin(int volume, List availableS int amount = recalculateVolume(volume); - return new ReactionInBasinResult(ticks, getCompletedResults(volumeInLiters), amount); + return new ReactionInBasinResult(ticks, getCompletedResults(amount), amount); }; /** @@ -762,12 +762,12 @@ public Map getCompletedResults(double volumeInLiters) { continue; }; - float molesPerBucketOfReaction = reactionResults.get(result); - int numberOfResult = (int) (volumeInLiters * molesPerBucketOfReaction / result.getRequiredMoles()); + float molesPerLiterOfReaction = reactionResults.get(result); + int numberOfResult = (int) (volumeInLiters * molesPerLiterOfReaction / result.getRequiredMoles()); if (numberOfResult == 0) continue; // Decrease the amount of Reaction that has happened - reactionResults.replace(result, molesPerBucketOfReaction - numberOfResult * result.getRequiredMoles() / (float)volumeInLiters); + reactionResults.replace(result, molesPerLiterOfReaction - numberOfResult * result.getRequiredMoles() / (float)volumeInLiters); results.put(result, numberOfResult); }; diff --git a/src/main/java/com/petrolpark/destroy/chemistry/legacy/ReactionResult.java b/src/main/java/com/petrolpark/destroy/chemistry/legacy/ReactionResult.java index 19bc52adf..799008e9e 100644 --- a/src/main/java/com/petrolpark/destroy/chemistry/legacy/ReactionResult.java +++ b/src/main/java/com/petrolpark/destroy/chemistry/legacy/ReactionResult.java @@ -60,7 +60,7 @@ public boolean isOneOff() { */ public abstract void onVatReaction(Level level, VatControllerBlockEntity vatController); - public Collection getPrecipitatesForJEI() { + public Collection getAllPrecipitates() { return Collections.emptySet(); }; }; diff --git a/src/main/java/com/petrolpark/destroy/chemistry/legacy/reactionresult/CombinedReactionResult.java b/src/main/java/com/petrolpark/destroy/chemistry/legacy/reactionresult/CombinedReactionResult.java index 287c71f47..d95c242be 100644 --- a/src/main/java/com/petrolpark/destroy/chemistry/legacy/reactionresult/CombinedReactionResult.java +++ b/src/main/java/com/petrolpark/destroy/chemistry/legacy/reactionresult/CombinedReactionResult.java @@ -45,8 +45,8 @@ public void onVatReaction(Level level, VatControllerBlockEntity vatController) { }; @Override - public Collection getPrecipitatesForJEI() { - return childResults.stream().flatMap(r -> r.getPrecipitatesForJEI().stream()).toList(); + public Collection getAllPrecipitates() { + return childResults.stream().flatMap(r -> r.getAllPrecipitates().stream()).toList(); }; }; diff --git a/src/main/java/com/petrolpark/destroy/chemistry/legacy/reactionresult/PrecipitateReactionResult.java b/src/main/java/com/petrolpark/destroy/chemistry/legacy/reactionresult/PrecipitateReactionResult.java index a75aef766..9e861d56b 100644 --- a/src/main/java/com/petrolpark/destroy/chemistry/legacy/reactionresult/PrecipitateReactionResult.java +++ b/src/main/java/com/petrolpark/destroy/chemistry/legacy/reactionresult/PrecipitateReactionResult.java @@ -42,7 +42,7 @@ public void onVatReaction(Level level, VatControllerBlockEntity vatController) { }; @Override - public Collection getPrecipitatesForJEI() { + public Collection getAllPrecipitates() { return Collections.singleton(this); }; diff --git a/src/main/java/com/petrolpark/destroy/compat/jei/category/ReactionCategory.java b/src/main/java/com/petrolpark/destroy/compat/jei/category/ReactionCategory.java index 247a9b3e8..b18b8a6f5 100644 --- a/src/main/java/com/petrolpark/destroy/compat/jei/category/ReactionCategory.java +++ b/src/main/java/com/petrolpark/destroy/compat/jei/category/ReactionCategory.java @@ -135,7 +135,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, T recipe, IFocusGroup focuse }; }; - Collection precipitates = reaction.hasResult() ? reaction.getResult().getPrecipitatesForJEI() : Collections.emptyList(); + Collection precipitates = reaction.hasResult() ? reaction.getResult().getAllPrecipitates() : Collections.emptyList(); int j = 0; diff --git a/src/main/java/com/petrolpark/destroy/compat/jei/recipemanager/ItemReverseReactionRecipeManagerPlugin.java b/src/main/java/com/petrolpark/destroy/compat/jei/recipemanager/ItemReverseReactionRecipeManagerPlugin.java index d97ac32e7..169796590 100644 --- a/src/main/java/com/petrolpark/destroy/compat/jei/recipemanager/ItemReverseReactionRecipeManagerPlugin.java +++ b/src/main/java/com/petrolpark/destroy/compat/jei/recipemanager/ItemReverseReactionRecipeManagerPlugin.java @@ -52,7 +52,7 @@ public List getRecipes(IRecipeCategory recipeCategory, IFocus fo if (reaction.getItemReactants().stream().anyMatch(ir -> ((ir.isCatalyst() && searchCatalysts) || (!ir.isCatalyst() && searchInputs)) && ir.isItemValid(stack))) return true; // Check for precipitates - if (searchOutputs && reaction.hasResult()) reaction.getResult().getPrecipitatesForJEI().stream().anyMatch(p -> ItemStack.matches(p.getPrecipitate(), stack)); + if (searchOutputs && reaction.hasResult()) reaction.getResult().getAllPrecipitates().stream().anyMatch(p -> ItemStack.matches(p.getPrecipitate(), stack)); return false; // Unchecked conversion (but actually it is checked) diff --git a/src/main/java/com/petrolpark/destroy/recipe/ReactionInBasinRecipe.java b/src/main/java/com/petrolpark/destroy/recipe/ReactionInBasinRecipe.java index c8a43ae10..eafb1d667 100644 --- a/src/main/java/com/petrolpark/destroy/recipe/ReactionInBasinRecipe.java +++ b/src/main/java/com/petrolpark/destroy/recipe/ReactionInBasinRecipe.java @@ -10,6 +10,7 @@ import com.petrolpark.destroy.Destroy; import com.petrolpark.destroy.block.entity.behaviour.ExtendedBasinBehaviour; import com.petrolpark.destroy.capability.Pollution; +import com.petrolpark.destroy.chemistry.api.util.Constants; import com.petrolpark.destroy.chemistry.legacy.LegacyMixture; import com.petrolpark.destroy.chemistry.legacy.ReactionResult; import com.petrolpark.destroy.chemistry.legacy.LegacyMixture.Phases; @@ -17,6 +18,7 @@ import com.petrolpark.destroy.chemistry.legacy.reactionresult.PrecipitateReactionResult; import com.petrolpark.destroy.fluid.DestroyFluids; import com.petrolpark.destroy.fluid.MixtureFluid; +import com.petrolpark.destroy.util.ItemHelper; import com.petrolpark.destroy.util.vat.IVatHeaterBlock; import com.simibubi.create.content.processing.basin.BasinBlockEntity; import com.simibubi.create.content.processing.basin.BasinRecipe; @@ -87,7 +89,7 @@ public static ReactionInBasinRecipe create(Collection availableFluid int amount = fluidStack.getAmount(); totalAmount += amount; - mixtures.put(mixture, (double)amount); + mixtures.put(mixture, (double)amount / Constants.MILLIBUCKETS_PER_LITER); }; if (!containsMixtures) canReact = false; // Don't react without Mixtures, even if there are fluids which could be converted into Mixtures @@ -136,7 +138,7 @@ public static ReactionInBasinRecipe create(Collection availableFluid Map reactionResults = new HashMap<>(); - gatherReactionResults(result.reactionresults(), reactionResults, builder); // Gather all + gatherReactionResults(result.reactionResults(), reactionResults, builder); // Gather all ExtendedBasinBehaviour behaviour = basin.getBehaviour(ExtendedBasinBehaviour.TYPE); behaviour.setReactionResults(reactionResults); // Schedule the Reaction Results to occur once the Mixing has finished @@ -162,7 +164,8 @@ private static void gatherReactionResults(Map resultsOf }; gatherReactionResults(childMap, resultsToEnact, builder); } else if (reactionresult instanceof PrecipitateReactionResult precipitationResult) { - builder.output(precipitationResult.getPrecipitate()); + ItemStack precipitate = precipitationResult.getPrecipitate(); + ItemHelper.withCount(precipitate, resultsOfReaction.get(reactionresult) * precipitate.getCount()).forEach(builder::output); } else { // Don't deal with precipitations in the normal way resultsToEnact.put(reactionresult, resultsOfReaction.get(reactionresult)); }; @@ -177,9 +180,9 @@ protected int getMaxFluidInputCount() { /** * The outcome of {@link com.petrolpark.destroy.chemistry.legacy.LegacyReaction reacting} a {@link com.petrolpark.destroy.chemistry.legacy.LegacyReaction Mixture} in a Basin. * @param ticks The number of ticks it took for the Mixture to reach equilibrium - * @param reactionresults The {@link com.petrolpark.destroy.chemistry.legacy.ReactionResult results} of Reacting this Mixture + * @param reactionResults The {@link com.petrolpark.destroy.chemistry.legacy.ReactionResult results} of Reacting this Mixture * @param amount The amount (in mB) of resultant Mixture */ - public static record ReactionInBasinResult(int ticks, Map reactionresults, int amount) {}; + public static record ReactionInBasinResult(int ticks, Map reactionResults, int amount) {}; }; diff --git a/src/main/java/com/petrolpark/destroy/util/ItemHelper.java b/src/main/java/com/petrolpark/destroy/util/ItemHelper.java new file mode 100644 index 000000000..9bd81a087 --- /dev/null +++ b/src/main/java/com/petrolpark/destroy/util/ItemHelper.java @@ -0,0 +1,22 @@ +package com.petrolpark.destroy.util; + +import java.util.Collection; +import java.util.List; +import java.util.ArrayList; + +import net.minecraft.world.item.ItemStack; + +public class ItemHelper { + + /** + * Copies an Item in an ItemStack a given number of times. + * If the number exceeds the maximum stack size of the Item, it is split into multiple Item Stacks. + */ + public static Collection withCount(ItemStack stack, int count) { + int maxStackSize = stack.getMaxStackSize(); + List stacks = new ArrayList<>(1 + (count / maxStackSize)); + for (int i = 0; i < count / maxStackSize; i++) stacks.add(stack.copyWithCount(maxStackSize)); + stacks.add(stack.copyWithCount(count % maxStackSize)); + return stacks; + }; +};