generated from TeamGensouSpark/LunarCapitalFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
137 additions
and
37 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
38 changes: 38 additions & 0 deletions
38
src/main/java/io/github/teamgensouspark/grimoireofpatchouli/api/anvil/AnvilApi.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.teamgensouspark.grimoireofpatchouli.api.anvil; | ||
|
||
import java.util.HashMap; | ||
|
||
import io.github.teamgensouspark.grimoireofpatchouli.PatchouliModInfo; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.event.AnvilUpdateEvent; | ||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
|
||
@EventBusSubscriber(modid = PatchouliModInfo.MODID) | ||
public class AnvilApi { | ||
private static HashMap<String, AnvilReceipe> RECEPIES = new HashMap<>(); | ||
|
||
public static void regReceipe(String name, AnvilReceipe receipe) { | ||
AnvilApi.RECEPIES.put(name, receipe); | ||
} | ||
|
||
public static void unregReceipe(String name) { | ||
AnvilApi.RECEPIES.remove(name); | ||
} | ||
|
||
public static boolean hasRecepie(String name) { | ||
return AnvilApi.RECEPIES.containsKey(name); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void _InternalListener(AnvilUpdateEvent event) { | ||
ItemStack left = event.getLeft(); | ||
ItemStack right = event.getRight(); | ||
for (AnvilReceipe R : AnvilApi.RECEPIES.values()) { | ||
if (R.matchThen(left, right, () -> R.apply(event))) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/io/github/teamgensouspark/grimoireofpatchouli/api/anvil/AnvilReceipe.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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.github.teamgensouspark.grimoireofpatchouli.api.anvil; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.event.AnvilUpdateEvent; | ||
|
||
public class AnvilReceipe { | ||
public int cost = 10; | ||
public boolean isShape = false; | ||
public ItemStack result = ItemStack.EMPTY; | ||
public Predicate<ItemStack> left; | ||
public Predicate<ItemStack> right; | ||
|
||
public AnvilReceipe(Predicate<ItemStack> left, Predicate<ItemStack> right) { | ||
this.left = left; | ||
this.right = right; | ||
} | ||
|
||
public AnvilReceipe() { | ||
} | ||
|
||
public AnvilReceipe setLeft(Predicate<ItemStack> left) { | ||
this.left = left; | ||
return this; | ||
} | ||
|
||
public AnvilReceipe setRight(Predicate<ItemStack> right) { | ||
this.right = right; | ||
return this; | ||
} | ||
|
||
public AnvilReceipe setCost(int cost) { | ||
this.cost = cost; | ||
return this; | ||
} | ||
|
||
public AnvilReceipe setShape(boolean isShape) { | ||
this.isShape = isShape; | ||
return this; | ||
} | ||
|
||
public AnvilReceipe setResult(ItemStack itemStack) { | ||
this.result = itemStack; | ||
return this; | ||
} | ||
|
||
public boolean match(ItemStack left, ItemStack right) { | ||
return isShape ? this.left.test(left) && this.right.test(right) | ||
: this.left.test(left) && this.right.test(right) || this.left.test(right) && this.right.test(left); | ||
} | ||
|
||
public boolean matchThen(ItemStack left, ItemStack right, Runnable F) { | ||
if (match(left, right)) { | ||
F.run(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public void apply(AnvilUpdateEvent event) { | ||
ItemStack result = this.result.copy(); | ||
if (result != ItemStack.EMPTY && result != null) { | ||
event.setOutput(result); | ||
event.setCost(cost); | ||
} | ||
} | ||
|
||
} |
37 changes: 0 additions & 37 deletions
37
src/main/java/io/github/teamgensouspark/grimoireofpatchouli/recepies/AnvilReceipe.java
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
src/main/java/io/github/teamgensouspark/grimoireofpatchouli/recepies/ModAnvilReceipes.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.github.teamgensouspark.grimoireofpatchouli.recepies; | ||
|
||
import arekkuusu.grimoireofalice.common.item.ModItems; | ||
import io.github.teamgensouspark.grimoireofpatchouli.api.anvil.AnvilApi; | ||
import io.github.teamgensouspark.grimoireofpatchouli.api.anvil.AnvilReceipe; | ||
import io.github.teamgensouspark.grimoireofpatchouli.utils.ModCompat; | ||
import net.minecraft.init.Enchantments; | ||
import net.minecraft.init.Items; | ||
import net.minecraft.item.ItemStack; | ||
|
||
public class ModAnvilReceipes { | ||
public static void init() { | ||
ItemStack BLACK_SAKURA = new ItemStack( | ||
io.github.teamgensouspark.grimoireofpatchouli.libs.vanilia.ModItems.BLACK_SAKURA); | ||
BLACK_SAKURA.addEnchantment(Enchantments.SMITE, 10); | ||
if (ModCompat.GOA.isLoaded()) { | ||
AnvilApi.regReceipe("black_sakura", | ||
new AnvilReceipe().setCost(30).setShape(false) | ||
.setLeft((stack) -> stack.getItem() == ModItems.HAKUROUKEN) | ||
.setRight((stack) -> stack.getItem() == ModItems.ROUKANKEN).setResult(BLACK_SAKURA)); | ||
} else { | ||
AnvilApi.regReceipe("black_sakura", | ||
new AnvilReceipe().setCost(30).setShape(false) | ||
.setLeft((stack) -> stack.getItem() == Items.DIAMOND_SWORD) | ||
.setRight((stack) -> stack.getItem() == Items.NETHER_STAR).setResult(BLACK_SAKURA)); | ||
} | ||
} | ||
} |