-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
177 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 101 additions & 10 deletions
111
src/main/java/io/redspace/ironsspellbooks/jei/ArcaneAnvilRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.