mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fix item duplication/sync glitch in the spellbook
This commit is contained in:
parent
697ae2b086
commit
3166fb3919
4 changed files with 8 additions and 27 deletions
|
@ -147,7 +147,6 @@ public class PlaceableSpell extends AbstractDelegatingSpell {
|
|||
if (compound.contains("castEntity")) {
|
||||
castEntity.fromNBT(compound.getCompound("castEntity"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<Map.Entry<Trait, Float>> {
|
|||
}
|
||||
|
||||
public static SpellTraits of(Inventory inventory) {
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
InventoryUtil.iterate(inventory).forEach(stacks::add);
|
||||
return of(stacks);
|
||||
return of(InventoryUtil.stream(inventory).toList());
|
||||
}
|
||||
|
||||
public static SpellTraits of(Collection<ItemStack> stacks) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<ItemStack> 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<ItemStack> stream(Inventory inventory) {
|
||||
return slots(inventory).map(inventory::getStack);
|
||||
}
|
||||
|
||||
static Stream<Integer> slots(Inventory inventory) {
|
||||
|
|
Loading…
Reference in a new issue