diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java index 2d2e3ed9..0f7af61d 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java @@ -147,7 +147,6 @@ public class PlaceableSpell extends AbstractDelegatingSpell { if (compound.contains("castEntity")) { castEntity.fromNBT(compound.getCompound("castEntity")); } - } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/SpellTraits.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/SpellTraits.java index cc1cd2cd..304a5e05 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/SpellTraits.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/SpellTraits.java @@ -1,6 +1,5 @@ package com.minelittlepony.unicopia.ability.magic.spell.trait; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.EnumMap; @@ -188,9 +187,7 @@ public final class SpellTraits implements Iterable> { } public static SpellTraits of(Inventory inventory) { - List stacks = new ArrayList<>(); - InventoryUtil.iterate(inventory).forEach(stacks::add); - return of(stacks); + return of(InventoryUtil.stream(inventory).toList()); } public static SpellTraits of(Collection stacks) { diff --git a/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java b/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java index 0848f8dc..033a930f 100644 --- a/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java +++ b/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java @@ -168,18 +168,16 @@ public class SpellbookScreenHandler extends ScreenHandler { super.onContentChanged(inventory); context.run((world, pos) -> { if (!world.isClient && !gemSlot.getStack().isEmpty()) { - outputSlot.setStack( - world.getServer().getRecipeManager() + ItemStack resultStack = input.hasIngredients() ? world.getServer().getRecipeManager() .getAllMatches(URecipes.SPELLBOOK, input, world) .stream().sorted(Comparator.comparing(SpellbookRecipe::getPriority)) .findFirst() .filter(recipe -> result.shouldCraftRecipe(world, (ServerPlayerEntity)this.inventory.player, recipe)) .map(recipe -> recipe.craft(input)) - .orElse(!input.hasIngredients() || input.getItemToModify().getItem() != UItems.GEMSTONE - ? ItemStack.EMPTY - : input.getTraits().applyTo(UItems.BOTCHED_GEM.getDefaultStack())) - ); + .orElse(input.getTraits().applyTo(UItems.BOTCHED_GEM.getDefaultStack())) : ItemStack.EMPTY; + outputSlot.setStack(resultStack); + setPreviousTrackedSlot(outputSlot.id, resultStack); ((ServerPlayerEntity)this.inventory.player).networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(syncId, nextRevision(), outputSlot.id, outputSlot.getStack())); } }); @@ -299,7 +297,6 @@ public class SpellbookScreenHandler extends ScreenHandler { super.close(playerEntity); context.run((world, pos) -> { dropInventory(playerEntity, input); - dropInventory(playerEntity, result); }); } @@ -492,7 +489,7 @@ public class SpellbookScreenHandler extends ScreenHandler { @Override public void onTakeItem(PlayerEntity player, ItemStack stack) { Pony pony = Pony.of(player); - InventoryUtil.iterate(input).forEach(s -> { + InventoryUtil.stream(input).forEach(s -> { pony.getDiscoveries().unlock(s.getItem()); }); //gemSlot.setStack(ItemStack.EMPTY); diff --git a/src/main/java/com/minelittlepony/unicopia/util/InventoryUtil.java b/src/main/java/com/minelittlepony/unicopia/util/InventoryUtil.java index 44deed66..f4893019 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/InventoryUtil.java +++ b/src/main/java/com/minelittlepony/unicopia/util/InventoryUtil.java @@ -2,24 +2,12 @@ package com.minelittlepony.unicopia.util; import java.util.stream.Stream; -import com.google.common.collect.AbstractIterator; - import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; public interface InventoryUtil { - static Iterable iterate(Inventory inventory) { - return () -> new AbstractIterator<>() { - private int slot = 0; - - @Override - protected ItemStack computeNext() { - if (slot >= inventory.size()) { - return endOfData(); - } - return inventory.getStack(slot++); - } - }; + static Stream stream(Inventory inventory) { + return slots(inventory).map(inventory::getStack); } static Stream slots(Inventory inventory) {