|
| 1 | +package modtweaker2.mods.botanicaladdons.handlers; |
| 2 | + |
| 3 | + |
| 4 | +import minetweaker.MineTweakerAPI; |
| 5 | +import minetweaker.api.item.IItemStack; |
| 6 | +import modtweaker2.helpers.InputHelper; |
| 7 | +import modtweaker2.helpers.LogHelper; |
| 8 | +import modtweaker2.utils.BaseListAddition; |
| 9 | +import modtweaker2.utils.BaseListRemoval; |
| 10 | +import net.minecraft.block.Block; |
| 11 | +import net.minecraft.item.ItemStack; |
| 12 | +import ninja.shadowfox.shadowfox_botany.api.ShadowFoxAPI; |
| 13 | +import ninja.shadowfox.shadowfox_botany.api.trees.IIridescentSaplingVariant; |
| 14 | +import ninja.shadowfox.shadowfox_botany.api.trees.IridescentSaplingBaseVariant; |
| 15 | +import stanhebben.zenscript.annotations.ZenClass; |
| 16 | +import stanhebben.zenscript.annotations.ZenMethod; |
| 17 | + |
| 18 | +import java.util.LinkedList; |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +@ZenClass("mods.botanicaladdons.IridescentTree") |
| 22 | +public class IridescentTree { |
| 23 | + |
| 24 | + protected static final String name = "Botanical Addons Iridescent Tree"; |
| 25 | + |
| 26 | + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 27 | + |
| 28 | + @ZenMethod |
| 29 | + public static void addVariant(IItemStack blockSoil, IItemStack blockWood, IItemStack blockLeaves, int metaMin, int metaMax, int metaShift) { |
| 30 | + Object soil = InputHelper.toObject(blockSoil); |
| 31 | + Object wood = InputHelper.toObject(blockWood); |
| 32 | + Object leaves = InputHelper.toObject(blockLeaves); |
| 33 | + if (soil == null || !(soil instanceof ItemStack) || !InputHelper.isABlock((ItemStack)soil)) { |
| 34 | + LogHelper.logError("Soil must be a block."); |
| 35 | + return; |
| 36 | + } |
| 37 | + else if (wood == null || !(wood instanceof ItemStack) || !InputHelper.isABlock((ItemStack)wood)) { |
| 38 | + LogHelper.logError("Wood must be a block."); |
| 39 | + return; |
| 40 | + } |
| 41 | + else if(leaves == null || !(leaves instanceof ItemStack) || !InputHelper.isABlock((ItemStack)leaves)) { |
| 42 | + LogHelper.logError("Leaves must be a block."); |
| 43 | + return; |
| 44 | + } |
| 45 | + Block soilBlock = Block.getBlockFromItem(((ItemStack)soil).getItem()); |
| 46 | + Block woodBlock = Block.getBlockFromItem(((ItemStack)wood).getItem()); |
| 47 | + Block leavesBlock = Block.getBlockFromItem(((ItemStack)leaves).getItem()); |
| 48 | + MineTweakerAPI.apply(new Add(new IridescentSaplingBaseVariant(soilBlock, woodBlock, leavesBlock, metaMin, metaMax, metaShift))); |
| 49 | + } |
| 50 | + |
| 51 | + @ZenMethod |
| 52 | + public static void addVariant(IItemStack blockSoil, IItemStack blockWood, IItemStack blockLeaves, int metaMin, int metaMax) { |
| 53 | + addVariant(blockSoil, blockWood, blockLeaves, metaMin, metaMax, 0); |
| 54 | + } |
| 55 | + |
| 56 | + @ZenMethod |
| 57 | + public static void addVariant(IItemStack blockSoil, IItemStack blockWood, IItemStack blockLeaves, int meta) { |
| 58 | + addVariant(blockSoil, blockWood, blockLeaves, meta, meta, 0); |
| 59 | + } |
| 60 | + |
| 61 | + @ZenMethod |
| 62 | + public static void addVariant(IItemStack blockSoil, IItemStack blockWood, IItemStack blockLeaves) { |
| 63 | + addVariant(blockSoil, blockWood, blockLeaves, 0, 15, 0); |
| 64 | + } |
| 65 | + |
| 66 | + private static class Add extends BaseListAddition<IIridescentSaplingVariant> { |
| 67 | + public Add(IIridescentSaplingVariant recipe) { |
| 68 | + super(IridescentTree.name, ShadowFoxAPI.treeVariants); |
| 69 | + |
| 70 | + recipes.add(recipe); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public String getRecipeInfo(IIridescentSaplingVariant recipe) { |
| 75 | + return LogHelper.getStackDescription(new ItemStack(recipe.getAcceptableSoils().get(0))); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 80 | + |
| 81 | + @ZenMethod |
| 82 | + public static void removeRecipe(IItemStack blockSoil) { |
| 83 | + // Get list of existing recipes, matching with parameter |
| 84 | + |
| 85 | + Object soil = InputHelper.toObject(blockSoil); |
| 86 | + if (soil == null || !(soil instanceof ItemStack) || !InputHelper.isABlock((ItemStack)soil)) { |
| 87 | + LogHelper.logError("Soil must be a block."); |
| 88 | + return; |
| 89 | + } |
| 90 | + Block soilBlock = Block.getBlockFromItem(((ItemStack)soil).getItem()); |
| 91 | + |
| 92 | + List<IIridescentSaplingVariant> recipes = new LinkedList<IIridescentSaplingVariant>(); |
| 93 | + |
| 94 | + for (IIridescentSaplingVariant r : ShadowFoxAPI.treeVariants) { |
| 95 | + if (r != null && r instanceof IridescentSaplingBaseVariant && r.getAcceptableSoils().get(0) == soilBlock) { |
| 96 | + recipes.add(r); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + // Check if we found the recipes and apply the action |
| 101 | + if(!recipes.isEmpty()) { |
| 102 | + MineTweakerAPI.apply(new Remove(recipes)); |
| 103 | + } else { |
| 104 | + LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", IridescentTree.name, soilBlock.toString())); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + private static class Remove extends BaseListRemoval<IIridescentSaplingVariant> { |
| 109 | + public Remove(List<IIridescentSaplingVariant> recipes) { |
| 110 | + super(IridescentTree.name, ShadowFoxAPI.treeVariants, recipes); |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public String getRecipeInfo(IIridescentSaplingVariant recipe) { |
| 115 | + return LogHelper.getStackDescription(new ItemStack(recipe.getAcceptableSoils().get(0))); |
| 116 | + } |
| 117 | + } |
| 118 | +} |
| 119 | + |
0 commit comments