Skip to content

Commit 138b60c

Browse files
committed
First src commit
1 parent 598e3c0 commit 138b60c

41 files changed

Lines changed: 3894 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.gradle/
2+
.idea/
3+
build/
4+
gradle/
5+
logs/
6+
eclipse/
7+
run/
8+
out/
9+
gradlew
10+
gradlew.bat

build.gradle

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
maven {
5+
name = 'forge'
6+
url = 'http://files.minecraftforge.net/maven'
7+
}
8+
maven {
9+
name = 'sonatype'
10+
url = 'https://oss.sonatype.org/content/repositories/snapshots/'
11+
}
12+
}
13+
dependencies {
14+
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
15+
}
16+
}
17+
18+
apply plugin: 'java'
19+
apply plugin: 'forge'
20+
21+
sourceCompatibility = '1.8'
22+
targetCompatibility = '1.8'
23+
24+
version = '1.0.0'
25+
group = 'recipenator'
26+
27+
configurations {
28+
includeJar
29+
}
30+
31+
minecraft {
32+
version = '1.7.10-10.13.4.1614-1.7.10'
33+
}
34+
35+
repositories {
36+
maven {
37+
name = "chickenbones"
38+
url = "http://chickenbones.net/maven/"
39+
}
40+
}
41+
42+
dependencies {
43+
compile group: 'org.luaj', name: 'luaj-jse', version: '3.0.1'
44+
compile 'codechicken:NotEnoughItems:1.7.10-1.0.5.120:dev'
45+
46+
includeJar group: 'org.luaj', name: 'luaj-jse', version: '3.0.1'
47+
48+
testCompile group: 'junit', name: 'junit', version: '4.11'
49+
}
50+
51+
jar {
52+
from {
53+
configurations.includeJar.collect { it.isDirectory() ? it : zipTree(it) }
54+
}
55+
}
56+
57+
processResources {
58+
// this will ensure that this task is redone when the versions change.
59+
inputs.property "version", project.version
60+
inputs.property "mcversion", project.minecraft.version
61+
// replace stuff in mcmod.info, nothing else
62+
from(sourceSets.main.resources.srcDirs) {
63+
include 'mcmod.info'
64+
// replace version and mcversion
65+
expand 'version': project.version, 'mcversion': project.minecraft.version
66+
}
67+
// copy everything else, thats not the mcmod.info
68+
from(sourceSets.main.resources.srcDirs) {
69+
exclude 'mcmod.info'
70+
}
71+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package recipenator;
2+
3+
import net.minecraft.item.Item;
4+
import recipenator.api.ILuaLibGetter;
5+
import recipenator.lualib.BaseLuaLib;
6+
import recipenator.lualib.item.ItemLib;
7+
import recipenator.lualib.oredict.OreDictLib;
8+
import recipenator.lualib.recipe.RecipeLib;
9+
import recipenator.utils.NamesTree;
10+
11+
import java.util.Collection;
12+
import java.util.HashSet;
13+
import java.util.Set;
14+
15+
public class DefaultLuaLibGetter implements ILuaLibGetter {
16+
@Override
17+
public Set<BaseLuaLib> getLibs() {
18+
Set<BaseLuaLib> libs = new HashSet<>();
19+
Collection names = Item.itemRegistry.getKeys();
20+
libs.add(new ItemLib(NamesTree.getTreeRoot(names)));
21+
libs.add(new OreDictLib());
22+
libs.add(new RecipeLib());
23+
return libs;
24+
}
25+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package recipenator;
2+
3+
import cpw.mods.fml.common.Mod;
4+
import cpw.mods.fml.common.Mod.EventHandler;
5+
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
6+
import net.minecraft.command.CommandBase;
7+
import net.minecraft.command.CommandHandler;
8+
import net.minecraft.command.ICommand;
9+
import net.minecraft.command.ICommandSender;
10+
import net.minecraft.server.MinecraftServer;
11+
import net.minecraft.server.management.ServerConfigurationManager;
12+
import net.minecraft.util.ChatComponentText;
13+
import recipenator.api.ILuaLibGetter;
14+
import recipenator.lualib.recipe.RecipeManager;
15+
import recipenator.utils.lua.LuaExecutor;
16+
17+
import java.io.File;
18+
import java.lang.reflect.Array;
19+
import java.util.Arrays;
20+
import java.util.Collections;
21+
import java.util.List;
22+
23+
@Mod(modid = "", useMetadata = true)
24+
public class RecipenatorMod {
25+
public static final String SCRIPT_FOLDER_NAME = "recipes";
26+
public static final ILuaLibGetter LUA_ENVIRONMENT = new DefaultLuaLibGetter();
27+
28+
public RecipenatorMod() { }
29+
30+
@EventHandler
31+
public void beforeServerStart(FMLServerAboutToStartEvent event) {
32+
((CommandHandler) event.getServer().getCommandManager()).registerCommand(new ICommand() {
33+
@Override
34+
public int compareTo(Object o) {
35+
return 0;
36+
}
37+
38+
@Override
39+
public String getCommandName() {
40+
return "recipenator";
41+
}
42+
43+
@Override
44+
public String getCommandUsage(ICommandSender commandSender) {
45+
return "";
46+
}
47+
48+
@Override
49+
public List getCommandAliases() {
50+
return Collections.singletonList("rn");
51+
}
52+
53+
@Override
54+
public void processCommand(ICommandSender commandSender, String[] arguments) {
55+
if (arguments.length == 0) return;
56+
57+
if (arguments[0].equals("reload")) {
58+
RecipeManager.removeAll();
59+
ExecuteScripts();
60+
}
61+
}
62+
63+
@Override
64+
public boolean canCommandSenderUseCommand(ICommandSender commandSender) {
65+
return true;
66+
}
67+
68+
@Override
69+
public List addTabCompletionOptions(ICommandSender commandSender, String[] arguments) {
70+
return null;
71+
}
72+
73+
@Override
74+
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
75+
return false;
76+
}
77+
});
78+
ExecuteScripts();
79+
}
80+
81+
public static void ExecuteScripts() {
82+
new LuaExecutor(new File(SCRIPT_FOLDER_NAME), LUA_ENVIRONMENT).execute();
83+
}
84+
85+
public static void logChat(String msg) {
86+
MinecraftServer server = MinecraftServer.getServer();
87+
assert server != null;
88+
89+
ServerConfigurationManager cm = server.getConfigurationManager();
90+
assert cm != null;
91+
92+
ChatComponentText text = new ChatComponentText(msg);
93+
cm.sendChatMsg(text);
94+
}
95+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package recipenator.api;
2+
3+
import recipenator.lualib.BaseLuaLib;
4+
5+
import java.util.Set;
6+
7+
public interface ILuaLibGetter {
8+
Set<BaseLuaLib> getLibs();
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package recipenator.api;
2+
3+
import net.minecraft.item.ItemStack;
4+
5+
public interface IRecipeComponent<T> {
6+
Object mulCount(int multiplier);
7+
8+
Object withMeta(int meta);
9+
10+
boolean equals(ItemStack component);
11+
12+
T getRecipeItem();
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package recipenator.api.annotation;
2+
3+
import recipenator.utils.lua.MetamethodType;
4+
5+
import java.lang.annotation.*;
6+
7+
@Inherited
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.METHOD)
10+
public @interface Metamethod {
11+
MetamethodType value();
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package recipenator.compatibility.nei;
2+
3+
import codechicken.nei.api.IConfigureNEI;
4+
5+
public class NEI_RNator_Config implements IConfigureNEI {
6+
@Override
7+
public void loadConfig() {
8+
RecipeHandlers.registerRecipe();
9+
}
10+
11+
@Override
12+
public String getName() {
13+
return "NEI Recipenator";
14+
}
15+
16+
@Override
17+
public String getVersion() {
18+
return "1.0.0";
19+
}
20+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package recipenator.compatibility.nei;
2+
3+
import codechicken.nei.NEIServerUtils;
4+
import codechicken.nei.api.API;
5+
import codechicken.nei.recipe.ShapedRecipeHandler;
6+
import codechicken.nei.recipe.ShapelessRecipeHandler;
7+
import net.minecraft.item.ItemStack;
8+
import net.minecraft.item.crafting.CraftingManager;
9+
import recipenator.lualib.recipe.RecipeShaped;
10+
import recipenator.lualib.recipe.RecipeShapeless;
11+
import recipenator.utils.RecipeHelper;
12+
13+
import java.util.List;
14+
15+
public class RecipeHandlers {
16+
public static void registerRecipe() {
17+
API.registerRecipeHandler(new ShapedHandler());
18+
API.registerUsageHandler(new ShapedHandler());
19+
API.registerRecipeHandler(new ShapelessHandler());
20+
API.registerUsageHandler(new ShapelessHandler());
21+
}
22+
23+
public static class ShapelessHandler extends ShapelessRecipeHandler {
24+
@Override
25+
public void loadCraftingRecipes(String outputId, Object... results) {
26+
if (outputId.equals("crafting") && getClass() == ShapelessHandler.class) {
27+
List recipeList = CraftingManager.getInstance().getRecipeList();
28+
for (Object recipe : recipeList) {
29+
if (!(recipe instanceof RecipeShapeless)) continue;
30+
CachedShapelessRecipe cache = toCachedRecipe((RecipeShapeless) recipe);
31+
arecipes.add(cache);
32+
}
33+
} else {
34+
super.loadCraftingRecipes(outputId, results);
35+
}
36+
}
37+
38+
@Override
39+
public void loadCraftingRecipes(ItemStack result) {
40+
List recipeList = CraftingManager.getInstance().getRecipeList();
41+
for (Object recipe : recipeList) {
42+
if (!(recipe instanceof RecipeShapeless)) continue;
43+
44+
RecipeShapeless recipeShapeless = (RecipeShapeless) recipe;
45+
if (!NEIServerUtils.areStacksSameTypeCrafting(recipeShapeless.getRecipeOutput(), result)) continue;
46+
47+
CachedShapelessRecipe cache = toCachedRecipe(recipeShapeless);
48+
arecipes.add(cache);
49+
}
50+
}
51+
52+
@Override
53+
public void loadUsageRecipes(ItemStack ingredient) {
54+
List recipeList = CraftingManager.getInstance().getRecipeList();
55+
for (Object recipe : recipeList) {
56+
if (!(recipe instanceof RecipeShapeless)) continue;
57+
58+
CachedShapelessRecipe cache = toCachedRecipe((RecipeShapeless) recipe);
59+
if (cache.contains(cache.ingredients, ingredient)) {
60+
cache.setIngredientPermutation(cache.ingredients, ingredient);
61+
this.arecipes.add(cache);
62+
}
63+
}
64+
}
65+
66+
private CachedShapelessRecipe toCachedRecipe(RecipeShapeless recipe) {
67+
return new CachedShapelessRecipe(recipe.getRecipeInputs(), recipe.getRecipeOutput());
68+
}
69+
}
70+
71+
public static class ShapedHandler extends ShapedRecipeHandler {
72+
@Override
73+
public void loadCraftingRecipes(String outputId, Object... results) {
74+
if (outputId.equals("crafting") && getClass() == ShapedHandler.class) {
75+
List recipeList = CraftingManager.getInstance().getRecipeList();
76+
for (Object irecipe : recipeList) {
77+
if (!(irecipe instanceof RecipeShaped)) continue;
78+
CachedShapedRecipe recipe = toCachedRecipe((RecipeShaped) irecipe);
79+
recipe.computeVisuals();
80+
arecipes.add(recipe);
81+
}
82+
} else {
83+
super.loadCraftingRecipes(outputId, results);
84+
}
85+
}
86+
87+
@Override
88+
public void loadCraftingRecipes(ItemStack result) {
89+
List recipeList = CraftingManager.getInstance().getRecipeList();
90+
for (Object recipe : recipeList) {
91+
if (!(recipe instanceof RecipeShaped)) continue;
92+
93+
RecipeShaped recipeShaped = (RecipeShaped) recipe;
94+
if (!NEIServerUtils.areStacksSameTypeCrafting(recipeShaped.getRecipeOutput(), result)) continue;
95+
96+
CachedShapedRecipe cache = toCachedRecipe(recipeShaped);
97+
cache.computeVisuals();
98+
arecipes.add(cache);
99+
}
100+
}
101+
102+
@Override
103+
public void loadUsageRecipes(ItemStack ingredient) {
104+
List recipeList = CraftingManager.getInstance().getRecipeList();
105+
for (Object recipe : recipeList) {
106+
if (!(recipe instanceof RecipeShaped)) continue;
107+
108+
CachedShapedRecipe cache = toCachedRecipe((RecipeShaped) recipe);
109+
if (!cache.contains(cache.ingredients, ingredient.getItem())) continue;
110+
111+
cache.computeVisuals();
112+
if (cache.contains(cache.ingredients, ingredient)) {
113+
cache.setIngredientPermutation(cache.ingredients, ingredient);
114+
this.arecipes.add(cache);
115+
}
116+
}
117+
}
118+
119+
private CachedShapedRecipe toCachedRecipe(RecipeShaped recipe) {
120+
RecipeHelper.Size size = recipe.getSize();
121+
return new CachedShapedRecipe(size.width, size.height, recipe.getRecipeInputs(), recipe.getRecipeOutput());
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)