-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added KubeJs support for "recipe and Addon: speed/efficiency/processing"
- Loading branch information
Showing
11 changed files
with
256 additions
and
6 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
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
73 changes: 73 additions & 0 deletions
73
src/main/java/net/yxiao233/ifeu/common/compact/kubejs/IndustrialForegoingComponents.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,73 @@ | ||
package net.yxiao233.ifeu.common.compact.kubejs; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonPrimitive; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import dev.architectury.fluid.FluidStack; | ||
import dev.latvian.mods.kubejs.fluid.FluidStackJS; | ||
import dev.latvian.mods.kubejs.fluid.InputFluid; | ||
import dev.latvian.mods.kubejs.recipe.RecipeJS; | ||
import dev.latvian.mods.kubejs.recipe.RecipeKey; | ||
import dev.latvian.mods.kubejs.recipe.component.ComponentRole; | ||
import dev.latvian.mods.kubejs.recipe.component.RecipeComponent; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.TagParser; | ||
|
||
public class IndustrialForegoingComponents { | ||
public static RecipeComponent<InputFluid> INPUT_FLUID = new RecipeComponent<>() { | ||
@Override | ||
public String componentType() { | ||
return "input_fluid"; | ||
} | ||
|
||
@Override | ||
public ComponentRole role() { | ||
return ComponentRole.INPUT; | ||
} | ||
|
||
@Override | ||
public Class<?> componentClass() { | ||
return InputFluid.class; | ||
} | ||
|
||
@Override | ||
public JsonElement write(RecipeJS recipeJS, InputFluid inputFluid) { | ||
var stack = ((FluidStackJS) inputFluid); | ||
return stack.kjs$isEmpty() ? null : new JsonPrimitive(stack.getFluidStack().write(new CompoundTag()).toString()); | ||
} | ||
|
||
private InputFluid readString(RecipeJS recipe, String string){ | ||
try { | ||
return recipe.readInputFluid(FluidStack.read(TagParser.parseTag(string))); | ||
} catch (CommandSyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public InputFluid read(RecipeJS recipeJS, Object o) { | ||
if(o instanceof JsonPrimitive primitive && primitive.isString()){ | ||
return readString(recipeJS,primitive.getAsString()); | ||
} | ||
return recipeJS.readInputFluid(o); | ||
} | ||
|
||
@Override | ||
public boolean hasPriority(RecipeJS recipe, Object from) { | ||
return recipe.inputFluidHasPriority(from); | ||
} | ||
|
||
@Override | ||
public String checkEmpty(RecipeKey<InputFluid> key, InputFluid value) { | ||
if(value.kjs$isEmpty()){ | ||
return "Input fluid '" + key.name + "' can't be empty!"; | ||
} | ||
return ""; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return componentType(); | ||
} | ||
}; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/net/yxiao233/ifeu/common/compact/kubejs/ModKubeJSPlugin.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,25 @@ | ||
package net.yxiao233.ifeu.common.compact.kubejs; | ||
|
||
import dev.latvian.mods.kubejs.KubeJSPlugin; | ||
import dev.latvian.mods.kubejs.recipe.schema.RegisterRecipeSchemasEvent; | ||
import dev.latvian.mods.kubejs.registry.RegistryInfo; | ||
import net.yxiao233.ifeu.common.compact.kubejs.item.EfficiencyAddonItemBuilder; | ||
import net.yxiao233.ifeu.common.compact.kubejs.item.ProcessingAddonItemBuilder; | ||
import net.yxiao233.ifeu.common.compact.kubejs.item.SpeedAddonItemBuilder; | ||
import net.yxiao233.ifeu.common.compact.kubejs.schema.InfuserSchema; | ||
|
||
public class ModKubeJSPlugin extends KubeJSPlugin { | ||
|
||
@Override | ||
public void init() { | ||
RegistryInfo.ITEM.addType("industrialforegoing:speed_addon", SpeedAddonItemBuilder.class, SpeedAddonItemBuilder::new); | ||
RegistryInfo.ITEM.addType("industrialforegoing:efficiency_addon", EfficiencyAddonItemBuilder.class, EfficiencyAddonItemBuilder::new); | ||
RegistryInfo.ITEM.addType("industrialforegoing:processing_addon", ProcessingAddonItemBuilder.class, ProcessingAddonItemBuilder::new); | ||
} | ||
|
||
@Override | ||
public void registerRecipeSchemas(RegisterRecipeSchemasEvent event) { | ||
event.namespace("ifeu") | ||
.register("infuser", InfuserSchema.SCHEMA); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/net/yxiao233/ifeu/common/compact/kubejs/item/EfficiencyAddonItemBuilder.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,34 @@ | ||
package net.yxiao233.ifeu.common.compact.kubejs.item; | ||
|
||
import dev.latvian.mods.kubejs.item.ItemBuilder; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.Item; | ||
import net.yxiao233.ifeu.common.item.ModEfficiencyAddonItem; | ||
import net.yxiao233.ifeu.common.registry.ModItems; | ||
|
||
public class EfficiencyAddonItemBuilder extends ItemBuilder { | ||
|
||
private int tier; | ||
private int formTier; | ||
|
||
public EfficiencyAddonItemBuilder(ResourceLocation i) { | ||
super(i); | ||
} | ||
|
||
public EfficiencyAddonItemBuilder setTier(int tier) { | ||
this.tier = tier; | ||
this.formTier = tier; | ||
return this; | ||
} | ||
|
||
public EfficiencyAddonItemBuilder setFormTier(int tier) { | ||
this.formTier = tier; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Item createObject() { | ||
int formTier = this.formTier == this.tier ? this.tier : this.formTier; | ||
return new ModEfficiencyAddonItem(formTier, tier, ModItems.TAB_ADDONS); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/net/yxiao233/ifeu/common/compact/kubejs/item/ProcessingAddonItemBuilder.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 net.yxiao233.ifeu.common.compact.kubejs.item; | ||
|
||
import dev.latvian.mods.kubejs.item.ItemBuilder; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.Item; | ||
import net.yxiao233.ifeu.common.item.ModProcessingAddonItem; | ||
import net.yxiao233.ifeu.common.registry.ModItems; | ||
|
||
public class ProcessingAddonItemBuilder extends ItemBuilder { | ||
private int tier; | ||
private int formTier; | ||
public ProcessingAddonItemBuilder(ResourceLocation i) { | ||
super(i); | ||
} | ||
|
||
public ProcessingAddonItemBuilder setTier(int tier){ | ||
this.tier = tier; | ||
this.formTier = tier; | ||
return this; | ||
} | ||
|
||
public ProcessingAddonItemBuilder setFormTier(int tier){ | ||
this.formTier = tier; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Item createObject() { | ||
int formTier = this.formTier == this.tier ? this.tier : this.formTier; | ||
return new ModProcessingAddonItem(formTier,tier, ModItems.TAB_ADDONS); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/net/yxiao233/ifeu/common/compact/kubejs/item/SpeedAddonItemBuilder.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 net.yxiao233.ifeu.common.compact.kubejs.item; | ||
|
||
import dev.latvian.mods.kubejs.item.ItemBuilder; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.Item; | ||
import net.yxiao233.ifeu.common.item.ModSpeedAddonItem; | ||
import net.yxiao233.ifeu.common.registry.ModItems; | ||
|
||
public class SpeedAddonItemBuilder extends ItemBuilder { | ||
private int tier; | ||
private int formTier; | ||
public SpeedAddonItemBuilder(ResourceLocation i) { | ||
super(i); | ||
} | ||
|
||
public SpeedAddonItemBuilder setTier(int tier){ | ||
this.tier = tier; | ||
this.formTier = tier; | ||
return this; | ||
} | ||
|
||
public SpeedAddonItemBuilder setFormTier(int tier){ | ||
this.formTier = tier; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Item createObject() { | ||
int formTier = this.formTier == this.tier ? this.tier : this.formTier; | ||
return new ModSpeedAddonItem(formTier,tier, ModItems.TAB_ADDONS); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/net/yxiao233/ifeu/common/compact/kubejs/schema/InfuserSchema.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,18 @@ | ||
package net.yxiao233.ifeu.common.compact.kubejs.schema; | ||
|
||
import dev.latvian.mods.kubejs.fluid.InputFluid; | ||
import dev.latvian.mods.kubejs.item.InputItem; | ||
import dev.latvian.mods.kubejs.item.OutputItem; | ||
import dev.latvian.mods.kubejs.recipe.RecipeKey; | ||
import dev.latvian.mods.kubejs.recipe.component.ItemComponents; | ||
import dev.latvian.mods.kubejs.recipe.component.TimeComponent; | ||
import dev.latvian.mods.kubejs.recipe.schema.RecipeSchema; | ||
import net.yxiao233.ifeu.common.compact.kubejs.IndustrialForegoingComponents; | ||
|
||
public interface InfuserSchema{ | ||
RecipeKey<OutputItem> OUTPUT = ItemComponents.OUTPUT.key("output"); | ||
RecipeKey<InputItem> INPUT = ItemComponents.INPUT.key("input"); | ||
RecipeKey<InputFluid> INPUT_FLUID = IndustrialForegoingComponents.INPUT_FLUID.key("inputFluid"); | ||
RecipeKey<Long> TIME = TimeComponent.TICKS.key("processingTime").optional(200L); | ||
RecipeSchema SCHEMA = new RecipeSchema(OUTPUT,INPUT,INPUT_FLUID,TIME); | ||
} |
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 @@ | ||
net.yxiao233.ifeu.common.compact.kubejs.ModKubeJSPlugin |