Added Recipe System

This commit is contained in:
Timo Ley 2021-04-17 16:58:10 +02:00
parent 42def51478
commit 7e06505e84
4 changed files with 76 additions and 2 deletions

View file

@ -0,0 +1,36 @@
package ley.modding.dartcraft.internal;
import ley.modding.tileralib.api.IIngredient;
import net.minecraft.item.Item;
public class ItemIngredient implements IIngredient {
char key;
int count;
Item item;
public ItemIngredient(char key, Item item) {
this.key = key;
this.item = item;
}
public ItemIngredient(int count, Item item) {
this.count = count;
this.item = item;
}
@Override
public char getKey() {
return key;
}
@Override
public int getCount() {
return count;
}
@Override
public Object getIngredient() {
return item;
}
}

View file

@ -2,13 +2,14 @@ package ley.modding.dartcraft.internal;
import cpw.mods.fml.common.registry.GameRegistry;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.tileralib.api.IIngredient;
import ley.modding.tileralib.api.IRegistry;
import ley.modding.tileralib.api.ITEProvider;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
public class Registry implements IRegistry {
@ -41,6 +42,27 @@ public class Registry implements IRegistry {
return GameRegistry.findBlock(getModID(), id);
}
@Override
public void addShapedRecipe(ItemStack output, String[] pattern, IIngredient[] ingredients) {
List<Object> objects = new ArrayList<Object>(Arrays.asList(pattern));
for (IIngredient i : ingredients) {
objects.add(i.getKey());
objects.add(i.getIngredient());
}
GameRegistry.addShapedRecipe(output, objects.toArray());
}
@Override
public void addShapelessRecipe(ItemStack output, IIngredient[] input) {
List<Object> objects = new ArrayList<Object>();
for (IIngredient ing : input) {
for (int i = 0; i < ing.getCount(); i++) {
objects.add(ing.getIngredient());
}
}
GameRegistry.addShapelessRecipe(output, objects.toArray());
}
@Override
public Item registerItem(Item item) {
if (item != null) {

View file

@ -0,0 +1,11 @@
package ley.modding.tileralib.api;
public interface IIngredient {
char getKey();
int getCount();
Object getIngredient();
}

View file

@ -3,6 +3,7 @@ package ley.modding.tileralib.api;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public interface IRegistry {
@ -16,4 +17,8 @@ public interface IRegistry {
Block getBlock(String id);
void addShapedRecipe(ItemStack output, String[] pattern, IIngredient[] ingredients);
void addShapelessRecipe(ItemStack output, IIngredient[] input);
}