Skip to content

Commit

Permalink
First src commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Techlone committed Mar 9, 2017
1 parent 598e3c0 commit 138b60c
Show file tree
Hide file tree
Showing 41 changed files with 3,894 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.gradle/
.idea/
build/
gradle/
logs/
eclipse/
run/
out/
gradlew
gradlew.bat
71 changes: 71 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
buildscript {
repositories {
mavenCentral()
maven {
name = 'forge'
url = 'http://files.minecraftforge.net/maven'
}
maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}

apply plugin: 'java'
apply plugin: 'forge'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

version = '1.0.0'
group = 'recipenator'

configurations {
includeJar
}

minecraft {
version = '1.7.10-10.13.4.1614-1.7.10'
}

repositories {
maven {
name = "chickenbones"
url = "http://chickenbones.net/maven/"
}
}

dependencies {
compile group: 'org.luaj', name: 'luaj-jse', version: '3.0.1'
compile 'codechicken:NotEnoughItems:1.7.10-1.0.5.120:dev'

includeJar group: 'org.luaj', name: 'luaj-jse', version: '3.0.1'

testCompile group: 'junit', name: 'junit', version: '4.11'
}

jar {
from {
configurations.includeJar.collect { it.isDirectory() ? it : zipTree(it) }
}
}

processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version': project.version, 'mcversion': project.minecraft.version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
25 changes: 25 additions & 0 deletions src/main/java/recipenator/DefaultLuaLibGetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package recipenator;

import net.minecraft.item.Item;
import recipenator.api.ILuaLibGetter;
import recipenator.lualib.BaseLuaLib;
import recipenator.lualib.item.ItemLib;
import recipenator.lualib.oredict.OreDictLib;
import recipenator.lualib.recipe.RecipeLib;
import recipenator.utils.NamesTree;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class DefaultLuaLibGetter implements ILuaLibGetter {
@Override
public Set<BaseLuaLib> getLibs() {
Set<BaseLuaLib> libs = new HashSet<>();
Collection names = Item.itemRegistry.getKeys();
libs.add(new ItemLib(NamesTree.getTreeRoot(names)));
libs.add(new OreDictLib());
libs.add(new RecipeLib());
return libs;
}
}
95 changes: 95 additions & 0 deletions src/main/java/recipenator/RecipenatorMod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package recipenator;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandHandler;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.ServerConfigurationManager;
import net.minecraft.util.ChatComponentText;
import recipenator.api.ILuaLibGetter;
import recipenator.lualib.recipe.RecipeManager;
import recipenator.utils.lua.LuaExecutor;

import java.io.File;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Mod(modid = "", useMetadata = true)
public class RecipenatorMod {
public static final String SCRIPT_FOLDER_NAME = "recipes";
public static final ILuaLibGetter LUA_ENVIRONMENT = new DefaultLuaLibGetter();

public RecipenatorMod() { }

@EventHandler
public void beforeServerStart(FMLServerAboutToStartEvent event) {
((CommandHandler) event.getServer().getCommandManager()).registerCommand(new ICommand() {
@Override
public int compareTo(Object o) {
return 0;
}

@Override
public String getCommandName() {
return "recipenator";
}

@Override
public String getCommandUsage(ICommandSender commandSender) {
return "";
}

@Override
public List getCommandAliases() {
return Collections.singletonList("rn");
}

@Override
public void processCommand(ICommandSender commandSender, String[] arguments) {
if (arguments.length == 0) return;

if (arguments[0].equals("reload")) {
RecipeManager.removeAll();
ExecuteScripts();
}
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender commandSender) {
return true;
}

@Override
public List addTabCompletionOptions(ICommandSender commandSender, String[] arguments) {
return null;
}

@Override
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
return false;
}
});
ExecuteScripts();
}

public static void ExecuteScripts() {
new LuaExecutor(new File(SCRIPT_FOLDER_NAME), LUA_ENVIRONMENT).execute();
}

public static void logChat(String msg) {
MinecraftServer server = MinecraftServer.getServer();
assert server != null;

ServerConfigurationManager cm = server.getConfigurationManager();
assert cm != null;

ChatComponentText text = new ChatComponentText(msg);
cm.sendChatMsg(text);
}
}
9 changes: 9 additions & 0 deletions src/main/java/recipenator/api/ILuaLibGetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package recipenator.api;

import recipenator.lualib.BaseLuaLib;

import java.util.Set;

public interface ILuaLibGetter {
Set<BaseLuaLib> getLibs();
}
13 changes: 13 additions & 0 deletions src/main/java/recipenator/api/IRecipeComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package recipenator.api;

import net.minecraft.item.ItemStack;

public interface IRecipeComponent<T> {
Object mulCount(int multiplier);

Object withMeta(int meta);

boolean equals(ItemStack component);

T getRecipeItem();
}
12 changes: 12 additions & 0 deletions src/main/java/recipenator/api/annotation/Metamethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package recipenator.api.annotation;

import recipenator.utils.lua.MetamethodType;

import java.lang.annotation.*;

@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Metamethod {
MetamethodType value();
}
20 changes: 20 additions & 0 deletions src/main/java/recipenator/compatibility/nei/NEI_RNator_Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package recipenator.compatibility.nei;

import codechicken.nei.api.IConfigureNEI;

public class NEI_RNator_Config implements IConfigureNEI {
@Override
public void loadConfig() {
RecipeHandlers.registerRecipe();
}

@Override
public String getName() {
return "NEI Recipenator";
}

@Override
public String getVersion() {
return "1.0.0";
}
}
124 changes: 124 additions & 0 deletions src/main/java/recipenator/compatibility/nei/RecipeHandlers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package recipenator.compatibility.nei;

import codechicken.nei.NEIServerUtils;
import codechicken.nei.api.API;
import codechicken.nei.recipe.ShapedRecipeHandler;
import codechicken.nei.recipe.ShapelessRecipeHandler;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import recipenator.lualib.recipe.RecipeShaped;
import recipenator.lualib.recipe.RecipeShapeless;
import recipenator.utils.RecipeHelper;

import java.util.List;

public class RecipeHandlers {
public static void registerRecipe() {
API.registerRecipeHandler(new ShapedHandler());
API.registerUsageHandler(new ShapedHandler());
API.registerRecipeHandler(new ShapelessHandler());
API.registerUsageHandler(new ShapelessHandler());
}

public static class ShapelessHandler extends ShapelessRecipeHandler {
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("crafting") && getClass() == ShapelessHandler.class) {
List recipeList = CraftingManager.getInstance().getRecipeList();
for (Object recipe : recipeList) {
if (!(recipe instanceof RecipeShapeless)) continue;
CachedShapelessRecipe cache = toCachedRecipe((RecipeShapeless) recipe);
arecipes.add(cache);
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}

@Override
public void loadCraftingRecipes(ItemStack result) {
List recipeList = CraftingManager.getInstance().getRecipeList();
for (Object recipe : recipeList) {
if (!(recipe instanceof RecipeShapeless)) continue;

RecipeShapeless recipeShapeless = (RecipeShapeless) recipe;
if (!NEIServerUtils.areStacksSameTypeCrafting(recipeShapeless.getRecipeOutput(), result)) continue;

CachedShapelessRecipe cache = toCachedRecipe(recipeShapeless);
arecipes.add(cache);
}
}

@Override
public void loadUsageRecipes(ItemStack ingredient) {
List recipeList = CraftingManager.getInstance().getRecipeList();
for (Object recipe : recipeList) {
if (!(recipe instanceof RecipeShapeless)) continue;

CachedShapelessRecipe cache = toCachedRecipe((RecipeShapeless) recipe);
if (cache.contains(cache.ingredients, ingredient)) {
cache.setIngredientPermutation(cache.ingredients, ingredient);
this.arecipes.add(cache);
}
}
}

private CachedShapelessRecipe toCachedRecipe(RecipeShapeless recipe) {
return new CachedShapelessRecipe(recipe.getRecipeInputs(), recipe.getRecipeOutput());
}
}

public static class ShapedHandler extends ShapedRecipeHandler {
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("crafting") && getClass() == ShapedHandler.class) {
List recipeList = CraftingManager.getInstance().getRecipeList();
for (Object irecipe : recipeList) {
if (!(irecipe instanceof RecipeShaped)) continue;
CachedShapedRecipe recipe = toCachedRecipe((RecipeShaped) irecipe);
recipe.computeVisuals();
arecipes.add(recipe);
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}

@Override
public void loadCraftingRecipes(ItemStack result) {
List recipeList = CraftingManager.getInstance().getRecipeList();
for (Object recipe : recipeList) {
if (!(recipe instanceof RecipeShaped)) continue;

RecipeShaped recipeShaped = (RecipeShaped) recipe;
if (!NEIServerUtils.areStacksSameTypeCrafting(recipeShaped.getRecipeOutput(), result)) continue;

CachedShapedRecipe cache = toCachedRecipe(recipeShaped);
cache.computeVisuals();
arecipes.add(cache);
}
}

@Override
public void loadUsageRecipes(ItemStack ingredient) {
List recipeList = CraftingManager.getInstance().getRecipeList();
for (Object recipe : recipeList) {
if (!(recipe instanceof RecipeShaped)) continue;

CachedShapedRecipe cache = toCachedRecipe((RecipeShaped) recipe);
if (!cache.contains(cache.ingredients, ingredient.getItem())) continue;

cache.computeVisuals();
if (cache.contains(cache.ingredients, ingredient)) {
cache.setIngredientPermutation(cache.ingredients, ingredient);
this.arecipes.add(cache);
}
}
}

private CachedShapedRecipe toCachedRecipe(RecipeShaped recipe) {
RecipeHelper.Size size = recipe.getSize();
return new CachedShapedRecipe(size.width, size.height, recipe.getRecipeInputs(), recipe.getRecipeOutput());
}
}
}
Loading

0 comments on commit 138b60c

Please sign in to comment.