Skip to content

Commit

Permalink
Expand GRS support
Browse files Browse the repository at this point in the history
  • Loading branch information
yor42 committed Nov 18, 2024
1 parent 0030e13 commit 082f699
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public SlotCrystal(IInventory inv, int _slot, int x, int y) {
public boolean isItemValid(ItemStack stack) {
if(slot == 0) {
for (ImagFusorRecipes.IFRecipe obj : ImagFusorRecipes.INSTANCE.getAllRecipe()) {
if (obj.consumeType.getItem() == stack.getItem()) return true;
if (obj.consumeType.test(stack)) return true;
}
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/academy/block/container/SlotMFItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public SlotMFItem(IInventory inv, int _slot, int x, int y) {
public boolean isItemValid(ItemStack stack) {
if(slot == 0) {
for (MetalFormerRecipes.RecipeObject obj : MetalFormerRecipes.INSTANCE.getAllRecipes()) {
if (obj.input.getItem() == stack.getItem()) return true;
if (obj.input.test(stack)) return true;
}
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/academy/block/tileentity/TileImagFusor.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private void updateWork() {
// Also check whether the amount of Liquid is enough,
// and whether the output of currentRecipe can be outputed into outputslot
// Added by Shielian
if(inventory[0].isEmpty() || currentRecipe.consumeType.getItem() != inventory[0].getItem()
if(inventory[0].isEmpty() || !currentRecipe.matches(inventory[0])
|| this.pullEnergy(CONSUME_PER_TICK) != CONSUME_PER_TICK || this.getLiquidAmount() < currentRecipe.consumeLiquid
|| (!inventory[SLOT_OUTPUT].isEmpty() && inventory[SLOT_OUTPUT].getItem() != currentRecipe.output.getItem())
) {
Expand All @@ -223,7 +223,7 @@ private void endWorking() {
if(isWorking()) {
int drained = tank.drain(currentRecipe.consumeLiquid, true).amount;
if(!world.isRemote) {
inventory[0].shrink(currentRecipe.consumeType.getCount());
inventory[0].shrink(currentRecipe.getInputAmount());
if(inventory[0].getCount() <= 0)
inventory[0]=ItemStack.EMPTY;

Expand Down Expand Up @@ -251,7 +251,7 @@ public boolean isWorking() {

public boolean isActionBlocked() {
return !isWorking() ||
(inventory[0].getCount() < currentRecipe.consumeType.getCount()) ||
(inventory[0].getCount() < currentRecipe.getInputAmount()) ||
(!inventory[1].isEmpty() && (!StackUtils.isStackDataEqual(inventory[1], currentRecipe.output) ||
inventory[1].getCount() + currentRecipe.output.getCount() > inventory[1].getMaxStackSize())) ||
currentRecipe.consumeLiquid > this.getLiquidAmount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void update() {
if(workCounter == WORK_TICKS) { // Finish the job.
ItemStack inputSlot = this.getStackInSlot(SLOT_IN);
ItemStack outputSlot = this.getStackInSlot(SLOT_OUT);
inputSlot.shrink(current.input.getCount());
inputSlot.shrink(current.getCount());
if(inputSlot.getCount() == 0)
this.setInventorySlotContents(SLOT_IN, ItemStack.EMPTY);

Expand Down
29 changes: 18 additions & 11 deletions src/main/java/cn/academy/crafting/ImagFusorRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cn.lambdalib2.s11n.network.NetworkS11n.NetS11nAdaptor;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;

import javax.annotation.Nullable;
import java.util.ArrayList;
Expand All @@ -26,9 +27,9 @@ public IFRecipe addRecipe(ItemStack consume, int liquid, ItemStack output) {

public IFRecipe addRecipe(IFRecipe recipe) {
for(IFRecipe r : recipeList) {
if(r.matches(recipe.consumeType)) {
throw new RuntimeException("Can't register multiple recipes for same item " + recipe.consumeType.getItem() +
"(#" + recipe.consumeType.getItemDamage() + ")!!");

if(r.consumeType == recipe.consumeType) {
throw new RuntimeException("Can't register multiple recipes for same item " + recipe.consumeType.toString()+"!!");
}
}

Expand All @@ -37,10 +38,6 @@ public IFRecipe addRecipe(IFRecipe recipe) {
return recipe;
}

public void removeRecipe(IFRecipe recipe) {
recipeList.removeIf(r -> r.matches(recipe.consumeType));
}

@Nullable
public IFRecipe removeRecipebyInput(ItemStack input) {
for(IFRecipe r : recipeList) {
Expand All @@ -67,20 +64,30 @@ public List<IFRecipe> getAllRecipe() {
public static class IFRecipe {

int id;
public final ItemStack consumeType;
public final Ingredient consumeType;
public final int inputAmount;
public final int consumeLiquid;
public final ItemStack output;

public IFRecipe(ItemStack stack, int liq, ItemStack _output) {
public IFRecipe(Ingredient stack, int _inputAmount, int liq, ItemStack _output) {
consumeType = stack;
inputAmount = _inputAmount;
consumeLiquid = liq;
output = _output;
}

public IFRecipe(ItemStack stack, int liq, ItemStack _output) {
this(Ingredient.fromStacks(stack), stack.getCount(), liq, _output);
}

public boolean matches(ItemStack input) {
return consumeType.getItem() == input.getItem() && consumeType.getItemDamage() == input.getItemDamage();
return consumeType.test(input) && inputAmount<=input.getCount();
}


public int getInputAmount() {
return inputAmount;
}

public int getID() {
return id;
}
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/cn/academy/crafting/MetalFormerRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cn.lambdalib2.s11n.network.NetworkS11n.NetS11nAdaptor;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import javax.annotation.Nullable;
Expand All @@ -23,21 +24,30 @@ public static class RecipeObject {
private int id = -1;

public final Mode mode;
public final ItemStack input;
public final Ingredient input;
public final int count;
public final ItemStack output;

public RecipeObject(ItemStack _input, ItemStack _output, Mode _mode) {
public RecipeObject(Ingredient _input, int _count, ItemStack _output, Mode _mode) {
input = _input;
output = _output;
count = _count;
mode = _mode;
}

public RecipeObject(ItemStack _input, ItemStack _output, Mode _mode) {
this(Ingredient.fromStacks(_input), _input.getCount(), _output, _mode);
}

public boolean accepts(ItemStack stack, Mode mode2) {
return stack != null &&
mode == mode2 &&
input.getItem() == stack.getItem() &&
input.getCount() <= stack.getCount() &&
input.getItemDamage() == stack.getItemDamage();
input.test(stack) &&
count <= stack.getCount();
}

public int getCount() {
return count;
}

public void setId(int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import cn.academy.Main;
import cn.academy.crafting.ImagFusorRecipes;
import cn.academy.crafting.MetalFormerRecipes;
import cn.academy.support.groovyscript.AcademyCraftGroovyPlugin;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.Example;
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.StandardListRegistry;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.item.ItemStack;
Expand All @@ -24,14 +26,52 @@ public Collection<ImagFusorRecipes.IFRecipe> getRecipes() {

@MethodDescription(example = @Example("item('academy:crystal_normal'), item('academy:crystal_low'), 3000"), type = MethodDescription.Type.ADDITION)
public void addRecipe(ItemStack output, IIngredient input, int liquidAmount){
for(ItemStack stack:input.getMatchingStacks()) {
this.add(new ImagFusorRecipes.IFRecipe(stack, liquidAmount, output));
}
this.add(new ImagFusorRecipes.IFRecipe(input.toMcIngredient(), input.getAmount(), liquidAmount, output));
}

@MethodDescription(example = @Example("item('academy:crystal_normal')"))
public void removeByInput(ItemStack input) {
this.remove(ImagFusorRecipes.INSTANCE.getRecipe(input));
}

@RecipeBuilderDescription(example = {
@Example(".input(item('minecraft:clay')).output(item('minecraft:diamond')).fluid(1000)"),
@Example(".input(item('minecraft:clay')).output(item('minecraft:diamond')).fluid(3000)"),
@Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:clay') * 2)")
})
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

public static class RecipeBuilder extends AbstractRecipeBuilder<ImagFusorRecipes.IFRecipe> {

@Property(defaultValue = "1000", comp = @Comp(gt = 0))
private int fluidAmount = 1000;

@RecipeBuilderMethodDescription(field = "fluidAmount")
public RecipeBuilder fluid(int fluid) {
this.fluidAmount = fluid;
return this;
}

@Override
public String getErrorMsg() {
return "Error Adding AcademyCraft Metal Former Recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, 1, 1, 1);
msg.add(fluidAmount <= 0, "fluidAmount must be an integer greater than 0, yet it was {}", fluidAmount);
}

@RecipeBuilderRegistrationMethod
@Override
public ImagFusorRecipes.IFRecipe register() {
if (!validate()) return null;
ImagFusorRecipes.IFRecipe recipe = new ImagFusorRecipes.IFRecipe(input.get(0).toMcIngredient(), input.get(0).getAmount(), fluidAmount, output.get(0));
AcademyCraftGroovyPlugin.FUSOR.add(recipe);
return recipe;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import cn.academy.block.tileentity.TileMetalFormer;
import cn.academy.crafting.ImagFusorRecipes;
import cn.academy.crafting.MetalFormerRecipes;
import cn.academy.support.groovyscript.AcademyCraftGroovyPlugin;
import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.Example;
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.compat.mods.roots.Moss;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.StandardListRegistry;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.item.Item;
Expand All @@ -27,7 +29,7 @@ public void addEtchRecipe(IIngredient input, ItemStack output){
this.addRecipe(input, output, TileMetalFormer.Mode.ETCH);
}

@MethodDescription(example = @Example("block('minecraft:cobblestone'), item('minecraft:stone_slab', 3)"), type = MethodDescription.Type.ADDITION)
@MethodDescription(example = @Example("item('minecraft:cobblestone'), item('minecraft:stone_slab', 3)"), type = MethodDescription.Type.ADDITION)
public void addInciseRecipe(IIngredient input, ItemStack output){
this.addRecipe(input, output, TileMetalFormer.Mode.INCISE);
}
Expand Down Expand Up @@ -93,9 +95,7 @@ public void removeByMode(TileMetalFormer.Mode mode){
}

public void addRecipe(IIngredient input, ItemStack output, TileMetalFormer.Mode mode){
for(ItemStack stack:input.getMatchingStacks()) {
this.add(new MetalFormerRecipes.RecipeObject(stack, output, mode));
}
this.add(new MetalFormerRecipes.RecipeObject(input.toMcIngredient(), input.getAmount(), output, mode));
}

public void removeByInputAndMode(IIngredient input, TileMetalFormer.Mode mode) {
Expand All @@ -114,4 +114,72 @@ public boolean add(MetalFormerRecipes.RecipeObject recipe) {
public Collection<MetalFormerRecipes.RecipeObject> getRecipes() {
return MetalFormerRecipes.INSTANCE.getAllRecipes();
}

@RecipeBuilderDescription(example = {
@Example(".input(item('minecraft:clay')).output(item('minecraft:diamond')).refine()"),
@Example(".input(item('minecraft:clay')).output(item('minecraft:diamond')).incise()"),
@Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:clay') * 2)")
})
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

public static class RecipeBuilder extends AbstractRecipeBuilder<MetalFormerRecipes.RecipeObject>{

@Property(defaultValue = "ETCH", comp = @Comp(not = "null"))
private TileMetalFormer.Mode MODE = TileMetalFormer.Mode.ETCH;

@Override
public String getErrorMsg() {
return "Error Adding AcademyCraft Metal Former Recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, 1, 1, 1);
msg.add(MODE == null, "mode must not be null!");
}

@RecipeBuilderMethodDescription
public RecipeBuilder mode(TileMetalFormer.Mode mode){
this.MODE = mode;
return this;
}
@RecipeBuilderMethodDescription
public RecipeBuilder incise(){
this.MODE = TileMetalFormer.Mode.INCISE;
return this;
}
@RecipeBuilderMethodDescription
public RecipeBuilder plate(){
this.MODE = TileMetalFormer.Mode.PLATE;
return this;
}
@RecipeBuilderMethodDescription
public RecipeBuilder refine(){
this.MODE = TileMetalFormer.Mode.REFINE;
return this;
}
@RecipeBuilderMethodDescription
public RecipeBuilder etch(){
this.MODE = TileMetalFormer.Mode.ETCH;
return this;
}

@Override
protected int getMaxItemInput() {
return 1;
}

@Override
@RecipeBuilderRegistrationMethod
public MetalFormerRecipes.RecipeObject register() {
if(!validate()){
return null;
}
MetalFormerRecipes.RecipeObject object = new MetalFormerRecipes.RecipeObject(input.get(0).toMcIngredient(), input.get(0).getAmount(), output.get(0), this.MODE);
AcademyCraftGroovyPlugin.FORMER.add(object);
return object;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -54,7 +55,9 @@ private static List<IRecipeWrapper> loadCraftingRecipes() {
List<IRecipeWrapper> lists = new ArrayList<>();
for(IFRecipe r : ImagFusorRecipes.INSTANCE.getAllRecipe()) {
lists.add(iIngredients -> {
iIngredients.setInput(VanillaTypes.ITEM, r.consumeType);
List<List<ItemStack>> inputLists = new ArrayList<>();
inputLists.add(Arrays.asList(r.consumeType.matchingStacks));
iIngredients.setInputLists(VanillaTypes.ITEM, inputLists);
iIngredients.setOutput(VanillaTypes.ITEM, r.output);
//r.cost
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import mezz.jei.api.ingredients.VanillaTypes;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -56,7 +58,9 @@ private static List<IRecipeWrapper> loadCraftingRecipes() {
List<IRecipeWrapper> lists = new ArrayList<>();
for(RecipeObject r : MetalFormerRecipes.INSTANCE.getAllRecipes()) {
lists.add(iIngredients -> {
iIngredients.setInput(VanillaTypes.ITEM, r.input);
List<List<ItemStack>> inputLists = new ArrayList<>();
inputLists.add(Arrays.asList(r.input.matchingStacks));
iIngredients.setInputLists(VanillaTypes.ITEM, inputLists);
iIngredients.setOutput(VanillaTypes.ITEM, r.output);
//r.mode
});
Expand Down
Loading

0 comments on commit 082f699

Please sign in to comment.