mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 20:42:16 +00:00
readded the old mods
This commit is contained in:
1 parent
d915201429
commit
627053fa06
63 files changed
+7265
-51
No files matched your search
Binary file not shown.
Binary file not shown.
+185
@@ -0,0 +1,185 @@
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.buildcraft;
|
||||
|
||||
import buildcraft.api.recipes.BuildcraftRecipes;
|
||||
import buildcraft.core.recipes.AssemblyRecipeManager;
|
||||
import buildcraft.core.recipes.AssemblyRecipeManager.AssemblyRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.buildcraft.AssemblyTable")
|
||||
@ModOnly(value="BuildCraft|Core", version="6.0")
|
||||
public class AssemblyTable {
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack output, double energy, IIngredient[] ingredients) {
|
||||
MineTweakerAPI.apply(new AddRecipeAction(output, energy, ingredients));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void remove(IIngredient output) {
|
||||
removeRecipe(output, null, false);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient output, @Optional IIngredient[] ingredients, @Optional boolean wildcard) {
|
||||
List<AssemblyRecipe> toRemove = new ArrayList<AssemblyRecipe>();
|
||||
|
||||
outer: for (AssemblyRecipe recipe : ((AssemblyRecipeManager) BuildcraftRecipes.assemblyTable).getRecipes()) {
|
||||
if (output.matches(MineTweakerMC.getIItemStack(recipe.getOutput()))
|
||||
&& ingredientsMatch(recipe, ingredients, wildcard)) {
|
||||
toRemove.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
for (AssemblyRecipe recipe : toRemove) {
|
||||
MineTweakerAPI.apply(new RemoveRecipeAction(recipe));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if ingredients from the recipe match with the given ingredients.
|
||||
*
|
||||
* @param recipe recipe to check
|
||||
* @param ingredients required ingredients
|
||||
* @param wildcard true if there can be more ingredients in the recipe than given, false otherwise
|
||||
* @return matching result
|
||||
*/
|
||||
private static boolean ingredientsMatch(AssemblyRecipe recipe, IIngredient[] ingredients, boolean wildcard) {
|
||||
if (ingredients == null)
|
||||
return true;
|
||||
|
||||
int matchedIngredients = 0;
|
||||
boolean[] matched = new boolean[ingredients.length];
|
||||
checkIngredient: for (int i = 0; i < recipe.getInputs().length; i++) {
|
||||
Object ingredientObject = recipe.getInputs()[i];
|
||||
if (ingredientObject instanceof Number)
|
||||
continue;
|
||||
|
||||
IIngredient recipeIngredient = MineTweakerMC.getIIngredient(recipe.getInputs()[i]);
|
||||
|
||||
for (int j = 0; j < ingredients.length; j++) {
|
||||
if (!matched[j] && ingredients[j].contains(recipeIngredient)) {
|
||||
matched[j] = true;
|
||||
matchedIngredients++;
|
||||
continue checkIngredient;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wildcard)
|
||||
return false;
|
||||
}
|
||||
|
||||
return matchedIngredients == ingredients.length;
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddRecipeAction implements IUndoableAction {
|
||||
private final IItemStack output;
|
||||
private final AssemblyRecipe recipe;
|
||||
|
||||
public AddRecipeAction(IItemStack output, double energy, IIngredient[] ingredients) {
|
||||
this.output = output;
|
||||
|
||||
Object[] mcIngredients = new Object[ingredients.length];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
mcIngredients[i] = ingredients[i].getInternal();
|
||||
if (mcIngredients[i] == null) {
|
||||
throw new IllegalArgumentException("Not a valid assembly table ingredient");
|
||||
}
|
||||
}
|
||||
|
||||
recipe = new AssemblyRecipe(MineTweakerMC.getItemStack(output), energy, mcIngredients);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
((AssemblyRecipeManager) BuildcraftRecipes.assemblyTable).getRecipes().add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
BuildcraftRecipes.assemblyTable.getRecipes().remove(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding assembly table recipe for " + output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing assembly table recipe for " + output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveRecipeAction implements IUndoableAction {
|
||||
private final AssemblyRecipe recipe;
|
||||
|
||||
public RemoveRecipeAction(AssemblyRecipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
BuildcraftRecipes.assemblyTable.getRecipes().remove(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
((AssemblyRecipeManager) BuildcraftRecipes.assemblyTable).getRecipes().add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing assembly table recipe for " + MineTweakerMC.getIItemStack(recipe.getOutput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring assembly table recipe for " + MineTweakerMC.getIItemStack(recipe.getOutput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+375
@@ -0,0 +1,375 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.buildcraft;
|
||||
|
||||
import buildcraft.api.core.StackKey;
|
||||
import buildcraft.api.fuels.IronEngineCoolant;
|
||||
import buildcraft.api.fuels.IronEngineFuel;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.buildcraft.Fuels")
|
||||
@ModOnly(value="BuildCraft|Core", version="6.0")
|
||||
public class Fuels {
|
||||
private static final Constructor CONSTRUCT_FUEL;
|
||||
|
||||
static {
|
||||
Constructor newFuel = null;
|
||||
try {
|
||||
newFuel = IronEngineFuel.Fuel.class.getDeclaredConstructor(Fluid.class, float.class, int.class);
|
||||
newFuel.setAccessible(true);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
MineTweakerAPI.logError("Could not load combustion engine fuel constructor", ex);
|
||||
} catch (SecurityException ex) {
|
||||
MineTweakerAPI.logError("Could not load combustion engine fuel constructor", ex);
|
||||
}
|
||||
|
||||
CONSTRUCT_FUEL = newFuel;
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addCombustionEngineFuel(ILiquidStack fuel, double powerPerCycle, int totalBurningTime) {
|
||||
MineTweakerAPI.apply(new AddFuelAction(fuel, powerPerCycle, totalBurningTime));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeCombustionEngineFuel(ILiquidStack fuel) {
|
||||
Fluid fluid = MineTweakerMC.getLiquidStack(fuel).getFluid();
|
||||
if (IronEngineFuel.fuels.containsKey(fluid.getName())) {
|
||||
MineTweakerAPI.apply(new RemoveFuelAction(fluid.getName(), IronEngineFuel.fuels.get(fluid.getName())));
|
||||
} else {
|
||||
MineTweakerAPI.logWarning("No such iron engine fuel: " + fluid.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addCombustionEngineCoolant(ILiquidStack coolant, float coolingPerMB) {
|
||||
MineTweakerAPI.apply(new AddLiquidCoolantAction(coolant.getName(), new MTCoolant(coolingPerMB)));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addCoolantItem(IItemStack coolantItem, ILiquidStack coolantLiquid) {
|
||||
MineTweakerAPI.apply(new AddCoolantItemAction(new StackKey(MineTweakerMC.getItemStack(coolantItem)), MineTweakerMC.getLiquidStack(coolantLiquid)));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeCombustionEngineCoolant(ILiquidStack coolant) {
|
||||
FluidStack fluid = MineTweakerMC.getLiquidStack(coolant);
|
||||
|
||||
if (IronEngineCoolant.isCoolant(fluid.getFluid())) {
|
||||
MineTweakerAPI.apply(new RemoveLiquidCoolantAction(fluid.getFluid().getName(), IronEngineCoolant.getCoolant(fluid)));
|
||||
} else {
|
||||
MineTweakerAPI.logWarning("No such iron engine coolant: " + fluid.getFluid().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeCoolantItem(IIngredient item) {
|
||||
int numRemoved = 0;
|
||||
for (IItemStack itemStack : item.getItems()) {
|
||||
StackKey key = new StackKey(MineTweakerMC.getItemStack(itemStack));
|
||||
if (IronEngineCoolant.solidCoolants.containsKey(key)) {
|
||||
MineTweakerAPI.apply(new RemoveCoolantItemAction(key, IronEngineCoolant.solidCoolants.get(key)));
|
||||
numRemoved++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numRemoved == 0) {
|
||||
MineTweakerAPI.logWarning("No such iron engine coolant: " + item);
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddFuelAction implements IUndoableAction {
|
||||
private final String fuelName;
|
||||
private final IronEngineFuel.Fuel fuel;
|
||||
|
||||
public AddFuelAction(ILiquidStack fuel, double powerPerCycle, int totalBurningTime) {
|
||||
fuelName = fuel.getName();
|
||||
IronEngineFuel.Fuel ieFuel = null;
|
||||
try {
|
||||
if (CONSTRUCT_FUEL == null)
|
||||
System.out.println("No constructor for fuel");
|
||||
|
||||
ieFuel = (IronEngineFuel.Fuel) CONSTRUCT_FUEL.newInstance(MineTweakerMC.getLiquidStack(fuel).getFluid(), (float) powerPerCycle, totalBurningTime);
|
||||
} catch (InstantiationException ex) {
|
||||
Logger.getLogger(Fuels.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
Logger.getLogger(Fuels.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Logger.getLogger(Fuels.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
Logger.getLogger(Fuels.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
this.fuel = ieFuel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
IronEngineFuel.fuels.put(fuelName, fuel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
IronEngineFuel.fuels.remove(fuelName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding iron engine fuel " + fuelName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing iron engine fuel " + fuelName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveFuelAction implements IUndoableAction {
|
||||
private final String fuelName;
|
||||
private final IronEngineFuel.Fuel fuel;
|
||||
|
||||
public RemoveFuelAction(String fuelName, IronEngineFuel.Fuel fuel) {
|
||||
this.fuelName = fuelName;
|
||||
this.fuel = fuel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
IronEngineFuel.fuels.remove(fuelName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
IronEngineFuel.fuels.put(fuelName, fuel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing iron engine fuel " + fuelName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring iron engine fuel " + fuelName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddLiquidCoolantAction implements IUndoableAction {
|
||||
private final String liquid;
|
||||
private final IronEngineCoolant.Coolant coolant;
|
||||
|
||||
public AddLiquidCoolantAction(String liquid, IronEngineCoolant.Coolant coolant) {
|
||||
this.liquid = liquid;
|
||||
this.coolant = coolant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
IronEngineCoolant.liquidCoolants.put(liquid, coolant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
IronEngineCoolant.liquidCoolants.remove(liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding iron engine coolant " + liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing iron engine coolant " + liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddCoolantItemAction implements IUndoableAction {
|
||||
private final StackKey item;
|
||||
private final FluidStack liquid;
|
||||
|
||||
public AddCoolantItemAction(StackKey item, FluidStack liquid) {
|
||||
this.item = item;
|
||||
this.liquid = liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
IronEngineCoolant.solidCoolants.put(item, liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
IronEngineCoolant.solidCoolants.remove(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding iron engine coolant item " + MineTweakerMC.getIItemStack(item.stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing iron engine coolant item " + MineTweakerMC.getIItemStack(item.stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveLiquidCoolantAction implements IUndoableAction {
|
||||
private final String liquid;
|
||||
private final IronEngineCoolant.Coolant coolant;
|
||||
|
||||
public RemoveLiquidCoolantAction(String liquid, IronEngineCoolant.Coolant coolant) {
|
||||
this.liquid = liquid;
|
||||
this.coolant = coolant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
IronEngineCoolant.liquidCoolants.remove(liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
IronEngineCoolant.liquidCoolants.put(liquid, coolant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing iron engine coolant " + liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring iron engine coolant " + liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveCoolantItemAction implements IUndoableAction {
|
||||
private final StackKey item;
|
||||
private final FluidStack liquid;
|
||||
|
||||
public RemoveCoolantItemAction(StackKey item, FluidStack liquid) {
|
||||
this.item = item;
|
||||
this.liquid = liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
IronEngineCoolant.solidCoolants.remove(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
IronEngineCoolant.solidCoolants.put(item, liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing iron engine coolant item " + item.stack.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring iron engine coolant item " + item.stack.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MTCoolant implements IronEngineCoolant.Coolant {
|
||||
private final float coolingPerMB;
|
||||
|
||||
public MTCoolant(float coolingPerMB) {
|
||||
this.coolingPerMB = coolingPerMB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDegreesCoolingPerMB(float f) {
|
||||
return coolingPerMB;
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.buildcraft;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IIntegrationRecipeFunction {
|
||||
public IItemStack recipe(IItemStack output, IItemStack inputA, IItemStack inputB);
|
||||
}
|
||||
+217
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.buildcraft;
|
||||
|
||||
import buildcraft.api.recipes.BuildcraftRecipes;
|
||||
import buildcraft.api.recipes.IIntegrationRecipeManager.IIntegrationRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.buildcraft.IntegrationTable")
|
||||
@ModOnly(value="BuildCraft|Core", version="6.0")
|
||||
public class IntegrationTable {
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack output, double energy, IIngredient inputA, IIngredient inputB, @Optional IIntegrationRecipeFunction function) {
|
||||
MineTweakerAPI.apply(new AddRecipeAction(output, energy, inputA, inputB, function));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void remove(IIngredient output) {
|
||||
removeRecipe(output, null, null);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient output, @Optional IIngredient inputA, @Optional IIngredient inputB) {
|
||||
List<IIntegrationRecipe> toRemove = new ArrayList<IIntegrationRecipe>();
|
||||
|
||||
outer: for (IIntegrationRecipe recipe : BuildcraftRecipes.integrationTable.getRecipes()) {
|
||||
for (ItemStack component : recipe.getComponents()) {
|
||||
if (!output.matches(MineTweakerMC.getIItemStack(component)))
|
||||
continue outer;
|
||||
|
||||
if (inputA != null) {
|
||||
for (ItemStack example1 : recipe.getExampleInputsA()) {
|
||||
if (!inputA.matches(MineTweakerMC.getIItemStack(example1))) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inputB != null) {
|
||||
for (ItemStack example2 : recipe.getExampleInputsB()) {
|
||||
if (!inputB.matches(MineTweakerMC.getIItemStack(example2))) {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toRemove.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
for (IIntegrationRecipe recipe : toRemove) {
|
||||
MineTweakerAPI.apply(new RemoveRecipeAction(recipe));
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action Classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddRecipeAction implements IUndoableAction {
|
||||
private final MTIntegrationRecipe recipe;
|
||||
|
||||
public AddRecipeAction(IItemStack output, double energy, IIngredient inputA, IIngredient inputB, IIntegrationRecipeFunction function) {
|
||||
recipe = new MTIntegrationRecipe(output, energy, inputA, inputB, function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
BuildcraftRecipes.integrationTable.addRecipe(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
BuildcraftRecipes.integrationTable.getRecipes().remove(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding integration table recipe for " + recipe.output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing integration table recipe for " + recipe.output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveRecipeAction implements IUndoableAction {
|
||||
private final IIntegrationRecipe recipe;
|
||||
|
||||
public RemoveRecipeAction(IIntegrationRecipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
BuildcraftRecipes.integrationTable.getRecipes().remove(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
BuildcraftRecipes.integrationTable.addRecipe(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing integration table recipe for " + MineTweakerMC.getIItemStack(recipe.getComponents()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring integration table recipe for " + MineTweakerMC.getIItemStack(recipe.getComponents()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MTIntegrationRecipe implements IIntegrationRecipe {
|
||||
private final IItemStack output;
|
||||
private final ItemStack[] components;
|
||||
private final double energy;
|
||||
private final IIngredient inputA;
|
||||
private final ItemStack[] inputAExamples;
|
||||
private final IIngredient inputB;
|
||||
private final ItemStack[] inputBExamples;
|
||||
private final IIntegrationRecipeFunction function;
|
||||
|
||||
private MTIntegrationRecipe(IItemStack output, double energy, IIngredient inputA, IIngredient inputB, IIntegrationRecipeFunction function) {
|
||||
this.output = output;
|
||||
this.components = new ItemStack[] { MineTweakerMC.getItemStack(output) };
|
||||
this.energy = energy;
|
||||
this.inputA = inputA;
|
||||
this.inputAExamples = MineTweakerMC.getExamples(inputA);
|
||||
this.inputB = inputB;
|
||||
this.inputBExamples = MineTweakerMC.getExamples(inputB);
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEnergyCost() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidInputA(ItemStack is) {
|
||||
return inputA.matches(MineTweakerMC.getIItemStack(is));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidInputB(ItemStack is) {
|
||||
return inputB.matches(MineTweakerMC.getIItemStack(is));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutputForInputs(ItemStack is, ItemStack is1, ItemStack[] iss) {
|
||||
if (function != null) {
|
||||
IItemStack actualInputA = MineTweakerMC.getIItemStack(is);
|
||||
IItemStack actualInputB = MineTweakerMC.getIItemStack(is1);
|
||||
return MineTweakerMC.getItemStack(function.recipe(output, actualInputA, actualInputB));
|
||||
} else {
|
||||
return MineTweakerMC.getItemStack(output);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getExampleInputsA() {
|
||||
return inputAExamples;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getExampleInputsB() {
|
||||
return inputBExamples;
|
||||
}
|
||||
}
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.buildcraft;
|
||||
|
||||
import buildcraft.api.recipes.BuildcraftRecipes;
|
||||
import buildcraft.core.recipes.RefineryRecipeManager;
|
||||
import buildcraft.core.recipes.RefineryRecipeManager.RefineryRecipe;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.buildcraft.Refinery")
|
||||
@ModOnly(value="BuildCraft|Core", version="6.0")
|
||||
public class Refinery {
|
||||
private static final Constructor CONSTRUCT_REFINERYRECIPE;
|
||||
private static final Field REFINERYRECIPEMANAGER_RECIPES;
|
||||
|
||||
static {
|
||||
Constructor constructor = null;
|
||||
try {
|
||||
constructor = RefineryRecipe.class.getDeclaredConstructor(FluidStack.class, FluidStack.class, FluidStack.class, int.class, int.class);
|
||||
constructor.setAccessible(true);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
Logger.getLogger(Refinery.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (SecurityException ex) {
|
||||
Logger.getLogger(Refinery.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
Field recipes = null;
|
||||
try {
|
||||
recipes = RefineryRecipeManager.class.getDeclaredField("recipes");
|
||||
recipes.setAccessible(true);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
Logger.getLogger(Refinery.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (SecurityException ex) {
|
||||
Logger.getLogger(Refinery.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
CONSTRUCT_REFINERYRECIPE = constructor;
|
||||
REFINERYRECIPEMANAGER_RECIPES = recipes;
|
||||
}
|
||||
|
||||
|
||||
@ZenMethod
|
||||
public static void addRecipe(ILiquidStack output, int energyPerMB, int ticksPerMB, ILiquidStack input1, @Optional ILiquidStack input2) {
|
||||
MineTweakerAPI.apply(new AddRecipeAction(output, energyPerMB, ticksPerMB, input1, input2));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void remove(ILiquidStack output) {
|
||||
Fluid fluid = MineTweakerMC.getLiquidStack(output).getFluid();
|
||||
|
||||
List<RefineryRecipe> toRemove = new ArrayList<RefineryRecipe>();
|
||||
for (RefineryRecipe recipe : ((RefineryRecipeManager) BuildcraftRecipes.refinery).getRecipes()) {
|
||||
if (recipe.getResult().getFluid() == fluid) {
|
||||
toRemove.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
for (RefineryRecipe recipe : toRemove) {
|
||||
MineTweakerAPI.apply(new RemoveRecipeAction(recipe));
|
||||
}
|
||||
}
|
||||
|
||||
private static SortedSet<RefineryRecipe> getRecipes() {
|
||||
try {
|
||||
return (SortedSet<RefineryRecipe>) REFINERYRECIPEMANAGER_RECIPES.get((RefineryRecipeManager) BuildcraftRecipes.refinery);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Logger.getLogger(Refinery.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
Logger.getLogger(Refinery.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
throw new RuntimeException("Refinery recipes unavailable");
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action Classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddRecipeAction implements IUndoableAction {
|
||||
private final ILiquidStack output;
|
||||
private final RefineryRecipe recipe;
|
||||
|
||||
public AddRecipeAction(ILiquidStack output, int energyPerMB, int ticksPerMB, ILiquidStack input1, ILiquidStack input2) {
|
||||
this.output = output;
|
||||
|
||||
RefineryRecipe rrecipe = null;
|
||||
try {
|
||||
rrecipe = (RefineryRecipe) CONSTRUCT_REFINERYRECIPE.newInstance(
|
||||
MineTweakerMC.getLiquidStack(input1),
|
||||
MineTweakerMC.getLiquidStack(input2),
|
||||
MineTweakerMC.getLiquidStack(output),
|
||||
energyPerMB,
|
||||
ticksPerMB);
|
||||
} catch (InstantiationException ex) {
|
||||
Logger.getLogger(Refinery.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
Logger.getLogger(Refinery.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Logger.getLogger(Refinery.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
Logger.getLogger(Refinery.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
recipe = rrecipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
getRecipes().add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
getRecipes().add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding refinery recipe for " + output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing refinery recipe for " + output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveRecipeAction implements IUndoableAction {
|
||||
private final RefineryRecipe recipe;
|
||||
|
||||
public RemoveRecipeAction(RefineryRecipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
getRecipes().remove(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
getRecipes().add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing refinery recipe for "
|
||||
+ recipe.getResult().getFluid().getLocalizedName(recipe.getResult());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring refinery recipe for "
|
||||
+ recipe.getResult().getFluid().getLocalizedName(recipe.getResult());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
+138
@@ -0,0 +1,138 @@
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.buildcraft61;
|
||||
|
||||
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
|
||||
import buildcraft.api.recipes.IFlexibleRecipe;
|
||||
import buildcraft.core.recipes.FlexibleRecipe;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.buildcraft.AssemblyTable")
|
||||
@ModOnly(value="BuildCraft|Core", version="6.1")
|
||||
public class AssemblyTable {
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack output, double energy, IIngredient[] ingredients) {
|
||||
MineTweakerAPI.apply(new AddRecipeAction(output, energy, ingredients));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void remove(IIngredient output) {
|
||||
removeRecipe(output, null, false);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient output, @Optional IIngredient[] ingredients, @Optional boolean wildcard) {
|
||||
List<IFlexibleRecipe<ItemStack>> toRemove = BuildcraftRecipes.removeRecipes(
|
||||
output,
|
||||
ingredients,
|
||||
BuildcraftRecipeRegistry.assemblyTable.getRecipes());
|
||||
|
||||
for (IFlexibleRecipe<ItemStack> recipe : toRemove) {
|
||||
ItemStack recipeOutput = recipe instanceof FlexibleRecipe ? (ItemStack)(((FlexibleRecipe) recipe).output) : null;
|
||||
MineTweakerAPI.apply(new RemoveRecipeAction(recipe, recipeOutput));
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddRecipeAction implements IUndoableAction {
|
||||
private final IItemStack output;
|
||||
private final IFlexibleRecipe<ItemStack> recipe;
|
||||
|
||||
public AddRecipeAction(IItemStack output, double energy, IIngredient[] ingredients) {
|
||||
this.output = output;
|
||||
this.recipe = new MTFlexibleRecipe(output, ingredients, (int) energy, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
BuildcraftRecipeRegistry.assemblyTable.addRecipe(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
BuildcraftRecipeRegistry.assemblyTable.removeRecipe(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding assembly table recipe for " + output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing assembly table recipe for " + output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveRecipeAction implements IUndoableAction {
|
||||
private final IFlexibleRecipe<ItemStack> recipe;
|
||||
private final ItemStack output;
|
||||
|
||||
public RemoveRecipeAction(IFlexibleRecipe<ItemStack> recipe, ItemStack output) {
|
||||
this.recipe = recipe;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
BuildcraftRecipeRegistry.assemblyTable.removeRecipe(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
BuildcraftRecipeRegistry.assemblyTable.addRecipe(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing assembly table recipe for " + MineTweakerMC.getIItemStack(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring assembly table recipe for " + MineTweakerMC.getIItemStack(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package minetweaker.mods.buildcraft61;
|
||||
|
||||
import buildcraft.api.recipes.IFlexibleRecipe;
|
||||
import buildcraft.core.recipes.FlexibleRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IngredientAny;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class BuildcraftRecipes
|
||||
{
|
||||
private BuildcraftRecipes() {}
|
||||
|
||||
public static List<IFlexibleRecipe<ItemStack>> removeRecipes(IIngredient output, IIngredient[] inputs, Collection<? extends IFlexibleRecipe<ItemStack>> recipes)
|
||||
{
|
||||
if (output == IngredientAny.INSTANCE && (inputs == null || inputs.length == 0))
|
||||
return new ArrayList<IFlexibleRecipe<ItemStack>>(recipes);
|
||||
|
||||
List<IFlexibleRecipe<ItemStack>> results = new ArrayList<IFlexibleRecipe<ItemStack>>();
|
||||
for (IFlexibleRecipe<ItemStack> recipe : recipes) {
|
||||
if (recipe instanceof FlexibleRecipe && matches(output, inputs, (FlexibleRecipe) recipe))
|
||||
results.add(recipe);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private static boolean matches(IIngredient output, IIngredient[] inputs, FlexibleRecipe<ItemStack> recipe)
|
||||
{
|
||||
ItemStack recipeOutput = (ItemStack) recipe.getOutput();
|
||||
if (!output.matches(MineTweakerMC.getIItemStack(recipeOutput)))
|
||||
return false;
|
||||
|
||||
if (inputs == null || inputs.length == 0)
|
||||
return true;
|
||||
|
||||
boolean[] matches = new boolean[inputs.length];
|
||||
outer: for (Object recipeInputObject : recipe.getInputs())
|
||||
{
|
||||
IIngredient recipeIngredient = MineTweakerMC.getIIngredient(recipeInputObject);
|
||||
for (int i = 0; i < inputs.length; i++) {
|
||||
if (!matches[i] && inputs[i].contains(recipeIngredient))
|
||||
{
|
||||
matches[i] = true;
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.buildcraft61;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IIntegrationRecipeFunction {
|
||||
public IItemStack recipe(IItemStack output, IItemStack inputA, IItemStack inputB);
|
||||
}
|
||||
+237
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.buildcraft61;
|
||||
|
||||
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
|
||||
import buildcraft.api.recipes.CraftingResult;
|
||||
import buildcraft.api.recipes.IFlexibleCrafter;
|
||||
import buildcraft.api.recipes.IIntegrationRecipe;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.buildcraft.IntegrationTable")
|
||||
@ModOnly(value="BuildCraft|Core", version="6.1")
|
||||
public class IntegrationTable {
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack output, double energy, IIngredient inputA, IIngredient inputB, @Optional IIntegrationRecipeFunction function) {
|
||||
MineTweakerAPI.apply(new AddRecipeAction(output, energy, inputA, inputB, function));
|
||||
}
|
||||
|
||||
/*@ZenMethod
|
||||
public static void remove(IIngredient output) {
|
||||
removeRecipe(output, null, null);
|
||||
}*/
|
||||
|
||||
/*@ZenMethod
|
||||
public static void removeRecipe(IIngredient output, @Optional IIngredient inputA, @Optional IIngredient inputB) {
|
||||
IIngredient[] ingredients = null;
|
||||
if (inputA != null && inputB != null) {
|
||||
ingredients = new IIngredient[] { inputA, inputB };
|
||||
} else if (inputA != null) {
|
||||
ingredients = new IIngredient[] { inputA };
|
||||
} else if (inputB != null) {
|
||||
ingredients = new IIngredient[] { inputB };
|
||||
}
|
||||
|
||||
List<? extends IIntegrationRecipe> recipes = BuildcraftRecipeRegistry.integrationTable.getRecipes();
|
||||
List<IFlexibleRecipe<ItemStack>> toRemove = BuildcraftRecipes.removeRecipes(output, ingredients, recipes);
|
||||
|
||||
for (IFlexibleRecipe<ItemStack> recipe : toRemove) {
|
||||
MineTweakerAPI.apply(new RemoveRecipeAction(recipe));
|
||||
}
|
||||
}*/
|
||||
|
||||
// ######################
|
||||
// ### Action Classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddRecipeAction implements IUndoableAction {
|
||||
private final MTIntegrationRecipe recipe;
|
||||
|
||||
public AddRecipeAction(IItemStack output, double energy, IIngredient inputA, IIngredient inputB, IIntegrationRecipeFunction function) {
|
||||
recipe = new MTIntegrationRecipe(output, energy, inputA, inputB, function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
BuildcraftRecipeRegistry.integrationTable.addRecipe(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
BuildcraftRecipeRegistry.integrationTable.getRecipes().remove(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding integration table recipe for " + recipe.output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing integration table recipe for " + recipe.output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/*
|
||||
private static class RemoveRecipeAction implements IUndoableAction {
|
||||
private final IFlexibleRecipe<ItemStack> recipe;
|
||||
|
||||
public RemoveRecipeAction(IFlexibleRecipe<ItemStack> recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
BuildcraftRecipeRegistry.integrationTable.getRecipes().remove(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
BuildcraftRecipeRegistry.integrationTable.getRecipes().add((IIntegrationRecipe) recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing integration table recipe for " + MineTweakerMC.getIItemStack(recipe.getComponents()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring integration table recipe for " + MineTweakerMC.getIItemStack(recipe.getComponents()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
|
||||
private static class MTIntegrationRecipe implements IIntegrationRecipe {
|
||||
private static int idCounter = 0;
|
||||
|
||||
private final String id;
|
||||
private final IItemStack output;
|
||||
private final ItemStack[] components;
|
||||
private final double energy;
|
||||
private final IIngredient inputA;
|
||||
private final ItemStack[] inputAExamples;
|
||||
private final IIngredient inputB;
|
||||
private final ItemStack[] inputBExamples;
|
||||
private final IIntegrationRecipeFunction function;
|
||||
|
||||
private MTIntegrationRecipe(IItemStack output, double energy, IIngredient inputA, IIngredient inputB, IIntegrationRecipeFunction function) {
|
||||
this.id = "mtIntegration" + (idCounter++);
|
||||
this.output = output;
|
||||
this.components = new ItemStack[] { MineTweakerMC.getItemStack(output) };
|
||||
this.energy = energy;
|
||||
this.inputA = inputA;
|
||||
this.inputAExamples = MineTweakerMC.getExamples(inputA);
|
||||
this.inputB = inputB;
|
||||
this.inputBExamples = MineTweakerMC.getExamples(inputB);
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidInputA(ItemStack is) {
|
||||
return inputA.matches(MineTweakerMC.getIItemStack(is));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidInputB(ItemStack is) {
|
||||
return inputB.matches(MineTweakerMC.getIItemStack(is));
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public ItemStack getOutputForInputs(ItemStack is, ItemStack is1, ItemStack[] iss) {
|
||||
if (function != null) {
|
||||
IItemStack actualInputA = MineTweakerMC.getIItemStack(is);
|
||||
IItemStack actualInputB = MineTweakerMC.getIItemStack(is1);
|
||||
return MineTweakerMC.getItemStack(function.recipe(output, actualInputA, actualInputB));
|
||||
} else {
|
||||
return MineTweakerMC.getItemStack(output);
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public boolean canBeCrafted(IFlexibleCrafter ifc)
|
||||
{
|
||||
return inputA.matches(MineTweakerMC.getIItemStack(ifc.getCraftingItemStack(0)))
|
||||
&& (inputB == null || inputB.matches(MineTweakerMC.getIItemStack(ifc.getCraftingItemStack(1))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftingResult<ItemStack> craft(IFlexibleCrafter ifc, boolean bln)
|
||||
{
|
||||
if (!canBeCrafted(ifc))
|
||||
return null;
|
||||
|
||||
CraftingResult<ItemStack> result = new CraftingResult<ItemStack>();
|
||||
result.crafted = MineTweakerMC.getItemStack(output);
|
||||
|
||||
ItemStack consumedA = new ItemStack(ifc.getCraftingItemStack(0).getItem(), inputA.getAmount(), ifc.getCraftingItemStack(0).getItemDamage());
|
||||
consumedA.setTagCompound(ifc.getCraftingItemStack(0).stackTagCompound);
|
||||
result.usedItems.add(consumedA);
|
||||
|
||||
if (inputB != null) {
|
||||
ItemStack consumedB = new ItemStack(ifc.getCraftingItemStack(1).getItem(), inputB.getAmount(), ifc.getCraftingItemStack(0).getItemDamage());
|
||||
consumedB.setTagCompound(ifc.getCraftingItemStack(1).stackTagCompound);
|
||||
result.usedItems.add(consumedB);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftingResult<ItemStack> canCraft(ItemStack is)
|
||||
{
|
||||
if (inputB != null)
|
||||
return null;
|
||||
|
||||
if (!inputA.matches(MineTweakerMC.getIItemStack(is)))
|
||||
return null;
|
||||
|
||||
CraftingResult<ItemStack> result = new CraftingResult<ItemStack>();
|
||||
result.crafted = MineTweakerMC.getItemStack(output);
|
||||
ItemStack consumed = new ItemStack(is.getItem(), inputA.getAmount(), is.getItemDamage());
|
||||
consumed.setTagCompound(is.stackTagCompound);
|
||||
result.usedItems.add(consumed);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package minetweaker.mods.buildcraft61;
|
||||
|
||||
import buildcraft.api.recipes.CraftingResult;
|
||||
import buildcraft.api.recipes.IFlexibleCrafter;
|
||||
import buildcraft.api.recipes.IFlexibleRecipe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import minetweaker.mc1710.liquid.MCLiquidStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MTFlexibleRecipe implements IFlexibleRecipe<ItemStack>
|
||||
{
|
||||
private static int idCounter = 0;
|
||||
|
||||
private final String id;
|
||||
private final IItemStack output;
|
||||
private final IIngredient[] inputs;
|
||||
private final int energyCost;
|
||||
private final long craftingTime;
|
||||
|
||||
public MTFlexibleRecipe(IItemStack output, IIngredient[] inputs, int energyCost, long craftingTime)
|
||||
{
|
||||
if (inputs.length == 0)
|
||||
throw new IllegalArgumentException("recipe must have at least 1 input");
|
||||
|
||||
this.id = "minetweaker" + (idCounter++);
|
||||
this.output = output;
|
||||
this.inputs = inputs;
|
||||
this.energyCost = energyCost;
|
||||
this.craftingTime = craftingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeCrafted(IFlexibleCrafter ifc)
|
||||
{
|
||||
List<IItemStack> items = new ArrayList<IItemStack>();
|
||||
for (int i = 0; i < ifc.getCraftingItemStackSize(); i++) {
|
||||
if (ifc.getCraftingItemStack(i) != null)
|
||||
items.add(MineTweakerMC.getIItemStack(ifc.getCraftingItemStack(i)));
|
||||
}
|
||||
|
||||
List<ILiquidStack> liquids = new ArrayList<ILiquidStack>();
|
||||
for (int i = 0; i < ifc.getCraftingFluidStackSize(); i++) {
|
||||
if (ifc.getCraftingFluidStack(i) != null)
|
||||
liquids.add(new MCLiquidStack(ifc.getCraftingFluidStack(i)));
|
||||
}
|
||||
|
||||
outer: for (IIngredient ingredient : inputs) {
|
||||
for (IItemStack item : items) {
|
||||
if (ingredient.matches(item))
|
||||
continue outer;
|
||||
}
|
||||
|
||||
for (ILiquidStack liquid : liquids) {
|
||||
if (ingredient.matches(liquid))
|
||||
continue outer;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftingResult<ItemStack> craft(IFlexibleCrafter ifc, boolean preview)
|
||||
{
|
||||
CraftingResult<ItemStack> result = new CraftingResult<ItemStack>();
|
||||
|
||||
List<IItemStack> items = new ArrayList<IItemStack>();
|
||||
for (int i = 0; i < ifc.getCraftingItemStackSize(); i++) {
|
||||
if (ifc.getCraftingItemStack(i) != null)
|
||||
items.add(MineTweakerMC.getIItemStack(ifc.getCraftingItemStack(i)));
|
||||
}
|
||||
|
||||
List<ILiquidStack> liquids = new ArrayList<ILiquidStack>();
|
||||
for (int i = 0; i < ifc.getCraftingFluidStackSize(); i++) {
|
||||
if (ifc.getCraftingFluidStack(i) != null)
|
||||
liquids.add(new MCLiquidStack(ifc.getCraftingFluidStack(i)));
|
||||
}
|
||||
|
||||
result.energyCost = energyCost;
|
||||
result.craftingTime = craftingTime;
|
||||
|
||||
outer: for (IIngredient ingredient : inputs) {
|
||||
for (IItemStack item : items) {
|
||||
if (ingredient.matches(item)) {
|
||||
result.usedItems.add(MineTweakerMC.getItemStack(item.withAmount(ingredient.getAmount())));
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
|
||||
for (ILiquidStack liquid : liquids) {
|
||||
if (ingredient.matches(liquid)) {
|
||||
result.usedFluids.add(MineTweakerMC.getLiquidStack(liquid.withAmount(ingredient.getAmount())));
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftingResult<ItemStack> canCraft(ItemStack is)
|
||||
{
|
||||
if (!output.matches(MineTweakerMC.getIItemStack(is)))
|
||||
return null;
|
||||
|
||||
/*if (inputs.length > 1)
|
||||
return null;
|
||||
|
||||
if (!inputs[0].matches(MineTweakerMC.getIItemStack(is)))
|
||||
return null;*/
|
||||
|
||||
CraftingResult<ItemStack> result = new CraftingResult<ItemStack>();
|
||||
result.crafted = MineTweakerMC.getItemStack(output);
|
||||
ItemStack consumed = new ItemStack(is.getItem(), inputs[0].getAmount(), is.getItemDamage());
|
||||
consumed.setTagCompound(is.stackTagCompound);
|
||||
result.usedItems.add(consumed);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
+103
@@ -0,0 +1,103 @@
|
||||
package minetweaker.mods.ic2;
|
||||
|
||||
import ic2.api.item.IC2Items;
|
||||
import java.util.List;
|
||||
import minetweaker.IBracketHandler;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.BracketHandler;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.ZenTokener;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.expression.ExpressionInt;
|
||||
import stanhebben.zenscript.expression.ExpressionCallStatic;
|
||||
import stanhebben.zenscript.expression.ExpressionString;
|
||||
import stanhebben.zenscript.expression.partial.IPartialExpression;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.symbols.IZenSymbol;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.natives.IJavaMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
* Makes a ic2-item specific item syntax available in the form <item-ic2:name[:meta]>.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@BracketHandler
|
||||
@ModOnly("IC2")
|
||||
public class IC2BracketHandler implements IBracketHandler {
|
||||
public static IItemStack getItem(String name, int meta) {
|
||||
ItemStack stack = IC2Items.getItem(name);
|
||||
stack.setItemDamage(meta);
|
||||
return getIItemStack(stack);
|
||||
}
|
||||
|
||||
private final IJavaMethod method;
|
||||
|
||||
public IC2BracketHandler() {
|
||||
method = MineTweakerAPI.getJavaMethod(IC2BracketHandler.class, "getItem", String.class, int.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> tokens) {
|
||||
if (tokens.size() >= 5) {
|
||||
if (tokens.get(0).getValue().equals("ic2")
|
||||
&& tokens.get(1).getValue().equals("-")
|
||||
&& tokens.get(2).getValue().equals("item")
|
||||
&& tokens.get(3).getValue().equals(":")) {
|
||||
String name = tokens.get(4).getValue();
|
||||
int meta = 0;
|
||||
if (tokens.size() > 6 && tokens.get(5).getValue().equals(":")) {
|
||||
if (tokens.get(6).getType() == ZenTokener.T_INTVALUE) {
|
||||
meta = Integer.parseInt(tokens.get(6).getValue());
|
||||
} else if (tokens.get(6).getValue().equals("*")) {
|
||||
meta = OreDictionary.WILDCARD_VALUE;
|
||||
} else {
|
||||
MineTweakerAPI.logError("Not a valid meta value: " + tokens.get(6).getValue());
|
||||
}
|
||||
}
|
||||
ItemStack item = IC2Items.getItem(name);
|
||||
if (item == null) {
|
||||
MineTweakerAPI.logError("Not a valid IC2 item: " + name);
|
||||
return null;
|
||||
} else {
|
||||
return new ItemReferenceSymbol(environment, name, meta);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Private inner classes ###
|
||||
// #############################
|
||||
|
||||
private class ItemReferenceSymbol implements IZenSymbol {
|
||||
private final IEnvironmentGlobal environment;
|
||||
private final String name;
|
||||
private final int meta;
|
||||
|
||||
public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta) {
|
||||
this.environment = environment;
|
||||
this.name = name;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartialExpression instance(ZenPosition position) {
|
||||
return new ExpressionCallStatic(
|
||||
position,
|
||||
environment,
|
||||
method,
|
||||
new ExpressionString(position, name),
|
||||
new ExpressionInt(position, meta, ZenType.INT));
|
||||
}
|
||||
}
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
package minetweaker.mods.ic2;
|
||||
|
||||
import ic2.api.tile.ExplosionWhitelist;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Manages the explosion whitelist in IC2. Blocks on this whitelist will not resist
|
||||
* an explosion but won't be destroyed.
|
||||
*
|
||||
* The explosion code by default ignores blocks which absorb more than 1000 explosion power to
|
||||
* prevent abusing personal safes, Trade-O-Mats and other blocks to serve as a cheap and
|
||||
* invulnerable reactor chambers. Said blocks will not shield the explosion and won't get
|
||||
* destroyed.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.ExplosionWhitelist")
|
||||
@ModOnly("IC2")
|
||||
public class IC2ExplosionWhitelist {
|
||||
/**
|
||||
* Adds a block to the explosion whitelist.
|
||||
*
|
||||
* @param item item to add
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void add(IItemStack item) {
|
||||
ItemStack iStack = getItemStack(item);
|
||||
Block block = Block.getBlockFromItem(iStack.getItem());
|
||||
if (block == null) {
|
||||
MineTweakerAPI.logError("This item is not a block");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new AddAction(block));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a block from the explosion whitelist.
|
||||
*
|
||||
* @param item item to remove
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void remove(IItemStack item) {
|
||||
ItemStack iStack = getItemStack(item);
|
||||
Block block = Block.getBlockFromItem(iStack.getItem());
|
||||
if (block == null) {
|
||||
MineTweakerAPI.logError("This item is not a block");
|
||||
} else {
|
||||
if (ExplosionWhitelist.isBlockWhitelisted(block)) {
|
||||
MineTweakerAPI.logWarning("This block is not in the whitelist");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new RemoveAction(block));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given item is already whitelisted.
|
||||
*
|
||||
* @param item item to check
|
||||
* @return true if whitelisted
|
||||
*/
|
||||
@ZenMethod
|
||||
public static boolean isWhitelisted(IItemStack item) {
|
||||
ItemStack iStack = getItemStack(item);
|
||||
Block block = Block.getBlockFromItem(iStack.getItem());
|
||||
if (block == null) {
|
||||
MineTweakerAPI.logWarning("This item is not a block");
|
||||
return false;
|
||||
} else {
|
||||
return ExplosionWhitelist.isBlockWhitelisted(block);
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddAction implements IUndoableAction {
|
||||
private final Block block;
|
||||
|
||||
public AddAction(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
ExplosionWhitelist.addWhitelistedBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
ExplosionWhitelist.removeWhitelistedBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding block to IC2 explosion whitelist: " + block.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing block from IC2 explosion whitelist: " + block.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveAction implements IUndoableAction {
|
||||
private final Block block;
|
||||
|
||||
public RemoveAction(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
ExplosionWhitelist.removeWhitelistedBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
ExplosionWhitelist.addWhitelistedBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing block from IC2 explosion whitelist: " + block.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Adding block to IC2 explosion whitelist: " + block.getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2;
|
||||
|
||||
import ic2.api.recipe.IRecipeInput;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Wrapper class for ITweakerItemStackPatterns to IC2 recipe inputs.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class IC2RecipeInput implements IRecipeInput {
|
||||
private final IIngredient ingredient;
|
||||
|
||||
public IC2RecipeInput(IIngredient ingredient) {
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack subject) {
|
||||
return ingredient.matches(getIItemStack(subject));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return ingredient.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getInputs() {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
for (IItemStack item : ingredient.getItems()) {
|
||||
items.add(getItemStack(item));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 89 * hash + (this.ingredient != null ? this.ingredient.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final IC2RecipeInput other = (IC2RecipeInput) obj;
|
||||
if (this.ingredient != other.ingredient && (this.ingredient == null || !this.ingredient.equals(other.ingredient))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
package minetweaker.mods.ic2;
|
||||
|
||||
import ic2.api.recipe.IMachineRecipeManager;
|
||||
import ic2.api.recipe.IMachineRecipeManagerExt;
|
||||
import java.util.Arrays;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.OneWayAction;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MachineAddRecipeAction extends OneWayAction {
|
||||
private final String name;
|
||||
private final IMachineRecipeManager machine;
|
||||
private final ItemStack[] output;
|
||||
private final IC2RecipeInput input;
|
||||
private final NBTTagCompound tag;
|
||||
|
||||
public MachineAddRecipeAction(String name, IMachineRecipeManager machine, ItemStack[] output, NBTTagCompound tag, IC2RecipeInput input) {
|
||||
this.name = name;
|
||||
this.machine = machine;
|
||||
this.output = output;
|
||||
this.input = input;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
try {
|
||||
if (machine instanceof IMachineRecipeManagerExt) {
|
||||
((IMachineRecipeManagerExt) machine).addRecipe(input, tag, true, output);
|
||||
} else {
|
||||
machine.addRecipe(input, tag, output);
|
||||
}
|
||||
} catch (RuntimeException ex) {
|
||||
MineTweakerAPI.logError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
if (output.length == 1) {
|
||||
return "Adding " + name + " recipe for " + output[0].getDisplayName();
|
||||
} else {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("Adding ").append(name).append(" recipe for ");
|
||||
result.append("[");
|
||||
for (int i = 0; i < output.length; i++) {
|
||||
if (i == 0) {
|
||||
result.append(", ");
|
||||
} else {
|
||||
result.append(output[i].getDisplayName());
|
||||
}
|
||||
}
|
||||
result.append("]");
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
|
||||
hash = 47 * hash + (this.machine != null ? this.machine.hashCode() : 0);
|
||||
hash = 47 * hash + Arrays.deepHashCode(this.output);
|
||||
hash = 47 * hash + (this.input != null ? this.input.hashCode() : 0);
|
||||
hash = 47 * hash + (this.tag != null ? this.tag.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final MachineAddRecipeAction other = (MachineAddRecipeAction) obj;
|
||||
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
if (this.machine != other.machine && (this.machine == null || !this.machine.equals(other.machine))) {
|
||||
return false;
|
||||
}
|
||||
if (!Arrays.deepEquals(this.output, other.output)) {
|
||||
return false;
|
||||
}
|
||||
if (this.input != other.input && (this.input == null || !this.input.equals(other.input))) {
|
||||
return false;
|
||||
}
|
||||
if (this.tag != other.tag && (this.tag == null || !this.tag.equals(other.tag))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package minetweaker.mods.ic2.crops;
|
||||
|
||||
import ic2.api.crops.CropCard;
|
||||
import stanhebben.zenscript.annotations.ZenCaster;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Read-only data accessor for crops
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
@ZenClass("mods.ic2.Crop")
|
||||
public class Crop {
|
||||
private CropCard cc;
|
||||
|
||||
@ZenGetter("name")
|
||||
public String name() {
|
||||
return cc.name();
|
||||
}
|
||||
|
||||
@ZenGetter("owner")
|
||||
public String owner() {
|
||||
return cc.owner();
|
||||
}
|
||||
|
||||
@ZenGetter("displayName")
|
||||
public String displayName() {
|
||||
return cc.displayName();
|
||||
}
|
||||
|
||||
@ZenGetter("hashCode")
|
||||
public int hashCode() {
|
||||
return cc.hashCode();
|
||||
}
|
||||
|
||||
@ZenGetter("discoveredBy")
|
||||
public String discoveredBy() {
|
||||
return cc.discoveredBy();
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public String desc(int i) {
|
||||
return cc.desc(i);
|
||||
}
|
||||
|
||||
@ZenGetter("tier")
|
||||
public int tier() {
|
||||
return cc.tier();
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public int stat(int n) {
|
||||
return cc.stat(n);
|
||||
}
|
||||
|
||||
@ZenGetter("attributes")
|
||||
public String[] attributes() {
|
||||
return cc.attributes();
|
||||
}
|
||||
|
||||
@ZenGetter("maxSize")
|
||||
public int maxSize() {
|
||||
return cc.maxSize();
|
||||
}
|
||||
|
||||
@ZenGetter("dropGainChance")
|
||||
public float dropGainChance() {
|
||||
return cc.dropGainChance();
|
||||
}
|
||||
|
||||
@ZenCaster
|
||||
public String toString() {
|
||||
return cc.toString();
|
||||
}
|
||||
|
||||
public Crop(CropCard cc) {
|
||||
super();
|
||||
this.cc = cc;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+262
@@ -0,0 +1,262 @@
|
||||
package minetweaker.mods.ic2.crops;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import ic2.api.crops.CropCard;
|
||||
import ic2.api.crops.Crops;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.OneWayAction;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import stanhebben.zenscript.annotations.ZenCaster;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
/**
|
||||
* Provides access to IC2 crop system in general
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
@ZenClass("mods.ic2.CropsConfig")
|
||||
@ModOnly("IC2")
|
||||
public class CropsConfig {
|
||||
/**
|
||||
* Action to add a new seed for a base crop
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
private static final class RegisterBaseSeedAction extends OneWayAction {
|
||||
private IItemStack seed;
|
||||
private CropCard c;
|
||||
private int sz;
|
||||
private int growth;
|
||||
private int gain;
|
||||
private int resist;
|
||||
|
||||
public RegisterBaseSeedAction(IItemStack seed, CropCard c, int sz, int growth, int gain, int resist) {
|
||||
this.seed = seed;
|
||||
this.c = c;
|
||||
this.sz = sz;
|
||||
this.growth = growth;
|
||||
this.gain = gain;
|
||||
this.resist = resist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Registering base seed for crop " + c.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Crops.instance.registerBaseSeed(MineTweakerMC.getItemStack(seed), c, sz, growth, gain, resist);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action to register a new crop
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
private static final class RegisterCropCardAction extends OneWayAction {
|
||||
private CropCard c;
|
||||
|
||||
public RegisterCropCardAction(CropCard c) {
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
// TODO Auto-generated method stub
|
||||
return "Registering crop " + c.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Crops.instance.registerCrop(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action to add a biome nutrient bonus
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
private static final class AddBiomeNutrientBonusAction extends OneWayAction {
|
||||
private String biomeType;
|
||||
private int nutrientBonus;
|
||||
|
||||
public AddBiomeNutrientBonusAction(String biomeType, int nutrientBonus) {
|
||||
this.biomeType = biomeType;
|
||||
this.nutrientBonus = nutrientBonus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting biome nutrient bonus for " + biomeType + " biomes to " +
|
||||
nutrientBonus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Crops.instance.addBiomenutrientsBonus(BiomeDictionary.Type.valueOf(biomeType),
|
||||
nutrientBonus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action to add a biome humidity bonus
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
private static final class AddBiomeHumidityBonusAction extends OneWayAction {
|
||||
private String biomeType;
|
||||
private int humidityBonus;
|
||||
|
||||
public AddBiomeHumidityBonusAction(String biomeType, int humidityBonus) {
|
||||
this.biomeType = biomeType;
|
||||
this.humidityBonus = humidityBonus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Setting biome humidity bonus for " + biomeType + " biomes to " +
|
||||
humidityBonus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Crops.instance.addBiomehumidityBonus(BiomeDictionary.Type.valueOf(biomeType),
|
||||
humidityBonus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a nutrient bonus to crops in a specific biome
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addBiomeNutrientBonus(String biomeType, int nutrientBonus) {
|
||||
if(BiomeDictionary.Type.valueOf(biomeType) == null) {
|
||||
MineTweakerAPI.logWarning("invalid biome type: " + biomeType);
|
||||
} else if (nutrientBonus < -10 || nutrientBonus > 10) {
|
||||
MineTweakerAPI.logWarning("nutrient bonus " + nutrientBonus +
|
||||
" not in -10, +10 range");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new AddBiomeNutrientBonusAction(biomeType, nutrientBonus));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a humidity bonus to crops in a specific biome
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addBiomeHumidityBonus(String biomeType, int humidityBonus) {
|
||||
if(BiomeDictionary.Type.valueOf(biomeType) == null) {
|
||||
MineTweakerAPI.logWarning("invalid biome type: " + biomeType);
|
||||
} else if (humidityBonus < -10 || humidityBonus > 10) {
|
||||
MineTweakerAPI.logWarning("humidity bonus " + humidityBonus +
|
||||
" not in -10, +10 range");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new AddBiomeHumidityBonusAction(biomeType, humidityBonus));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new synthetic crop to manipulate
|
||||
* @param cropOwner The mod that owns the crop
|
||||
* @param cropName The name of the crop
|
||||
*/
|
||||
@ZenMethod
|
||||
public static SyntheticCrop newCrop(String cropName, String cropOwner) {
|
||||
return new SyntheticCrop(cropName, cropOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a crop into the crop system
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void registerCrop(CropCard c) {
|
||||
MineTweakerAPI.apply(new RegisterCropCardAction(c));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new base seed item to plant a crop
|
||||
*
|
||||
* @param seed The item to plant with
|
||||
* @param c The crop being planted
|
||||
* @param sz The initial size of the planted crop
|
||||
* @param growth The initial growth stat of the planted crop
|
||||
* @param gain The initial gain stat of the planted crop
|
||||
* @param resist The initial resistance of the planted crop
|
||||
*/
|
||||
public static void registerBaseSeed(IItemStack seed, CropCard c, int sz,
|
||||
int growth, int gain, int resist) {
|
||||
MineTweakerAPI.apply(new RegisterBaseSeedAction(seed, c, sz, growth, gain, resist));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a crop by its name and owning mod
|
||||
* @param owner The mod that owns the crop
|
||||
* @param name The name of the crop
|
||||
* @return A crop with the given name, owned by the given mod
|
||||
*/
|
||||
@ZenMethod
|
||||
public static Crop getCrop(String owner, String name) {
|
||||
return new Crop(Crops.instance.getCropCard(owner, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a crop by the seed that plants it
|
||||
* @param seed The seed that plants the crop
|
||||
* @return The crop planted by the seed
|
||||
*/
|
||||
@ZenMethod
|
||||
public static Crop getCrop(IItemStack seed) {
|
||||
return new Crop(Crops.instance.getCropCard(MineTweakerMC.getItemStack(seed)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the currently registered crops
|
||||
* @return All of the currently registered crops
|
||||
*/
|
||||
@ZenGetter("crops")
|
||||
public static List<Crop> getAllCrops() {
|
||||
Collection<CropCard> ccList = Crops.instance.getCrops();
|
||||
|
||||
List<Crop> cList = new ArrayList<Crop>(ccList.size());
|
||||
for (CropCard cropCard : ccList) {
|
||||
cList.add(new Crop(cropCard));
|
||||
}
|
||||
|
||||
return cList;
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
package minetweaker.mods.ic2.crops;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenSetter;
|
||||
|
||||
/**
|
||||
* Contains all of the growth requirements for an IC2 crop in one easy place
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
@ZenClass("mods.ic2.GrowthRequirements")
|
||||
public class GrowthRequirements {
|
||||
|
||||
private int minNutrients;
|
||||
private int minHumidity;
|
||||
private int minAirQuality;
|
||||
|
||||
private int minLight;
|
||||
private int maxLight = 17;
|
||||
|
||||
private IItemStack requiredBlock;
|
||||
|
||||
/**
|
||||
* Get the minimum amount of nutrients this plant needs to grow
|
||||
* @return The minimum amount of nutrients this plant needs
|
||||
*/
|
||||
@ZenGetter("minNutrients")
|
||||
public int getMinNutrients() {
|
||||
return minNutrients;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum amount of nutrients this plant needs to grow
|
||||
* @param minNutrients The new minimum amount of nutrients this plant requires
|
||||
*/
|
||||
@ZenSetter("minNutrients")
|
||||
public void setMinNutrients(int minNutrients) {
|
||||
this.minNutrients = minNutrients;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum amount of humidity this plant requires
|
||||
* @return The minimum amount of humidity this plant requires
|
||||
*/
|
||||
@ZenGetter("minHumidity")
|
||||
public int getMinHumidity() {
|
||||
return minHumidity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum amount of humidity this plant requires
|
||||
* @param minHumidity The new minimum amount of humidity this plant requires
|
||||
*/
|
||||
@ZenSetter("minHumidity")
|
||||
public void setMinHumidity(int minHumidity) {
|
||||
this.minHumidity = minHumidity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum air quality this plant requires
|
||||
* @return The minimum air quality this plant requires
|
||||
*/
|
||||
@ZenGetter("minAirQuality")
|
||||
public int getMinAirQuality() {
|
||||
return minAirQuality;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum air quality this plant requires
|
||||
* @param minAirQuality The new amount of air quality this plant requires
|
||||
*/
|
||||
@ZenSetter("minAirQuality")
|
||||
public void setMinAirQuality(int minAirQuality) {
|
||||
this.minAirQuality = minAirQuality;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum amount of light this plant requires
|
||||
* @return The minimum amount of light this plant requires
|
||||
*/
|
||||
@ZenGetter("minLight")
|
||||
public int getMinLight() {
|
||||
return minLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum amount of light this plant requires
|
||||
* @param minLight The new minimum amount of light this plant requires
|
||||
*/
|
||||
@ZenSetter("minLight")
|
||||
public void setMinLight(int minLight) {
|
||||
this.minLight = minLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum amount of light this plant can have
|
||||
* @return The maximum amount of light this plant can have
|
||||
*/
|
||||
@ZenGetter("maxLight")
|
||||
public int getMaxLight() {
|
||||
return maxLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum amount of light this plant can have
|
||||
* @param maxLight The new maximum amount of light thi plant can have
|
||||
*/
|
||||
@ZenSetter("maxLight")
|
||||
public void setMaxLight(int maxLight) {
|
||||
this.maxLight = maxLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block that is required to be below this one
|
||||
* @return The block required to be below this one
|
||||
*/
|
||||
@ZenGetter("requiredBlock")
|
||||
public IItemStack getRequiredBlock() {
|
||||
return requiredBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block required to be below this one
|
||||
* @param requiredBlock The new block required to be below this one
|
||||
*/
|
||||
@ZenSetter("requiredBlock")
|
||||
public void setRequiredBlock(IItemStack requiredBlock) {
|
||||
this.requiredBlock = requiredBlock;
|
||||
}
|
||||
|
||||
|
||||
public GrowthRequirements(int minNutrients, int minHumidity, int minAirQuality, int minLight, int maxLight,
|
||||
IItemStack requiredBlock) {
|
||||
super();
|
||||
this.minNutrients = minNutrients;
|
||||
this.minHumidity = minHumidity;
|
||||
this.minAirQuality = minAirQuality;
|
||||
this.minLight = minLight;
|
||||
this.maxLight = maxLight;
|
||||
this.requiredBlock = requiredBlock;
|
||||
}
|
||||
}
|
||||
+295
@@ -0,0 +1,295 @@
|
||||
package minetweaker.mods.ic2.crops;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ic2.api.crops.CropCard;
|
||||
import ic2.api.crops.ICropTile;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import stanhebben.zenscript.annotations.ZenSetter;
|
||||
|
||||
/**
|
||||
* A synthetic crop, created in ZS
|
||||
*
|
||||
* For your crop textures to be picked up, put them at owner + ":crops/crop" +
|
||||
* name + "." + size where owner is the mod responsible for the crop name is the
|
||||
* name of the crop size is the current size of the crop, starting at 0 for new
|
||||
* crops
|
||||
*
|
||||
* Localizations will be looked for at owner + ".crop." + name where each field
|
||||
* has the value it has above
|
||||
*
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
@ZenClass("mods.ic2.SyntheticCrop")
|
||||
public class SyntheticCrop extends CropCard {
|
||||
|
||||
private String name;
|
||||
private String owner;
|
||||
|
||||
private int tier;
|
||||
|
||||
private int[] stats = new int[4];
|
||||
private String[] attributes;
|
||||
|
||||
private int maxSize;
|
||||
|
||||
private float dropChance;
|
||||
private IItemStack fruit;
|
||||
|
||||
private GrowthRequirements reqs;
|
||||
|
||||
/**
|
||||
* Create a new synthetic crop
|
||||
*
|
||||
* @param cropName
|
||||
* The name of this crop
|
||||
* @param cropOwner
|
||||
* The mod creating this crop
|
||||
*/
|
||||
public SyntheticCrop(String cropName, String cropOwner) {
|
||||
name = cropName;
|
||||
}
|
||||
|
||||
// Required IC2 Interface
|
||||
/**
|
||||
* Gets the name of this crop used as a identifier
|
||||
*/
|
||||
@Override
|
||||
@ZenGetter("name")
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mod that owns this crop
|
||||
*/
|
||||
@Override
|
||||
@ZenGetter("owner")
|
||||
public String owner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the localization key used for this crop
|
||||
*/
|
||||
@Override
|
||||
public String displayName() {
|
||||
return owner + ".crop." + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the seed tier of this crop.
|
||||
*/
|
||||
@Override
|
||||
@ZenGetter("tier")
|
||||
public int tier() {
|
||||
return tier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of a particular stat for this crop
|
||||
*
|
||||
* Stats: - 0: Chemistry (Industrial uses based on chemical plant
|
||||
* components) - 1: Consumable (Food, potion ingredients, stuff meant to be
|
||||
* eaten or similarly used) - 2: Defensive (Plants with defense capabilities
|
||||
* (damaging, explosive, chemical) or special abilities in general) - 3:
|
||||
* Colorful (How colorful/aesthetically/beautiful is the plant, like
|
||||
* dye-plants or plants without actual effects) - 4: Weed (Is this plant
|
||||
* weed-like and rather unwanted/quick-spreading? Rare super-breed plants
|
||||
* should have low values here)
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
@ZenMethod
|
||||
public int stat(int n) {
|
||||
return stats[n];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets any additional attributes of this crop
|
||||
*/
|
||||
@Override
|
||||
@ZenGetter("attributes")
|
||||
public String[] attributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum size of this crop
|
||||
*/
|
||||
@Override
|
||||
@ZenGetter("maxSize")
|
||||
public int maxSize() {
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerSprites(IIconRegister iconRegister) {
|
||||
textures = new IIcon[maxSize()];
|
||||
|
||||
for (int i = 1; i <= textures.length; i++) {
|
||||
textures[i - 1] = iconRegister.registerIcon(owner() + ":crop/crop" + name() + "." + i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrow(ICropTile crop) {
|
||||
if (crop.getSize() == maxSize) {
|
||||
return false;
|
||||
} else if (reqs == null) {
|
||||
return true;
|
||||
} else {
|
||||
if(!crop.isBlockBelow(MineTweakerMC.getBlock(reqs.getRequiredBlock()))) {
|
||||
return false;
|
||||
} else if(crop.getAirQuality() < reqs.getMinAirQuality()){
|
||||
return false;
|
||||
} else if(crop.getHumidity() < reqs.getMinHumidity()) {
|
||||
return false;
|
||||
} else if(crop.getNutrients() < reqs.getMinNutrients()) {
|
||||
return false;
|
||||
} else {
|
||||
int lgh = crop.getLightLevel();
|
||||
return reqs.getMinLight() < lgh && reqs.getMaxLight() > lgh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOptimalHavestSize(ICropTile crop) {
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeHarvested(ICropTile crop) {
|
||||
return crop.getSize() == maxSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getGain(ICropTile crop) {
|
||||
return MineTweakerMC.getItemStack(fruit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chance for this crop to drop an item
|
||||
*/
|
||||
@Override
|
||||
@ZenGetter("dropChance")
|
||||
public float dropGainChance() {
|
||||
return dropChance;
|
||||
};
|
||||
|
||||
// ZS Support
|
||||
|
||||
/**
|
||||
* Sets the tier of this crop
|
||||
*
|
||||
* @param tier
|
||||
* The new tier of this crop
|
||||
*/
|
||||
@ZenSetter("tier")
|
||||
public void setTier(int tier) {
|
||||
this.tier = tier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all of the stats for this crop
|
||||
*
|
||||
* @param stats
|
||||
* The new stats to give to this crop
|
||||
*/
|
||||
@ZenSetter("stats")
|
||||
public void setStats(int[] stats) {
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an individual stat for this crop
|
||||
*
|
||||
* @param stat
|
||||
* The stat to set a value for
|
||||
* @param val
|
||||
* The new value for this stat
|
||||
*/
|
||||
@ZenMethod
|
||||
public void setStat(int stat, int val) {
|
||||
if (stat < 0 || stat > 3) {
|
||||
MineTweakerAPI.logWarning("invalid stat index " + stat);
|
||||
} else {
|
||||
stats[stat] = val;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the additional attributes for this crop
|
||||
*
|
||||
* @param attributes
|
||||
* Sets the attributes of this crop
|
||||
*/
|
||||
@ZenSetter("attributes")
|
||||
public void setAttributes(String[] attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum size this crop goes to
|
||||
*
|
||||
* @param maxSize
|
||||
* The new max size of this crop
|
||||
*/
|
||||
@ZenSetter("maxSize")
|
||||
public void setMaxSize(int maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the item this crop gives when harvested
|
||||
*
|
||||
* @param fruit
|
||||
* The item to give from the crop
|
||||
*/
|
||||
@ZenSetter("fruit")
|
||||
public void setFruit(IItemStack fruit) {
|
||||
this.fruit = fruit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the chance for this plant to yield its fruit
|
||||
*
|
||||
* @param dropChance
|
||||
* The new chance for this plant to yield fruit
|
||||
*/
|
||||
@ZenSetter("dropChance")
|
||||
public void setDropChance(int dropChance) {
|
||||
this.dropChance = dropChance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current requirements for this plant to grow
|
||||
*
|
||||
* @return The current growth requirements for this plant
|
||||
*/
|
||||
public GrowthRequirements getReqs() {
|
||||
return reqs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current growth requirements for this plant to grow
|
||||
*
|
||||
* @param reqs
|
||||
* The new requirements for this plant to grow
|
||||
*/
|
||||
public void setReqs(GrowthRequirements reqs) {
|
||||
this.reqs = reqs;
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.expand;
|
||||
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemCondition;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
@ModOnly("IC2")
|
||||
public class IngredientExpansion {
|
||||
@ZenMethod
|
||||
public static IIngredient onlyIC2ChargeAtLeast(IIngredient ingredient, final int charge) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return ItemExpansion.getIC2Charge(stack) >= charge;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static IIngredient onlyIC2ChargeAtMost(IIngredient ingredient, final int charge) {
|
||||
return ingredient.only(new IItemCondition() {
|
||||
@Override
|
||||
public boolean matches(IItemStack stack) {
|
||||
return ItemExpansion.getIC2Charge(stack) <= charge;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static IIngredient transformIC2Discharge(IIngredient ingredient, final int amount) {
|
||||
return ingredient.transform(new IItemTransformer() {
|
||||
@Override
|
||||
public IItemStack transform(IItemStack item, IPlayer byPlayer) {
|
||||
return ItemExpansion.ic2Discharge(item, amount, 0).withAmount(item.getAmount() + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package minetweaker.mods.ic2.expand;
|
||||
|
||||
import ic2.api.item.ElectricItem;
|
||||
import ic2.api.item.IElectricItem;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenExpansion;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenExpansion("minecraft.item.IItemStack")
|
||||
@ModOnly("IC2")
|
||||
public class ItemExpansion {
|
||||
/**
|
||||
* Gets the charge level of this item.
|
||||
*
|
||||
* @param stack target
|
||||
* @return charge level
|
||||
*/
|
||||
@ZenGetter("ic2getCharge")
|
||||
public static double getIC2Charge(IItemStack stack) {
|
||||
return ElectricItem.manager.getCharge(getItemStack(stack));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tier level of this item.
|
||||
*
|
||||
* @param stack target
|
||||
* @return tier level
|
||||
*/
|
||||
@ZenGetter("ic2tier")
|
||||
public static int getIC2Tier(IItemStack stack) {
|
||||
ItemStack iStack = getItemStack(stack);
|
||||
if (iStack.getItem() instanceof IElectricItem) {
|
||||
return ((IElectricItem) iStack.getItem()).getTier(iStack);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the transfer limit of the specified stack.
|
||||
*
|
||||
* @param stack target
|
||||
* @return
|
||||
*/
|
||||
@ZenGetter("ic2transferLimit")
|
||||
public static double getIC2TransferLimit(IItemStack stack) {
|
||||
ItemStack iStack = getItemStack(stack);
|
||||
if (iStack.getItem() instanceof IElectricItem) {
|
||||
return ((IElectricItem) iStack.getItem()).getTransferLimit(iStack);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully charged IC2 item.
|
||||
*
|
||||
* @param stack target
|
||||
* @return charged item
|
||||
*/
|
||||
@ZenGetter("ic2charged")
|
||||
public static IItemStack getIC2Charged(IItemStack stack) {
|
||||
ItemStack iStack = getItemStack(stack);
|
||||
if (iStack.getItem() instanceof IElectricItem) {
|
||||
IElectricItem eItem = (IElectricItem) iStack.getItem();
|
||||
Item item = eItem.getChargedItem(iStack);
|
||||
ItemStack stack2 = new ItemStack(item, 1, 0);
|
||||
ElectricItem.manager.charge(stack2, eItem.getMaxCharge(stack2), eItem.getTier(stack2), true, false);
|
||||
return getIItemStack(stack2);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully discharged IC2 item.
|
||||
*
|
||||
* @param stack target
|
||||
* @return discharged item
|
||||
*/
|
||||
@ZenGetter("ic2discharged")
|
||||
public static IItemStack getIC2Discharged(IItemStack stack) {
|
||||
ItemStack iStack = getItemStack(stack);
|
||||
if (iStack.getItem() instanceof IElectricItem) {
|
||||
IElectricItem eItem = (IElectricItem) iStack.getItem();
|
||||
Item item = eItem.getEmptyItem(iStack);
|
||||
return getItemStack(item, 1, 0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Charges the item with the specified amount and returns the charged item.
|
||||
*
|
||||
* @param stack target
|
||||
* @param amount charge amount
|
||||
* @param tier charge tier
|
||||
* @return charged item
|
||||
*/
|
||||
@ZenMethod("ic2charge")
|
||||
public static IItemStack ic2Charge(IItemStack stack, double amount, @Optional int tier) {
|
||||
if (tier == 0) {
|
||||
tier = getIC2Tier(stack);
|
||||
}
|
||||
|
||||
ItemStack iStack = getItemStack(stack).copy();
|
||||
ElectricItem.manager.charge(iStack, amount, tier, true, false);
|
||||
return getIItemStack(iStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Discharges the item with the specified amount and returns the discharged item.
|
||||
*
|
||||
* @param stack target
|
||||
* @param amount discharge amount
|
||||
* @param tier charge tier
|
||||
* @return discharged item
|
||||
*/
|
||||
@ZenMethod("ic2discharge")
|
||||
public static IItemStack ic2Discharge(IItemStack stack, int amount, @Optional int tier) {
|
||||
if (tier == 0) {
|
||||
tier = getIC2Tier(stack);
|
||||
}
|
||||
|
||||
ItemStack iStack = getItemStack(stack).copy();
|
||||
ElectricItem.manager.discharge(iStack, amount, tier, true, false, false);
|
||||
return getIItemStack(iStack);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Provides access to the IC2 Blast Furnace recipes.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.BlastFurnace")
|
||||
@ModOnly("IC2")
|
||||
public class BlastFurnace {
|
||||
/**
|
||||
* Adds a new recipe to the blast furnace.
|
||||
*
|
||||
* The recipe input can be any pattern, as long as the stack size is determined.
|
||||
* The output can be any item stack.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredient recipe input
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(
|
||||
@NotNull IItemStack output,
|
||||
@NotNull IIngredient ingredient) {
|
||||
if (ingredient.getAmount() < 0) {
|
||||
MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction(
|
||||
"blast furnace",
|
||||
Recipes.blastfurance,
|
||||
getItemStacks(output),
|
||||
null,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the recipe output for the given input. Will return the output
|
||||
* of a single item, even if the stack contains multiple items.
|
||||
*
|
||||
* @param input recipe input
|
||||
* @return recipe output
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemStack getOutput(
|
||||
@NotNull IItemStack input) {
|
||||
RecipeOutput output = Recipes.blastfurance.getOutputFor(getItemStack(input), false);
|
||||
if (output == null || output.items.isEmpty()) return null;
|
||||
return getIItemStack(output.items.get(0));
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Provides access to the IC2 Block Cutter recipes.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.BlockCutter")
|
||||
@ModOnly("IC2")
|
||||
public class BlockCutter {
|
||||
/**
|
||||
* Adds a new recipe to the block cutter.
|
||||
*
|
||||
* The recipe input can be any pattern, as long as the stack size is determined.
|
||||
* The output can be any item stack.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredient recipe input
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(
|
||||
@NotNull IItemStack output,
|
||||
@NotNull IIngredient ingredient) {
|
||||
if (ingredient.getAmount() < 0) {
|
||||
MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction(
|
||||
"block cutter",
|
||||
Recipes.blockcutter,
|
||||
getItemStacks(output),
|
||||
null,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the recipe output for the given input. Will return the output
|
||||
* of a single item, even if the stack contains multiple items.
|
||||
*
|
||||
* @param input recipe input
|
||||
* @return recipe output
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemStack getOutput(
|
||||
@NotNull IItemStack input) {
|
||||
RecipeOutput output = Recipes.blockcutter.getOutputFor(getItemStack(input), false);
|
||||
if (output == null || output.items.isEmpty()) return null;
|
||||
return getIItemStack(output.items.get(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.RecipeInputFluidContainer;
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.OneWayAction;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.ic2.Canner")
|
||||
@ModOnly("IC2")
|
||||
public class Canner {
|
||||
@ZenMethod
|
||||
public static void addBottleRecipe(IItemStack output, IIngredient container, IIngredient fill) {
|
||||
MineTweakerAPI.apply(new AddBottleIngredientAction(container, fill, output));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addBottleRecipe(IItemStack output, IIngredient container, ILiquidStack liquid) {
|
||||
MineTweakerAPI.apply(new AddBottleLiquidAction(container, liquid, output));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addEnrichRecipe(ILiquidStack output, ILiquidStack input, IIngredient additive) {
|
||||
MineTweakerAPI.apply(new AddEnrichIngredientAction(input, additive, output));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addEnrichRecipe(ILiquidStack output, ILiquidStack input, ILiquidStack additive) {
|
||||
MineTweakerAPI.apply(new AddEnrichLiquidAction(input, additive, output));
|
||||
}
|
||||
|
||||
private static class AddBottleIngredientAction extends OneWayAction {
|
||||
private final IIngredient container;
|
||||
private final IIngredient fill;
|
||||
private final IItemStack output;
|
||||
|
||||
public AddBottleIngredientAction(IIngredient container, IIngredient fill, IItemStack output) {
|
||||
this.container = container;
|
||||
this.fill = fill;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Recipes.cannerBottle.addRecipe(
|
||||
new IC2RecipeInput(container),
|
||||
new IC2RecipeInput(fill),
|
||||
getItemStack(output));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding canner bottle recipe " + container + " + " + fill + " => " + output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 67 * hash + (this.container != null ? this.container.hashCode() : 0);
|
||||
hash = 67 * hash + (this.fill != null ? this.fill.hashCode() : 0);
|
||||
hash = 67 * hash + (this.output != null ? this.output.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final AddBottleIngredientAction other = (AddBottleIngredientAction) obj;
|
||||
if (this.container != other.container && (this.container == null || !this.container.equals(other.container))) {
|
||||
return false;
|
||||
}
|
||||
if (this.fill != other.fill && (this.fill == null || !this.fill.equals(other.fill))) {
|
||||
return false;
|
||||
}
|
||||
if (this.output != other.output && (this.output == null || !this.output.equals(other.output))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddBottleLiquidAction extends OneWayAction {
|
||||
private final IIngredient container;
|
||||
private final ILiquidStack fill;
|
||||
private final IItemStack output;
|
||||
|
||||
public AddBottleLiquidAction(IIngredient container, ILiquidStack fill, IItemStack output) {
|
||||
this.container = container;
|
||||
this.fill = fill;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Recipes.cannerBottle.addRecipe(
|
||||
new IC2RecipeInput(container),
|
||||
new RecipeInputFluidContainer(
|
||||
((FluidStack) fill.getInternal()).getFluid(),
|
||||
fill.getAmount()),
|
||||
getItemStack(output));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding cannor bottle recipe " + container + " + " + fill + " => " + output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddEnrichIngredientAction extends OneWayAction {
|
||||
private final ILiquidStack input;
|
||||
private final IIngredient additive;
|
||||
private final ILiquidStack output;
|
||||
|
||||
public AddEnrichIngredientAction(ILiquidStack input, IIngredient additive, ILiquidStack output) {
|
||||
this.input = input;
|
||||
this.additive = additive;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Recipes.cannerEnrich.addRecipe((FluidStack) input.getInternal(), new IC2RecipeInput(additive), (FluidStack) output.getInternal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding canner enrich recipe " + input + " + " + additive + " => " + output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 47 * hash + (this.input != null ? this.input.hashCode() : 0);
|
||||
hash = 47 * hash + (this.additive != null ? this.additive.hashCode() : 0);
|
||||
hash = 47 * hash + (this.output != null ? this.output.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final AddEnrichIngredientAction other = (AddEnrichIngredientAction) obj;
|
||||
if (this.input != other.input && (this.input == null || !this.input.equals(other.input))) {
|
||||
return false;
|
||||
}
|
||||
if (this.additive != other.additive && (this.additive == null || !this.additive.equals(other.additive))) {
|
||||
return false;
|
||||
}
|
||||
if (this.output != other.output && (this.output == null || !this.output.equals(other.output))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddEnrichLiquidAction extends OneWayAction {
|
||||
private final ILiquidStack input;
|
||||
private final ILiquidStack additive;
|
||||
private final ILiquidStack output;
|
||||
|
||||
public AddEnrichLiquidAction(ILiquidStack input, ILiquidStack additive, ILiquidStack output) {
|
||||
this.input = input;
|
||||
this.additive = additive;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Recipes.cannerEnrich.addRecipe(
|
||||
(FluidStack) input.getInternal(), new RecipeInputFluidContainer(
|
||||
((FluidStack) additive.getInternal()).getFluid(),
|
||||
additive.getAmount()),
|
||||
(FluidStack) output.getInternal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding canner enrich recipe " + input + " + " + additive + " => " + output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 19 * hash + (this.input != null ? this.input.hashCode() : 0);
|
||||
hash = 19 * hash + (this.additive != null ? this.additive.hashCode() : 0);
|
||||
hash = 19 * hash + (this.output != null ? this.output.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final AddEnrichLiquidAction other = (AddEnrichLiquidAction) obj;
|
||||
if (this.input != other.input && (this.input == null || !this.input.equals(other.input))) {
|
||||
return false;
|
||||
}
|
||||
if (this.additive != other.additive && (this.additive == null || !this.additive.equals(other.additive))) {
|
||||
return false;
|
||||
}
|
||||
if (this.output != other.output && (this.output == null || !this.output.equals(other.output))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Provides access to the IC2 compressor recipes. Recipes can be added but not
|
||||
* removed, due to IC2 API restrictions.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.Compressor")
|
||||
@ModOnly("IC2")
|
||||
public class Compressor {
|
||||
/**
|
||||
* Adds a new recipe to the compressor.
|
||||
*
|
||||
* The recipe input can be any pattern, as long as the stack size is determined.
|
||||
* The output can be any item stack.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredient recipe input
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(
|
||||
@NotNull IItemStack output,
|
||||
@NotNull IIngredient ingredient) {
|
||||
if (ingredient.getAmount() < 0) {
|
||||
MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction(
|
||||
"compressor",
|
||||
Recipes.compressor,
|
||||
getItemStacks(output),
|
||||
null,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the recipe output for the given input. Will return the output
|
||||
* of a single item, even if the stack contains multiple items.
|
||||
*
|
||||
* @param input recipe input
|
||||
* @return recipe output
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemStack getOutput(
|
||||
@NotNull IItemStack input) {
|
||||
RecipeOutput output = Recipes.compressor.getOutputFor(getItemStack(input), false);
|
||||
if (output == null || output.items.isEmpty()) {
|
||||
System.out.println("No output");
|
||||
return null;
|
||||
}
|
||||
return getIItemStack(output.items.get(0));
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Provides access to the IC2 Extractor recipes.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.Extractor")
|
||||
@ModOnly("IC2")
|
||||
public class Extractor {
|
||||
/**
|
||||
* Adds a new recipe to the extractor.
|
||||
*
|
||||
* The recipe input can be any pattern, as long as the stack size is determined.
|
||||
* The output can be any item stack.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredient recipe input
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(
|
||||
@NotNull IItemStack output,
|
||||
@NotNull IIngredient ingredient) {
|
||||
if (ingredient.getAmount() < 0) {
|
||||
MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction(
|
||||
"extractor",
|
||||
Recipes.extractor,
|
||||
getItemStacks(output),
|
||||
null,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the recipe output for the given input. Will return the output
|
||||
* of a single item, even if the stack contains multiple items.
|
||||
*
|
||||
* @param input recipe input
|
||||
* @return recipe output
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemStack getOutput(
|
||||
@NotNull IItemStack input) {
|
||||
RecipeOutput output = Recipes.extractor.getOutputFor(getItemStack(input), false);
|
||||
if (output == null || output.items.isEmpty()) return null;
|
||||
return getIItemStack(output.items.get(0));
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.OneWayAction;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Add a fluid to the fluid heat generator
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.ic2.FluidHeatGenerator")
|
||||
@ModOnly("IC2")
|
||||
public class FluidHeatGenerator {
|
||||
@ZenMethod
|
||||
public static void addFluid(ILiquidStack liquidPerTick, int heatPerTick) {
|
||||
MineTweakerAPI.apply(new AddFluidAction(liquidPerTick.getName(), liquidPerTick.getAmount(), heatPerTick));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static boolean accepts(ILiquidStack liquid) {
|
||||
return Recipes.FluidHeatGenerator.acceptsFluid(FluidRegistry.getFluid(liquid.getName()));
|
||||
}
|
||||
|
||||
private static class AddFluidAction extends OneWayAction {
|
||||
private final String name;
|
||||
private final int liquidPerTick;
|
||||
private final int heatPerTick;
|
||||
|
||||
public AddFluidAction(String name, int liquidPerTick, int heatPerTick) {
|
||||
this.name = name;
|
||||
this.liquidPerTick = liquidPerTick;
|
||||
this.heatPerTick = heatPerTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Recipes.FluidHeatGenerator.addFluid(name, liquidPerTick, heatPerTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding liquid " + name + " as fluid heat generator fuel";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
|
||||
hash = 47 * hash + this.liquidPerTick;
|
||||
hash = 47 * hash + this.heatPerTick;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final AddFluidAction other = (AddFluidAction) obj;
|
||||
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
if (this.liquidPerTick != other.liquidPerTick) {
|
||||
return false;
|
||||
}
|
||||
if (this.heatPerTick != other.heatPerTick) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Provides access to the IC2 macerator recipes. Recipes can be added but not
|
||||
* removed, due to IC2 API restrictions.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.Macerator")
|
||||
@ModOnly("IC2")
|
||||
public class Macerator {
|
||||
/**
|
||||
* Adds a new recipe to the macerator.
|
||||
*
|
||||
* The recipe input can be any pattern, as long as the stack size is determined.
|
||||
* The output can be any item stack.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredient recipe input
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(
|
||||
@NotNull IItemStack output,
|
||||
@NotNull IIngredient ingredient) {
|
||||
if (ingredient.getAmount() < 0) {
|
||||
MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction(
|
||||
"macerator",
|
||||
Recipes.macerator,
|
||||
getItemStacks(output),
|
||||
null,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the recipe output for the given input. Will return the output
|
||||
* of a single item, even if the stack contains multiple items.
|
||||
*
|
||||
* @param input recipe input
|
||||
* @return recipe output
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemStack getOutput(
|
||||
@NotNull IItemStack input) {
|
||||
RecipeOutput output = Recipes.macerator.getOutputFor(getItemStack(input), false);
|
||||
if (output == null || output.items.isEmpty()) return null;
|
||||
return getIItemStack(output.items.get(0));
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.ic2.MatterAmplifier")
|
||||
@ModOnly("IC2")
|
||||
public class MatterAmplifier {
|
||||
private MatterAmplifier() {}
|
||||
|
||||
@ZenMethod
|
||||
public static void setAmplifier(IIngredient item, int amplifier) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setInteger("amplification", amplifier);
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction("matter amplifier", Recipes.matterAmplifier, new ItemStack[0], data, new IC2RecipeInput(item)));
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.MetalFormer")
|
||||
@ModOnly("IC2")
|
||||
public class MetalFormer {
|
||||
/**
|
||||
* Adds an extruding recipe to the metal former.
|
||||
*
|
||||
* @param output output item
|
||||
* @param input input item
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addExtrudingRecipe(IItemStack output, IIngredient input) {
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction(
|
||||
"metal former - extruding",
|
||||
Recipes.metalformerExtruding,
|
||||
getItemStacks(output),
|
||||
null,
|
||||
new IC2RecipeInput(input)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extruding output for the given input.
|
||||
*
|
||||
* @param input input item
|
||||
* @return output item, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemStack getExtrudingOutput(IItemStack input) {
|
||||
RecipeOutput output = Recipes.metalformerExtruding.getOutputFor(getItemStack(input), false);
|
||||
if (output == null || output.items.isEmpty()) return null;
|
||||
return getIItemStack(output.items.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a rolling recipe to the metal former.
|
||||
*
|
||||
* @param output output item
|
||||
* @param input input item
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRollingRecipe(IItemStack output, IIngredient input) {
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction(
|
||||
"metal former - rolling",
|
||||
Recipes.metalformerRolling,
|
||||
getItemStacks(output),
|
||||
null,
|
||||
new IC2RecipeInput(input)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extruding output for the given input.
|
||||
*
|
||||
* @param input input item
|
||||
* @return output item, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemStack getRollingOutput(IItemStack input) {
|
||||
RecipeOutput output = Recipes.metalformerRolling.getOutputFor(getItemStack(input), false);
|
||||
if (output == null || output.items.isEmpty()) return null;
|
||||
return getIItemStack(output.items.get(0));
|
||||
}
|
||||
/**
|
||||
* Adds a extruding recipe to the metal former.
|
||||
*
|
||||
* @param output output item
|
||||
* @param input input item
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addCuttingRecipe(IItemStack output, IIngredient input) {
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction(
|
||||
"metal former - cutting",
|
||||
Recipes.metalformerCutting,
|
||||
getItemStacks(output),
|
||||
null,
|
||||
new IC2RecipeInput(input)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cutting output for the given input.
|
||||
*
|
||||
* @param input input item
|
||||
* @return output item, or null
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemStack getCuttingOutput(IItemStack input) {
|
||||
RecipeOutput output = Recipes.metalformerCutting.getOutputFor(getItemStack(input), false);
|
||||
if (output == null || output.items.isEmpty()) return null;
|
||||
return getIItemStack(output.items.get(0));
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStacks;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.OreWasher")
|
||||
@ModOnly("IC2")
|
||||
public class OreWasher {
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack[] output, IIngredient input, int millibuckets) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setInteger("amount", millibuckets);
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction(
|
||||
"ore washer",
|
||||
Recipes.oreWashing,
|
||||
getItemStacks(output),
|
||||
nbt,
|
||||
new IC2RecipeInput(input)));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static IItemStack[] getOutput(IItemStack input) {
|
||||
RecipeOutput output = Recipes.oreWashing.getOutputFor(getItemStack(input), false);
|
||||
if (output == null || output.items.isEmpty()) return null;
|
||||
return getIItemStacks(output.items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.OneWayAction;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.ic2.Recycler")
|
||||
@ModOnly("IC2")
|
||||
public class Recycler {
|
||||
@ZenMethod
|
||||
public static void addBlacklist(IIngredient ingredient) {
|
||||
MineTweakerAPI.apply(new AddBlacklistAction(ingredient));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static boolean isBlacklisted(IItemStack item) {
|
||||
return Recipes.recyclerBlacklist.contains(getItemStack(item));
|
||||
}
|
||||
|
||||
private static class AddBlacklistAction extends OneWayAction {
|
||||
private IIngredient ingredient;
|
||||
|
||||
public AddBlacklistAction(IIngredient ingredient) {
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Recipes.recyclerBlacklist.add(new IC2RecipeInput(ingredient));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding " + ingredient + " to the recycler blacklist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 29 * hash + (this.ingredient != null ? this.ingredient.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final AddBlacklistAction other = (AddBlacklistAction) obj;
|
||||
if (this.ingredient != other.ingredient && (this.ingredient == null || !this.ingredient.equals(other.ingredient))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.OneWayAction;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.ic2.ScrapBox")
|
||||
@ModOnly("IC2")
|
||||
public class ScrapBox {
|
||||
/**
|
||||
* Adds an item drop.
|
||||
*
|
||||
* Reference scrap box chance values:
|
||||
*
|
||||
* 0.1: Diamond
|
||||
* 0.5: Cake, Gold Helmet, Iron Ore, Gold Ore
|
||||
* 1.0: Wooden tools, Soul Sand, Sign, Leather, Feather, Bone
|
||||
* 1.5: Apple, Bread
|
||||
* 2.0: Netherrack, Rotten Flesh
|
||||
* 3.0: Grass, Gravel
|
||||
* 4.0: Stick
|
||||
* 5.0: Dirt, Wooden Hoe
|
||||
*
|
||||
* @param stack weighted item stack to add
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addDrop(WeightedItemStack stack) {
|
||||
MineTweakerAPI.apply(new AddDropAction(stack));
|
||||
}
|
||||
|
||||
private static class AddDropAction extends OneWayAction {
|
||||
private final WeightedItemStack stack;
|
||||
|
||||
public AddDropAction(WeightedItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Recipes.scrapboxDrops.addDrop(getItemStack(stack.getStack()), stack.getChance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding scrapbox drop " + stack.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 71 * hash + (this.stack != null ? this.stack.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final AddDropAction other = (AddDropAction) obj;
|
||||
if (this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.OneWayAction;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Add a fluid to the semi-fluid generator
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.ic2.SemiFluidGenerator")
|
||||
@ModOnly("IC2")
|
||||
public class SemiFluidGenerator {
|
||||
@ZenMethod
|
||||
public static void addFluid(ILiquidStack liquidPerTick, int energyPerTick) {
|
||||
MineTweakerAPI.apply(new AddFluidAction(liquidPerTick.getName(), liquidPerTick.getAmount(), energyPerTick));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static boolean accepts(ILiquidStack liquid) {
|
||||
return Recipes.semiFluidGenerator.acceptsFluid(FluidRegistry.getFluid(liquid.getName()));
|
||||
}
|
||||
|
||||
private static class AddFluidAction extends OneWayAction {
|
||||
private final String name;
|
||||
private final int liquidPerTick;
|
||||
private final int energyPerTick;
|
||||
|
||||
public AddFluidAction(String name, int liquidPerTick, int energyPerTick) {
|
||||
this.name = name;
|
||||
this.liquidPerTick = liquidPerTick;
|
||||
this.energyPerTick = energyPerTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Recipes.semiFluidGenerator.addFluid(name, liquidPerTick, energyPerTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding liquid " + name + " as semifluid fuel";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0);
|
||||
hash = 47 * hash + this.liquidPerTick;
|
||||
hash = 47 * hash + this.energyPerTick;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final AddFluidAction other = (AddFluidAction) obj;
|
||||
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
if (this.liquidPerTick != other.liquidPerTick) {
|
||||
return false;
|
||||
}
|
||||
if (this.energyPerTick != other.energyPerTick) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package minetweaker.mods.ic2.machines;
|
||||
|
||||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStacks;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import minetweaker.mods.ic2.IC2RecipeInput;
|
||||
import minetweaker.mods.ic2.MachineAddRecipeAction;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
* Provides access to the IC2 compressor recipes. Recipes can be added but not
|
||||
* removed, due to IC2 API restrictions.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.ic2.ThermalCentrifuge")
|
||||
@ModOnly("IC2")
|
||||
public class ThermalCentrifuge {
|
||||
/**
|
||||
* Adds a new recipe to the centrifuge.
|
||||
*
|
||||
* The recipe input can be any ingredient, as long as the stack size is determined.
|
||||
* The output is an array of item stacks.
|
||||
*
|
||||
* @param output recipe outputs
|
||||
* @param ingredient recipe input
|
||||
* @param minHeat minimum centrifuge heat level
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack[] output, IIngredient ingredient, int minHeat) {
|
||||
if (ingredient.getAmount() < 0) {
|
||||
MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known");
|
||||
} else {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("minHeat", minHeat);
|
||||
MineTweakerAPI.apply(new MachineAddRecipeAction(
|
||||
"thermal centrifuge",
|
||||
Recipes.centrifuge,
|
||||
getItemStacks(output),
|
||||
tag,
|
||||
new IC2RecipeInput(ingredient)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new recipe to the centrifuge.
|
||||
*
|
||||
* The recipe input can be any ingredient, as long as the stack size is determined.
|
||||
* The output can be any item stack.
|
||||
*
|
||||
* @param output recipe output
|
||||
* @param ingredient recipe input
|
||||
* @param minHeat minimum centrifuge heat level
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack output, IIngredient ingredient, int minHeat) {
|
||||
addRecipe(new IItemStack[] { output }, ingredient, minHeat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the recipe output for the given input. Will return the output
|
||||
* of a single item, even if the stack contains multiple items.
|
||||
*
|
||||
* @param input recipe input
|
||||
* @return recipe output
|
||||
*/
|
||||
@ZenMethod
|
||||
public static IItemStack[] getOutput(IItemStack input) {
|
||||
RecipeOutput output = Recipes.centrifuge.getOutputFor(getItemStack(input), false);
|
||||
if (output == null || output.items.isEmpty()) return null;
|
||||
return getIItemStacks(output.items);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public enum FertilizableType {
|
||||
REPLACE,
|
||||
BONEMEAL
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr;
|
||||
|
||||
import java.util.Map;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.MineTweakerImplementationAPI.ReloadEvent;
|
||||
import minetweaker.annotations.OnRegister;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.server.ICommandFunction;
|
||||
import minetweaker.util.IEventHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import cofh.lib.util.WeightedRandomItemStack;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import powercrystals.minefactoryreloaded.api.IFactoryFertilizer;
|
||||
import powercrystals.minefactoryreloaded.api.IFactoryFruit;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MFRCommands {
|
||||
private static final String[] DESCRIPTION = {
|
||||
" MineFactory commands:",
|
||||
" /minetweaker mfr fertilizers",
|
||||
" Lists all fertilizers",
|
||||
" /minetweaker mfr fruits",
|
||||
" Lists all known fruit blocks",
|
||||
" /minetweaker mfr laserores",
|
||||
" Lists all ores known to the mining laser",
|
||||
" /minetweaker mfr rubbertreebiomes",
|
||||
" Lists all biomes for the rubber tree",
|
||||
" /minetweaker mfr sludgedrops",
|
||||
" Lists all sludge boiler drops"
|
||||
};
|
||||
|
||||
@OnRegister
|
||||
public static void onRegister() {
|
||||
MineTweakerImplementationAPI.onReloadEvent(new IEventHandler<ReloadEvent>() {
|
||||
@Override
|
||||
public void handle(ReloadEvent event) {
|
||||
MineTweakerImplementationAPI.addMineTweakerCommand("mfr", DESCRIPTION, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
if (arguments.length < 1) {
|
||||
player.sendChat("Please specify a mfr command");
|
||||
} else {
|
||||
if (arguments[0].equals("fertilizers")) {
|
||||
MineTweakerAPI.logCommand("Fertilizers:");
|
||||
|
||||
for (Map.Entry<Item, IFactoryFertilizer> fertilizer : MFRRegistry.getFertilizers().entrySet()) {
|
||||
IItemStack item = MineTweakerMC.getItemStack(fertilizer.getKey(), 1, 0);
|
||||
String message = "- " + item + " (" + item.getDisplayName() + ")";
|
||||
MineTweakerAPI.logCommand(message);
|
||||
}
|
||||
|
||||
player.sendChat("Fertilizer list generated; see minetweaker.log");
|
||||
} else if (arguments[0].equals("fruits")) {
|
||||
MineTweakerAPI.logCommand("Fruit Blocks:");
|
||||
|
||||
for (Map.Entry<Block, IFactoryFruit> fruitBlock : MFRRegistry.getFruits().entrySet()) {
|
||||
Block block = fruitBlock.getKey();
|
||||
String message = "- " + block.getUnlocalizedName() + " (" + block.getLocalizedName() + ")";
|
||||
MineTweakerAPI.logCommand(message);
|
||||
}
|
||||
|
||||
player.sendChat("Fluit blocks list generated; see minetweaker.log");
|
||||
} else if (arguments[0].equals("laserores")) {
|
||||
MineTweakerAPI.logCommand("Laser ores:");
|
||||
|
||||
for (WeightedRandom.Item randomItem : MFRRegistry.getLaserOres()) {
|
||||
if (randomItem instanceof WeightedRandomItemStack) {
|
||||
WeightedRandomItemStack randomItemStack = (WeightedRandomItemStack) randomItem;
|
||||
IItemStack item = MineTweakerMC.getIItemStack(randomItemStack.getStack());
|
||||
MineTweakerAPI.logCommand(" (" + randomItemStack.itemWeight + "): " + item + " (" + item.getDisplayName() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
player.sendChat("Laser ore list generated; see minetweaker.log");
|
||||
|
||||
for (int i = 0; i < MineTweakerAPI.COLOR_NAMES.length; i++) {
|
||||
if (MFRRegistry.getLaserPreferredOres(i) != null && !MFRRegistry.getLaserPreferredOres(i).isEmpty()) {
|
||||
MineTweakerAPI.logCommand("Laser affinity " + i + " (" + MineTweakerAPI.COLOR_NAMES[i] + "):");
|
||||
|
||||
for (ItemStack item : MFRRegistry.getLaserPreferredOres(i)) {
|
||||
IItemStack iitem = MineTweakerMC.getIItemStack(item);
|
||||
MineTweakerAPI.logCommand(" " + iitem + " (" + iitem.getDisplayName() + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.sendChat("Laser preferred ore list generated; see minetweaker.log");
|
||||
} else if (arguments[0].equals("rubbertreebiomes")) {
|
||||
MineTweakerAPI.logCommand("Rubber tree biomes:");
|
||||
for (String biome : MFRRegistry.getRubberTreeBiomes()) {
|
||||
MineTweakerAPI.logCommand(" " + biome);
|
||||
}
|
||||
|
||||
player.sendChat("Rubber tree biome list generated; see minetweaker.log");
|
||||
} else if (arguments[0].equals("sludgedrops")) {
|
||||
MineTweakerAPI.logCommand("Sludge drops:");
|
||||
|
||||
for (WeightedRandom.Item randItem : MFRRegistry.getSludgeDrops()) {
|
||||
if (randItem instanceof WeightedRandomItemStack) {
|
||||
WeightedRandomItemStack randomItem = (WeightedRandomItemStack) randItem;
|
||||
IItemStack item = MineTweakerMC.getIItemStack(randomItem.getStack());
|
||||
MineTweakerAPI.logCommand(" (" + randomItem.itemWeight + "): " + item + " (" + item.getDisplayName() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
player.sendChat("Sludge drop list generated; see minetweaker.log");
|
||||
} else {
|
||||
player.sendChat("Unknown mfr command: " + arguments[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public enum PrePlantAction {
|
||||
NONE,
|
||||
TILL
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import static minetweaker.mc1710.util.MineTweakerPlatformUtils.getLivingEntityClass;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.AutoSpawner")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class AutoSpawner {
|
||||
@ZenMethod
|
||||
public static void addBlacklist(String entityClassName) {
|
||||
MineTweakerAPI.apply(new AutoSpawnerAddBlacklistAction(getLivingEntityClass(entityClassName)));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeBlacklist(String entityClassName) {
|
||||
MineTweakerAPI.apply(new AutoSpawnerRemoveBlacklistAction(getLivingEntityClass(entityClassName)));
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AutoSpawnerAddBlacklistAction implements IUndoableAction {
|
||||
private final Class<? extends EntityLivingBase> entityClass;
|
||||
private final boolean existed;
|
||||
|
||||
public AutoSpawnerAddBlacklistAction(Class<? extends EntityLivingBase> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
existed = MFRRegistry.getAutoSpawnerClassBlacklist().contains(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (!existed)
|
||||
MFRRegistry.registerAutoSpawnerBlacklistClass(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
if (!existed)
|
||||
MFRRegistry.getAutoSpawnerClassBlacklist().remove(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding auto-spawner blacklist " + entityClass.getCanonicalName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing auto-spawner blacklist " + entityClass.getCanonicalName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AutoSpawnerRemoveBlacklistAction implements IUndoableAction {
|
||||
private final Class<? extends EntityLivingBase> entityClass;
|
||||
private final boolean existed;
|
||||
|
||||
public AutoSpawnerRemoveBlacklistAction(Class<? extends EntityLivingBase> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
existed = MFRRegistry.getAutoSpawnerClassBlacklist().contains(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (existed)
|
||||
MFRRegistry.getAutoSpawnerClassBlacklist().remove(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
if (existed)
|
||||
MFRRegistry.getAutoSpawnerClassBlacklist().add(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing auto-spawner blacklist " + entityClass.getCanonicalName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring auto-spawner blacklist " + entityClass.getCanonicalName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+349
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import java.util.Random;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemDye;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import powercrystals.minefactoryreloaded.api.FertilizerType;
|
||||
import powercrystals.minefactoryreloaded.api.IFactoryFertilizable;
|
||||
import powercrystals.minefactoryreloaded.api.IFactoryFertilizer;
|
||||
import minetweaker.mods.mfr.FertilizableType;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.Fertilizer")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class Fertilizer {
|
||||
@ZenMethod
|
||||
public static void addFertilizable(IItemStack block, String fertilizeType, @Optional String method, @Optional IItemStack replacement) {
|
||||
FertilizerType fertilizer;
|
||||
if (fertilizeType.equals("any")) {
|
||||
fertilizer = null;
|
||||
} else if (fertilizeType.equals("normal")) {
|
||||
fertilizer = FertilizerType.GrowPlant;
|
||||
} else if (fertilizeType.equals("grass")) {
|
||||
fertilizer = FertilizerType.Grass;
|
||||
} else if (fertilizeType.equals("magic")) {
|
||||
fertilizer = FertilizerType.GrowMagicalCrop;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown fertilizer type: " + fertilizeType);
|
||||
}
|
||||
|
||||
FertilizableType type = FertilizableType.BONEMEAL;
|
||||
|
||||
if (method == null || method.equals("bonemeal")) {
|
||||
type = FertilizableType.BONEMEAL;
|
||||
} else if (method.equals("replace")) {
|
||||
type = FertilizableType.REPLACE;
|
||||
if (replacement == null)
|
||||
throw new IllegalArgumentException("replace method requires a replacement block");
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown fertilization method: " + method);
|
||||
}
|
||||
|
||||
MineTweakerAPI.apply(new FertilizerAddFertilizableAction(block, replacement, fertilizer, type));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeFertilizable(IItemStack item) {
|
||||
MineTweakerAPI.apply(new FertilizerRemoveFertilizableAction(item));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addFertilizer(IItemStack item, String type) {
|
||||
FertilizerType fertilizerType;
|
||||
if (type.equals("grass")) {
|
||||
fertilizerType = FertilizerType.Grass;
|
||||
} else if (type.equals("normal")) {
|
||||
fertilizerType = FertilizerType.GrowPlant;
|
||||
} else if (type.equals("magic")) {
|
||||
fertilizerType = FertilizerType.GrowMagicalCrop;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown fertilizer type: " + type);
|
||||
}
|
||||
|
||||
MineTweakerAPI.apply(new FertilizerAddFertilizerAction(item, fertilizerType));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeFertilizer(IItemStack item) {
|
||||
MineTweakerAPI.apply(new FertilizerRemoveFertilizerAction(item));
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action Classes ###
|
||||
// ######################
|
||||
|
||||
public static class FertilizerAddFertilizableAction implements IUndoableAction {
|
||||
private final IItemStack block;
|
||||
private final IItemStack plant;
|
||||
private final FertilizerType type;
|
||||
private final FertilizableType method;
|
||||
|
||||
private final IFactoryFertilizable old;
|
||||
|
||||
public FertilizerAddFertilizableAction(IItemStack block, IItemStack plant, FertilizerType type, FertilizableType method) {
|
||||
this.block = block;
|
||||
this.plant = plant;
|
||||
this.type = type;
|
||||
this.method = method;
|
||||
|
||||
old = MFRRegistry.getFertilizables().get(MineTweakerMC.getBlock(block));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.registerFertilizable(new SimpleFertilizable(block, plant, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
if (old == null) {
|
||||
MFRRegistry.getFertilizables().remove(MineTweakerMC.getBlock(block));
|
||||
} else {
|
||||
MFRRegistry.registerFertilizable(old);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Making " + block.getDisplayName() + " fertilizable";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
if (old == null) {
|
||||
return "Removing fertilizable " + block.getDisplayName();
|
||||
} else {
|
||||
return "Restoring fertilizable " + block.getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FertilizerAddFertilizerAction implements IUndoableAction {
|
||||
private final IItemStack item;
|
||||
private final FertilizerType type;
|
||||
|
||||
private final IFactoryFertilizer old;
|
||||
|
||||
public FertilizerAddFertilizerAction(IItemStack item, FertilizerType type) {
|
||||
this.item = item;
|
||||
this.type = type;
|
||||
|
||||
old = MFRRegistry.getFertilizers().get(MineTweakerMC.getItemStack(item).getItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.registerFertilizer(new SimpleFertilizer(MineTweakerMC.getItemStack(item), type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
if (old == null) {
|
||||
MFRRegistry.getFertilizers().remove(MineTweakerMC.getItemStack(item).getItem());
|
||||
} else {
|
||||
MFRRegistry.registerFertilizer(old);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding fertilizer " + item.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
if (old == null) {
|
||||
return "Removing fertilizer " + item.getDisplayName();
|
||||
} else {
|
||||
return "Restoring fertilizer " + item.getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FertilizerRemoveFertilizableAction implements IUndoableAction {
|
||||
private final IItemStack item;
|
||||
private final IFactoryFertilizable old;
|
||||
|
||||
public FertilizerRemoveFertilizableAction(IItemStack item) {
|
||||
this.item = item;
|
||||
old = MFRRegistry.getFertilizables().get(MineTweakerMC.getBlock(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getFertilizables().remove(MineTweakerMC.getBlock(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.registerFertilizable(old);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing fertilizable " + item.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring fertilizable " + item.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FertilizerRemoveFertilizerAction implements IUndoableAction {
|
||||
private final IItemStack item;
|
||||
private final IFactoryFertilizer old;
|
||||
|
||||
public FertilizerRemoveFertilizerAction(IItemStack item) {
|
||||
this.item = item;
|
||||
this.old = MFRRegistry.getFertilizers().get(MineTweakerMC.getItemStack(item).getItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getFertilizers().remove(MineTweakerMC.getItemStack(item).getItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.registerFertilizer(old);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing fertilizer " + item.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring fertilizer " + item.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SimpleFertilizable implements IFactoryFertilizable {
|
||||
private final IItemStack block;
|
||||
private final IItemStack plant;
|
||||
private final FertilizerType type;
|
||||
|
||||
public SimpleFertilizable(IItemStack block, IItemStack plant, FertilizerType type) {
|
||||
this.block = block;
|
||||
this.plant = plant;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getPlant() {
|
||||
return MineTweakerMC.getBlock(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFertilize(World world, int x, int y, int z, FertilizerType fertilizerType) {
|
||||
if (this.type != null && type != fertilizerType)
|
||||
return false;
|
||||
|
||||
IItemStack blockAt = MineTweakerMC.getIItemStack(new ItemStack(world.getBlock(x, y, z), 1, world.getBlockMetadata(x, y, z)));
|
||||
return block.matches(blockAt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fertilize(World world, Random rand, int x, int y, int z, FertilizerType fertilizerType) {
|
||||
if (plant == null) {
|
||||
return ItemDye.applyBonemeal(
|
||||
new ItemStack((Item) Item.itemRegistry.getObject("minecraft:dyePowder"), 1, 15),
|
||||
world,
|
||||
x, y, z,
|
||||
null);
|
||||
} else {
|
||||
ItemStack istack = MineTweakerMC.getItemStack(plant);
|
||||
world.setBlock(x, y, z, Block.getBlockFromItem(istack.getItem()), plant.getDamage(), 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class SimpleFertilizer implements IFactoryFertilizer {
|
||||
private final ItemStack item;
|
||||
private final FertilizerType type;
|
||||
|
||||
public SimpleFertilizer(ItemStack item, FertilizerType type) {
|
||||
this.item = item;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getFertilizer() {
|
||||
return item.getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FertilizerType getFertilizerType(ItemStack is) {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consume(ItemStack fertilizer) {
|
||||
fertilizer.stackSize--;
|
||||
}
|
||||
}
|
||||
}
|
||||
+360
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.block.IBlockPattern;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import minetweaker.mc1710.block.MCBlockDefinition;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import powercrystals.minefactoryreloaded.api.IFactoryFruit;
|
||||
import powercrystals.minefactoryreloaded.api.ReplacementBlock;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.FruitPicker")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class FruitPicker {
|
||||
@ZenMethod
|
||||
public static void addFruit(IBlockPattern block, IBlock replacement, WeightedItemStack drop) {
|
||||
addFruit(block, replacement, new WeightedItemStack[] { drop });
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addFruit(IBlockPattern block, IBlock replacement, WeightedItemStack[] drops) {
|
||||
TweakerFruit fruit = new TweakerFruit(block, replacement, drops);
|
||||
MineTweakerAPI.apply(new AddFruitAction(fruit));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeFruit(IBlockPattern block) {
|
||||
MineTweakerAPI.apply(new RemoveFruitAction(block));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addLog(IBlockPattern block) {
|
||||
MineTweakerAPI.apply(new AddLogAction(block));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeLog(IBlockPattern block) {
|
||||
MineTweakerAPI.apply(new RemoveLogAction(block));
|
||||
}
|
||||
|
||||
// #####################
|
||||
// ### Inner classes ###
|
||||
// #####################
|
||||
|
||||
private static class TweakerFruit {
|
||||
private final IBlockPattern block;
|
||||
private final IBlock replacement;
|
||||
private final WeightedItemStack[] possibleDrops;
|
||||
|
||||
public TweakerFruit(IBlockPattern block, IBlock replacement, WeightedItemStack[] possibleDrops) {
|
||||
this.block = block;
|
||||
this.replacement = replacement;
|
||||
this.possibleDrops = possibleDrops;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TweakerFruitPartial implements IFactoryFruit {
|
||||
private final Block block;
|
||||
private final List<TweakerFruit> fruits;
|
||||
|
||||
public TweakerFruitPartial(Block block) {
|
||||
this.block = block;
|
||||
fruits = new ArrayList<TweakerFruit>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getPlant() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePicked(World world, int x, int y, int z) {
|
||||
for (TweakerFruit fruit : fruits) {
|
||||
if (fruit.block.matches(MineTweakerMC.getBlock(world, x, y, z)))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean breakBlock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplacementBlock getReplacementBlock(World world, int x, int y, int z) {
|
||||
IBlock iBlock = MineTweakerMC.getBlock(world, x, y, z);
|
||||
for (TweakerFruit fruit : fruits) {
|
||||
if (fruit.block.matches(iBlock))
|
||||
return new ReplacementBlock(MineTweakerMC.getBlock(fruit.replacement)).setMeta(iBlock.getMeta());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prePick(World world, int x, int y, int z) {}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(World world, Random rand, int x, int y, int z) {
|
||||
IBlock iBlock = MineTweakerMC.getBlock(world, x, y, z);
|
||||
for (TweakerFruit fruit : fruits) {
|
||||
if (fruit.block.matches(iBlock))
|
||||
return Arrays.asList(MineTweakerMC.getItemStacks(WeightedItemStack.pickRandomDrops(rand, fruit.possibleDrops)));
|
||||
}
|
||||
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postPick(World world, int x, int y, int z) {}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddFruitAction implements IUndoableAction {
|
||||
private final TweakerFruit fruit;
|
||||
|
||||
public AddFruitAction(TweakerFruit fruit) {
|
||||
this.fruit = fruit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Map<Block, IFactoryFruit> fruits = MFRRegistry.getFruits();
|
||||
for (IBlock partial : fruit.block.getBlocks()) {
|
||||
Block block = ((MCBlockDefinition) partial.getDefinition()).getInternalBlock();
|
||||
if (fruits != null && fruits.containsKey(block)) {
|
||||
IFactoryFruit existingFruit = fruits.get(block);
|
||||
if (existingFruit instanceof TweakerFruitPartial) {
|
||||
TweakerFruitPartial existingFruitPartial = (TweakerFruitPartial) existingFruit;
|
||||
if (!existingFruitPartial.fruits.contains(fruit)) {
|
||||
existingFruitPartial.fruits.add(fruit);
|
||||
}
|
||||
} else {
|
||||
MineTweakerAPI.logError("A non-MineTweaker fruit already exists for this ID");
|
||||
}
|
||||
} else {
|
||||
TweakerFruitPartial factoryFruit = new TweakerFruitPartial(block);
|
||||
MFRRegistry.registerFruit(factoryFruit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
Map<Block, IFactoryFruit> fruits = MFRRegistry.getFruits();
|
||||
for (IBlock partial : fruit.block.getBlocks()) {
|
||||
Block block = MineTweakerMC.getBlock(partial);
|
||||
IFactoryFruit factoryFruit = fruits.get(block);
|
||||
if (factoryFruit != null && factoryFruit instanceof TweakerFruitPartial) {
|
||||
((TweakerFruitPartial) factoryFruit).fruits.remove(fruit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding Fruit Picker fruit block " + fruit.block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing Fruit Picker fruit block " + fruit.block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveFruitAction implements IUndoableAction {
|
||||
private final IBlockPattern block;
|
||||
private final Map<Block, IFactoryFruit> removed;
|
||||
|
||||
public RemoveFruitAction(IBlockPattern block) {
|
||||
this.block = block;
|
||||
|
||||
Map<Block, IFactoryFruit> fruits = MFRRegistry.getFruits();
|
||||
removed = new HashMap<Block, IFactoryFruit>();
|
||||
for (IBlock partial : block.getBlocks()) {
|
||||
Block mcBlock = MineTweakerMC.getBlock(partial);
|
||||
if (fruits.containsKey(mcBlock)) {
|
||||
removed.put(mcBlock, fruits.get(mcBlock));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Map<Block, IFactoryFruit> fruits = MFRRegistry.getFruits();
|
||||
for (Block key : removed.keySet()) {
|
||||
fruits.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
Map<Block, IFactoryFruit> fruits = MFRRegistry.getFruits();
|
||||
for (Map.Entry<Block, IFactoryFruit> restore : removed.entrySet()) {
|
||||
fruits.put(restore.getKey(), restore.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing fruit picker fruit block " + block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring fruit picker fruit block " + block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddLogAction implements IUndoableAction {
|
||||
private final IBlockPattern block;
|
||||
private final List<Block> addedLogs = new ArrayList<Block>();
|
||||
|
||||
public AddLogAction(IBlockPattern block) {
|
||||
this.block = block;
|
||||
|
||||
for (IBlock partial : block.getBlocks()) {
|
||||
Block mcBlock = MineTweakerMC.getBlock(partial);
|
||||
if (!MFRRegistry.getFruitLogBlocks().contains(mcBlock)) {
|
||||
if (!addedLogs.contains(mcBlock))
|
||||
addedLogs.add(mcBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Block log : addedLogs) {
|
||||
MFRRegistry.registerFruitLogBlock(log);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (Block log : addedLogs) {
|
||||
MFRRegistry.getFruitLogBlocks().remove(log);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding MFR Fruit Picker log block " + block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing MFR Fruit Picker log block " + block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveLogAction implements IUndoableAction {
|
||||
private final IBlockPattern block;
|
||||
private final List<Block> removedLogs = new ArrayList<Block>();
|
||||
|
||||
public RemoveLogAction(IBlockPattern block) {
|
||||
this.block = block;
|
||||
|
||||
for (IBlock partial : block.getBlocks()) {
|
||||
Block mcBlock = MineTweakerMC.getBlock(partial);
|
||||
if (MFRRegistry.getFruitLogBlocks().contains(mcBlock)) {
|
||||
if (!removedLogs.contains(mcBlock))
|
||||
removedLogs.add(mcBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Block log : removedLogs) {
|
||||
MFRRegistry.getFruitLogBlocks().remove(log);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (Block log : removedLogs) {
|
||||
MFRRegistry.registerFruitLogBlock(log);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing MFR Fruit Picker log block " + block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring MFR Fruit Picker log block " + block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import static minetweaker.mc1710.util.MineTweakerPlatformUtils.getLivingEntityClass;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import powercrystals.minefactoryreloaded.api.IFactoryGrindable;
|
||||
import powercrystals.minefactoryreloaded.api.MobDrop;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.Grinder")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class Grinder {
|
||||
public static void addBlacklist(String entityClassName) {
|
||||
Class<? extends EntityLivingBase> entityClass = getLivingEntityClass(entityClassName);
|
||||
MineTweakerAPI.apply(new AddBlacklistAction(entityClass));
|
||||
}
|
||||
|
||||
public static void removeBlacklist(String entityClassName) {
|
||||
Class<? extends EntityLivingBase> entityClass = getLivingEntityClass(entityClassName);
|
||||
if (!MFRRegistry.getGrinderBlacklist().contains(entityClass)) {
|
||||
MineTweakerAPI.logWarning(entityClassName + " is not blacklisted in the MFR Grinder");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new RemoveBlacklistAction(entityClass));
|
||||
}
|
||||
}
|
||||
|
||||
public static void addGrindable(String entityClassName) {
|
||||
addGrindable(entityClassName, new WeightedItemStack[0]);
|
||||
}
|
||||
|
||||
public static void addGrindable(String entityClassName, WeightedItemStack possibleDrop) {
|
||||
addGrindable(entityClassName, new WeightedItemStack[] { possibleDrop });
|
||||
}
|
||||
|
||||
public static void addGrindable(String entityClassName, WeightedItemStack[] possibleDrops) {
|
||||
Class<? extends EntityLivingBase> entityClass = getLivingEntityClass(entityClassName);
|
||||
MineTweakerAPI.apply(new AddGrindableAction(entityClass, possibleDrops));
|
||||
}
|
||||
|
||||
public static void removeGrindable(String entityClassName) {
|
||||
Class<? extends EntityLivingBase> entityClass = getLivingEntityClass(entityClassName);
|
||||
if (!MFRRegistry.getGrindables().containsKey(entityClass)) {
|
||||
MineTweakerAPI.logError("No such grindable entity: " + entityClassName);
|
||||
} else {
|
||||
MineTweakerAPI.apply(new RemoveGrindableAction(entityClass));
|
||||
}
|
||||
}
|
||||
|
||||
// #######################
|
||||
// ### Private classes ###
|
||||
// #######################
|
||||
|
||||
private static class SimpleGrindable implements IFactoryGrindable {
|
||||
private final Class<? extends EntityLivingBase> entityClass;
|
||||
private final WeightedItemStack[] drops;
|
||||
|
||||
public SimpleGrindable(Class<? extends EntityLivingBase> entityClass, WeightedItemStack[] drops) {
|
||||
this.entityClass = entityClass;
|
||||
this.drops = drops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends EntityLivingBase> getGrindableEntity() {
|
||||
return entityClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobDrop> grind(World world, EntityLivingBase entity, Random random) {
|
||||
List<MobDrop> dropList = new ArrayList<MobDrop>();
|
||||
for (IItemStack itemStack : WeightedItemStack.pickRandomDrops(random, drops)) {
|
||||
dropList.add(new MobDrop(1, MineTweakerMC.getItemStack(itemStack)));
|
||||
}
|
||||
return dropList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processEntity(EntityLivingBase entity) {
|
||||
entity.attackEntityFrom(DamageSource.generic, entity.getMaxHealth() * 20);
|
||||
return entity.isDead;
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddBlacklistAction implements IUndoableAction {
|
||||
private final Class<? extends EntityLivingBase> entityClass;
|
||||
|
||||
public AddBlacklistAction(Class<? extends EntityLivingBase> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.registerGrinderBlacklist(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getGrinderBlacklist().remove(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding " + entityClass.getName() + " to the MFR Grinder blacklist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing " + entityClass.getName() + " from the MFR Grinder blacklist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveBlacklistAction implements IUndoableAction {
|
||||
private final Class<? extends EntityLivingBase> entityClass;
|
||||
|
||||
public RemoveBlacklistAction(Class<? extends EntityLivingBase> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getGrinderBlacklist().remove(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.registerGrinderBlacklist(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing " + entityClass + " from the MFR Grinder blacklist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + entityClass + " to the MFR Grinder blacklist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddGrindableAction implements IUndoableAction {
|
||||
private final SimpleGrindable grindable;
|
||||
|
||||
public AddGrindableAction(Class<? extends EntityLivingBase> entityClass, WeightedItemStack[] possibleDrops) {
|
||||
grindable = new SimpleGrindable(entityClass, possibleDrops);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.registerGrindable(grindable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getGrindables().remove(grindable.entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding MFR Grindable " + grindable.entityClass.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing MFR Grindable " + grindable.entityClass.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveGrindableAction implements IUndoableAction {
|
||||
private final Class<? extends EntityLivingBase> entityClass;
|
||||
private final IFactoryGrindable grindable;
|
||||
|
||||
public RemoveGrindableAction(Class<? extends EntityLivingBase> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
grindable = MFRRegistry.getGrindables().get(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getGrindables().remove(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.registerGrindable(grindable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing grindable " + entityClass.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring grindable " + entityClass.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+301
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.block.IBlockPattern;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import minetweaker.mc1710.block.MCBlockDefinition;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import powercrystals.minefactoryreloaded.api.HarvestType;
|
||||
import powercrystals.minefactoryreloaded.api.IFactoryHarvestable;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.Harvester")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class Harvester {
|
||||
@ZenMethod
|
||||
public static void addHarvestable(IItemStack item) {
|
||||
addHarvestable(item.asBlock(), (WeightedItemStack[]) null, null);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addHarvestable(IItemStack item, String type) {
|
||||
addHarvestable(item.asBlock(), (WeightedItemStack[]) null, type);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addHarvestable(IItemStack item, WeightedItemStack drop, @Optional String type) {
|
||||
addHarvestable(item.asBlock(), drop, type);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addHarvestable(IItemStack item, WeightedItemStack[] drops, @Optional String type) {
|
||||
addHarvestable(item.asBlock(), drops, type);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addHarvestable(IBlockPattern block, WeightedItemStack drop, @Optional String type) {
|
||||
addHarvestable(block, new WeightedItemStack[] { drop }, type);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addHarvestable(IBlockPattern block, WeightedItemStack[] drops, @Optional String type) {
|
||||
TweakerHarvestable harvestable = new TweakerHarvestable(block, drops, type);
|
||||
MineTweakerAPI.apply(new AddHarvestableAction(harvestable));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeHarvestable(IBlockPattern block) {
|
||||
MineTweakerAPI.apply(new RemoveHarvestableAction(block));
|
||||
}
|
||||
|
||||
// #####################
|
||||
// ### Inner classes ###
|
||||
// #####################
|
||||
|
||||
private static class TweakerHarvestable {
|
||||
private final IBlockPattern block;
|
||||
private final WeightedItemStack[] possibleDrops;
|
||||
private final HarvestType type;
|
||||
|
||||
public TweakerHarvestable(IBlockPattern block, WeightedItemStack[] possibleDrops, String stringType) {
|
||||
this.block = block;
|
||||
this.possibleDrops = possibleDrops;
|
||||
|
||||
HarvestType type = HarvestType.Normal;
|
||||
if (stringType == null || stringType.equals("normal")) {
|
||||
type = HarvestType.Normal;
|
||||
} else if (stringType.equals("column")) {
|
||||
type = HarvestType.Column;
|
||||
} else if (stringType.equals("leaveBottom")) {
|
||||
type = HarvestType.LeaveBottom;
|
||||
} else if (stringType.equals("tree")) {
|
||||
type = HarvestType.Tree;
|
||||
} else if (stringType.equals("treeFlipped")) {
|
||||
type = HarvestType.TreeFlipped;
|
||||
} else if (stringType.equals("treeLeaf")) {
|
||||
type = HarvestType.TreeLeaf;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown harvestable type: " + stringType);
|
||||
}
|
||||
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TweakerHarvestablePartial implements IFactoryHarvestable {
|
||||
private final Block block;
|
||||
private final List<TweakerHarvestable> harvestables;
|
||||
|
||||
public TweakerHarvestablePartial(Block block) {
|
||||
this.block = block;
|
||||
harvestables = new ArrayList<TweakerHarvestable>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getPlant() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarvestType getHarvestType() {
|
||||
// WARNING: first type will be used
|
||||
// Also, take into account the possibility of having no harvestable yet
|
||||
HarvestType result = harvestables.isEmpty() ? HarvestType.Normal : harvestables.get(0).type;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean breakBlock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeHarvested(World world, Map<String, Boolean> map, int x, int y, int z) {
|
||||
IBlock block = MineTweakerMC.getBlock(world, x, y, z);
|
||||
|
||||
for (TweakerHarvestable harvestable : harvestables) {
|
||||
if (harvestable.block.matches(block))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(World world, Random random, Map<String, Boolean> map, int x, int y, int z) {
|
||||
IBlock iBlock = MineTweakerMC.getBlock(world, x, y, z);
|
||||
for (TweakerHarvestable harvestable : harvestables) {
|
||||
if (harvestable.block.matches(iBlock)) {
|
||||
if (harvestable.possibleDrops == null) {
|
||||
Block mcBlock = ((MCBlockDefinition) iBlock.getDefinition()).getInternalBlock();
|
||||
List<ItemStack> result = mcBlock.getDrops(world, x, y, z, iBlock.getMeta(), 0);
|
||||
return result;
|
||||
} else {
|
||||
List<ItemStack> result = Arrays.asList(MineTweakerMC.getItemStacks(WeightedItemStack.pickRandomDrops(random, harvestable.possibleDrops)));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preHarvest(World world, int x, int y, int z) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHarvest(World world, int x, int y, int z) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddHarvestableAction implements IUndoableAction {
|
||||
private final TweakerHarvestable harvestable;
|
||||
|
||||
public AddHarvestableAction(TweakerHarvestable harvestable) {
|
||||
this.harvestable = harvestable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Map<Block, IFactoryHarvestable> harvestables = MFRRegistry.getHarvestables();
|
||||
for (IBlock partial : harvestable.block.getBlocks()) {
|
||||
Block block = MineTweakerMC.getBlock(partial);
|
||||
if (harvestable != null && harvestables.containsKey(block)) {
|
||||
IFactoryHarvestable existingHarvestable = harvestables.get(block);
|
||||
if (existingHarvestable instanceof TweakerHarvestablePartial) {
|
||||
TweakerHarvestablePartial existingHarvestablePartial = (TweakerHarvestablePartial) existingHarvestable;
|
||||
if (!existingHarvestablePartial.harvestables.contains(harvestable)) {
|
||||
existingHarvestablePartial.harvestables.add(harvestable);
|
||||
}
|
||||
} else {
|
||||
MineTweakerAPI.logError("A non-MineTweaker fruit already exists for this ID");
|
||||
}
|
||||
} else {
|
||||
TweakerHarvestablePartial factoryFruit = new TweakerHarvestablePartial(block);
|
||||
factoryFruit.harvestables.add(harvestable);
|
||||
MFRRegistry.registerHarvestable(factoryFruit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
Map<Block, IFactoryHarvestable> harvestables = MFRRegistry.getHarvestables();
|
||||
for (IBlock partial : harvestable.block.getBlocks()) {
|
||||
Block block = MineTweakerMC.getBlock(partial);
|
||||
IFactoryHarvestable factoryHarvestable = harvestables.get(block);
|
||||
if (factoryHarvestable != null && factoryHarvestable instanceof TweakerHarvestablePartial) {
|
||||
((TweakerHarvestablePartial) factoryHarvestable).harvestables.remove(harvestable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding Harvester harvestable block " + harvestable.block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing Harvester harvestable block " + harvestable.block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveHarvestableAction implements IUndoableAction {
|
||||
private final IBlockPattern block;
|
||||
private final Map<Block, IFactoryHarvestable> removed;
|
||||
|
||||
public RemoveHarvestableAction(IBlockPattern block) {
|
||||
this.block = block;
|
||||
|
||||
Map<Block, IFactoryHarvestable> harvestables = MFRRegistry.getHarvestables();
|
||||
removed = new HashMap<Block, IFactoryHarvestable>();
|
||||
for (IBlock partial : block.getBlocks()) {
|
||||
Block iBlock = MineTweakerMC.getBlock(partial);
|
||||
if (harvestables.containsKey(iBlock)) {
|
||||
removed.put(iBlock, harvestables.get(iBlock));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
Map<Block, IFactoryHarvestable> harvestables = MFRRegistry.getHarvestables();
|
||||
for (Block key : removed.keySet()) {
|
||||
harvestables.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
Map<Block, IFactoryHarvestable> harvestables = MFRRegistry.getHarvestables();
|
||||
for (Map.Entry<Block, IFactoryHarvestable> restore : removed.entrySet()) {
|
||||
harvestables.put(restore.getKey(), restore.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing Harvester harvestable block " + block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring Harvester harvestable block " + block.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public interface IRedNetFunction {
|
||||
public int[] calculate(long time, int[] inputs);
|
||||
}
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import cofh.lib.util.WeightedRandomItemStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.MiningLaser")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class MiningLaser {
|
||||
@ZenMethod
|
||||
public static void addOre(WeightedItemStack ore) {
|
||||
MineTweakerAPI.apply(new AddOreAction(ore));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeOre(IIngredient ore) {
|
||||
MineTweakerAPI.apply(new RemoveOreAction(ore));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addPreferredOre(int color, IIngredient ore) {
|
||||
MineTweakerAPI.apply(new AddPreferredOreAction(color, ore));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removePreferredOre(int color, IIngredient ore) {
|
||||
MineTweakerAPI.apply(new RemovePreferredOreAction(color, ore));
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddOreAction implements IUndoableAction {
|
||||
private final WeightedRandomItemStack item;
|
||||
|
||||
public AddOreAction(WeightedItemStack item) {
|
||||
this.item = new WeightedRandomItemStack(MineTweakerMC.getItemStack(item.getStack()), (int) item.getChance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getLaserOres().add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getLaserOres().remove(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding laser ore " + item.getStack().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing laser ore " + item.getStack().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveOreAction implements IUndoableAction {
|
||||
private final IIngredient ingredient;
|
||||
private final List<WeightedRandomItemStack> removed;
|
||||
|
||||
public RemoveOreAction(IIngredient ingredient) {
|
||||
this.ingredient = ingredient;
|
||||
removed = new ArrayList<WeightedRandomItemStack>();
|
||||
|
||||
for (WeightedRandom.Item iStack : MFRRegistry.getLaserOres()) {
|
||||
if (iStack instanceof WeightedRandomItemStack) {
|
||||
WeightedRandomItemStack stack = (WeightedRandomItemStack) iStack;
|
||||
if (ingredient.matches(MineTweakerMC.getIItemStack(stack.getStack()))) {
|
||||
removed.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getLaserOres().removeAll(removed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getLaserOres().addAll(removed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing laser ore " + ingredient.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring laser ore " + ingredient.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddPreferredOreAction implements IUndoableAction {
|
||||
private final int color;
|
||||
private final IIngredient ore;
|
||||
|
||||
public AddPreferredOreAction(int color, IIngredient ore) {
|
||||
this.color = color;
|
||||
this.ore = ore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (IItemStack item : ore.getItems()) {
|
||||
MFRRegistry.addLaserPreferredOre(color, MineTweakerMC.getItemStack(item));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (IItemStack item : ore.getItems()) {
|
||||
ItemStack stack = MineTweakerMC.getItemStack(item);
|
||||
MFRRegistry.getLaserPreferredOres(color).remove(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding laser preferred ore " + ore + " to color " + color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing laser preferred ore " + ore + " from color " + color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemovePreferredOreAction implements IUndoableAction {
|
||||
private final int color;
|
||||
private final IIngredient ore;
|
||||
private final List<ItemStack> toRemove;
|
||||
|
||||
public RemovePreferredOreAction(int color, IIngredient ore) {
|
||||
this.color = color;
|
||||
this.ore = ore;
|
||||
|
||||
toRemove = new ArrayList<ItemStack>();
|
||||
for (ItemStack item : MFRRegistry.getLaserPreferredOres(color)) {
|
||||
if (ore.matches(MineTweakerMC.getIItemStack(item))) {
|
||||
toRemove.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getLaserPreferredOres(color).removeAll(toRemove);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getLaserPreferredOres(color).addAll(toRemove);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing preferred ore " + ore + " for color " + color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Adding preferred ore " + ore + " for color " + color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.block.IBlockPattern;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import powercrystals.minefactoryreloaded.api.IFactoryPlantable;
|
||||
import powercrystals.minefactoryreloaded.api.ReplacementBlock;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.Planter")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class Planter {
|
||||
private static final IBlockPattern GRASS_OR_DIRT;
|
||||
|
||||
static {
|
||||
IBlock blockDirt = MineTweakerMC.getBlockAnyMeta((Block) Block.blockRegistry.getObject("minecraft:dirt"));
|
||||
IBlock blockGrass = MineTweakerMC.getBlockAnyMeta((Block) Block.blockRegistry.getObject("minecraft:grass"));
|
||||
GRASS_OR_DIRT = blockDirt.or(blockGrass);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addPlantable(IItemStack seed, @Optional IBlockPattern canPlantOn) {
|
||||
IBlock block = seed.asBlock();
|
||||
if (block == null) {
|
||||
MineTweakerAPI.logError("The given seed has no block equivalant");
|
||||
}
|
||||
addPlantable(seed, block, canPlantOn);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addPlantable(IItemStack seed, IItemStack itemblock, @Optional IBlockPattern canPlantOn) {
|
||||
IBlock block = itemblock.asBlock();
|
||||
if (block == null) {
|
||||
MineTweakerAPI.logError("The given itemblock has no block equivalant");
|
||||
}
|
||||
addPlantable(seed, block, canPlantOn);
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addPlantable(IIngredient seed, IBlock block, @Optional IBlockPattern canPlantOn) {
|
||||
if (canPlantOn == null) {
|
||||
canPlantOn = GRASS_OR_DIRT;
|
||||
}
|
||||
|
||||
if (seed.getItems() == null) {
|
||||
MineTweakerAPI.logError("Seed must be a defined ingredient and cannot be <*>");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new AddPlantableAction(new TweakerPlantable(seed, block, canPlantOn)));
|
||||
}
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removePlantable(IIngredient seed) {
|
||||
MineTweakerAPI.apply(new RemovePlantableAction(seed));
|
||||
}
|
||||
|
||||
// #####################
|
||||
// ### Inner classes ###
|
||||
// #####################
|
||||
|
||||
private static class TweakerPlantable {
|
||||
private final IIngredient seed;
|
||||
private final IBlock block;
|
||||
private final IBlockPattern canPlantOn;
|
||||
|
||||
public TweakerPlantable(IIngredient seed, IBlock block, IBlockPattern canPlantOn) {
|
||||
this.seed = seed;
|
||||
this.block = block;
|
||||
this.canPlantOn = canPlantOn;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TweakerPlantablePartial implements IFactoryPlantable {
|
||||
private final Item seed;
|
||||
private final List<TweakerPlantable> plantables;
|
||||
|
||||
public TweakerPlantablePartial(Item seed) {
|
||||
this.seed = seed;
|
||||
plantables = new ArrayList<TweakerPlantable>();
|
||||
}
|
||||
|
||||
public TweakerPlantablePartial(Item seed, TweakerPlantable plantable) {
|
||||
this(seed);
|
||||
|
||||
plantables.add(plantable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlanted(ItemStack is, boolean bln) {
|
||||
IItemStack iSeed = MineTweakerMC.getIItemStack(is);
|
||||
for (TweakerPlantable plantable : plantables) {
|
||||
if (plantable.seed.matches(iSeed))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplacementBlock getPlantedBlock(World world, int i, int i1, int i2, ItemStack seed) {
|
||||
IItemStack iSeed = MineTweakerMC.getIItemStack(seed);
|
||||
for (TweakerPlantable plantable : plantables) {
|
||||
if (plantable.seed.matches(iSeed))
|
||||
return new ReplacementBlock(MineTweakerMC.getBlock(plantable.block)).setMeta(plantable.block.getMeta());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlantedHere(World world, int x, int y, int z, ItemStack seed) {
|
||||
if (!world.isAirBlock(x, y, z))
|
||||
return false;
|
||||
|
||||
for (TweakerPlantable plantable : plantables) {
|
||||
if (!plantable.seed.matches(MineTweakerMC.getIItemStack(seed)))
|
||||
continue;
|
||||
|
||||
if (!plantable.canPlantOn.matches(MineTweakerMC.getBlock(world, x, y - 1, z)))
|
||||
continue;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prePlant(World world, int i, int i1, int i2, ItemStack is) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postPlant(World world, int i, int i1, int i2, ItemStack is) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddPlantableAction implements IUndoableAction {
|
||||
private final TweakerPlantable plantable;
|
||||
|
||||
private AddPlantableAction(TweakerPlantable plantable) {
|
||||
this.plantable = plantable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (IItemStack iitem : plantable.seed.getItems()) {
|
||||
Item item = MineTweakerMC.getItemStack(iitem).getItem();
|
||||
if (MFRRegistry.getPlantables().containsKey(item)) {
|
||||
IFactoryPlantable existing = MFRRegistry.getPlantables().get(item);
|
||||
if (existing instanceof TweakerPlantablePartial) {
|
||||
((TweakerPlantablePartial) existing).plantables.add(plantable);
|
||||
} else {
|
||||
MineTweakerAPI.logError("Existing non-MineTweaker plantable already exists for seed ID " + Item.itemRegistry.getNameForObject(item));
|
||||
}
|
||||
} else {
|
||||
MFRRegistry.registerPlantable(new TweakerPlantablePartial(item, plantable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (IItemStack iItem : plantable.seed.getItems()) {
|
||||
Item item = MineTweakerMC.getItemStack(iItem).getItem();
|
||||
IFactoryPlantable existing = MFRRegistry.getPlantables().get(item);
|
||||
if (existing instanceof TweakerPlantablePartial) {
|
||||
((TweakerPlantablePartial) existing).plantables.remove(plantable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding MFR Plantable for seed " + plantable.seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing MFR Plantable for seed " + plantable.seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemovePlantableAction implements IUndoableAction {
|
||||
private final IIngredient seed;
|
||||
private final Map<Item, IFactoryPlantable> removed;
|
||||
|
||||
private RemovePlantableAction(IIngredient seed) {
|
||||
this.seed = seed;
|
||||
|
||||
removed = new HashMap<Item, IFactoryPlantable>();
|
||||
for (IItemStack iItem : seed.getItems()) {
|
||||
Item item = MineTweakerMC.getItemStack(iItem).getItem();
|
||||
if (!removed.containsKey(item)) {
|
||||
if (MFRRegistry.getPlantables().containsKey(item)) {
|
||||
removed.put(item, MFRRegistry.getPlantables().get(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Item seedItem : removed.keySet()) {
|
||||
MFRRegistry.getPlantables().remove(seedItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (Map.Entry<Item, IFactoryPlantable> removedEntry : removed.entrySet()) {
|
||||
MFRRegistry.getPlantables().put(removedEntry.getKey(), removedEntry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing MFR Planter seed " + seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring MFR Planter seed " + seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.liquid.WeightedLiquidStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import static minetweaker.mc1710.util.MineTweakerPlatformUtils.getLivingEntityClass;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import powercrystals.minefactoryreloaded.api.IFactoryRanchable;
|
||||
import powercrystals.minefactoryreloaded.api.RanchedItem;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.AutoSpawner")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class Rancher {
|
||||
private static final Random random = new Random();
|
||||
|
||||
@ZenMethod
|
||||
public static void addRanchable(String entityClassName, WeightedItemStack[] possibleDrops, @Optional WeightedLiquidStack[] possibleLiquids) {
|
||||
if (possibleLiquids == null)
|
||||
possibleLiquids = new WeightedLiquidStack[0];
|
||||
|
||||
Class<? extends EntityLivingBase> entityClass = getLivingEntityClass(entityClassName);
|
||||
MineTweakerAPI.apply(new AddRanchableAction(new TweakerRanchable(entityClass, possibleDrops, possibleLiquids)));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRanchable(String entityClassName) {
|
||||
Class<? extends EntityLivingBase> entityClass = getLivingEntityClass(entityClassName);
|
||||
if (!MFRRegistry.getRanchables().containsKey(entityClass)) {
|
||||
MineTweakerAPI.logWarning("No such ranchable: " + entityClassName);
|
||||
} else {
|
||||
MineTweakerAPI.apply(new RemoveRanchableAction(MFRRegistry.getRanchables().get(entityClass)));
|
||||
}
|
||||
}
|
||||
|
||||
// #######################
|
||||
// ### Private classes ###
|
||||
// #######################
|
||||
|
||||
private static class TweakerRanchable implements IFactoryRanchable {
|
||||
private final Class<? extends EntityLivingBase> entityClass;
|
||||
private final WeightedItemStack[] possibleDrops;
|
||||
private final WeightedLiquidStack[] possibleLiquids;
|
||||
|
||||
public TweakerRanchable(Class<? extends EntityLivingBase> entityClass, WeightedItemStack[] possibleDrops, WeightedLiquidStack[] possibleLiquids) {
|
||||
this.entityClass = entityClass;
|
||||
this.possibleDrops = possibleDrops;
|
||||
this.possibleLiquids = possibleLiquids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends EntityLivingBase> getRanchableEntity() {
|
||||
return entityClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RanchedItem> ranch(World world, EntityLivingBase entity, IInventory inventory) {
|
||||
List<RanchedItem> result = new ArrayList<RanchedItem>();
|
||||
if (entityClass.isAssignableFrom(entity.getClass())) {
|
||||
for (IItemStack droppedItem : WeightedItemStack.pickRandomDrops(random, possibleDrops)) {
|
||||
result.add(new RanchedItem(MineTweakerMC.getItemStack(droppedItem)));
|
||||
}
|
||||
|
||||
for (ILiquidStack droppedLiquid : WeightedLiquidStack.pickRandomDrops(random, possibleLiquids)) {
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if (stack != null) {
|
||||
ItemStack filled = FluidContainerRegistry.fillFluidContainer(MineTweakerMC.getLiquidStack(droppedLiquid), stack);
|
||||
if (filled != null) {
|
||||
inventory.setInventorySlotContents(i, filled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddRanchableAction implements IUndoableAction {
|
||||
private final TweakerRanchable ranchable;
|
||||
|
||||
public AddRanchableAction(TweakerRanchable ranchable) {
|
||||
this.ranchable = ranchable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.registerRanchable(ranchable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getRanchables().remove(ranchable.entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding ranchable entity " + ranchable.entityClass.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing ranchable entity " + ranchable.entityClass.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveRanchableAction implements IUndoableAction {
|
||||
private final IFactoryRanchable ranchable;
|
||||
|
||||
public RemoveRanchableAction(IFactoryRanchable ranchable) {
|
||||
this.ranchable = ranchable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getRanchables().remove(ranchable.getRanchableEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getRanchables().put(ranchable.getRanchableEntity(), ranchable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing ranchable entity " + ranchable.getRanchableEntity().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring ranchable entity " + ranchable.getRanchableEntity().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import powercrystals.minefactoryreloaded.api.rednet.IRedNetLogicCircuit;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.RedNet")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class RedNet {
|
||||
@ZenMethod
|
||||
public static void addCircuit(String name, String[] inputs, String[] outputs, IRedNetFunction function) {
|
||||
MineTweakerAPI.apply(new AddCircuitAction(new TweakerRedNetLogicCircuit(name, inputs, outputs, function)));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeCircuit(String name) {
|
||||
List<IRedNetLogicCircuit> toRemove = new ArrayList<IRedNetLogicCircuit>();
|
||||
for (IRedNetLogicCircuit circuit : MFRRegistry.getRedNetLogicCircuits()) {
|
||||
if (circuit.getUnlocalizedName().equals(name)) {
|
||||
toRemove.add(circuit);
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove.isEmpty()) {
|
||||
MineTweakerAPI.logWarning("No such rednet circuit: " + name);
|
||||
} else {
|
||||
for (IRedNetLogicCircuit toRemoveEntry : toRemove) {
|
||||
MineTweakerAPI.apply(new RemoveCircuitAction(toRemoveEntry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Private inner classes ###
|
||||
// #############################
|
||||
|
||||
private static class TweakerRedNetLogicCircuit implements IRedNetLogicCircuit {
|
||||
private final String name;
|
||||
private final String[] inputs;
|
||||
private final String[] outputs;
|
||||
private final IRedNetFunction function;
|
||||
|
||||
public TweakerRedNetLogicCircuit(String name, String[] inputs, String[] outputs, IRedNetFunction function) {
|
||||
this.name = name;
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getInputCount() {
|
||||
return (byte) inputs.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getOutputCount() {
|
||||
return (byte) outputs.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] recalculateOutputValues(long l, int[] ints) {
|
||||
return function.calculate(l, ints);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInputPinLabel(int i) {
|
||||
return inputs[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOutputPinLabel(int i) {
|
||||
return outputs[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttc) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttc) {
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddCircuitAction implements IUndoableAction {
|
||||
private final TweakerRedNetLogicCircuit circuit;
|
||||
|
||||
public AddCircuitAction(TweakerRedNetLogicCircuit circuit) {
|
||||
this.circuit = circuit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.registerRedNetLogicCircuit(circuit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getRedNetLogicCircuits().remove(circuit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding rednet circuit " + circuit.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing rednet circuit " + circuit.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveCircuitAction implements IUndoableAction {
|
||||
private final IRedNetLogicCircuit circuit;
|
||||
|
||||
public RemoveCircuitAction(IRedNetLogicCircuit circuit) {
|
||||
this.circuit = circuit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getRedNetLogicCircuits().remove(circuit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getRedNetLogicCircuits().add(circuit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing RedNet circuit " + circuit.getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring RedNet circuit " + circuit.getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.RubberTree")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class RubberTree {
|
||||
@ZenMethod
|
||||
public static void addBiome(String biome) {
|
||||
MineTweakerAPI.apply(new AddBiomeAction(biome));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeBiome(String biome) {
|
||||
MineTweakerAPI.apply(new RemoveBiomeAction(biome));
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddBiomeAction implements IUndoableAction {
|
||||
private final String biome;
|
||||
|
||||
public AddBiomeAction(String biome) {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.registerRubberTreeBiome(biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return MFRRegistry.getRubberTreeBiomes() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getRubberTreeBiomes().remove(biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding rubber tree biome " + biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing rubber tree biome " + biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveBiomeAction implements IUndoableAction {
|
||||
private final String biome;
|
||||
|
||||
private RemoveBiomeAction(String biome) {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getRubberTreeBiomes().remove(biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getRubberTreeBiomes().add(biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing rubber tree biome " + biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Adding rubber tree biome " + biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import static minetweaker.mc1710.util.MineTweakerPlatformUtils.getLivingEntityClass;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.SafariNet")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class SafariNet {
|
||||
@ZenMethod
|
||||
public static void addBlacklist(String entityClassName) {
|
||||
Class<? extends EntityLivingBase> entityClass = getLivingEntityClass(entityClassName);
|
||||
MineTweakerAPI.apply(new AddBlacklistAction(entityClass));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeBlacklist(String entityClassName) {
|
||||
Class<? extends EntityLivingBase> entityClass = getLivingEntityClass(entityClassName);
|
||||
if (!MFRRegistry.getSafariNetBlacklist().contains(entityClass)) {
|
||||
MineTweakerAPI.logWarning(entityClassName + " is not in the safari net blacklist");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new RemoveBlacklistAction(entityClass));
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddBlacklistAction implements IUndoableAction {
|
||||
private final Class<? extends EntityLivingBase> entityClass;
|
||||
|
||||
public AddBlacklistAction(Class<? extends EntityLivingBase> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.registerSafariNetBlacklist(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getSafariNetBlacklist().remove(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Blacklisting " + entityClass.getName() + " in the safari net";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing " + entityClass.getName() + " from the safari net blacklist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveBlacklistAction implements IUndoableAction {
|
||||
private final Class<? extends EntityLivingBase> entityClass;
|
||||
|
||||
public RemoveBlacklistAction(Class<? extends EntityLivingBase> entityClass) {
|
||||
this.entityClass = entityClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getSafariNetBlacklist().remove(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getSafariNetBlacklist().add(entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing " + entityClass.getName() + " from the safari net blacklist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + entityClass.getName() + " to the safari net blacklist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mods.mfr.machines;
|
||||
|
||||
import cofh.lib.util.WeightedRandomItemStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import powercrystals.minefactoryreloaded.MFRRegistry;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
@ZenClass("mods.mfr.SludgeBoiler")
|
||||
@ModOnly("MineFactoryReloaded")
|
||||
public class SludgeBoiler {
|
||||
@ZenMethod
|
||||
public static void addDrop(WeightedItemStack item) {
|
||||
MineTweakerAPI.apply(new AddDropAction(item));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeDrop(IIngredient item) {
|
||||
if (MFRRegistry.getSludgeDrops() == null) {
|
||||
MineTweakerAPI.logWarning("Cannot remove drops from the sludge boiler");
|
||||
} else {
|
||||
MineTweakerAPI.apply(new RemoveDropAction(item));
|
||||
}
|
||||
}
|
||||
|
||||
// ######################
|
||||
// ### Action classes ###
|
||||
// ######################
|
||||
|
||||
private static class AddDropAction implements IUndoableAction {
|
||||
private final WeightedRandomItemStack item;
|
||||
|
||||
public AddDropAction(WeightedItemStack item) {
|
||||
this.item = new WeightedRandomItemStack(MineTweakerMC.getItemStack(item.getStack()), (int) item.getChance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MFRRegistry.getSludgeDrops().add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
MFRRegistry.getSludgeDrops().remove(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding sludge boiler drop " + item.getStack().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing sludge boiler drop " + item.getStack().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveDropAction implements IUndoableAction {
|
||||
private final IIngredient item;
|
||||
private final List<WeightedRandomItemStack> toRemove;
|
||||
|
||||
private RemoveDropAction(IIngredient item) {
|
||||
this.item = item;
|
||||
|
||||
toRemove = new ArrayList<WeightedRandomItemStack>();
|
||||
for (WeightedRandom.Item iStack : MFRRegistry.getSludgeDrops()) {
|
||||
if (iStack instanceof WeightedRandomItemStack) {
|
||||
WeightedRandomItemStack itemStack = (WeightedRandomItemStack) iStack;
|
||||
if (item.matches(MineTweakerMC.getIItemStack(itemStack.getStack()))) {
|
||||
toRemove.add(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (WeightedRandomItemStack itemStack : toRemove) {
|
||||
MFRRegistry.getSludgeDrops().remove(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
for (WeightedRandomItemStack item : toRemove) {
|
||||
MFRRegistry.getSludgeDrops().add(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Removing " + toRemove.size() + " sludge boiler drops for " + item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Restoring " + toRemove.size() + " sludge boiler drops for " + item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,165 @@
|
||||
package minetweaker.mods.nei;
|
||||
|
||||
import codechicken.nei.api.API;
|
||||
import stanhebben.zenscript.annotations.NotNull;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.OneWayAction;
|
||||
import minetweaker.annotations.ModOnly;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* MineTweaker NEI support.
|
||||
*
|
||||
* Enables hiding NEI items as well as adding new item stacks. These item stacks
|
||||
* can then show a custom message or contain NBT data. Can be used to show
|
||||
* a custom message or lore with certain items, or to provide spawnable items
|
||||
* with specific NBT tags.
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenClass("mods.nei.NEI")
|
||||
@ModOnly("NotEnoughItems")
|
||||
public class NEI {
|
||||
/**
|
||||
* Hides a specific item in NEI. Will take into account metadata values, if
|
||||
* any.
|
||||
*
|
||||
* @param item item to be hidden
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void hide(@NotNull IItemStack item) {
|
||||
MineTweakerAPI.apply(new NEIHideItemAction(getItemStack(item)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a NEI entry. The item stack can contain damage values and NBT tags.
|
||||
*
|
||||
* @param stack item stack to be added
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addEntry(@NotNull IItemStack stack) {
|
||||
MineTweakerAPI.apply(new NEIAddEntryAction(getItemStack(stack)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides a name in NEI. Note that this will not change the original
|
||||
* display name, but it will change the way it is displayed in NEI.
|
||||
*
|
||||
* @param item item
|
||||
* @param name item name
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void overrideName(@NotNull IItemStack item, @NotNull String name) {
|
||||
MineTweakerAPI.apply(new NEIOverrideNameAction(getItemStack(item), name));
|
||||
}
|
||||
|
||||
// #############################
|
||||
// ### Private inner classes ###
|
||||
// #############################
|
||||
|
||||
private static class NEIAddEntryAction implements IUndoableAction {
|
||||
private final ItemStack item;
|
||||
|
||||
public NEIAddEntryAction(ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
API.addItemListEntry(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
API.hideItem(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding " + item.getDisplayName() + " as NEI entry";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Removing " + item.getDisplayName() + " as NEI entry";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class NEIHideItemAction implements IUndoableAction {
|
||||
private final ItemStack stack;
|
||||
|
||||
public NEIHideItemAction(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
API.hideItem(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
API.addItemListEntry(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Hiding " + stack.getUnlocalizedName() + " in NEI";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return "Displaying " + stack.getUnlocalizedName() + " in NEI";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class NEIOverrideNameAction extends OneWayAction {
|
||||
private final ItemStack item;
|
||||
private final String name;
|
||||
|
||||
public NEIOverrideNameAction(ItemStack item, String name) {
|
||||
this.item = item;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
API.setOverrideName(item, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Overriding NEI item name of " + item.getUnlocalizedName() + " to " + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,74 +19,75 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FuelTweaker{
|
||||
public class FuelTweaker {
|
||||
public static final FuelTweaker INSTANCE = new FuelTweaker();
|
||||
private final HashMap<Item, List<SetFuelPattern>> quickList = new HashMap<Item, List<SetFuelPattern>>();
|
||||
private List<IFuelHandler> original;
|
||||
|
||||
private FuelTweaker(){
|
||||
private FuelTweaker() {
|
||||
}
|
||||
|
||||
public void register(){
|
||||
try{
|
||||
public void register() {
|
||||
try {
|
||||
Field fuelHandlers = GameRegistry.class.getDeclaredField("fuelHandlers");
|
||||
fuelHandlers.setAccessible(true);
|
||||
original = (List<IFuelHandler>) fuelHandlers.get(null);
|
||||
List<IFuelHandler> modified = new ArrayList<IFuelHandler>();
|
||||
modified.add(new OverridingFuelHandler());
|
||||
fuelHandlers.set(null, modified);
|
||||
}catch(NoSuchFieldException ex){
|
||||
} catch (NoSuchFieldException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not get GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
}catch(SecurityException ex){
|
||||
} catch (SecurityException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
}catch(IllegalAccessException ex){
|
||||
} catch (IllegalAccessException ex) {
|
||||
System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values.");
|
||||
}
|
||||
}
|
||||
|
||||
public void addFuelPattern(SetFuelPattern pattern){
|
||||
public void addFuelPattern(SetFuelPattern pattern) {
|
||||
List<IItemStack> items = pattern.getPattern().getItems();
|
||||
if(items == null){
|
||||
if (items == null) {
|
||||
MineTweakerAPI.logError("Cannot set fuel for <*>");
|
||||
return;
|
||||
}
|
||||
|
||||
for(IItemStack item : pattern.getPattern().getItems()){
|
||||
for (IItemStack item : pattern.getPattern().getItems()) {
|
||||
ItemStack itemStack = MineTweakerMC.getItemStack(item);
|
||||
Item mcItem = itemStack.getItem();
|
||||
if(!quickList.containsKey(mcItem)){
|
||||
if (!quickList.containsKey(mcItem)) {
|
||||
quickList.put(mcItem, new ArrayList<SetFuelPattern>());
|
||||
}
|
||||
quickList.get(mcItem).add(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFuelPattern(SetFuelPattern pattern){
|
||||
for(IItemStack item : pattern.getPattern().getItems()){
|
||||
public void removeFuelPattern(SetFuelPattern pattern) {
|
||||
for (IItemStack item : pattern.getPattern().getItems()) {
|
||||
ItemStack itemStack = MineTweakerMC.getItemStack(item);
|
||||
Item mcItem = itemStack.getItem();
|
||||
if(quickList.containsKey(mcItem)){
|
||||
if (quickList.containsKey(mcItem)) {
|
||||
quickList.get(mcItem).remove(pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class OverridingFuelHandler implements IFuelHandler{
|
||||
private class OverridingFuelHandler implements IFuelHandler {
|
||||
@Override
|
||||
public int getBurnTime(ItemStack fuel){
|
||||
if(quickList.containsKey(fuel.getItem())){
|
||||
public int getBurnTime(ItemStack fuel) {
|
||||
if (quickList.containsKey(fuel.getItem())) {
|
||||
IItemStack stack = MineTweakerMC.getIItemStack(fuel);
|
||||
|
||||
for(SetFuelPattern override : quickList.get(fuel.getItem())){
|
||||
if(override.getPattern().matches(stack)){
|
||||
for (SetFuelPattern override : quickList.get(fuel.getItem())) {
|
||||
if (override.getPattern().matches(stack)) {
|
||||
return override.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
for(IFuelHandler handler : original){
|
||||
max = Math.max(max, handler.getBurnTime(fuel));
|
||||
for (IFuelHandler handler : original) {
|
||||
if (handler != this)
|
||||
max = Math.max(max, handler.getBurnTime(fuel));
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
@@ -145,28 +145,3 @@ task assembleAll(dependsOn: [
|
||||
assembleDevFull19]) {
|
||||
|
||||
}
|
||||
|
||||
task zendoc1710(type: Javadoc) {
|
||||
source = files([
|
||||
'MineTweaker3-API/src/main/java',
|
||||
'MineTweaker3-MC1710-Main/src/main/java']
|
||||
+ projects1710.collect { it + '/src/main/java' })
|
||||
|
||||
destinationDir = file("build/zendoc1710")
|
||||
options.docletpath = [file('buildSrc/build/libs/buildSrc.jar')].asList()
|
||||
options.doclet = 'stanhebben.zenscript.docs.ZenScriptDoclet'
|
||||
|
||||
def classpathList = [
|
||||
project(":ZenScript").jar.archivePath,
|
||||
project(':MineTweaker3-MC1710-Main').jar.archivePath
|
||||
]
|
||||
|
||||
for (p in projects1710) {
|
||||
for (file in project(':' + p).configurations.compile) {
|
||||
classpathList += file
|
||||
}
|
||||
}
|
||||
|
||||
options.classpath = classpathList.asList()
|
||||
options.addStringOption("baseurl", "/doc/mc1710/")
|
||||
}
|
||||
@@ -16,11 +16,11 @@ ext.javaToolsJar = ((URLClassLoader) ToolProvider.getSystemToolClassLoader()).ge
|
||||
|
||||
ext.forgeVersion1710 = "1.7.10-10.13.4.1614-1.7.10"
|
||||
ext.projects1710 = [
|
||||
'MineTweaker3-MC1710-Main'
|
||||
//'MineTweaker3-MC1710-Mod-IC2',
|
||||
// 'MineTweaker3-MC1710-Mod-NEI',
|
||||
// 'MineTweaker3-MC1710-Mod-MFR',
|
||||
// 'MineTweaker3-MC1710-Mod-Buildcraft'
|
||||
'MineTweaker3-MC1710-Main',
|
||||
'MineTweaker3-MC1710-Mod-IC2',
|
||||
'MineTweaker3-MC1710-Mod-NEI',
|
||||
'MineTweaker3-MC1710-Mod-MFR',
|
||||
'MineTweaker3-MC1710-Mod-Buildcraft'
|
||||
]
|
||||
|
||||
// ####################
|
||||
|
||||
Reference in new issue
Block a user