Skip to content

Commit

Permalink
Update marcin212's minetweaker integration to use the new API
Browse files Browse the repository at this point in the history
  • Loading branch information
bloxgate committed May 9, 2018
1 parent 6bddf31 commit 7b8ba92
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 94 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ repositories {
url = "http://default.mobiusstrip.eu/maven/"
}
ivy {
name = 'MineTweaker3'
artifactPattern = "http://minetweaker3.powerofbytes.com/download/[module]-[classifier]-[revision].[ext]"
name 'MineTweaker3'
artifactPattern "http://minetweaker3.powerofbytes.com/download/[module]-[classifier]-[revision].[ext]"
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/mods/eln/Eln.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import mods.eln.api.Utilities;
import mods.eln.api.recipe.Recipe;
import mods.eln.api.recipe.RecipesList;
import mods.eln.packets.*;
import mods.eln.cable.CableRenderDescriptor;
import mods.eln.client.ClientKeyHandler;
import mods.eln.client.SoundLoader;
Expand Down Expand Up @@ -149,7 +148,6 @@
import mods.eln.transparentnode.waterturbine.WaterTurbineDescriptor;
import mods.eln.transparentnode.windturbine.WindTurbineDescriptor;
import mods.eln.wiki.Data;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.command.ICommandManager;
Expand All @@ -170,7 +168,6 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.WorldServer;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
Expand Down Expand Up @@ -965,8 +962,8 @@ public void postInit(FMLPostInitializationEvent event) {
serverEventListener = new ServerEventListener();

if(Loader.isModLoaded("MineTweaker3")){
MinetweakerIntegration.instance.initialize();
}
MinetweakerIntegration.INSTANCE.initialize();
}
}

/*
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/mods/eln/api/Misc.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mods.eln.api;

import java.lang.reflect.Field;

/**
* Created by Gregory Maddra on 2016-11-16.
*/
Expand All @@ -9,7 +11,9 @@ public static Object getRecipeList(String list){
try {
Class<?> Eln = getEln();
Object instanceObject = getElnInstance(Eln);
return Eln != null ? Eln.getDeclaredField(list).get(instanceObject) : null;
Field recipeList = Eln.getDeclaredField(list);
recipeList.setAccessible(true);
return Eln != null ? recipeList.get(instanceObject) : null;
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/mods/eln/api/recipe/CompressorRecipeList.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package mods.eln.api.recipe;

import java.util.ArrayList;

import mods.eln.api.Misc;
import net.minecraft.item.ItemStack;

import java.util.ArrayList;

public class CompressorRecipeList implements IELNMachineRecipeList {
private static RecipesList recipes = (RecipesList) Misc.getRecipeList("compressorRecipes");

Expand Down Expand Up @@ -38,8 +38,13 @@ public void addRecipe(ItemStack input, ItemStack output, double energy){
Recipe recipe = new Recipe(input, output, energy);
recipes.addRecipe(recipe);
}

/**

public void addRecipe(Recipe recipe) {
//Maintain existing checks
addRecipe(recipe.input, recipe.output, recipe.energy);
}

/**
* Removes a recipe from the compressor
* @param input an ItemStack representing the input of the recipe
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/mods/eln/api/recipe/IELNMachineRecipeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface IELNMachineRecipeList {

void addRecipe(ItemStack input, ItemStack output, double energy) throws IllegalArgumentException;

void addRecipe(Recipe recipe);

void removeRecipe(ItemStack input);

void removeRecipeByOutput(ItemStack output);
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/mods/eln/api/recipe/MaceratorRecipeList.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package mods.eln.api.recipe;

import java.util.ArrayList;

import mods.eln.api.Misc;
import net.minecraft.item.ItemStack;

import java.util.ArrayList;

public class MaceratorRecipeList implements IELNMachineRecipeList {

private static RecipesList recipes = (RecipesList) Misc.getRecipeList("maceratorRecipes");
Expand Down Expand Up @@ -42,8 +42,13 @@ public void addRecipe(ItemStack input, ItemStack output, double energy) {
recipes.addRecipe(recipe);
System.out.println("Added recipe to macerator!");
}

/**

public void addRecipe(Recipe recipe) {
//Maintain existing checks
addRecipe(recipe.input, recipe.output, recipe.energy);
}

/**
* Removes a recipe from the macerator
* @param input an ItemStack representing the input of the recipe
*/
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/mods/eln/api/recipe/MagnetizerRecipeList.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package mods.eln.api.recipe;

import java.util.ArrayList;

import mods.eln.api.Misc;
import net.minecraft.item.ItemStack;

import java.util.ArrayList;

public class MagnetizerRecipeList implements IELNMachineRecipeList {
private static RecipesList recipes = (RecipesList) Misc.getRecipeList("magnetiserRecipes");
/**
private static RecipesList recipes = (RecipesList) Misc.getRecipeList("magnetizerRecipes");

/**
* Adds a new recipe to the magnetizer
* @param input an ItemStack representing the input of the recipe
* @param output an ItemStack[] representing the outputs of the recipe
Expand Down Expand Up @@ -38,7 +38,12 @@ public void addRecipe(ItemStack input, ItemStack output, double energy){
Recipe recipe = new Recipe(input, output, energy);
recipes.addRecipe(recipe);
}


public void addRecipe(Recipe recipe) {
//Maintain existing checks
addRecipe(recipe.input, recipe.output, recipe.energy);
}

/**
* Removes a recipe from the magnetizer
* @param input an ItemStack representing the input of the recipe
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/mods/eln/api/recipe/PlateMachineRecipeList.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package mods.eln.api.recipe;

import java.util.ArrayList;

import mods.eln.api.Misc;
import net.minecraft.item.ItemStack;

import java.util.ArrayList;

public class PlateMachineRecipeList implements IELNMachineRecipeList {
private static RecipesList recipes = (RecipesList) Misc.getRecipeList("plateMachineRecipes");

Expand Down Expand Up @@ -38,8 +38,13 @@ public void addRecipe(ItemStack input, ItemStack output, double energy){
Recipe recipe = new Recipe(input, output, energy);
recipes.addRecipe(recipe);
}

/**

public void addRecipe(Recipe recipe) {
//Maintain existing checks
addRecipe(recipe.input, recipe.output, recipe.energy);
}

/**
* Removes a recipe from the plate machine
* @param input an ItemStack representing the input of the recipe
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mods.eln.integration.minetweaker

import minetweaker.MineTweakerAPI
import mods.eln.integration.minetweaker.machines.Compressor
import mods.eln.integration.minetweaker.machines.Macerator
import mods.eln.integration.minetweaker.machines.Magnetizer
import mods.eln.integration.minetweaker.machines.PlateMachine

object MinetweakerIntegration {

fun initialize() {
MineTweakerAPI.registerClass(Macerator::class.java)
MineTweakerAPI.registerClass(Compressor::class.java)
MineTweakerAPI.registerClass(Magnetizer::class.java)
MineTweakerAPI.registerClass(PlateMachine::class.java)
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mods.eln.integration.minetweaker.utils;

import mods.eln.misc.Recipe;
import mods.eln.api.recipe.Recipe;

public class AddRecipe extends BasicUndoableAction {
Recipe recipe;
Expand All @@ -17,7 +17,7 @@ public void apply() {

@Override
public void undo() {
machine.recipes.getRecipes().remove(recipe);
}
machine.recipes.removeRecipe(recipe.input);
}

}
Original file line number Diff line number Diff line change
@@ -1,51 +1,38 @@
package mods.eln.integration.minetweaker.utils;

import java.util.ArrayList;

import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import minetweaker.api.minecraft.MineTweakerMC;
import mods.eln.Eln;
import mods.eln.misc.Recipe;
import mods.eln.misc.RecipesList;

import mods.eln.api.recipe.*;
import net.minecraft.item.ItemStack;

public class MinetweakerMachine {

public static MinetweakerMachine MACERATOR = new MinetweakerMachine(Eln.instance.maceratorRecipes, "Adding Macerator Recipe", "Removing Macerator Recipe");
public static MinetweakerMachine COMPRESSOR = new MinetweakerMachine(Eln.instance.compressorRecipes, "Adding Compressor Recipe", "Removing Compressor Recipe");
public static MinetweakerMachine MAGNETIZER = new MinetweakerMachine(Eln.instance.magnetiserRecipes, "Adding Magnetizer Recipe", "Removing Magnetizer Recipe");
public static MinetweakerMachine PLATEMACHINE = new MinetweakerMachine(Eln.instance.plateMachineRecipes, "Adding Plate Machine Recipe", "Removing Plate Machine Recipe");
public static MinetweakerMachine MACERATOR = new MinetweakerMachine(new MaceratorRecipeList(), "Adding Macerator Recipe", "Removing Macerator Recipe");
public static MinetweakerMachine COMPRESSOR = new MinetweakerMachine(new CompressorRecipeList(), "Adding Compressor Recipe", "Removing Compressor Recipe");
public static MinetweakerMachine MAGNETIZER = new MinetweakerMachine(new MagnetizerRecipeList(), "Adding Magnetizer Recipe", "Removing Magnetizer Recipe");
public static MinetweakerMachine PLATEMACHINE = new MinetweakerMachine(new PlateMachineRecipeList(), "Adding Plate Machine Recipe", "Removing Plate Machine Recipe");

public RecipesList recipes;
public String removeDesc;
public IELNMachineRecipeList recipes;
public String removeDesc;
public String addDesc;

public MinetweakerMachine(RecipesList recipes, String addDesc, String removeDesc) {
this.recipes = recipes;
this.addDesc = addDesc;
public MinetweakerMachine(IELNMachineRecipeList recipeList, String addDesc, String removeDesc) {
this.recipes = recipeList;
this.addDesc = addDesc;
this.removeDesc = removeDesc;
}

public void addRecipe(IIngredient input, double energy, IItemStack[] output)
{
if (input == null || output == null || energy < 0)
return;
if (output.length > 4) {
throw new IllegalArgumentException("Too much outputs");
}

ArrayList<ItemStack> outs = new ArrayList<ItemStack>();
for (IIngredient i : output) {
ItemStack stack = MineTweakerMC.getItemStack(i);
if (stack != null) {
outs.add(stack);
}
}

Recipe recipe = new Recipe(MineTweakerMC.getItemStack(input), outs.toArray(new ItemStack[] {}), energy);
ItemStack inStack = MineTweakerMC.getItemStack(input);
ItemStack[] outStacks = new ItemStack[output.length];
for (int i = 0; i < output.length; i++) {
outStacks[i] = MineTweakerMC.getItemStack(output[i]);
}

Recipe recipe = new Recipe(inStack, outStacks, energy);

MineTweakerAPI.apply(new AddRecipe(this, recipe));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package mods.eln.integration.minetweaker.utils;

import java.util.ArrayList;

import minetweaker.api.item.IIngredient;
import minetweaker.api.minecraft.MineTweakerMC;
import mods.eln.Eln;
import mods.eln.misc.Recipe;
import mods.eln.api.recipe.Recipe;

import java.util.ArrayList;


public class RemoveRecipe extends BasicUndoableAction{
Expand All @@ -15,22 +14,27 @@ public class RemoveRecipe extends BasicUndoableAction{
public RemoveRecipe(MinetweakerMachine machine, IIngredient input) {
super(machine);
this.input = input;
}
this.toRemove = new ArrayList<>();
}

@Override
public void apply() {
toRemove = new ArrayList<Recipe>();
for (Recipe r : Eln.instance.maceratorRecipes.getRecipes()){
if(input.matches(MineTweakerMC.getIItemStack(r.input))){
toRemove.add(r);
}
}
machine.recipes.getRecipes().removeAll(toRemove);
}
for (Recipe recipe : machine.recipes.getRecipes()) {
if (input.matches(MineTweakerMC.getIItemStack(recipe.input))) {
toRemove.add(recipe);
}
}
for (Recipe recipe : toRemove) {
machine.recipes.removeRecipe(recipe.input);
}
}

@Override
public void undo() {
machine.recipes.getRecipes().addAll(toRemove);
}
for (Recipe recipe : toRemove) {
machine.recipes.addRecipe(recipe);
}
toRemove = new ArrayList<>();
}

}

0 comments on commit 7b8ba92

Please sign in to comment.