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:
parent
61188e755d
commit
5dbad187ef
2 changed files with 7 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue