Skip to content

Commit

Permalink
Merge branch '1.19.2' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
iron431 committed Jul 5, 2024
2 parents 43c4f4e + df443de commit 4435861
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void draw(@NotNull AlchemistCauldronJeiRecipe recipe, IRecipeSlotsView re
var font = Minecraft.getInstance().font;
int y = (getHeight() / 2) - 14;
int x = (getWidth() - font.width(inputText)) / 2;
guiHelper.drawString(font, inputText, x, y, ChatFormatting.RED.getColor());
guiHelper.drawString(font, inputText, x, y, Math.min(ServerConfigs.SCROLL_RECYCLE_CHANCE.get(), 1d) == 1d ? ChatFormatting.GREEN.getColor() : ChatFormatting.RED.getColor());
}
}
}
111 changes: 101 additions & 10 deletions src/main/java/io/redspace/ironsspellbooks/jei/ArcaneAnvilRecipe.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,112 @@
package io.redspace.ironsspellbooks.jei;

import io.redspace.ironsspellbooks.api.registry.SpellRegistry;
import io.redspace.ironsspellbooks.api.spells.AbstractSpell;
import io.redspace.ironsspellbooks.api.spells.ISpellContainer;
import io.redspace.ironsspellbooks.capabilities.magic.UpgradeData;
import io.redspace.ironsspellbooks.item.Scroll;
import io.redspace.ironsspellbooks.item.UpgradeOrbItem;
import io.redspace.ironsspellbooks.registries.ItemRegistry;
import io.redspace.ironsspellbooks.util.UpgradeUtils;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.IntStream;

public record ArcaneAnvilRecipe(List<ItemStack> leftInputs, List<ItemStack> rightInputs, List<ItemStack> outputs) {
public ArcaneAnvilRecipe(List<ItemStack> leftInputs, List<ItemStack> rightInputs, List<ItemStack> outputs) {
this.leftInputs = List.copyOf(leftInputs);
this.rightInputs = List.copyOf(rightInputs);
this.outputs = List.copyOf(outputs);
public class ArcaneAnvilRecipe {
enum Type {
Scroll_Upgrade,
Item_Upgrade,
Imbue
}

public boolean isValid() {
if (leftInputs.isEmpty() || rightInputs.isEmpty() || outputs.isEmpty()) {
return false;
}
@NotNull Type type;
@Nullable
ItemStack leftItem;
@Nullable
List<ItemStack> rightItem;
@Nullable
AbstractSpell spell;
@Nullable
int level;

return true;
public ArcaneAnvilRecipe(ItemStack leftItem, List<ItemStack> rightItem) {
this.leftItem = leftItem;
this.rightItem = rightItem;
this.type = Type.Item_Upgrade;
}

public ArcaneAnvilRecipe(ItemStack leftItem, AbstractSpell spell) {
this.leftItem = leftItem;
this.spell = spell;
this.type = Type.Imbue;
}

public ArcaneAnvilRecipe(AbstractSpell spell, int baseLevel) {
this.spell = spell;
this.level = baseLevel;
this.type = Type.Scroll_Upgrade;
}

public Tuple<List<ItemStack>, List<ItemStack>, List<ItemStack>> getRecipeItems() {
return switch (this.type) {
case Scroll_Upgrade -> {
var scroll1 = new ItemStack(ItemRegistry.SCROLL.get());
var scroll2 = new ItemStack(ItemRegistry.SCROLL.get());
ISpellContainer.createScrollContainer(spell, level, scroll1);
ISpellContainer.createScrollContainer(spell, level + 1, scroll2);
yield new Tuple<>(List.of(scroll1), List.of(scroll1), List.of(scroll2));
}
case Imbue -> {
var tuple = new Tuple<List<ItemStack>, List<ItemStack>, List<ItemStack>>(new ArrayList<ItemStack>(), new ArrayList<ItemStack>(), new ArrayList<ItemStack>());
SpellRegistry.getEnabledSpells().forEach(spell -> {
IntStream.rangeClosed(spell.getMinLevel(), spell.getMaxLevel()).forEach(i -> {
var scroll = new ItemStack(ItemRegistry.SCROLL.get());
ISpellContainer.createScrollContainer(spell, i, scroll);
var result = leftItem.copy();
ISpellContainer.createScrollContainer(spell, i, result);

tuple.a.add(leftItem);
tuple.b.add(scroll);
tuple.c.add(result);
});
});

yield tuple;
}
case Item_Upgrade -> {
var tuple = new Tuple<List<ItemStack>, List<ItemStack>, List<ItemStack>>(new ArrayList<ItemStack>(), new ArrayList<ItemStack>(), new ArrayList<ItemStack>());
rightItem.forEach(upgradeStack -> {
var result = leftItem.copy();
UpgradeData.setUpgradeData(result, UpgradeData.NONE.addUpgrade(result, ((UpgradeOrbItem) upgradeStack.getItem()).getUpgradeType(), UpgradeUtils.getRelevantEquipmentSlot(leftItem)));
tuple.a.add(leftItem);
tuple.b.add(upgradeStack);
tuple.c.add(result);
});
yield tuple;
}
};
}

private ItemStack spellContainerOf(ItemStack stack, ISpellContainer container) {
container.save(stack);
return stack;
}

public record Tuple<A, B, C>(A a, B b, C c) {

}

// public boolean isValid() {
// if (leftInputs.isEmpty() || rightInputs.isEmpty() || outputs.isEmpty()) {
// return false;
// }
//
// return true;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ public IDrawable getIcon() {
@Override
public void setRecipe(IRecipeLayoutBuilder builder, ArcaneAnvilRecipe recipe, IFocusGroup focuses) {
//TODO: optimization potential here: don't store 500 item stacks of scrolls, just enumerate them here and throw them away when done
List<ItemStack> leftInputs = recipe.leftInputs();
List<ItemStack> rightInputs = recipe.rightInputs();
List<ItemStack> outputs = recipe.outputs();
// List<ItemStack> leftInputs = recipe.leftInputs();
// List<ItemStack> rightInputs = recipe.rightInputs();
// List<ItemStack> outputs = recipe.outputs();
var recipeitems = recipe.getRecipeItems();
List<ItemStack> leftInputs = recipeitems.a();
List<ItemStack> rightInputs = recipeitems.b();
List<ItemStack> outputs = recipeitems.c();

IRecipeSlotBuilder leftInputSlot = builder.addSlot(RecipeIngredientRole.INPUT, 1, 1)
.addItemStacks(leftInputs)
Expand Down Expand Up @@ -121,7 +125,7 @@ private void drawScrollInfo(Minecraft minecraft, GuiGraphics guiGraphics, ISpell
var inputText = String.format("L%d", inputSpellData.getLevel());
var inputColor = inputSpellData.getSpell().getRarity(inputSpellData.getLevel()).getChatFormatting().getColor().intValue();

var outputSpellData = outputScroll.getSpellAtIndex(0);
var outputSpellData = outputScroll.getSpellAtIndex(0);
var outputText = String.format("L%d", outputSpellData.getLevel());
var outputColor = outputSpellData.getSpell().getRarity(outputSpellData.getLevel()).getChatFormatting().getColor().intValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

Expand All @@ -41,74 +43,43 @@ public static List<ArcaneAnvilRecipe> getRecipes(IVanillaRecipeFactory vanillaRe
}

private static Stream<ArcaneAnvilRecipe> getScrollRecipes(IVanillaRecipeFactory vanillaRecipeFactory, IIngredientManager ingredientManager) {
return SpellRegistry.REGISTRY.get().getValues().stream()
.filter(spell -> spell != SpellRegistry.none() && spell.isEnabled())
return SpellRegistry.getEnabledSpells().stream()
.sorted(Comparator.comparing(AbstractSpell::getSpellId))
.map(ArcaneAnvilRecipeMaker::enumerateScrollCombinations)
.filter(ArcaneAnvilRecipe::isValid); //Filter out any blank recipes created where min and max spell level are equal
.flatMap(spell -> IntStream.rangeClosed(spell.getMinLevel(), spell.getMaxLevel()).mapToObj(i -> new ArcaneAnvilRecipe(spell, i)));
/*.filter(ArcaneAnvilRecipe::isValid)*///Filter out any blank recipes created where min and max spell level are equal
}

private static Stream<ArcaneAnvilRecipe> getImbueRecipes(IVanillaRecipeFactory vanillaRecipeFactory, IIngredientManager ingredientManager) {
var scrollStack = new ItemStack(ItemRegistry.SCROLL.get());
var leftInputs = new ArrayList<ItemStack>();
var rightInputs = new ArrayList<ItemStack>();
var outputs = new ArrayList<ItemStack>();

SpellRegistry.REGISTRY.get().getValues().stream()
.filter(spell -> spell != SpellRegistry.none() && spell.isEnabled())
.sorted(Comparator.comparing(AbstractSpell::getSpellId))
.forEach((spellType) -> {
ForgeRegistries.ITEMS.getValues().stream().filter((k) -> k instanceof SwordItem).forEach((swordItem) -> {
var inputSwordStack = new ItemStack(swordItem);
IntStream.rangeClosed(spellType.getMinLevel(), spellType.getMaxLevel())
.forEach((spellLevel) -> {
leftInputs.add(inputSwordStack);
rightInputs.add(getScrollStack(scrollStack, spellType, spellLevel));
outputs.add(getScrollStack(inputSwordStack, spellType, spellLevel));
});
});
});

return Stream.of(new ArcaneAnvilRecipe(leftInputs, rightInputs, outputs));
return ForgeRegistries.ITEMS.getValues().stream()
.filter(item -> Utils.canImbue(new ItemStack(item)) && item.getItemCategory() != null)
.map(item -> new ArcaneAnvilRecipe(new ItemStack(item), (AbstractSpell) null));
}

private static Stream<ArcaneAnvilRecipe> getUpgradeRecipes(IVanillaRecipeFactory vanillaRecipeFactory, IIngredientManager ingredientManager) {
var leftInputs = new ArrayList<ItemStack>();
var rightInputs = new ArrayList<ItemStack>();
var outputs = new ArrayList<ItemStack>();
ForgeRegistries.ITEMS.getValues().forEach(item -> {
if (item instanceof UpgradeOrbItem upgradeOrbItem) {
ForgeRegistries.ITEMS.getValues().forEach(item2 -> {
if (Utils.canBeUpgraded(new ItemStack(item2))) {
ItemStack left = new ItemStack(item2);
ItemStack result = left.copy();
UpgradeData.setUpgradeData(result, UpgradeData.NONE.addUpgrade(result, upgradeOrbItem.getUpgradeType(), UpgradeUtils.getRelevantEquipmentSlot(left)));
leftInputs.add(left);
rightInputs.add(new ItemStack(upgradeOrbItem));
outputs.add(result);
}
});
}
});
return Stream.of(new ArcaneAnvilRecipe(leftInputs, rightInputs, outputs));
return ForgeRegistries.ITEMS.getValues().stream()
.filter(item -> item instanceof UpgradeOrbItem)
.flatMap(upgradeOrb ->
ForgeRegistries.ITEMS.getValues().stream()
.filter(item -> Utils.canBeUpgraded(new ItemStack(item)) && item.getItemCategory() != null)
.map(item -> new ArcaneAnvilRecipe(new ItemStack(item), List.of(new ItemStack(upgradeOrb)))));
}

private static ArcaneAnvilRecipe enumerateScrollCombinations(AbstractSpell spell) {
var scrollStack = new ItemStack(ItemRegistry.SCROLL.get());

var leftInputs = new ArrayList<ItemStack>();
var rightInputs = new ArrayList<ItemStack>();
var outputs = new ArrayList<ItemStack>();

IntStream.range(spell.getMinLevel(), spell.getMaxLevel())
.forEach((spellLevel) -> {
leftInputs.add(getScrollStack(scrollStack, spell, spellLevel));
rightInputs.add(getScrollStack(scrollStack, spell, spellLevel));
outputs.add(getScrollStack(scrollStack, spell, spellLevel + 1));
});

return new ArcaneAnvilRecipe(leftInputs, rightInputs, outputs);
}
// private static ArcaneAnvilRecipe enumerateScrollCombinations(AbstractSpell spell) {
// var scrollStack = new ItemStack(ItemRegistry.SCROLL.get());
//
// var leftInputs = new ArrayList<ItemStack>();
// var rightInputs = new ArrayList<ItemStack>();
// var outputs = new ArrayList<ItemStack>();
//
// IntStream.range(spell.getMinLevel(), spell.getMaxLevel())
// .forEach((spellLevel) -> {
// leftInputs.add(getScrollStack(scrollStack, spell, spellLevel));
// rightInputs.add(getScrollStack(scrollStack, spell, spellLevel));
// outputs.add(getScrollStack(scrollStack, spell, spellLevel + 1));
// });
//
// return new ArcaneAnvilRecipe(leftInputs, rightInputs, outputs);
// }

private static ItemStack getScrollStack(ItemStack stack, AbstractSpell spell, int spellLevel) {
var scrollStack = stack.copy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@
public class CommonSetup {
@SubscribeEvent
public static void onModConfigLoadingEvent(ModConfigEvent.Loading event) {
IronsSpellbooks.LOGGER.debug("onModConfigLoadingEvent");
//IronsSpellbooks.LOGGER.debug("onModConfigLoadingEvent");
if (event.getConfig().getType() == ModConfig.Type.SERVER) {

SpellRegistry.onConfigReload();
ServerConfigs.onConfigReload();
}
}

@SubscribeEvent
public static void onModConfigReloadingEvent(ModConfigEvent.Reloading event) {
IronsSpellbooks.LOGGER.debug("onModConfigReloadingEvent");
//IronsSpellbooks.LOGGER.debug("onModConfigReloadingEvent");
if (event.getConfig().getType() == ModConfig.Type.SERVER) {
SpellRegistry.onConfigReload();
ServerConfigs.onConfigReload();
Expand Down
Loading

0 comments on commit 4435861

Please sign in to comment.