diff options
Diffstat (limited to 'src/main/java/me/shedaniel/plugin/potion')
| -rw-r--r-- | src/main/java/me/shedaniel/plugin/potion/VanillaPotionCategory.java | 189 | ||||
| -rwxr-xr-x | src/main/java/me/shedaniel/plugin/potion/VanillaPotionRecipe.java | 48 |
2 files changed, 237 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/plugin/potion/VanillaPotionCategory.java b/src/main/java/me/shedaniel/plugin/potion/VanillaPotionCategory.java new file mode 100644 index 000000000..b9f3cf85e --- /dev/null +++ b/src/main/java/me/shedaniel/plugin/potion/VanillaPotionCategory.java @@ -0,0 +1,189 @@ +package me.shedaniel.plugin.potion; + +import me.shedaniel.api.IDisplayCategory; +import me.shedaniel.gui.REIRenderHelper; +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.REISlot; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.resources.I18n; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import java.awt.*; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class VanillaPotionCategory implements IDisplayCategory<VanillaPotionRecipe> { + private List<VanillaPotionRecipe> recipes = new ArrayList<>(); + + @Override + public String getId() { + return "potion"; + } + + @Override + public String getDisplayName() { + return I18n.format("category.rei.brewing"); + } + + @Override + public void addRecipe(VanillaPotionRecipe recipe) { + recipes.add(recipe); + } + + @Override + public void resetRecipes() { + recipes = new ArrayList<>(); + } + + @Override + public List<REISlot> setupDisplay(int number) { + List<REISlot> list = new LinkedList<>(); + REISlot blazePowderSlot = new REISlot(32, 62 + number * 75); + blazePowderSlot.setDrawBackground(false); + blazePowderSlot.setStack(new ItemStack(Items.BLAZE_POWDER)); + list.add(blazePowderSlot); + REISlot inputSlot = new REISlot(30 + 41, 62 + number * 75); + inputSlot.setDrawBackground(true); + inputSlot.setStackList(recipes.get(number).getInput().get(0)); + list.add(inputSlot); + REISlot reactWithSlot = new REISlot(30 + 64, 62 + number * 75); + reactWithSlot.setDrawBackground(false); + reactWithSlot.setStackList(recipes.get(number).getInput().get(1)); + list.add(reactWithSlot); + REISlot outputSlotOne = new REISlot(30 + 41, 62 + 34 + number * 75); + outputSlotOne.setDrawBackground(false); + outputSlotOne.setStackList(recipes.get(number).getOutput(0)); + list.add(outputSlotOne); + REISlot outputSlotTwo = new REISlot(30 + 64, 62 + 41 + number * 75); + outputSlotTwo.setDrawBackground(false); + outputSlotTwo.setStackList(recipes.get(number).getOutput(1)); + list.add(outputSlotTwo); + return new LinkedList<>(); + } + + @Override + public boolean canDisplay(VanillaPotionRecipe recipe) { + return false; + } + + @Override + public void drawExtras() { + + } + + private static final ResourceLocation RECIPE_GUI = new ResourceLocation("textures/gui/container/brewing_stand.png"); + + @Override + public void addWidget(List<Control> controls, int number) { + controls.add(new PotionScreen(30, 60 + number * 75)); + PotionSlot blazePowderSlot = new PotionSlot(32, 62 + number * 75); + blazePowderSlot.setDrawBackground(false); + blazePowderSlot.setExtraTooltip(getTooltip(SlotType.BLAZE_POWDER)); + blazePowderSlot.setStack(new ItemStack(Items.BLAZE_POWDER)); + controls.add(blazePowderSlot); + PotionSlot inputSlot = new PotionSlot(30 + 41, 62 + number * 75); + inputSlot.setDrawBackground(true); + inputSlot.setExtraTooltip(getTooltip(SlotType.INPUT)); + inputSlot.setStackList(recipes.get(number).getInput().get(0)); + controls.add(inputSlot); + PotionSlot reactWithSlot = new PotionSlot(30 + 63, 62 + number * 75); + reactWithSlot.setDrawBackground(false); + reactWithSlot.setExtraTooltip(getTooltip(SlotType.REACT)); + reactWithSlot.setStackList(recipes.get(number).getInput().get(1)); + controls.add(reactWithSlot); + PotionSlot outputSlotOne = new PotionSlot(30 + 40, 62 + 34 + number * 75); + outputSlotOne.setDrawBackground(false); + outputSlotOne.setExtraTooltip(getTooltip(SlotType.OUTPUT)); + outputSlotOne.setDrawMiniBackground(true); + outputSlotOne.setStackList(recipes.get(number).getOutput(0)); + controls.add(outputSlotOne); + PotionSlot outputSlotTwo = new PotionSlot(30 + 63, 62 + 41 + number * 75); + outputSlotTwo.setDrawBackground(false); + outputSlotTwo.setExtraTooltip(getTooltip(SlotType.OUTPUT)); + outputSlotTwo.setDrawMiniBackground(true); + outputSlotTwo.setStackList(recipes.get(number).getOutput(1)); + controls.add(outputSlotTwo); + PotionSlot outputSlotThree = new PotionSlot(30 + 86, 62 + 34 + number * 75); + outputSlotThree.setDrawBackground(false); + outputSlotThree.setExtraTooltip(getTooltip(SlotType.OUTPUT)); + outputSlotThree.setDrawMiniBackground(true); + outputSlotThree.setStackList(recipes.get(number).getOutput(2)); + controls.add(outputSlotThree); + } + + @Override + public ItemStack getCategoryIcon() { + return new ItemStack(Blocks.BREWING_STAND.asItem()); + } + + private class PotionScreen extends Control { + + public PotionScreen(int x, int y) { + super(x, y, 103, 60); + } + + @Override + public void draw() { + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.disableLighting(); + Minecraft.getInstance().getTextureManager().bindTexture(RECIPE_GUI); + this.drawTexturedModalRect(rect.x, rect.y, 16, 15, 103, 60, 0); + this.drawTexturedModalRect(rect.x + 97 - 16, rect.y + 16 - 15, 176, 0, 9, (int) (((double) System.currentTimeMillis() % 2800d / 2800d) * 28), 0); + this.drawTexturedModalRect(rect.x + 45, rect.y, 110, 15, 15, 27, 0); + this.drawTexturedModalRect(rect.x + 44, rect.y + 29, 176, 29, (int) (((double) System.currentTimeMillis() % 2800d / 2800d) * 18), 4, 0); + } + } + + private class PotionSlot extends REISlot { + + protected boolean drawMiniBackground = false; + + public PotionSlot(int x, int y) { + super(x, y); + } + + public void setDrawMiniBackground(boolean drawMiniBackground) { + this.drawMiniBackground = drawMiniBackground; + } + + @Override + public void draw() { + if (getStack().isEmpty()) + return; + if (drawMiniBackground) { + Minecraft.getInstance().getTextureManager().bindTexture(RECIPE_GUI); + drawTexturedModalRect(rect.x + 1, rect.y + 1, 0 + 2, 222 + 2, rect.width - 4, rect.height - 4); + } + super.draw(); + } + + @Override + protected void drawTooltip() { + List<String> toolTip = getTooltip(); + toolTip.add(I18n.format("text.rei.mod", getMod())); + Point mouse = REIRenderHelper.getMouseLoc(); + Minecraft.getInstance().currentScreen.drawHoveringText(toolTip, mouse.x, mouse.y); + } + } + + public static String getTooltip(SlotType slotType) { + switch (slotType) { + case INPUT: + return I18n.format("category.rei.brewing.input"); + case REACT: + return I18n.format("category.rei.brewing.reactant"); + case OUTPUT: + return I18n.format("category.rei.brewing.result"); + } + return null; + } + + public enum SlotType { + INPUT, REACT, OUTPUT, BLAZE_POWDER; + } +} diff --git a/src/main/java/me/shedaniel/plugin/potion/VanillaPotionRecipe.java b/src/main/java/me/shedaniel/plugin/potion/VanillaPotionRecipe.java new file mode 100755 index 000000000..3f4592a90 --- /dev/null +++ b/src/main/java/me/shedaniel/plugin/potion/VanillaPotionRecipe.java @@ -0,0 +1,48 @@ +package me.shedaniel.plugin.potion; + +import me.shedaniel.api.IRecipe; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public class VanillaPotionRecipe implements IRecipe<ItemStack> { + + private ItemStack[] input, reactWith, output; + + @Override + public String getId() { + return "potion"; + } + + public VanillaPotionRecipe(ItemStack[] input, ItemStack[] reactWith, ItemStack[] output) { + this.input = input; + this.reactWith = reactWith; + this.output = output; + } + + @Override + public List<ItemStack> getOutput() { + return Arrays.asList(output); + } + + @Override + public List<List<ItemStack>> getInput() { + List<List<ItemStack>> input = new LinkedList<>(); + input.add(new ArrayList<>(Arrays.asList(this.input))); + input.add(new ArrayList<>(Arrays.asList(this.reactWith))); + return input; + } + + public List<ItemStack> getOutput(int slot) { + List<ItemStack> stack = new ArrayList<>(); + for(int i = 0; i < slot * 2; i++) + stack.add(new ItemStack(Blocks.AIR)); + for(int i = 0; i < 6 - slot * 2; i++) + stack.addAll(getOutput()); + return stack; + } +} |
