Fix build issues

This commit is contained in:
Sollace 2024-10-08 18:26:20 +01:00
parent 6956e38f2b
commit 2170357c33
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
11 changed files with 76 additions and 89 deletions

Binary file not shown.

Binary file not shown.

View file

@ -7,7 +7,6 @@ import java.util.stream.Collectors;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.container.inventory.SpellbookInventory;
import com.minelittlepony.unicopia.item.EnchantableItem; import com.minelittlepony.unicopia.item.EnchantableItem;
import com.minelittlepony.unicopia.recipe.URecipes; import com.minelittlepony.unicopia.recipe.URecipes;
import com.minelittlepony.unicopia.util.InventoryUtil; import com.minelittlepony.unicopia.util.InventoryUtil;
@ -93,20 +92,20 @@ public class SpellCraftingRecipe implements SpellbookRecipe {
} }
@Override @Override
public boolean matches(SpellbookInventory inventory, World world) { public boolean matches(Input inventory, World world) {
if (!material.test(inventory.getItemToModify())) { if (!material.test(inventory.stackToModify())) {
return false; return false;
} }
if (requiredItems.isEmpty()) { if (requiredItems.isEmpty()) {
return requiredTraits.test(inventory.getTraits()); return requiredTraits.test(inventory.traits());
} }
var outstandingRequirements = new ArrayList<>(requiredItems); var outstandingRequirements = new ArrayList<>(requiredItems);
var ingredients = InventoryUtil.slots(inventory) var ingredients = InventoryUtil.slots(inventory)
.filter(slot -> !inventory.getStack(slot).isEmpty()) .filter(slot -> !inventory.getStackInSlot(slot).isEmpty())
.map(slot -> Pair.of(slot, inventory.getStack(slot))) .map(slot -> Pair.of(slot, inventory.getStackInSlot(slot)))
.collect(Collectors.toList()); .collect(Collectors.toList());
outstandingRequirements.removeIf(requirement -> { outstandingRequirements.removeIf(requirement -> {
@ -125,7 +124,7 @@ public class SpellCraftingRecipe implements SpellbookRecipe {
} }
@Override @Override
public ItemStack craft(SpellbookInventory inventory, WrapperLookup registries) { public ItemStack craft(Input inventory, WrapperLookup registries) {
return getResult(registries).copy(); return getResult(registries).copy();
} }

View file

@ -1,7 +1,6 @@
package com.minelittlepony.unicopia.ability.magic.spell.crafting; package com.minelittlepony.unicopia.ability.magic.spell.crafting;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.container.inventory.SpellbookInventory;
import com.minelittlepony.unicopia.item.*; import com.minelittlepony.unicopia.item.*;
import com.minelittlepony.unicopia.recipe.URecipes; import com.minelittlepony.unicopia.recipe.URecipes;
import com.minelittlepony.unicopia.util.InventoryUtil; import com.minelittlepony.unicopia.util.InventoryUtil;
@ -41,10 +40,10 @@ public record SpellDuplicatingRecipe (IngredientWithSpell material) implements S
} }
@Override @Override
public boolean matches(SpellbookInventory inventory, World world) { public boolean matches(Input inventory, World world) {
ItemStack stack = inventory.getItemToModify(); ItemStack stack = inventory.stackToModify();
return InventoryUtil.stream(inventory) return InventoryUtil.stream(inventory)
.limit(inventory.size() - 1) .limit(inventory.getSize() - 1)
.filter(i -> !i.isEmpty()) .filter(i -> !i.isEmpty())
.noneMatch(i -> !i.isOf(UItems.GEMSTONE) || !EnchantableItem.isEnchanted(i)) .noneMatch(i -> !i.isOf(UItems.GEMSTONE) || !EnchantableItem.isEnchanted(i))
&& material.test(stack) && material.test(stack)
@ -52,7 +51,7 @@ public record SpellDuplicatingRecipe (IngredientWithSpell material) implements S
} }
@Override @Override
public ItemStack craft(SpellbookInventory inventory, WrapperLookup registries) { public ItemStack craft(Input inventory, WrapperLookup registries) {
return InventoryUtil.stream(inventory) return InventoryUtil.stream(inventory)
.filter(i -> i.isOf(UItems.GEMSTONE)) .filter(i -> i.isOf(UItems.GEMSTONE))
.filter(EnchantableItem::isEnchanted) .filter(EnchantableItem::isEnchanted)

View file

@ -1,7 +1,6 @@
package com.minelittlepony.unicopia.ability.magic.spell.crafting; package com.minelittlepony.unicopia.ability.magic.spell.crafting;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.container.inventory.SpellbookInventory;
import com.minelittlepony.unicopia.item.*; import com.minelittlepony.unicopia.item.*;
import com.mojang.serialization.MapCodec; import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
@ -38,16 +37,16 @@ public record SpellEnhancingRecipe (IngredientWithSpell material) implements Spe
} }
@Override @Override
public boolean matches(SpellbookInventory inventory, World world) { public boolean matches(Input inventory, World world) {
ItemStack stack = inventory.getItemToModify(); ItemStack stack = inventory.stackToModify();
return material.test(stack) && EnchantableItem.isEnchanted(stack); return material.test(stack) && EnchantableItem.isEnchanted(stack);
} }
@Override @Override
public ItemStack craft(SpellbookInventory inventory, WrapperLookup registries) { public ItemStack craft(Input inventory, WrapperLookup registries) {
return SpellTraits.of(inventory.getItemToModify()) return SpellTraits.of(inventory.stackToModify())
.add(inventory.getTraits()) .add(inventory.traits())
.applyTo(inventory.getItemToModify()); .applyTo(inventory.stackToModify());
} }
@Override @Override

View file

@ -2,16 +2,17 @@ package com.minelittlepony.unicopia.ability.magic.spell.crafting;
import java.util.List; import java.util.List;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.container.inventory.SpellbookInventory;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.recipe.URecipes; import com.minelittlepony.unicopia.recipe.URecipes;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Recipe; import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType; import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.input.RecipeInput;
public interface SpellbookRecipe extends Recipe<SpellbookInventory> { public interface SpellbookRecipe extends Recipe<SpellbookRecipe.Input> {
@Override @Override
default RecipeType<?> getType() { default RecipeType<?> getType() {
return URecipes.SPELLBOOK; return URecipes.SPELLBOOK;
@ -52,4 +53,37 @@ public interface SpellbookRecipe extends Recipe<SpellbookInventory> {
mystery(stacks.toArray(ItemStack[]::new)); mystery(stacks.toArray(ItemStack[]::new));
} }
} }
public record Input(ItemStack stackToModify, ItemStack[] stacks, float[] factors, SpellTraits traits, int gemSlotIndex) implements RecipeInput {
@Override
public ItemStack getStackInSlot(int slot) {
return stacks[slot];
}
public float getFactor(int slot) {
return factors[slot];
}
@Override
public int getSize() {
return stacks.length;
}
public boolean hasIngredients() {
for (int i = 0; i < gemSlotIndex; i++) {
if (!getStackInSlot(i).isEmpty()) {
return true;
}
}
return false;
}
public ItemStack getFallbackStack() {
if (stackToModify().isOf(UItems.GEMSTONE) || stackToModify().isOf(UItems.BOTCHED_GEM)) {
return traits().applyTo(UItems.BOTCHED_GEM.getDefaultStack());
}
return ItemStack.EMPTY;
}
}
} }

View file

@ -7,7 +7,6 @@ import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellbookRecipe;
import com.minelittlepony.unicopia.compat.trinkets.TrinketsDelegate; import com.minelittlepony.unicopia.compat.trinkets.TrinketsDelegate;
import com.minelittlepony.unicopia.container.inventory.*; import com.minelittlepony.unicopia.container.inventory.*;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.recipe.URecipes; import com.minelittlepony.unicopia.recipe.URecipes;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
@ -188,13 +187,14 @@ public class SpellbookScreenHandler extends ScreenHandler {
context.run((world, pos) -> { context.run((world, pos) -> {
if (!world.isClient && !gemSlot.getStack().isEmpty()) { if (!world.isClient && !gemSlot.getStack().isEmpty()) {
Comparator<RecipeEntry<SpellbookRecipe>> comparator = Comparator.comparing(e -> e.value().getPriority()); Comparator<RecipeEntry<SpellbookRecipe>> comparator = Comparator.comparing(e -> e.value().getPriority());
SpellbookRecipe.Input input = this.input.createInput();
ItemStack resultStack = input.hasIngredients() ? world.getServer().getRecipeManager() ItemStack resultStack = input.hasIngredients() ? world.getServer().getRecipeManager()
.getAllMatches(URecipes.SPELLBOOK, input, world) .getAllMatches(URecipes.SPELLBOOK, input, world)
.stream().sorted(comparator) .stream().sorted(comparator)
.findFirst() .findFirst()
.filter(recipe -> result.shouldCraftRecipe(world, (ServerPlayerEntity)this.inventory.player, recipe)) .filter(recipe -> result.shouldCraftRecipe(world, (ServerPlayerEntity)this.inventory.player, recipe))
.map(recipe -> recipe.value().craft(input, world.getRegistryManager())) .map(recipe -> recipe.value().craft(input, world.getRegistryManager()))
.orElseGet(this::getFallbackStack) : ItemStack.EMPTY; .orElseGet(input::getFallbackStack) : ItemStack.EMPTY;
outputSlot.setStack(resultStack); outputSlot.setStack(resultStack);
setPreviousTrackedSlot(outputSlot.id, resultStack); setPreviousTrackedSlot(outputSlot.id, resultStack);
@ -203,15 +203,6 @@ public class SpellbookScreenHandler extends ScreenHandler {
}); });
} }
private ItemStack getFallbackStack() {
ItemStack gemStack = gemSlot.getStack();
if (gemStack.isOf(UItems.GEMSTONE) || gemStack.isOf(UItems.BOTCHED_GEM)) {
return input.getTraits().applyTo(UItems.BOTCHED_GEM.getDefaultStack());
}
return ItemStack.EMPTY;
}
@Override @Override
public boolean canInsertIntoSlot(ItemStack stack, Slot slot) { public boolean canInsertIntoSlot(ItemStack stack, Slot slot) {
return slot != null && slot.canInsert(stack) && slot.isEnabled(); return slot != null && slot.canInsert(stack) && slot.isEnabled();

View file

@ -1,15 +1,15 @@
package com.minelittlepony.unicopia.container.inventory; package com.minelittlepony.unicopia.container.inventory;
import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellbookRecipe;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.container.SpellbookScreenHandler; import com.minelittlepony.unicopia.container.SpellbookScreenHandler;
import com.minelittlepony.unicopia.util.InventoryUtil; import com.minelittlepony.unicopia.util.InventoryUtil;
import net.minecraft.inventory.CraftingInventory; import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.recipe.input.RecipeInput;
import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.Slot;
public class SpellbookInventory extends CraftingInventory implements RecipeInput { public class SpellbookInventory extends CraftingInventory {
private final SpellbookScreenHandler handler; private final SpellbookScreenHandler handler;
public SpellbookInventory(SpellbookScreenHandler handler, int width, int height) { public SpellbookInventory(SpellbookScreenHandler handler, int width, int height) {
@ -21,15 +21,6 @@ public class SpellbookInventory extends CraftingInventory implements RecipeInput
return handler.gemSlot.getStack(); return handler.gemSlot.getStack();
} }
public boolean hasIngredients() {
for (int i = 0; i < handler.GEM_SLOT_INDEX; i++) {
if (!getStack(i).isEmpty()) {
return true;
}
}
return false;
}
public float getFactor(int slot) { public float getFactor(int slot) {
Slot s = handler.slots.get(slot); Slot s = handler.slots.get(slot);
return s instanceof SpellbookSlot ? ((SpellbookSlot)s).getWeight() : 0; return s instanceof SpellbookSlot ? ((SpellbookSlot)s).getWeight() : 0;
@ -42,13 +33,13 @@ public class SpellbookInventory extends CraftingInventory implements RecipeInput
); );
} }
@Override public SpellbookRecipe.Input createInput() {
public ItemStack getStackInSlot(int slot) { float[] factors = new float[size()];
return this.getStack(slot); ItemStack[] stacks = new ItemStack[size()];
} for (int i = 0; i < size(); i++) {
factors[i] = getFactor(i);
@Override stacks[i] = getStack(i);
public int getSize() { }
return size(); return new SpellbookRecipe.Input(getItemToModify(), stacks, factors, getTraits(), handler.GEM_SLOT_INDEX);
} }
} }

View file

@ -26,7 +26,6 @@ import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.RecipeType; import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.input.CraftingRecipeInput; import net.minecraft.recipe.input.CraftingRecipeInput;
import net.minecraft.recipe.input.RecipeInput;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
@ -170,16 +169,5 @@ public class CuttingBoardRecipeJsonBuilder {
@Override @Override
public RecipeType<?> getType() { return TYPE; } public RecipeType<?> getType() { return TYPE; }
static class CuttingInput implements RecipeInput {
@Override
public ItemStack getStackInSlot(int slot) {
return null;
}
@Override
public int getSize() {
return 0;
}
}
} }
} }

View file

@ -11,8 +11,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.SingleStackInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
@ -127,41 +125,20 @@ public class TransformCropsRecipe implements Recipe<TransformCropsRecipe.Placeme
return width >= SIDE_LENGTH && height >= SIDE_LENGTH; return width >= SIDE_LENGTH && height >= SIDE_LENGTH;
} }
public static record PlacementArea (Pony pony, BlockPos position) implements SingleStackInventory, RecipeInput { public static record PlacementArea (Pony pony, BlockPos position) implements RecipeInput {
@Override
public void markDirty() { }
@Override
public ItemStack getStack() {
return ItemStack.EMPTY;
}
@Override
public ItemStack decreaseStack(int var1) {
return ItemStack.EMPTY;
}
@Override
public void setStack(ItemStack var1) { }
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
return SingleStackInventory.super.isEmpty();
}
@Override
public boolean canPlayerUse(PlayerEntity player) {
return false; return false;
} }
@Override @Override
public ItemStack getStackInSlot(int slot) { public ItemStack getStackInSlot(int slot) {
return getStack(slot); return ItemStack.EMPTY;
} }
@Override @Override
public int getSize() { public int getSize() {
return size(); return 0;
} }
} }

View file

@ -5,16 +5,25 @@ import java.util.stream.Stream;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.recipe.input.RecipeInput;
public interface InventoryUtil { public interface InventoryUtil {
static Stream<ItemStack> stream(Inventory inventory) { static Stream<ItemStack> stream(Inventory inventory) {
return slots(inventory).map(inventory::getStack); return slots(inventory).map(inventory::getStack);
} }
static Stream<ItemStack> stream(RecipeInput inventory) {
return slots(inventory).map(inventory::getStackInSlot);
}
static Stream<Integer> slots(Inventory inventory) { static Stream<Integer> slots(Inventory inventory) {
return Stream.iterate(0, i -> i < inventory.size(), i -> i + 1); return Stream.iterate(0, i -> i < inventory.size(), i -> i + 1);
} }
static Stream<Integer> slots(RecipeInput inventory) {
return Stream.iterate(0, i -> i < inventory.getSize(), i -> i + 1);
}
static int getOpenSlot(Inventory inventory) { static int getOpenSlot(Inventory inventory) {
for (int i = 0; i < inventory.size(); i++) { for (int i = 0; i < inventory.size(); i++) {
if (inventory.getStack(i).isEmpty()) { if (inventory.getStack(i).isEmpty()) {