-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added partial EMI support - adding and removing item and fluid entries
- Loading branch information
1 parent
86d6e0b
commit 9581b84
Showing
24 changed files
with
186 additions
and
96 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
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
32 changes: 32 additions & 0 deletions
32
src/main/java/dev/latvian/mods/kubejs/integration/emi/EMIAddEntriesKubeEvent.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,32 @@ | ||
package dev.latvian.mods.kubejs.integration.emi; | ||
|
||
import dev.emi.emi.api.EmiRegistry; | ||
import dev.emi.emi.api.stack.EmiStack; | ||
import dev.latvian.mods.kubejs.recipe.viewer.AddEntriesKubeEvent; | ||
import dev.latvian.mods.kubejs.recipe.viewer.RecipeViewerEntryType; | ||
import dev.latvian.mods.rhino.Context; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.neoforged.neoforge.fluids.FluidStack; | ||
|
||
public class EMIAddEntriesKubeEvent implements AddEntriesKubeEvent { | ||
private final RecipeViewerEntryType type; | ||
private final EmiRegistry registry; | ||
|
||
public EMIAddEntriesKubeEvent(RecipeViewerEntryType type, EmiRegistry registry) { | ||
this.type = type; | ||
this.registry = registry; | ||
} | ||
|
||
@Override | ||
public void add(Context cx, Object[] items) { | ||
for (var item : items) { | ||
var entry = type.wrapEntry(cx, item); | ||
|
||
if (type == RecipeViewerEntryType.ITEM) { | ||
registry.addEmiStack(EmiStack.of((ItemStack) entry)); | ||
} else if (type == RecipeViewerEntryType.FLUID) { | ||
registry.addEmiStack(EMIIntegration.fluid((FluidStack) entry)); | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/dev/latvian/mods/kubejs/integration/emi/EMIIntegration.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 dev.latvian.mods.kubejs.integration.emi; | ||
|
||
import dev.emi.emi.api.stack.EmiStack; | ||
import dev.latvian.mods.kubejs.item.ItemPredicate; | ||
import net.neoforged.neoforge.fluids.FluidStack; | ||
import net.neoforged.neoforge.fluids.crafting.FluidIngredient; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.function.Predicate; | ||
|
||
public class EMIIntegration { | ||
public static EmiStack fluid(FluidStack stack) { | ||
return EmiStack.of(stack.getFluid(), stack.getComponentsPatch(), stack.getAmount()); | ||
} | ||
|
||
public static Predicate<EmiStack> predicate(ItemPredicate ingredient) { | ||
return emiStack -> { | ||
var is = emiStack.getItemStack(); | ||
return !is.isEmpty() && ingredient.test(is); | ||
}; | ||
} | ||
|
||
public static Predicate<EmiStack> predicate(FluidIngredient ingredient) { | ||
var set = new HashSet<>(Arrays.stream(ingredient.getStacks()).map(EMIIntegration::fluid).toList()); | ||
return set::contains; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/dev/latvian/mods/kubejs/integration/emi/EMIRemoveEntriesKubeEvent.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,29 @@ | ||
package dev.latvian.mods.kubejs.integration.emi; | ||
|
||
import dev.emi.emi.api.EmiRegistry; | ||
import dev.latvian.mods.kubejs.recipe.viewer.RecipeViewerEntryType; | ||
import dev.latvian.mods.kubejs.recipe.viewer.RemoveEntriesKubeEvent; | ||
import dev.latvian.mods.rhino.Context; | ||
import net.minecraft.world.item.crafting.Ingredient; | ||
import net.neoforged.neoforge.fluids.crafting.FluidIngredient; | ||
|
||
public class EMIRemoveEntriesKubeEvent implements RemoveEntriesKubeEvent { | ||
private final RecipeViewerEntryType type; | ||
private final EmiRegistry registry; | ||
|
||
public EMIRemoveEntriesKubeEvent(RecipeViewerEntryType type, EmiRegistry registry) { | ||
this.type = type; | ||
this.registry = registry; | ||
} | ||
|
||
@Override | ||
public void remove(Context cx, Object filter) { | ||
var predicate = type.wrapPredicate(cx, filter); | ||
|
||
if (type == RecipeViewerEntryType.ITEM) { | ||
registry.removeEmiStacks(EMIIntegration.predicate((Ingredient) predicate)); | ||
} else if (type == RecipeViewerEntryType.FLUID) { | ||
registry.removeEmiStacks(EMIIntegration.predicate((FluidIngredient) predicate)); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/dev/latvian/mods/kubejs/integration/emi/KubeJSEMIPlugin.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,62 @@ | ||
package dev.latvian.mods.kubejs.integration.emi; | ||
|
||
import dev.emi.emi.api.EmiEntrypoint; | ||
import dev.emi.emi.api.EmiPlugin; | ||
import dev.emi.emi.api.EmiRegistry; | ||
import dev.emi.emi.api.stack.EmiStack; | ||
import dev.latvian.mods.kubejs.recipe.viewer.RecipeViewerEntryType; | ||
import dev.latvian.mods.kubejs.recipe.viewer.RecipeViewerEvents; | ||
import dev.latvian.mods.kubejs.recipe.viewer.server.RecipeViewerData; | ||
import dev.latvian.mods.kubejs.script.ScriptType; | ||
|
||
@EmiEntrypoint | ||
public class KubeJSEMIPlugin implements EmiPlugin { | ||
@Override | ||
public void register(EmiRegistry registry) { | ||
var remote = RecipeViewerData.remote; | ||
|
||
for (var type : RecipeViewerEntryType.ALL_TYPES.get()) { | ||
if (RecipeViewerEvents.REMOVE_ENTRIES.hasListeners(type)) { | ||
RecipeViewerEvents.REMOVE_ENTRIES.post(ScriptType.CLIENT, type, new EMIRemoveEntriesKubeEvent(type, registry)); | ||
} | ||
|
||
if (RecipeViewerEvents.REMOVE_ENTRIES_COMPLETELY.hasListeners(type)) { | ||
RecipeViewerEvents.REMOVE_ENTRIES_COMPLETELY.post(ScriptType.CLIENT, type, new EMIRemoveEntriesKubeEvent(type, registry)); | ||
} | ||
} | ||
|
||
if (remote != null) { | ||
for (var ingredient : remote.itemData().removedEntries()) { | ||
registry.removeEmiStacks(EMIIntegration.predicate(ingredient)); | ||
} | ||
|
||
for (var ingredient : remote.itemData().completelyRemovedEntries()) { | ||
registry.removeEmiStacks(EMIIntegration.predicate(ingredient)); | ||
} | ||
|
||
for (var ingredient : remote.fluidData().removedEntries()) { | ||
registry.removeEmiStacks(EMIIntegration.predicate(ingredient)); | ||
} | ||
|
||
for (var ingredient : remote.fluidData().completelyRemovedEntries()) { | ||
registry.removeEmiStacks(EMIIntegration.predicate(ingredient)); | ||
} | ||
} | ||
|
||
for (var type : RecipeViewerEntryType.ALL_TYPES.get()) { | ||
if (RecipeViewerEvents.ADD_ENTRIES.hasListeners(type)) { | ||
RecipeViewerEvents.ADD_ENTRIES.post(ScriptType.CLIENT, type, new EMIAddEntriesKubeEvent(type, registry)); | ||
} | ||
} | ||
|
||
if (remote != null) { | ||
for (var stack : remote.itemData().addedEntries()) { | ||
registry.addEmiStack(EmiStack.of(stack)); | ||
} | ||
|
||
for (var stack : remote.fluidData().addedEntries()) { | ||
registry.addEmiStack(EmiStack.of(stack.getFluid(), stack.getComponentsPatch(), stack.getAmount())); | ||
} | ||
} | ||
} | ||
} |
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
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
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
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.