From 0e4713115500fc8d8ab3a099ad64fd7b8f3330ea Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Tue, 13 Jan 2015 03:06:06 -0500 Subject: [PATCH 1/4] Start NEI handling. Unfinished. --- src/main/java/com/cricketcraft/chisel/Features.java | 8 ++++---- .../java/com/cricketcraft/chisel/carving/Carving.java | 5 +++++ .../com/cricketcraft/chisel/carving/CarvingGroup.java | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cricketcraft/chisel/Features.java b/src/main/java/com/cricketcraft/chisel/Features.java index b916e08a..946b1f50 100644 --- a/src/main/java/com/cricketcraft/chisel/Features.java +++ b/src/main/java/com/cricketcraft/chisel/Features.java @@ -2514,19 +2514,19 @@ public enum Features { private String requiredMod; - Features() { + private Features() { this(null, null); } - Features(Features parent) { + private Features(Features parent) { this(null, parent); } - Features(String requiredMod) { + private Features(String requiredMod) { this(requiredMod, null); } - Features(String requriedMod, Features parent) { + private Features(String requriedMod, Features parent) { this.requiredMod = requriedMod; this.parent = parent; } diff --git a/src/main/java/com/cricketcraft/chisel/carving/Carving.java b/src/main/java/com/cricketcraft/chisel/carving/Carving.java index 3fb0e5dd..1d6d7e17 100644 --- a/src/main/java/com/cricketcraft/chisel/carving/Carving.java +++ b/src/main/java/com/cricketcraft/chisel/carving/Carving.java @@ -1,6 +1,7 @@ package com.cricketcraft.chisel.carving; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -179,4 +180,8 @@ public class Carving { return blockGroup.sound; } + + public Collection getGroups() { + return carvingGroupsByVariation.values(); + } } diff --git a/src/main/java/com/cricketcraft/chisel/carving/CarvingGroup.java b/src/main/java/com/cricketcraft/chisel/carving/CarvingGroup.java index 90507d54..73e4c10d 100644 --- a/src/main/java/com/cricketcraft/chisel/carving/CarvingGroup.java +++ b/src/main/java/com/cricketcraft/chisel/carving/CarvingGroup.java @@ -3,6 +3,8 @@ package com.cricketcraft.chisel.carving; import java.util.ArrayList; import java.util.List; +import com.google.common.collect.ImmutableList; + public class CarvingGroup { public CarvingGroup(String n) { @@ -15,4 +17,8 @@ public class CarvingGroup { String oreName; List variations = new ArrayList(); + + public List getVariations() { + return ImmutableList.copyOf(variations); + } } \ No newline at end of file From 54514b6b721ff273d74ccd2770a86d4671deb4de Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Tue, 13 Jan 2015 03:07:32 -0500 Subject: [PATCH 2/4] Add NEI handler class --- .../compat/nei/RecipeHandlerChisel.java | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/main/java/com/cricketcraft/chisel/compat/nei/RecipeHandlerChisel.java diff --git a/src/main/java/com/cricketcraft/chisel/compat/nei/RecipeHandlerChisel.java b/src/main/java/com/cricketcraft/chisel/compat/nei/RecipeHandlerChisel.java new file mode 100644 index 00000000..272a09dc --- /dev/null +++ b/src/main/java/com/cricketcraft/chisel/compat/nei/RecipeHandlerChisel.java @@ -0,0 +1,105 @@ +package com.cricketcraft.chisel.compat.nei; + +import java.awt.Rectangle; +import java.util.List; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; + +import org.lwjgl.opengl.GL11; + +import codechicken.lib.gui.GuiDraw; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.TemplateRecipeHandler; + +import com.cricketcraft.chisel.carving.Carving; +import com.cricketcraft.chisel.carving.CarvingGroup; +import com.cricketcraft.chisel.carving.CarvingVariation; +import com.cricketcraft.chisel.client.gui.GuiChisel; +import com.google.common.collect.Lists; + +public class RecipeHandlerChisel extends TemplateRecipeHandler { + + @Override + public String getRecipeName() { + return "Chiseling"; + } + + @Override + public String getGuiTexture() { + return "Chisel:textures/chisel2Gui.png"; + } + + public PositionedStack getResult() { + return null; + } + + @Override + public Class getGuiClass() { + return GuiChisel.class; + } + + @Override + public String getOverlayIdentifier() { + return "EnderIOSagMill"; + } + + @Override + public void loadTransferRects() { + transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(149, 32, 16, 16), "ChiselRecipes", new Object[0])); + } + + public void loadCraftingRecipes(String outputId, Object... results) { + // is this right? idk + for (CarvingGroup g : Carving.chisel.getGroups()) { + arecipes.add(new CachedChiselRecipe(g)); + } + } + + @Override + public void loadCraftingRecipes(final ItemStack result) { + // unfinished + } + + @Override + public void loadUsageRecipes(ItemStack ingredient) { + // unfinished + } + + @Override + public void drawBackground(int recipeIndex) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GuiDraw.changeTexture(getGuiTexture()); + GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 166, 65); + } + + public class CachedChiselRecipe extends TemplateRecipeHandler.CachedRecipe { + + private PositionedStack input; + private List outputs; + + @Override + public List getIngredients() { + return Lists.newArrayList(input); + } + + @Override + public PositionedStack getResult() { + return outputs.size() > 0 ? outputs.get(0) : null; + } + + public CachedChiselRecipe(CarvingGroup group) { + this.outputs = Lists.newArrayList(); + for (CarvingVariation v : group.getVariations()) { + if (this.input == null) { + this.input = new PositionedStack(stack(v), 10, 10); + } + outputs.add(new PositionedStack(stack(v), 50, 10)); + } + } + + private ItemStack stack(CarvingVariation v) { + return new ItemStack(v.block, 1, v.damage); + } + } +} \ No newline at end of file From 93465884ab7fd474aa3593984a8305be7649bc1b Mon Sep 17 00:00:00 2001 From: Tonius Date: Wed, 14 Jan 2015 11:10:29 +0100 Subject: [PATCH 3/4] Un-hardcoded smooth stone chiseling and made it configurable --- src/main/java/com/cricketcraft/chisel/Features.java | 2 ++ src/main/java/com/cricketcraft/chisel/carving/Carving.java | 3 --- .../java/com/cricketcraft/chisel/config/Configurations.java | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cricketcraft/chisel/Features.java b/src/main/java/com/cricketcraft/chisel/Features.java index 946b1f50..8eca5f10 100644 --- a/src/main/java/com/cricketcraft/chisel/Features.java +++ b/src/main/java/com/cricketcraft/chisel/Features.java @@ -2021,6 +2021,8 @@ public enum Features { void addBlocks() { BlockCarvable stonebricksmooth = (BlockCarvable) new BlockCarvable(Material.rock).setCreativeTab(ChiselTabs.tabStoneChiselBlocks).setHardness(1.5F).setResistance(10.0F) .setStepSound(Block.soundTypeStone); + if (Configurations.allowSmoothStone) + Carving.chisel.addVariation("stonebricksmooth", Blocks.stone, 0, -1); for (int i = 0; i < 4; i++) { if (i == 1) { if (Configurations.allowMossy) diff --git a/src/main/java/com/cricketcraft/chisel/carving/Carving.java b/src/main/java/com/cricketcraft/chisel/carving/Carving.java index 1d6d7e17..1d39af2e 100644 --- a/src/main/java/com/cricketcraft/chisel/carving/Carving.java +++ b/src/main/java/com/cricketcraft/chisel/carving/Carving.java @@ -100,9 +100,6 @@ public class Carving { } public CarvingGroup getGroup(Block block, int metadata) { - if (block.equals(Blocks.stone)) - block = Blocks.stonebrick; - // Check name first CarvingGroup res; int i = OreDictionary.getOreID(block.getUnlocalizedName()); diff --git a/src/main/java/com/cricketcraft/chisel/config/Configurations.java b/src/main/java/com/cricketcraft/chisel/config/Configurations.java index 06b9d95a..dfb63382 100644 --- a/src/main/java/com/cricketcraft/chisel/config/Configurations.java +++ b/src/main/java/com/cricketcraft/chisel/config/Configurations.java @@ -18,6 +18,7 @@ public class Configurations { public static boolean ghostCloud; public static int factoryBlockAmount; public static boolean allowMossy; + public static boolean allowSmoothStone; public static boolean chiselRecipe; public static boolean enableFMP; public static boolean chiselStoneToCobbleBricks; @@ -54,6 +55,7 @@ public class Configurations { ghostCloud = config.get(category, "doesCloudRenderLikeGhost", true).getBoolean(true); factoryBlockAmount = config.get(category, "amountYouGetFromFactoryBlockCrafting", 32).getInt(32); allowMossy = config.get(category, "allowCobbleToMossyInChisel", true).getBoolean(true); + allowSmoothStone = config.get(category, "allowSmoothStoneToStoneBricksAndBack", true).getBoolean(true); chiselRecipe = config.get(category, "chiselAlternateRecipe", false, "Use alternative crafting recipe for the chisel").getBoolean(false); enableFMP = config.get(category, "enableFMP", true, "Do you want to enable FMP").getBoolean(true); chiselStoneToCobbleBricks = config.get(category, "chiselStoneToCobbleBricks", true, "Chisel stone to cobblestone and bricks by left clicking.").getBoolean(false); From bd9ee178139fed569459ed879951fad5d10fc05f Mon Sep 17 00:00:00 2001 From: Tonius Date: Wed, 14 Jan 2015 11:31:12 +0100 Subject: [PATCH 4/4] Fixed up NEI handler --- .../cricketcraft/chisel/carving/Carving.java | 14 +- .../chisel/carving/CarvingGroup.java | 13 +- .../chisel/carving/CarvingVariation.java | 6 + .../chisel/compat/nei/NEIChiselConfig.java | 27 +++ .../compat/nei/RecipeHandlerChisel.java | 211 ++++++++++++------ .../assets/chisel/textures/chiselNEI.png | Bin 0 -> 1882 bytes 6 files changed, 199 insertions(+), 72 deletions(-) create mode 100644 src/main/java/com/cricketcraft/chisel/compat/nei/NEIChiselConfig.java create mode 100644 src/main/resources/assets/chisel/textures/chiselNEI.png diff --git a/src/main/java/com/cricketcraft/chisel/carving/Carving.java b/src/main/java/com/cricketcraft/chisel/carving/Carving.java index 1d39af2e..05366412 100644 --- a/src/main/java/com/cricketcraft/chisel/carving/Carving.java +++ b/src/main/java/com/cricketcraft/chisel/carving/Carving.java @@ -1,12 +1,11 @@ package com.cricketcraft.chisel.carving; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.List; import net.minecraft.block.Block; -import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; @@ -121,7 +120,7 @@ public class Carving { return null; } - CarvingGroup getGroup(String name) { + public CarvingGroup getGroup(String name) { CarvingGroup group = carvingGroupsByName.get(name); if (group == null) { group = new CarvingGroup(name); @@ -178,7 +177,12 @@ public class Carving { return blockGroup.sound; } - public Collection getGroups() { - return carvingGroupsByVariation.values(); + public List getSortedGroupNames() { + List names = new ArrayList(); + for (String s : carvingGroupsByName.keySet()) { + names.add(s); + } + Collections.sort(names); + return names; } } diff --git a/src/main/java/com/cricketcraft/chisel/carving/CarvingGroup.java b/src/main/java/com/cricketcraft/chisel/carving/CarvingGroup.java index 73e4c10d..09c40808 100644 --- a/src/main/java/com/cricketcraft/chisel/carving/CarvingGroup.java +++ b/src/main/java/com/cricketcraft/chisel/carving/CarvingGroup.java @@ -17,8 +17,17 @@ public class CarvingGroup { String oreName; List variations = new ArrayList(); - + public List getVariations() { return ImmutableList.copyOf(variations); } -} \ No newline at end of file + + public String getName() { + return name; + } + + public String getOreName() { + return oreName; + } + +} diff --git a/src/main/java/com/cricketcraft/chisel/carving/CarvingVariation.java b/src/main/java/com/cricketcraft/chisel/carving/CarvingVariation.java index 20fa16ca..99da0f9e 100644 --- a/src/main/java/com/cricketcraft/chisel/carving/CarvingVariation.java +++ b/src/main/java/com/cricketcraft/chisel/carving/CarvingVariation.java @@ -1,6 +1,7 @@ package com.cricketcraft.chisel.carving; import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; public class CarvingVariation implements Comparable { @@ -20,4 +21,9 @@ public class CarvingVariation implements Comparable { public Block block; public int meta; public int damage; + + public ItemStack getStack() { + return new ItemStack(block, 1, damage); + } + } diff --git a/src/main/java/com/cricketcraft/chisel/compat/nei/NEIChiselConfig.java b/src/main/java/com/cricketcraft/chisel/compat/nei/NEIChiselConfig.java new file mode 100644 index 00000000..4e1a85fc --- /dev/null +++ b/src/main/java/com/cricketcraft/chisel/compat/nei/NEIChiselConfig.java @@ -0,0 +1,27 @@ +package com.cricketcraft.chisel.compat.nei; + +import com.cricketcraft.chisel.Chisel; + +import codechicken.nei.api.API; +import codechicken.nei.api.IConfigureNEI; + +public class NEIChiselConfig implements IConfigureNEI { + + @Override + public String getName() { + return Chisel.MOD_NAME; + } + + @Override + public String getVersion() { + return Chisel.VERSION; + } + + @Override + public void loadConfig() { + RecipeHandlerChisel handler = new RecipeHandlerChisel(); + API.registerRecipeHandler(handler); + API.registerUsageHandler(handler); + } + +} diff --git a/src/main/java/com/cricketcraft/chisel/compat/nei/RecipeHandlerChisel.java b/src/main/java/com/cricketcraft/chisel/compat/nei/RecipeHandlerChisel.java index 272a09dc..1fb59e3e 100644 --- a/src/main/java/com/cricketcraft/chisel/compat/nei/RecipeHandlerChisel.java +++ b/src/main/java/com/cricketcraft/chisel/compat/nei/RecipeHandlerChisel.java @@ -1,105 +1,186 @@ package com.cricketcraft.chisel.compat.nei; +import java.awt.Point; import java.awt.Rectangle; +import java.util.ArrayList; import java.util.List; -import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; import org.lwjgl.opengl.GL11; import codechicken.lib.gui.GuiDraw; +import codechicken.nei.NEIServerUtils; import codechicken.nei.PositionedStack; import codechicken.nei.recipe.TemplateRecipeHandler; import com.cricketcraft.chisel.carving.Carving; import com.cricketcraft.chisel.carving.CarvingGroup; import com.cricketcraft.chisel.carving.CarvingVariation; -import com.cricketcraft.chisel.client.gui.GuiChisel; -import com.google.common.collect.Lists; public class RecipeHandlerChisel extends TemplateRecipeHandler { + private static final int SLOTS_PER_PAGE = 45; + + public class CachedChiselRecipe extends CachedRecipe { + + private List input = new ArrayList(); + private List outputs = new ArrayList(); + public Point focus; + + public CachedChiselRecipe(List variations, ItemStack base, ItemStack focus) { + PositionedStack pStack = new PositionedStack(base != null ? base : variations, 74, 4); + pStack.setMaxSize(1); + this.input.add(pStack); + + int row = 0; + int col = 0; + for (ItemStack v : variations) { + this.outputs.add(new PositionedStack(v, 3 + 18 * col, 37 + 18 * row)); + + if (focus != null && NEIServerUtils.areStacksSameTypeCrafting(focus, v)) { + this.focus = new Point(2 + 18 * col, 36 + 18 * row); + } + + col++; + if (col > 8) { + col = 0; + row++; + } + } + } + + public CachedChiselRecipe(List variations) { + this(variations, null, null); + } + + @Override + public List getIngredients() { + return this.getCycledIngredients(cycleticks / 20, this.input); + } + + @Override + public List getOtherStacks() { + return this.outputs; + } + + @Override + public PositionedStack getResult() { + return null; + } + + } + @Override public String getRecipeName() { - return "Chiseling"; + return "Chisel"; } @Override public String getGuiTexture() { - return "Chisel:textures/chisel2Gui.png"; - } - - public PositionedStack getResult() { - return null; - } - - @Override - public Class getGuiClass() { - return GuiChisel.class; - } - - @Override - public String getOverlayIdentifier() { - return "EnderIOSagMill"; - } - - @Override - public void loadTransferRects() { - transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(149, 32, 16, 16), "ChiselRecipes", new Object[0])); - } - - public void loadCraftingRecipes(String outputId, Object... results) { - // is this right? idk - for (CarvingGroup g : Carving.chisel.getGroups()) { - arecipes.add(new CachedChiselRecipe(g)); - } - } - - @Override - public void loadCraftingRecipes(final ItemStack result) { - // unfinished - } - - @Override - public void loadUsageRecipes(ItemStack ingredient) { - // unfinished + return "Chisel:textures/chiselNEI.png"; } @Override public void drawBackground(int recipeIndex) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GuiDraw.changeTexture(getGuiTexture()); - GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 166, 65); + GuiDraw.drawTexturedModalRect(0, 0, 0, 0, 166, 130); + + Point focus = ((CachedChiselRecipe) this.arecipes.get(recipeIndex)).focus; + if (focus != null) { + GuiDraw.drawTexturedModalRect(focus.x, focus.y, 166, 0, 18, 18); + } } - public class CachedChiselRecipe extends TemplateRecipeHandler.CachedRecipe { + @Override + public int recipiesPerPage() { + return 1; + } - private PositionedStack input; - private List outputs; + @Override + public void loadTransferRects() { + this.transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(75, 22, 15, 13), "chisel2.chisel", new Object[0])); + } - @Override - public List getIngredients() { - return Lists.newArrayList(input); - } - - @Override - public PositionedStack getResult() { - return outputs.size() > 0 ? outputs.get(0) : null; - } - - public CachedChiselRecipe(CarvingGroup group) { - this.outputs = Lists.newArrayList(); - for (CarvingVariation v : group.getVariations()) { - if (this.input == null) { - this.input = new PositionedStack(stack(v), 10, 10); + public void loadCraftingRecipes(String outputId, Object... results) { + if (outputId.equals("chisel2.chisel")) { + for (String name : Carving.chisel.getSortedGroupNames()) { + CarvingGroup g = Carving.chisel.getGroup(name); + if (!g.getVariations().isEmpty()) { + addCached(getVariationStacks(g)); + } + } + } else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadCraftingRecipes(ItemStack result) { + for (String name : Carving.chisel.getSortedGroupNames()) { + CarvingGroup g = Carving.chisel.getGroup(name); + List variations = getVariationStacks(g); + for (ItemStack stack : variations) { + if (NEIServerUtils.areStacksSameTypeCrafting(stack, result)) { + addCached(variations, null, result); } - outputs.add(new PositionedStack(stack(v), 50, 10)); } } - - private ItemStack stack(CarvingVariation v) { - return new ItemStack(v.block, 1, v.damage); + } + + @Override + public void loadUsageRecipes(ItemStack ingredient) { + for (String name : Carving.chisel.getSortedGroupNames()) { + CarvingGroup g = Carving.chisel.getGroup(name); + List variations = getVariationStacks(g); + for (ItemStack stack : variations) { + if (NEIServerUtils.areStacksSameTypeCrafting(stack, ingredient)) { + addCached(variations, ingredient, null); + } + } } } -} \ No newline at end of file + + private void addCached(List variations, ItemStack base, ItemStack focus) { + if (variations.size() > SLOTS_PER_PAGE) { + List> parts = new ArrayList>(); + int size = variations.size(); + for (int i = 0; i < size; i += SLOTS_PER_PAGE) { + parts.add(new ArrayList(variations.subList(i, Math.min(size, i + SLOTS_PER_PAGE)))); + } + for (List part : parts) { + this.arecipes.add(new CachedChiselRecipe(part, base, focus)); + } + } else { + this.arecipes.add(new CachedChiselRecipe(variations, base, focus)); + } + } + + private void addCached(List variations) { + addCached(variations, null, null); + } + + private static List getVariationStacks(CarvingGroup g) { + List stacks = new ArrayList(); + for (CarvingVariation v : g.getVariations()) { + stacks.add(v.getStack()); + } + String oreName = g.getOreName(); + if (oreName != null) { + check: for (ItemStack ore : OreDictionary.getOres(oreName)) { + for (ItemStack stack : stacks) { + if (NEIServerUtils.areStacksSameTypeCrafting(stack, ore)) { + continue check; + } + } + stacks.add(ore.copy()); + } + } + return stacks; + } + +} diff --git a/src/main/resources/assets/chisel/textures/chiselNEI.png b/src/main/resources/assets/chisel/textures/chiselNEI.png new file mode 100644 index 0000000000000000000000000000000000000000..f74a713da36150b5e57860f044cc6e15b2a1c8ad GIT binary patch literal 1882 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5Fo{p?&#~tz_78O`%fY(0|PTd zfKP}kP~6^OGp*#H0kf#RcJGz5ly2!zjbnGeb+B|(0{z+^v? z0YmV2c2!`6a~60+7BevL9RguSQ4OyKprAyFYeY$Kep*R+Vo@qXL1JcJiC$i6iGqoq zfu3>Cv*`g03`_?+T^vIy;@-|Wop;DVfMv47ga7+y*n}i0cQa2~F1lvjE)yyFZQGxG zO+0%0sX$GR<=r-mu7=BP{=eS4F|OG#|GRFwoKFD<<8$6{IiCd#-)h|%zufO-ib%BQ zO1NJxa-f-0z9*-ak`d%8+&dne(}nn_q1~ zZi6LbAXvoU`1hC3uPbcfUBD1F!(^4eo;Oh0mH0IdS* zV|~))k6r%_3zL|Xs= literal 0 HcmV?d00001