diff options
Diffstat (limited to 'src/main/java/me/shedaniel/plugin')
7 files changed, 423 insertions, 28 deletions
diff --git a/src/main/java/me/shedaniel/plugin/RandomRecipe.java b/src/main/java/me/shedaniel/plugin/RandomRecipe.java new file mode 100644 index 000000000..5dcdb9d4a --- /dev/null +++ b/src/main/java/me/shedaniel/plugin/RandomRecipe.java @@ -0,0 +1,33 @@ +package me.shedaniel.plugin; + +import me.shedaniel.api.IRecipe; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public class RandomRecipe implements IRecipe<ItemStack> { + + private String id; + + public RandomRecipe(String id) { + this.id = id; + } + + @Override + public String getId() { + return id; + } + + @Override + public List<ItemStack> getOutput() { + return new LinkedList<>(Arrays.asList(new ItemStack[]{new ItemStack(Blocks.BEETROOTS.asItem())})); + } + + @Override + public List<List<ItemStack>> getInput() { + return new LinkedList<>(Arrays.asList(new LinkedList<>(Arrays.asList(new ItemStack[]{new ItemStack(Blocks.OAK_LOG.asItem())})))); + } +} diff --git a/src/main/java/me/shedaniel/plugin/TestRandomCategory.java b/src/main/java/me/shedaniel/plugin/TestRandomCategory.java new file mode 100644 index 000000000..4773e7e55 --- /dev/null +++ b/src/main/java/me/shedaniel/plugin/TestRandomCategory.java @@ -0,0 +1,72 @@ +package me.shedaniel.plugin; + +import me.shedaniel.api.IDisplayCategory; +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.REISlot; +import me.shedaniel.plugin.crafting.VanillaCraftingRecipe; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class TestRandomCategory implements IDisplayCategory<RandomRecipe> { + + private String id; + private List<RandomRecipe> recipes; + private ItemStack item; + + public TestRandomCategory(String id, ItemStack item) { + this.id = id; + this.item = item; + } + + @Override + public String getId() { + return id; + } + + @Override + public String getDisplayName() { + return id; + } + + @Override + public void addRecipe(RandomRecipe recipe) { + if (this.recipes == null) + this.recipes = new ArrayList<>(); + this.recipes.add(recipe); + } + + @Override + public void resetRecipes() { + this.recipes = new ArrayList<>(); + } + + @Override + public List<REISlot> setupDisplay(int number) { + return new LinkedList<>(); + } + + @Override + public boolean canDisplay(RandomRecipe recipe) { + return false; + } + + @Override + public void drawExtras() { + + } + + @Override + public void addWidget(List<Control> controls, int number) { + + } + + @Override + public ItemStack getCategoryIcon() { + return item; + } +} diff --git a/src/main/java/me/shedaniel/plugin/VanillaPlugin.java b/src/main/java/me/shedaniel/plugin/VanillaPlugin.java index 22c87a168..70e7918da 100755 --- a/src/main/java/me/shedaniel/plugin/VanillaPlugin.java +++ b/src/main/java/me/shedaniel/plugin/VanillaPlugin.java @@ -1,31 +1,47 @@ package me.shedaniel.plugin; -import me.shedaniel.api.IAEIPlugin; -import me.shedaniel.impl.AEIRecipeManager; +import me.shedaniel.api.IREIPlugin; +import me.shedaniel.impl.REIRecipeManager; +import me.shedaniel.listenerdefinitions.PotionCraftingAdder; import me.shedaniel.plugin.crafting.VanillaCraftingCategory; import me.shedaniel.plugin.crafting.VanillaCraftingRecipe; import me.shedaniel.plugin.crafting.VanillaShapedCraftingRecipe; import me.shedaniel.plugin.crafting.VanillaShapelessCraftingRecipe; import me.shedaniel.plugin.furnace.VanillaFurnaceCategory; import me.shedaniel.plugin.furnace.VanillaFurnaceRecipe; -import net.minecraft.item.crafting.FurnaceRecipe; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.item.crafting.ShapedRecipe; -import net.minecraft.item.crafting.ShapelessRecipe; +import me.shedaniel.plugin.potion.VanillaPotionCategory; +import me.shedaniel.plugin.potion.VanillaPotionRecipe; +import net.minecraft.init.Items; +import net.minecraft.init.PotionTypes; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.*; +import net.minecraft.potion.PotionType; +import net.minecraft.potion.PotionUtils; +import net.minecraft.util.registry.IRegistry; -import java.util.Arrays; import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; -public class VanillaPlugin implements IAEIPlugin { +public class VanillaPlugin implements IREIPlugin, PotionCraftingAdder { + + private List<VanillaPotionRecipe> potionRecipes = new LinkedList<>(); + @Override public void register() { List<VanillaCraftingRecipe> recipes = new LinkedList<>(); List<VanillaFurnaceRecipe> furnaceRecipes = new LinkedList<>(); - AEIRecipeManager.instance().addDisplayAdapter(new VanillaCraftingCategory()); - AEIRecipeManager.instance().addDisplayAdapter(new VanillaFurnaceCategory()); + REIRecipeManager.instance().addDisplayAdapter(new VanillaCraftingCategory()); + REIRecipeManager.instance().addDisplayAdapter(new VanillaFurnaceCategory()); + REIRecipeManager.instance().addDisplayAdapter(new VanillaPotionCategory()); +// REIRecipeManager.instance().addDisplayAdapter(new TestRandomCategory("a", new ItemStack(Blocks.ACACIA_BUTTON.asItem()))); +// REIRecipeManager.instance().addDisplayAdapter(new TestRandomCategory("b", new ItemStack(Blocks.ACACIA_LOG.asItem()))); +// REIRecipeManager.instance().addDisplayAdapter(new TestRandomCategory("c", new ItemStack(Blocks.ACACIA_LOG.asItem()))); +// REIRecipeManager.instance().addDisplayAdapter(new TestRandomCategory("d", new ItemStack(Blocks.ACACIA_LOG.asItem()))); +// REIRecipeManager.instance().addDisplayAdapter(new TestRandomCategory("e", new ItemStack(Blocks.ACACIA_LOG.asItem()))); - for(IRecipe recipe : AEIRecipeManager.instance().recipeManager.getRecipes()) { + for(IRecipe recipe : REIRecipeManager.instance().recipeManager.getRecipes()) { if (recipe instanceof ShapelessRecipe) { recipes.add(new VanillaShapelessCraftingRecipe((ShapelessRecipe) recipe)); } @@ -36,8 +52,30 @@ public class VanillaPlugin implements IAEIPlugin { furnaceRecipes.add(new VanillaFurnaceRecipe((FurnaceRecipe) recipe)); } } + IRegistry.POTION.stream().filter(potionType -> !potionType.equals(PotionTypes.EMPTY)).forEach(potionType -> { + ItemStack basePotion = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), potionType), + splashPotion = PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION), potionType), + lingeringPotion = PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION), potionType); + potionRecipes.add(new VanillaPotionRecipe(new ItemStack[]{basePotion}, Ingredient.fromItems(Items.GUNPOWDER).getMatchingStacks(), + new ItemStack[]{splashPotion})); + potionRecipes.add(new VanillaPotionRecipe(new ItemStack[]{splashPotion}, Ingredient.fromItems(Items.DRAGON_BREATH).getMatchingStacks(), + new ItemStack[]{lingeringPotion})); + }); - AEIRecipeManager.instance().addRecipe("vanilla", recipes); - AEIRecipeManager.instance().addRecipe("furnace", furnaceRecipes); + REIRecipeManager.instance().addRecipe("vanilla", recipes); + REIRecipeManager.instance().addRecipe("furnace", furnaceRecipes); + REIRecipeManager.instance().addRecipe("potion", potionRecipes.stream().collect(Collectors.toList())); +// REIRecipeManager.instance().addPotionRecipe("a", new RandomRecipe("a")); +// REIRecipeManager.instance().addPotionRecipe("b", new RandomRecipe("b")); +// REIRecipeManager.instance().addPotionRecipe("c", new RandomRecipe("c")); +// REIRecipeManager.instance().addPotionRecipe("d", new RandomRecipe("d")); +// REIRecipeManager.instance().addPotionRecipe("e", new RandomRecipe("e")); + } + + @Override + public void addPotionRecipe(PotionType inputType, Item reagent, PotionType outputType) { + potionRecipes.add(new VanillaPotionRecipe(new ItemStack[]{PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), inputType)}, + Ingredient.fromItems(reagent).getMatchingStacks(), + new ItemStack[]{PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), outputType)})); } } diff --git a/src/main/java/me/shedaniel/plugin/crafting/VanillaCraftingCategory.java b/src/main/java/me/shedaniel/plugin/crafting/VanillaCraftingCategory.java index e064f05a4..1c37ed292 100755 --- a/src/main/java/me/shedaniel/plugin/crafting/VanillaCraftingCategory.java +++ b/src/main/java/me/shedaniel/plugin/crafting/VanillaCraftingCategory.java @@ -1,11 +1,14 @@ package me.shedaniel.plugin.crafting; import me.shedaniel.api.IDisplayCategory; -import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.REISlot; import me.shedaniel.gui.widget.Control; import me.shedaniel.gui.widget.WidgetArrow; import net.minecraft.client.MainWindow; import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.I18n; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import java.util.ArrayList; @@ -23,7 +26,7 @@ public class VanillaCraftingCategory implements IDisplayCategory<VanillaCrafting @Override public String getDisplayName() { - return "Crafting"; + return I18n.format("category.rei.crafting"); } @Override @@ -39,13 +42,13 @@ public class VanillaCraftingCategory implements IDisplayCategory<VanillaCrafting } @Override - public List<AEISlot> setupDisplay(int number) { - List<AEISlot> slots = new LinkedList<>(); + public List<REISlot> setupDisplay(int number) { + List<REISlot> slots = new LinkedList<>(); int count = 0; List<List<ItemStack>> input = recipes.get(number).getInput(); for(int y = 0; y < 3; y++) { for(int x = 0; x < 3; x++) { - AEISlot slot = new AEISlot(20 + x * 18, 75 + y * 18 + number * 75); + REISlot slot = new REISlot(20 + x * 18, 75 + y * 18 + number * 75); slot.setDrawBackground(true); slots.add(slot); count++; @@ -58,7 +61,7 @@ public class VanillaCraftingCategory implements IDisplayCategory<VanillaCrafting } else if (!input.get(i).isEmpty()) slots.get(i).setStackList(input.get(i)); } - AEISlot slot = new AEISlot(130, 75 + 18 + number * 75); + REISlot slot = new REISlot(130, 75 + 18 + number * 75); slot.setDrawBackground(true); slot.setStack(recipes.get(number).getOutput().get(0).copy()); @@ -103,4 +106,10 @@ public class VanillaCraftingCategory implements IDisplayCategory<VanillaCrafting } return num; } + + @Override + public ItemStack getCategoryIcon() { + return new ItemStack(Blocks.CRAFTING_TABLE.asItem()); + } + } diff --git a/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java b/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java index e4c65cca1..1f38b6964 100755 --- a/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java +++ b/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java @@ -1,10 +1,11 @@ package me.shedaniel.plugin.furnace; import me.shedaniel.api.IDisplayCategory; -import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.REISlot; import me.shedaniel.gui.widget.Control; import me.shedaniel.gui.widget.WidgetArrow; -import me.shedaniel.plugin.crafting.VanillaCraftingRecipe; +import net.minecraft.client.resources.I18n; +import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntityFurnace; @@ -24,7 +25,7 @@ public class VanillaFurnaceCategory implements IDisplayCategory<VanillaFurnaceRe @Override public String getDisplayName() { - return "Smelting"; + return I18n.format("category.rei.smelting"); } @Override @@ -40,20 +41,20 @@ public class VanillaFurnaceCategory implements IDisplayCategory<VanillaFurnaceRe } @Override - public List<AEISlot> setupDisplay(int number) { - List<AEISlot> slots = new LinkedList<>(); - AEISlot inputSlot = new AEISlot(50, 70 + number * 75); + public List<REISlot> setupDisplay(int number) { + List<REISlot> slots = new LinkedList<>(); + REISlot inputSlot = new REISlot(50, 70 + number * 75); inputSlot.setStackList(recipes.get(number).getInput().get(0)); inputSlot.setDrawBackground(true); - AEISlot outputSlot = new AEISlot(110, 70 + number * 75); + REISlot outputSlot = new REISlot(110, 70 + number * 75); outputSlot.setStackList(recipes.get(number).getOutput()); outputSlot.setDrawBackground(true); - AEISlot fuelSlot = new AEISlot(80, 100 + number * 75); + REISlot fuelSlot = new REISlot(80, 100 + number * 75); fuelSlot.setStackList(getFuel()); fuelSlot.setDrawBackground(true); - fuelSlot.setExtraTooltip("Fuel"); + fuelSlot.setExtraTooltip(I18n.format("category.rei.smelting.fuel")); slots.add(inputSlot); slots.add(outputSlot); @@ -80,4 +81,9 @@ public class VanillaFurnaceCategory implements IDisplayCategory<VanillaFurnaceRe private List<ItemStack> getFuel() { return TileEntityFurnace.getBurnTimes().keySet().stream().map(Item::getDefaultInstance).collect(Collectors.toList()); } + + @Override + public ItemStack getCategoryIcon() { + return new ItemStack(Blocks.FURNACE.asItem()); + } } 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; + } +} |
