From 69d066d25a48f585f9b4b7fa3540fda8cac3801b Mon Sep 17 00:00:00 2001 From: temp1011 <34900092+temp1011@users.noreply.github.com> Date: Sat, 8 Sep 2018 22:12:03 +0100 Subject: [PATCH 1/3] add modtweaker methods for charcoal pit --- .../compat/forestry/CharcoalPile.java | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/main/java/com/blamejared/compat/forestry/CharcoalPile.java diff --git a/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java b/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java new file mode 100644 index 0000000..a007ecf --- /dev/null +++ b/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java @@ -0,0 +1,155 @@ +package com.blamejared.compat.forestry; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; + +import forestry.api.arboriculture.ICharcoalManager; +import forestry.api.arboriculture.TreeManager; + +import com.blamejared.ModTweaker; +import com.blamejared.mtlib.utils.BaseAction; +import crafttweaker.CraftTweakerAPI; +import crafttweaker.annotations.ModOnly; +import crafttweaker.annotations.ZenRegister; +import crafttweaker.api.block.IBlock; +import crafttweaker.api.item.IItemStack; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.forestry.Carpenter") +@ModOnly("forestry") +@ZenRegister +public class CharcoalPile { + + public static final String NAME = "Forestry Charcoal Piles"; + + @ZenMethod + public static void addPile(IBlock block, int amount) { + ModTweaker.LATE_ADDITIONS.add(new Add(asBlock(block), amount)); + } + + @ZenMethod + public static void addPileState(crafttweaker.api.block.IBlockState state, int amount) { + ModTweaker.LATE_ADDITIONS.add(new Add(asBlockState(state), amount)); + } + + @ZenMethod + public static void addPileStack(IItemStack stack, int amount) { + ModTweaker.LATE_ADDITIONS.add(new Add(asBlock(stack.asBlock()), amount)); + } + + private static class Add extends BaseCharcoal { + + private int amount; + + protected Add(Block block, int amount) { + super(block); + this.amount = amount; + } + + protected Add(IBlockState state, int amount) { + super(state); + this.amount = amount; + } + + @Override + public void apply() { + if (manager == null) { + CraftTweakerAPI.logError("Charcoal manager is null, probably the charcoal module is not enabled"); + return; + } + if (block != null) { + manager.registerWall(block, amount); + } else if (state != null) { + manager.registerWall(state, amount); + } else { + CraftTweakerAPI.logError("Both block and blockstate were null, no wall registered"); + } + } + } + + @ZenMethod + public static void removePile(IBlock block) { + ModTweaker.LATE_REMOVALS.add(new Remove(asBlock(block))); + } + + @ZenMethod + public static void removePileState(crafttweaker.api.block.IBlockState state) { + ModTweaker.LATE_REMOVALS.add(new Remove(asBlockState(state))); + } + + @ZenMethod + public static void removePileStack(IItemStack stack) { + ModTweaker.LATE_REMOVALS.add(new Remove(asBlock(stack.asBlock()))); + } + + private static class Remove extends BaseCharcoal { + + protected Remove(Block block) { + super(block); + } + + protected Remove(IBlockState state) { + super(state); + } + + @Override + public void apply() { + if (manager == null) { + CraftTweakerAPI.logError("Charcoal manager is null, probably the charcoal module is not enabled"); + return; + } + boolean success = false; + if (block != null) { + success = manager.removeWall(block); + } else if (state != null) { + success = manager.removeWall(state); + } else { + CraftTweakerAPI.logError("Both block and blockstate were null, no wall removed"); + } + if (!success) { + CraftTweakerAPI.logError("Removing wall was not successful"); + } + } + } + + private static class BaseCharcoal extends BaseAction { + + protected static ICharcoalManager manager = TreeManager.charcoalManager; + protected Block block; + protected IBlockState state; + + protected BaseCharcoal(Block block) { + super(CharcoalPile.NAME); + this.block = block; + } + + protected BaseCharcoal(IBlockState state) { + super(CharcoalPile.NAME); + this.state = state; + } + + @Override + public void apply() { + + } + } + + + // helpers, here for now + private static Block asBlock(IBlock block) { + Object internal = block.getDefinition().getInternal(); + if (!(internal instanceof Block)) { + CraftTweakerAPI.logError("Not a valid block: " + block); + } + return (Block) internal; + } + + private static IBlockState asBlockState(crafttweaker.api.block.IBlockState blockstate) { + Object internal = blockstate.getInternal(); + if (!(internal instanceof IBlockState)) { + CraftTweakerAPI.logError("Not a valid blockstate: " + blockstate); + } + return (IBlockState) internal; + } +} From 7ec926ca7cff8d3f6e9cb7d7b23d3b960c58dd6b Mon Sep 17 00:00:00 2001 From: temp1011 Date: Sun, 9 Sep 2018 14:37:53 +0100 Subject: [PATCH 2/3] fix crashes and add docs --- build.gradle | 4 +- .../compat/forestry/CharcoalPile.java | 63 +++++++++++++++---- 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index b431043..b8a6431 100644 --- a/build.gradle +++ b/build.gradle @@ -51,7 +51,7 @@ repositories { url "http://maven.tterrag.com" } maven { - url "https://dl.bintray.com/raoulvdberge/dev/" + url "https://repo.raoulvdberge.com/" } maven { url = "http://maven.thiakil.com" @@ -93,7 +93,7 @@ dependencies { } deobfCompile "team.chisel.ctm:CTM:MC1.12-0.2.3.12" - deobfCompile("refinedstorage:refinedstorage:1.5.32-1498") { + deobfCompile("refinedstorage:refinedstorage:1.6.5-283") { exclude group: 'mezz.jei' } deobfCompile("knightminer.tcomplement:TinkersComplement:1.12.1-0.2.1.3") { diff --git a/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java b/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java index a007ecf..8ee79f0 100644 --- a/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java +++ b/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java @@ -1,5 +1,7 @@ package com.blamejared.compat.forestry; +import javax.annotation.Nullable; + import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -16,31 +18,47 @@ import crafttweaker.api.item.IItemStack; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; -@ZenClass("mods.forestry.Carpenter") +@ZenClass("mods.forestry.CharcoalWall") @ModOnly("forestry") @ZenRegister public class CharcoalPile { - public static final String NAME = "Forestry Charcoal Piles"; + public static final String NAME = "Forestry Charcoal Wall"; + /** + * add a charcoal wall for the given {@link IBlock} + * @param block the block for the wall + * @param amount the amount of charcoal the wall provides + */ @ZenMethod - public static void addPile(IBlock block, int amount) { + public static void addWall(IBlock block, int amount) { ModTweaker.LATE_ADDITIONS.add(new Add(asBlock(block), amount)); } + /** + * add a charcoal wall for the given {@link crafttweaker.api.block.IBlockState} + * @param state the state for the wall (more specific than just a block) + * @param amount the amount of charcoal the wall provides + */ @ZenMethod - public static void addPileState(crafttweaker.api.block.IBlockState state, int amount) { + public static void addWallState(crafttweaker.api.block.IBlockState state, int amount) { ModTweaker.LATE_ADDITIONS.add(new Add(asBlockState(state), amount)); } + /** + * add a charcoal wall for the block corresponding {@link IItemStack} + * will fail if the stack can't be converted to a block + * @param stack the stack form of the wall + * @param amount the amount of charcoal the wall provides + */ @ZenMethod - public static void addPileStack(IItemStack stack, int amount) { + public static void addWallStack(IItemStack stack, int amount) { ModTweaker.LATE_ADDITIONS.add(new Add(asBlock(stack.asBlock()), amount)); } private static class Add extends BaseCharcoal { - private int amount; + private final int amount; protected Add(Block block, int amount) { super(block); @@ -68,18 +86,31 @@ public class CharcoalPile { } } + /** + * Removes the first wall that matches the given {@link IBlock} + * @param block the block to match + */ @ZenMethod - public static void removePile(IBlock block) { + public static void removeWall(IBlock block) { ModTweaker.LATE_REMOVALS.add(new Remove(asBlock(block))); } + /** + * Removes the first wall that matches the given {@link crafttweaker.api.block.IBlockState} + * @param state the state to match + */ @ZenMethod - public static void removePileState(crafttweaker.api.block.IBlockState state) { + public static void removeWallState(crafttweaker.api.block.IBlockState state) { ModTweaker.LATE_REMOVALS.add(new Remove(asBlockState(state))); } + /** + * Removes the first wall that matches the block given by the {@link IItemStack} + * Will fail if the stack can't be converted to a block + * @param stack the stack to match + */ @ZenMethod - public static void removePileStack(IItemStack stack) { + public static void removeWallStack(IItemStack stack) { ModTweaker.LATE_REMOVALS.add(new Remove(asBlock(stack.asBlock()))); } @@ -115,40 +146,46 @@ public class CharcoalPile { private static class BaseCharcoal extends BaseAction { - protected static ICharcoalManager manager = TreeManager.charcoalManager; - protected Block block; - protected IBlockState state; + protected static final ICharcoalManager manager = TreeManager.charcoalManager; + protected final Block block; + protected final IBlockState state; protected BaseCharcoal(Block block) { super(CharcoalPile.NAME); this.block = block; + this.state = null; } protected BaseCharcoal(IBlockState state) { super(CharcoalPile.NAME); this.state = state; + this.block = null; } @Override public void apply() { - + CraftTweakerAPI.logError("BaseCharcoal.apply() is not implemented"); } } // helpers, here for now + @Nullable private static Block asBlock(IBlock block) { Object internal = block.getDefinition().getInternal(); if (!(internal instanceof Block)) { CraftTweakerAPI.logError("Not a valid block: " + block); + return null; } return (Block) internal; } + @Nullable private static IBlockState asBlockState(crafttweaker.api.block.IBlockState blockstate) { Object internal = blockstate.getInternal(); if (!(internal instanceof IBlockState)) { CraftTweakerAPI.logError("Not a valid blockstate: " + blockstate); + return null; } return (IBlockState) internal; } From d74e5f04373d649a062977b68e8a8d4ce6abd1c0 Mon Sep 17 00:00:00 2001 From: temp1011 Date: Wed, 12 Sep 2018 16:16:30 +0100 Subject: [PATCH 3/3] add method for converting IItemStack to Block --- .../blamejared/compat/forestry/CharcoalPile.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java b/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java index 8ee79f0..67f490f 100644 --- a/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java +++ b/src/main/java/com/blamejared/compat/forestry/CharcoalPile.java @@ -9,6 +9,7 @@ import forestry.api.arboriculture.ICharcoalManager; import forestry.api.arboriculture.TreeManager; import com.blamejared.ModTweaker; +import com.blamejared.mtlib.helpers.InputHelper; import com.blamejared.mtlib.utils.BaseAction; import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ModOnly; @@ -53,7 +54,7 @@ public class CharcoalPile { */ @ZenMethod public static void addWallStack(IItemStack stack, int amount) { - ModTweaker.LATE_ADDITIONS.add(new Add(asBlock(stack.asBlock()), amount)); + ModTweaker.LATE_ADDITIONS.add(new Add(asBlock(stack), amount)); } private static class Add extends BaseCharcoal { @@ -111,7 +112,7 @@ public class CharcoalPile { */ @ZenMethod public static void removeWallStack(IItemStack stack) { - ModTweaker.LATE_REMOVALS.add(new Remove(asBlock(stack.asBlock()))); + ModTweaker.LATE_REMOVALS.add(new Remove(asBlock(stack))); } private static class Remove extends BaseCharcoal { @@ -189,4 +190,13 @@ public class CharcoalPile { } return (IBlockState) internal; } + + @Nullable + private static Block asBlock(IItemStack stack) { + if(!InputHelper.isABlock(stack)) { + CraftTweakerAPI.logError("Not a valid block: " + stack.getDisplayName()); + return null; + } + return asBlock(stack.asBlock()); + } }