- Updated all exNihilo mod hookins
This commit is contained in:
parent
c757841e06
commit
80f03ba32b
4 changed files with 220 additions and 83 deletions
|
@ -1,17 +1,16 @@
|
||||||
package modtweaker2.mods.exnihilo.handlers;
|
package modtweaker2.mods.exnihilo.handlers;
|
||||||
|
|
||||||
import static modtweaker2.helpers.InputHelper.toStack;
|
import static modtweaker2.helpers.InputHelper.toStack;
|
||||||
|
import minetweaker.IUndoableAction;
|
||||||
import minetweaker.MineTweakerAPI;
|
import minetweaker.MineTweakerAPI;
|
||||||
import minetweaker.api.item.IItemStack;
|
import minetweaker.api.item.IItemStack;
|
||||||
import modtweaker2.utils.BaseMapAddition;
|
import net.minecraft.item.Item;
|
||||||
import modtweaker2.utils.BaseMapRemoval;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import stanhebben.zenscript.annotations.Optional;
|
import stanhebben.zenscript.annotations.Optional;
|
||||||
import stanhebben.zenscript.annotations.ZenClass;
|
import stanhebben.zenscript.annotations.ZenClass;
|
||||||
import stanhebben.zenscript.annotations.ZenMethod;
|
import stanhebben.zenscript.annotations.ZenMethod;
|
||||||
import exnihilo.registries.CompostRegistry;
|
import exnihilo.registries.CompostRegistry;
|
||||||
import exnihilo.registries.helpers.Color;
|
import exnihilo.registries.helpers.Color;
|
||||||
import exnihilo.registries.helpers.Compostable;
|
|
||||||
|
|
||||||
@ZenClass("mods.exnihilo.Composting")
|
@ZenClass("mods.exnihilo.Composting")
|
||||||
public class Compost {
|
public class Compost {
|
||||||
|
@ -19,19 +18,54 @@ public class Compost {
|
||||||
@ZenMethod
|
@ZenMethod
|
||||||
public static void addRecipe(IItemStack input, double value, @Optional String hex) {
|
public static void addRecipe(IItemStack input, double value, @Optional String hex) {
|
||||||
hex = (hex == null || hex.equals("")) ? "35A82A" : hex;
|
hex = (hex == null || hex.equals("")) ? "35A82A" : hex;
|
||||||
MineTweakerAPI.apply(new Add(new Compostable(toStack(input).getItem(), toStack(input).getItemDamage(), Math.min(1.0F, (float) value), new Color(hex))));
|
MineTweakerAPI.apply(new Add(toStack(input).getItem(), toStack(input).getItemDamage(), Math.min(1.0F, (float) value), new Color(hex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Passes the list to the map list implementation, and adds the recipe
|
//Passes the list to the map list implementation, and adds the recipe
|
||||||
private static class Add extends BaseMapAddition {
|
private static class Add implements IUndoableAction
|
||||||
public Add(Compostable recipe) {
|
{
|
||||||
super("ExNihilo Composting", CompostRegistry.entries, recipe.item + ":" + recipe.meta, recipe);
|
private Item item;
|
||||||
|
private int meta;
|
||||||
|
private float value;
|
||||||
|
private Color color;
|
||||||
|
|
||||||
|
public Add(Item item, int meta, float value, Color color) {
|
||||||
|
this.item = item;
|
||||||
|
this.meta = meta;
|
||||||
|
this.value = value;
|
||||||
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRecipeInfo() {
|
public void apply() {
|
||||||
return new ItemStack(((Compostable) recipe).item, 1, ((Compostable) recipe).meta).getDisplayName();
|
CompostRegistry.register(item, meta, value, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUndo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describe() {
|
||||||
|
return "Adding Composting Recipe using " + item.getUnlocalizedName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeUndo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getOverrideKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void undo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -43,14 +77,41 @@ public class Compost {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Removes a recipe, will always remove the key, so all should be good
|
//Removes a recipe, will always remove the key, so all should be good
|
||||||
private static class Remove extends BaseMapRemoval {
|
private static class Remove implements IUndoableAction
|
||||||
|
{
|
||||||
|
private ItemStack stack;
|
||||||
|
|
||||||
public Remove(ItemStack stack) {
|
public Remove(ItemStack stack) {
|
||||||
super("ExNihilo Composting", CompostRegistry.entries, stack.getItem() + ":" + stack.getItemDamage(), stack);
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRecipeInfo() {
|
public void apply() {
|
||||||
return ((ItemStack) stack).getDisplayName();
|
CompostRegistry.unregister(stack.getItem(), stack.getItemDamage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUndo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describe() {
|
||||||
|
return "Removing Composting Recipe using " + stack.getUnlocalizedName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String describeUndo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getOverrideKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void undo() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package modtweaker2.mods.exnihilo.handlers;
|
||||||
import static modtweaker2.helpers.InputHelper.isABlock;
|
import static modtweaker2.helpers.InputHelper.isABlock;
|
||||||
import static modtweaker2.helpers.InputHelper.toFluid;
|
import static modtweaker2.helpers.InputHelper.toFluid;
|
||||||
import static modtweaker2.helpers.InputHelper.toStack;
|
import static modtweaker2.helpers.InputHelper.toStack;
|
||||||
|
import minetweaker.IUndoableAction;
|
||||||
import minetweaker.MineTweakerAPI;
|
import minetweaker.MineTweakerAPI;
|
||||||
import minetweaker.api.item.IItemStack;
|
import minetweaker.api.item.IItemStack;
|
||||||
import minetweaker.api.liquid.ILiquidStack;
|
import minetweaker.api.liquid.ILiquidStack;
|
||||||
|
@ -14,7 +15,6 @@ import stanhebben.zenscript.annotations.ZenClass;
|
||||||
import stanhebben.zenscript.annotations.ZenMethod;
|
import stanhebben.zenscript.annotations.ZenMethod;
|
||||||
import exnihilo.registries.CrucibleRegistry;
|
import exnihilo.registries.CrucibleRegistry;
|
||||||
import exnihilo.registries.HeatRegistry;
|
import exnihilo.registries.HeatRegistry;
|
||||||
import exnihilo.registries.helpers.HeatSource;
|
|
||||||
import exnihilo.registries.helpers.Meltable;
|
import exnihilo.registries.helpers.Meltable;
|
||||||
|
|
||||||
@ZenClass("mods.exnihilo.Crucible")
|
@ZenClass("mods.exnihilo.Crucible")
|
||||||
|
@ -72,21 +72,47 @@ public class Crucible {
|
||||||
if (isABlock(input)) {
|
if (isABlock(input)) {
|
||||||
Block theBlock = Block.getBlockFromItem(toStack(input).getItem());
|
Block theBlock = Block.getBlockFromItem(toStack(input).getItem());
|
||||||
int theMeta = toStack(input).getItemDamage();
|
int theMeta = toStack(input).getItemDamage();
|
||||||
MineTweakerAPI.apply(new AddHeatSource(new HeatSource(theBlock, theMeta, (float) value)));
|
MineTweakerAPI.apply(new AddHeatSource(theBlock, theMeta, (float) value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Passes the list to the base map implementation, and adds the recipe
|
//Passes the list to the base map implementation, and adds the recipe
|
||||||
private static class AddHeatSource extends BaseMapAddition {
|
private static class AddHeatSource implements IUndoableAction
|
||||||
public AddHeatSource(HeatSource recipe) {
|
{
|
||||||
super("ExNihilo Crucible - Heat Source", HeatRegistry.entries, recipe.block + ":" + recipe.meta, recipe);
|
Block source;
|
||||||
}
|
int sourceMeta;
|
||||||
|
float value;
|
||||||
|
|
||||||
|
public AddHeatSource(Block source, int sourceMeta, float value) {
|
||||||
|
this.source = source;
|
||||||
|
this.sourceMeta = sourceMeta;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply() {
|
||||||
|
HeatRegistry.register(source, sourceMeta, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canUndo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String describe() {
|
||||||
|
return "Adding ExNihilo Heat source of " + source.getLocalizedName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String describeUndo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getOverrideKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void undo() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRecipeInfo() {
|
|
||||||
return new ItemStack(((HeatSource) recipe).block, 1, ((HeatSource) recipe).meta).getDisplayName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -94,19 +120,41 @@ public class Crucible {
|
||||||
@ZenMethod
|
@ZenMethod
|
||||||
public static void removeHeatSource(IItemStack output) {
|
public static void removeHeatSource(IItemStack output) {
|
||||||
if (isABlock(output)) {
|
if (isABlock(output)) {
|
||||||
MineTweakerAPI.apply(new RemoveHeatSource(toStack(output)));
|
Block block = Block.getBlockFromItem(toStack(output).getItem());
|
||||||
|
MineTweakerAPI.apply(new RemoveHeatSource(block));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Removes a recipe, will always remove the key, so all should be good
|
//Removes a recipe, will always remove the key, so all should be good
|
||||||
private static class RemoveHeatSource extends BaseMapRemoval {
|
private static class RemoveHeatSource implements IUndoableAction
|
||||||
public RemoveHeatSource(ItemStack stack) {
|
{
|
||||||
super("ExNihilo Crucible - Heat Source", HeatRegistry.entries, Block.getBlockFromItem(stack.getItem()) + ":" + stack.getItemDamage(), stack);
|
Block block;
|
||||||
|
|
||||||
|
public RemoveHeatSource(Block block) {
|
||||||
|
this.block = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void apply() {
|
||||||
public String getRecipeInfo() {
|
HeatRegistry.unregister(block);
|
||||||
return ((ItemStack) stack).getDisplayName();
|
}
|
||||||
}
|
|
||||||
}
|
public boolean canUndo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String describe() {
|
||||||
|
return "Removing ExNihilo Heat source of " + block.getLocalizedName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String describeUndo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getOverrideKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void undo() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,13 @@ package modtweaker2.mods.exnihilo.handlers;
|
||||||
import static modtweaker2.helpers.InputHelper.isABlock;
|
import static modtweaker2.helpers.InputHelper.isABlock;
|
||||||
import static modtweaker2.helpers.InputHelper.toStack;
|
import static modtweaker2.helpers.InputHelper.toStack;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.List;
|
||||||
|
|
||||||
|
import minetweaker.IUndoableAction;
|
||||||
import minetweaker.MineTweakerAPI;
|
import minetweaker.MineTweakerAPI;
|
||||||
import minetweaker.api.item.IItemStack;
|
import minetweaker.api.item.IItemStack;
|
||||||
import modtweaker2.utils.BaseListAddition;
|
|
||||||
import modtweaker2.utils.BaseListRemoval;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import stanhebben.zenscript.annotations.ZenClass;
|
import stanhebben.zenscript.annotations.ZenClass;
|
||||||
import stanhebben.zenscript.annotations.ZenMethod;
|
import stanhebben.zenscript.annotations.ZenMethod;
|
||||||
|
@ -25,19 +24,50 @@ public class Hammer {
|
||||||
if (isABlock(input)) {
|
if (isABlock(input)) {
|
||||||
Block theBlock = Block.getBlockFromItem(toStack(input).getItem());
|
Block theBlock = Block.getBlockFromItem(toStack(input).getItem());
|
||||||
int theMeta = toStack(input).getItemDamage();
|
int theMeta = toStack(input).getItemDamage();
|
||||||
MineTweakerAPI.apply(new Add(new Smashable(theBlock, theMeta, toStack(output).getItem(), toStack(output).getItemDamage(), (float) chance, (float) luck)));
|
MineTweakerAPI.apply(new Add(theBlock, theMeta, toStack(output).getItem(), toStack(output).getItemDamage(), (float) chance, (float) luck));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Passes the list to the base list implementation, and adds the recipe
|
// Passes the list to the base list implementation, and adds the recipe
|
||||||
private static class Add extends BaseListAddition {
|
private static class Add implements IUndoableAction {
|
||||||
public Add(Smashable recipe) {
|
|
||||||
super("ExNihilo Hammer", HammerRegistry.rewards, recipe);
|
Block block;
|
||||||
|
int blockMeta;
|
||||||
|
Item output;
|
||||||
|
int outputMeta;
|
||||||
|
float chance;
|
||||||
|
float luck;
|
||||||
|
|
||||||
|
public Add(Block block, int blockMeta, Item output, int outputMeta, float chance, float luck) {
|
||||||
|
this.block = block;
|
||||||
|
this.blockMeta = blockMeta;
|
||||||
|
this.output = output;
|
||||||
|
this.outputMeta = outputMeta;
|
||||||
|
this.chance = chance;
|
||||||
|
this.luck = luck;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void apply() {
|
||||||
public String getRecipeInfo() {
|
HammerRegistry.register(block, blockMeta, output, outputMeta, chance, luck);
|
||||||
return new ItemStack(((Smashable) recipe).source, 1, ((Smashable) recipe).sourceMeta).getDisplayName();
|
}
|
||||||
|
|
||||||
|
public boolean canUndo() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String describe() {
|
||||||
|
return "Adding ExNihilo Hammer recipe by mining " + block.getLocalizedName() + " to get the result of " + output.getUnlocalizedName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String describeUndo() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getOverrideKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void undo() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,40 +81,44 @@ public class Hammer {
|
||||||
|
|
||||||
// Removes a recipe, apply is never the same for anything, so will always
|
// Removes a recipe, apply is never the same for anything, so will always
|
||||||
// need to override it
|
// need to override it
|
||||||
private static class Remove extends BaseListRemoval {
|
private static class Remove implements IUndoableAction {
|
||||||
|
ItemStack stack;
|
||||||
|
|
||||||
public Remove(ItemStack stack) {
|
public Remove(ItemStack stack) {
|
||||||
super("ExNihilo Hammer", HammerRegistry.rewards, stack);
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loops through the registry, to find the item that matches, saves that
|
// Loops through the registry, to find the item that matches, saves that
|
||||||
// recipe then removes it
|
// recipe then removes it
|
||||||
@Override
|
public void apply(){
|
||||||
public void apply() {
|
List<Smashable> smashables = HammerRegistry.rewards;
|
||||||
boolean found = false;
|
for(int i = 0; i < smashables.size(); i++){
|
||||||
Iterator<Smashable> smashables = HammerRegistry.rewards.iterator();
|
Smashable smash = smashables.get(i);
|
||||||
while (!found && smashables.hasNext()) {
|
if (smash != null && smash.source != null && Block.getBlockFromItem(stack.getItem()) != null)
|
||||||
|
if (smash.source == Block.getBlockFromItem(stack.getItem())){
|
||||||
Smashable reward = smashables.next();
|
HammerRegistry.rewards.remove(smash);
|
||||||
if (reward != null && reward.source != null && Block.getBlockFromItem(stack.getItem()) != null)
|
return;
|
||||||
if (reward.source == Block.getBlockFromItem(stack.getItem())) {
|
|
||||||
reward.source = Blocks.air;
|
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (Smashable r : HammerRegistry.rewards.) {
|
|
||||||
// ItemStack check = new ItemStack(r.item, 1, r.meta);
|
|
||||||
// if (check != null && areEqual(check, stack)) {
|
|
||||||
// recipe = r;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public boolean canUndo() {
|
||||||
public String getRecipeInfo() {
|
return false;
|
||||||
return stack.getDisplayName();
|
}
|
||||||
|
|
||||||
|
public String describe() {
|
||||||
|
return "Removing ExNihilo Hammer recipe of obtaining " + stack.getUnlocalizedName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String describeUndo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getOverrideKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void undo() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,20 +47,17 @@ public class Sieve {
|
||||||
|
|
||||||
public void apply() {
|
public void apply() {
|
||||||
SieveRegistry.register(source, sourceMeta, output, outputMeta, rarity);
|
SieveRegistry.register(source, sourceMeta, output, outputMeta, rarity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canUndo() {
|
public boolean canUndo() {
|
||||||
return source != null && output != null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String describe() {
|
public String describe() {
|
||||||
return "Adding ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName();
|
return "Adding ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String describeUndo()
|
public String describeUndo() {
|
||||||
{
|
|
||||||
return "Removing ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName();
|
return "Removing ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,8 +66,6 @@ public class Sieve {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void undo() {
|
public void undo() {
|
||||||
if(this.canUndo())
|
|
||||||
SieveRegistry.unregisterReward(this.source, this.sourceMeta, this.output, this.outputMeta);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,12 +124,11 @@ public class Sieve {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canUndo() {
|
public boolean canUndo() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String describe() {
|
public String describe() {
|
||||||
return "Removing ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName();
|
return "Removing ExNihilo Sieve Recipe using " + source.getLocalizedName() + " to get the result of " + output.getUnlocalizedName();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String describeUndo() {
|
public String describeUndo() {
|
||||||
|
|
Loading…
Reference in a new issue