Dispenser Scrap Box related bug fix. Thanks to aria1th.

* Cache World-common recipe and use it

solves weird recipe errors and small performance improvement 
Expects : RebornRecipes are Immutable

* okay what is that split?

this actually solves recipe getting evaporated by modifying recipe object itself
This commit is contained in:
AngelBottomless 2022-04-01 15:54:42 +09:00 committed by GitHub
parent 61188e755d
commit 5dbad187ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -24,6 +24,7 @@
package techreborn.api.recipe;
import com.google.common.collect.ImmutableList;
import net.minecraft.block.entity.BlockEntity;
import reborncore.common.crafting.RebornRecipe;
import reborncore.common.recipes.RecipeCrafter;
@ -36,6 +37,7 @@ import java.util.List;
* @author drcrazy
*/
public class ScrapboxRecipeCrafter extends RecipeCrafter {
private static ImmutableList<RebornRecipe> RecipeListCache = null;
/**
* @param parent {@link BlockEntity} Tile having this crafter
@ -49,7 +51,10 @@ public class ScrapboxRecipeCrafter extends RecipeCrafter {
@Override
public void updateCurrentRecipe() {
List<RebornRecipe> scrapboxRecipeList = ModRecipes.SCRAPBOX.getRecipes(blockEntity.getWorld());
if(RecipeListCache == null){
RecipeListCache = ImmutableList.copyOf(ModRecipes.SCRAPBOX.getRecipes(blockEntity.getWorld()));
}
List<RebornRecipe> scrapboxRecipeList = RecipeListCache;
if (scrapboxRecipeList.isEmpty()) {
setCurrentRecipe(null);
return;

View file

@ -59,7 +59,7 @@ public class TRDispenserBehavior {
public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
List<RebornRecipe> scrapboxRecipeList = ModRecipes.SCRAPBOX.getRecipes(pointer.getWorld());
int random = new Random().nextInt(scrapboxRecipeList.size());
ItemStack out = scrapboxRecipeList.get(random).getOutputs().get(0);
ItemStack out = scrapboxRecipeList.get(random).getOutputs().get(0).copy();
stack.split(1);
Direction facing = pointer.getBlockState().get(DispenserBlock.FACING);