From fe03c35dc0613aaf67bbde531a930cb9939c6096 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 2 Jan 2019 23:06:23 +0800 Subject: v1.4 Bug Fixes --- build.gradle | 6 +- src/main/java/me/shedaniel/Core.java | 55 +++++------ src/main/java/me/shedaniel/gui/ConfigGui.java | 2 +- .../java/me/shedaniel/gui/REIRenderHelper.java | 33 ++++++- src/main/java/me/shedaniel/gui/RecipeGui.java | 105 ++++++++++++--------- src/main/java/me/shedaniel/gui/widget/REISlot.java | 17 ++-- .../shedaniel/listenerdefinitions/PacketAdder.java | 21 ----- .../shedaniel/listeners/DrawContainerListener.java | 7 +- .../me/shedaniel/listeners/ResizeListener.java | 14 --- .../me/shedaniel/mixins/MixinMinecraftClient.java | 33 ------- .../java/me/shedaniel/network/CheatPacket.java | 6 +- .../java/me/shedaniel/plugin/RandomRecipe.java | 33 +++++++ .../me/shedaniel/plugin/TestRandomCategory.java | 69 ++++++++++++++ .../java/me/shedaniel/plugin/VanillaPlugin.java | 16 ++++ .../blastfurnace/VanillaBlastFurnaceCategory.java | 2 +- .../blastfurnace/VanillaBlastFurnaceRecipe.java | 2 +- .../plugin/furnace/VanillaFurnaceCategory.java | 2 +- .../plugin/furnace/VanillaFurnaceRecipe.java | 2 +- .../plugin/smoker/VanillaSmokerCategory.java | 2 +- .../plugin/smoker/VanillaSmokerRecipe.java | 2 +- .../assets/roughlyenoughitems/lang/en_us.json | 4 +- src/main/resources/fabric.mod.json | 4 +- src/main/resources/roughlyenoughitems.client.json | 3 +- 23 files changed, 268 insertions(+), 172 deletions(-) delete mode 100644 src/main/java/me/shedaniel/listenerdefinitions/PacketAdder.java delete mode 100755 src/main/java/me/shedaniel/listeners/ResizeListener.java delete mode 100644 src/main/java/me/shedaniel/mixins/MixinMinecraftClient.java create mode 100644 src/main/java/me/shedaniel/plugin/RandomRecipe.java create mode 100644 src/main/java/me/shedaniel/plugin/TestRandomCategory.java diff --git a/build.gradle b/build.gradle index 30fa6840f..c343e83b8 100755 --- a/build.gradle +++ b/build.gradle @@ -6,15 +6,15 @@ sourceCompatibility = 1.8 targetCompatibility = 1.8 archivesBaseName = "RoughlyEnoughItems" -version = "1.3-7" +version = "1.4-7" minecraft { } dependencies { minecraft "com.mojang:minecraft:18w50a" - mappings "net.fabricmc:yarn:18w50a.83" - modCompile "net.fabricmc:fabric-loader:0.3.1.82" + mappings "net.fabricmc:yarn:18w50a.90" + modCompile "net.fabricmc:fabric-loader:0.3.1.84" // Fabric API. This is technically optional, but you probably want it anyway. modCompile "net.fabricmc:fabric:0.1.2.63" diff --git a/src/main/java/me/shedaniel/Core.java b/src/main/java/me/shedaniel/Core.java index 08a72554f..3a1029097 100755 --- a/src/main/java/me/shedaniel/Core.java +++ b/src/main/java/me/shedaniel/Core.java @@ -1,16 +1,16 @@ package me.shedaniel; import me.shedaniel.config.REIConfig; +import me.shedaniel.listenerdefinitions.ClientTickable; import me.shedaniel.listenerdefinitions.IEvent; -import me.shedaniel.listenerdefinitions.PacketAdder; import me.shedaniel.listeners.DrawContainerListener; -import me.shedaniel.listeners.ResizeListener; import me.shedaniel.network.CheatPacket; -import me.shedaniel.network.DeletePacket; import me.shedaniel.plugin.VanillaPlugin; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.events.client.ClientTickEvent; import net.fabricmc.loader.FabricLoader; -import net.minecraft.network.NetworkSide; +import net.minecraft.client.MinecraftClient; +import net.minecraft.item.ItemStack; import java.io.*; import java.nio.file.Files; @@ -21,26 +21,7 @@ import java.util.List; /** * Created by James on 7/27/2018. */ -public class Core implements PacketAdder, ClientModInitializer { - @Override - public void registerHandshakingPackets(PacketRegistrationReceiver receiver) { - } - - @Override - public void registerPlayPackets(PacketRegistrationReceiver receiver) { - receiver.registerPacket(NetworkSide.SERVER, CheatPacket.class); - receiver.registerPacket(NetworkSide.SERVER, DeletePacket.class); - } - - @Override - public void registerStatusPackets(PacketRegistrationReceiver receiver) { - - } - - @Override - public void registerLoginPackets(PacketRegistrationReceiver receiver) { - - } +public class Core implements ClientModInitializer { private static List events = new LinkedList<>(); public static final File configFile = new File(FabricLoader.INSTANCE.getConfigDirectory(), "rei.json"); @@ -51,7 +32,8 @@ public class Core implements PacketAdder, ClientModInitializer { @Override public void onInitializeClient() { this.clientListener = new ClientListener(); - registerEvents(); + registerSelfEvents(); + registerFabricEvents(); try { loadConfig(); centreSearchBox = config.centreSearchBox; @@ -61,14 +43,23 @@ public class Core implements PacketAdder, ClientModInitializer { this.clientListener.onInitializeKeyBind(); } - private void registerEvents() { + private void registerFabricEvents() { + ClientTickEvent.CLIENT.register(minecraftClient -> { + getListeners(ClientTickable.class).forEach(ClientTickable::clientTick); + }); + } + + private void registerSelfEvents() { registerEvent(new DrawContainerListener()); - registerEvent(new ResizeListener()); - registerEvent(new VanillaPlugin()); registerEvent(clientListener); + registerPlugin(new VanillaPlugin()); + } + + public static void registerPlugin(VanillaPlugin vanillaPlugin) { + registerEvent(vanillaPlugin); } - public static void registerEvent(IEvent event) { + private static void registerEvent(IEvent event) { events.add(event); } @@ -88,7 +79,7 @@ public class Core implements PacketAdder, ClientModInitializer { try { InputStream in = Files.newInputStream(configFile.toPath()); config = REIConfig.GSON.fromJson(new InputStreamReader(in), REIConfig.class); - } catch (Exception e){ + } catch (Exception e) { failed = true; } if (failed || config == null) { @@ -113,4 +104,8 @@ public class Core implements PacketAdder, ClientModInitializer { } } + public static void cheatItems(ItemStack cheatedStack) { + MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CheatPacket(cheatedStack)); + } + } diff --git a/src/main/java/me/shedaniel/gui/ConfigGui.java b/src/main/java/me/shedaniel/gui/ConfigGui.java index c7dfad3ab..401ac103a 100644 --- a/src/main/java/me/shedaniel/gui/ConfigGui.java +++ b/src/main/java/me/shedaniel/gui/ConfigGui.java @@ -87,7 +87,7 @@ public class ConfigGui extends Gui { @Override public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) { - if (p_keyPressed_1_ == 256 && this.canClose()) { + if (p_keyPressed_1_ == 256 && this.doesEscapeKeyClose()) { this.close(); if (parent != null) MinecraftClient.getInstance().openGui(parent); diff --git a/src/main/java/me/shedaniel/gui/REIRenderHelper.java b/src/main/java/me/shedaniel/gui/REIRenderHelper.java index f4e66808a..f0cb15e8e 100755 --- a/src/main/java/me/shedaniel/gui/REIRenderHelper.java +++ b/src/main/java/me/shedaniel/gui/REIRenderHelper.java @@ -17,8 +17,10 @@ import net.minecraft.item.ItemStack; import java.awt.*; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; /** @@ -127,7 +129,12 @@ public class REIRenderHelper { } } if (overlayedGui instanceof RecipeGui) { - List controls = ((RecipeGui) overlayedGui).controls; + List controls = new LinkedList<>(((RecipeGui) overlayedGui).controls); + if (((RecipeGui) overlayedGui).slots != null) + controls.addAll(((RecipeGui) overlayedGui).slots); + controls.addAll(reiGui.controls.stream().filter(control -> { + return control instanceof REISlot; + }).collect(Collectors.toList())); Optional ctrl = controls.stream().filter(Control::isHighlighted).filter(Control::isEnabled).findFirst(); if (ctrl.isPresent()) { try { @@ -181,6 +188,30 @@ public class REIRenderHelper { public static boolean mouseScrolled(double direction) { if (!reiGui.visible) return false; + if (MinecraftClient.getInstance().currentGui instanceof RecipeGui) { + Window window = REIRenderHelper.getResolution(); + Point mouse = new Point((int) MinecraftClient.getInstance().mouse.getX(), (int) MinecraftClient.getInstance().mouse.getY()); + int mouseX = (int) (mouse.x * (double) window.getScaledWidth() / (double) window.method_4480()); + int mouseY = (int) (mouse.y * (double) window.getScaledHeight() / (double) window.method_4507()); + mouse = new Point(mouseX, mouseY); + + RecipeGui recipeGui = (RecipeGui) MinecraftClient.getInstance().currentGui; + System.out.printf("%b.%b.%b.%b.%b%n", mouse.getX() < window.getScaledWidth() / 2 + recipeGui.guiWidth / 2, mouse.getX() > window.getScaledWidth() / 2 - recipeGui.guiWidth / 2, + mouse.getY() < window.getScaledHeight() / 2 + recipeGui.guiHeight / 2, mouse.getY() > window.getScaledHeight() / 2 - recipeGui.guiHeight / 2, + recipeGui.recipes.get(recipeGui.selectedCategory).size() > 2); + if (mouse.getX() < window.getScaledWidth() / 2 + recipeGui.guiWidth / 2 && mouse.getX() > window.getScaledWidth() / 2 - recipeGui.guiWidth / 2 && + mouse.getY() < window.getScaledHeight() / 2 + recipeGui.guiHeight / 2 && mouse.getY() > window.getScaledHeight() / 2 - recipeGui.guiHeight / 2 && + recipeGui.recipes.get(recipeGui.selectedCategory).size() > 2) { + boolean failed = false; + if (direction > 0 && reiGui.buttonLeft.isEnabled()) + recipeGui.btnRecipeLeft.onClick.apply(0); + else if (direction < 0 && reiGui.buttonRight.isEnabled()) + recipeGui.btnRecipeRight.onClick.apply(0); + else failed = true; + if (!failed) + return true; + } + } if (direction > 0 && reiGui.buttonLeft.isEnabled()) reiGui.buttonLeft.onClick.apply(0); else if (direction < 0 && reiGui.buttonRight.isEnabled()) diff --git a/src/main/java/me/shedaniel/gui/RecipeGui.java b/src/main/java/me/shedaniel/gui/RecipeGui.java index 9ca41e958..bee43415b 100755 --- a/src/main/java/me/shedaniel/gui/RecipeGui.java +++ b/src/main/java/me/shedaniel/gui/RecipeGui.java @@ -17,10 +17,7 @@ import net.minecraft.container.Container; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; public class RecipeGui extends ContainerGui { @@ -29,19 +26,19 @@ public class RecipeGui extends ContainerGui { private final Window mainWindow; private final Container container; private final Gui prevScreen; - private final Map> recipes; - private int guiWidth = 176; - private int guiHeight = 222; + public final Map> recipes; + public final int guiWidth = 176; + public final int guiHeight = 222; ArrayList categories = new ArrayList<>(); private int categoryTabPage = 0; - private IDisplayCategory selectedCategory; + public IDisplayCategory selectedCategory; private int recipePointer = 0; - private List slots; - private int cycleCounter = 0; - private int[] itemPointer; + public List slots; List controls = new LinkedList<>(); private List tabs; private boolean tabsEnabled = false; + private Button btnCategoryPageLeft, btnCategoryPageRight; + public Button btnRecipeLeft, btnRecipeRight; public RecipeGui(Container p_i1072_1_, Gui prevScreen, Map> recipes) { super(new RecipeContainer()); @@ -66,7 +63,12 @@ public class RecipeGui extends ContainerGui { for(int i = 0; i < 6; i++) tabs.add(new Tab(i, 0, 0, 0, 28, 32)); tabs.forEach(tab -> tab.setOnClick(i -> { - return onClickTab(tab.getId()); + if (tab.getId() + categoryTabPage * 6 == categories.indexOf(selectedCategory)) + return false; + selectedCategory = categories.get(tab.getId() + categoryTabPage * 6); + recipePointer = 0; + updateRecipe(); + return false; })); updateRecipe(); } @@ -100,14 +102,15 @@ public class RecipeGui extends ContainerGui { private void updateRecipe() { int categoryPointer = categories.indexOf(selectedCategory); + IRecipe recipe = recipes.get(categories.get(categoryPointer)).get(recipePointer); - categories.get(categoryPointer).resetRecipes(); - categories.get(categoryPointer).addRecipe(recipe); - slots = categories.get(categoryPointer).setupDisplay(0); - if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) { - IRecipe recipe2 = recipes.get(categories.get(categoryPointer)).get(recipePointer + 1); - categories.get(categoryPointer).addRecipe(recipe2); - slots.addAll(categories.get(categoryPointer).setupDisplay(1)); + selectedCategory.resetRecipes(); + selectedCategory.addRecipe(recipe); + slots = selectedCategory.setupDisplay(0); + if (recipes.get(selectedCategory).size() >= recipePointer + 2) { + IRecipe recipe2 = recipes.get(selectedCategory).get(recipePointer + 1); + selectedCategory.addRecipe(recipe2); + slots.addAll(selectedCategory.setupDisplay(1)); } left = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2)); @@ -120,10 +123,10 @@ public class RecipeGui extends ContainerGui { btnCategoryRight.onClick = this::btnCategoryRight; btnCategoryLeft.onClick = this::btnCategoryLeft; - Button btnRecipeLeft = new Button(left + 10, top + 28, 15, 20, "<"); - Button btnRecipeRight = new Button(left + guiWidth - 25, top + 28, 15, 20, ">"); - btnRecipeLeft.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && recipePointer > 0); - btnRecipeRight.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && getCurrentPage() + 1 < getTotalPages()); + btnRecipeLeft = new Button(left + 10, top + 28, 15, 20, "<"); + btnRecipeRight = new Button(left + guiWidth - 25, top + 28, 15, 20, ">"); + btnRecipeLeft.setEnabled(recipes.get(selectedCategory).size() > 2); + btnRecipeRight.setEnabled(recipes.get(selectedCategory).size() > 2); btnRecipeRight.onClick = this::btnRecipeRight; btnRecipeLeft.onClick = this::btnRecipeLeft; @@ -133,19 +136,33 @@ public class RecipeGui extends ContainerGui { if (categories.size() <= 1) { btnCategoryLeft.setEnabled(false); btnCategoryRight.setEnabled(false); + } else if (categories.size() > 6) { + btnCategoryPageLeft = new Button(left, top - 52, 20, 20, "<"); + btnCategoryPageRight = new Button(left + guiWidth - 20, top - 52, 20, 20, ">"); + btnCategoryPageLeft.setOnClick(i -> { + categoryTabPage--; + if (categoryTabPage <= 0) + categoryTabPage = MathHelper.ceil(categories.size() / 6d); + updateRecipe(); + return true; + }); + btnCategoryPageRight.setOnClick(i -> { + categoryTabPage++; + if (categoryTabPage >= MathHelper.ceil(categories.size() / 6d)) + categoryTabPage = 0; + updateRecipe(); + return true; + }); + if (top - 52 >= 2) + controls.addAll(Arrays.asList(btnCategoryPageLeft, btnCategoryPageRight)); } controls.add(btnRecipeLeft); controls.add(btnRecipeRight); - itemPointer = new int[9]; - for(int i = 0; i < itemPointer.length; i++) { - itemPointer[i] = 0; - } - List newControls = new LinkedList<>(); categories.get(categoryPointer).addWidget(newControls, 0); - if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) + if (recipes.get(categories.get(categoryPointer)).size() >= recipePointer + 2) categories.get(categoryPointer).addWidget(newControls, 1); newControls.forEach(f -> f.move(left, top)); controls.addAll(newControls); @@ -167,14 +184,6 @@ public class RecipeGui extends ContainerGui { } } - private boolean onClickTab(int index) { - if (index + categoryTabPage * 6 == categories.indexOf(selectedCategory)) - return false; - selectedCategory = categories.get(index + categoryTabPage * 6); - updateRecipe(); - return false; - } - @Override protected void drawBackground(float v, int i, int i1) { //Tabs @@ -187,13 +196,18 @@ public class RecipeGui extends ContainerGui { drawBackground(); GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + GuiLighting.disable(); this.client.getTextureManager().bindTexture(CHEST_GUI_TEXTURE); int lvt_4_1_ = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2)); int lvt_5_1_ = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2)); this.drawTexturedRect(lvt_4_1_, lvt_5_1_, 0, 0, this.guiWidth, this.guiHeight); - slots.forEach(REISlot::draw); + slots.forEach(reiSlot -> { + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + GuiLighting.disable(); + reiSlot.draw(); + }); if (tabsEnabled) tabs.stream().filter(tab -> tab.getId() + categoryTabPage * 6 != categories.indexOf(selectedCategory)).forEach(tab -> { @@ -210,7 +224,6 @@ public class RecipeGui extends ContainerGui { this.client.openGui(prevScreen); return true; } - return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); } @@ -218,7 +231,7 @@ public class RecipeGui extends ContainerGui { recipePointer = 0; int categoryPointer = categories.indexOf(selectedCategory); categoryPointer--; - if (categoryPointer < 0) + if (categoryPointer <= 0) categoryPointer = categories.size() - 1; selectedCategory = categories.get(categoryPointer); categoryTabPage = categoryPointer / 6; @@ -240,27 +253,25 @@ public class RecipeGui extends ContainerGui { private boolean btnRecipeLeft(int button) { recipePointer -= 2; - if (recipePointer < 0) { - recipePointer = (getTotalPages() - 1) * 2; - } + if (recipePointer <= 0) + recipePointer = MathHelper.floor((recipes.get(selectedCategory).size() - 1) / 2d) * 2; updateRecipe(); return true; } private boolean btnRecipeRight(int button) { recipePointer += 2; - if (recipePointer >= recipes.get(selectedCategory).size()) { + if (recipePointer >= recipes.get(selectedCategory).size()) recipePointer = 0; - } updateRecipe(); return true; } private int riseDoublesToInt(double i) { - return (int) (i + (i % 1 == 0 ? 0 : 1)); + return MathHelper.ceil(i); } private int getTotalPages() { - return MathHelper.clamp(riseDoublesToInt(recipes.get(selectedCategory).size() / 2), 1, Integer.MAX_VALUE); + return MathHelper.clamp(riseDoublesToInt(recipes.get(selectedCategory).size() / 2d), 1, Integer.MAX_VALUE); } } diff --git a/src/main/java/me/shedaniel/gui/widget/REISlot.java b/src/main/java/me/shedaniel/gui/widget/REISlot.java index bf6159e2c..73faa85c4 100755 --- a/src/main/java/me/shedaniel/gui/widget/REISlot.java +++ b/src/main/java/me/shedaniel/gui/widget/REISlot.java @@ -1,9 +1,9 @@ package me.shedaniel.gui.widget; import com.google.common.collect.Lists; +import me.shedaniel.Core; import me.shedaniel.gui.REIRenderHelper; import me.shedaniel.listenerdefinitions.IMixinContainerGui; -import me.shedaniel.network.CheatPacket; import me.shedaniel.network.DeletePacket; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.ContainerGui; @@ -16,6 +16,7 @@ import net.minecraft.util.registry.Registry; import java.awt.*; import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; /** * Created by James on 7/28/2018. @@ -122,7 +123,7 @@ public class REISlot extends Control { if (button == 1) { cheatedStack.setAmount(cheatedStack.getMaxAmount()); } - MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CheatPacket(cheatedStack)); + Core.cheatItems(cheatedStack); return true; } } else { @@ -158,18 +159,16 @@ public class REISlot extends Control { } protected List getTooltip() { + final String modString = "§9§o" + getMod(); MinecraftClient mc = MinecraftClient.getInstance(); ContainerGui gui = REIRenderHelper.getOverlayedGui(); List toolTip = Lists.newArrayList(); - if (gui != null) { - toolTip = gui.getStackTooltip(getStack()); - } else { + if (gui != null) + toolTip = gui.getStackTooltip(getStack()).stream().filter(s -> !s.equals(modString)).collect(Collectors.toList()); + else toolTip.add(getStack().getDisplayName().getFormattedText()); - } - if (extraTooltip != null) { + if (extraTooltip != null) toolTip.add(extraTooltip); - } - return toolTip; } diff --git a/src/main/java/me/shedaniel/listenerdefinitions/PacketAdder.java b/src/main/java/me/shedaniel/listenerdefinitions/PacketAdder.java deleted file mode 100644 index 4102abee1..000000000 --- a/src/main/java/me/shedaniel/listenerdefinitions/PacketAdder.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.shedaniel.listenerdefinitions; - -import net.minecraft.network.NetworkSide; -import net.minecraft.network.NetworkState; -import net.minecraft.network.Packet; - -public interface PacketAdder extends IEvent { - - interface PacketRegistrationReceiver { - NetworkState registerPacket(NetworkSide direction, Class> packetClass); - } - - void registerHandshakingPackets(PacketRegistrationReceiver receiver); - - void registerPlayPackets(PacketRegistrationReceiver receiver); - - void registerStatusPackets(PacketRegistrationReceiver receiver); - - void registerLoginPackets(PacketRegistrationReceiver receiver); - -} diff --git a/src/main/java/me/shedaniel/listeners/DrawContainerListener.java b/src/main/java/me/shedaniel/listeners/DrawContainerListener.java index 02eda4b41..0f501a3f7 100755 --- a/src/main/java/me/shedaniel/listeners/DrawContainerListener.java +++ b/src/main/java/me/shedaniel/listeners/DrawContainerListener.java @@ -12,7 +12,7 @@ import net.minecraft.item.ItemGroup; /** * Created by James on 7/27/2018. */ -public class DrawContainerListener implements DrawContainer, GuiCickListener, GuiKeyDown, CharInput, ClientTickable, MouseScrollListener { +public class DrawContainerListener implements DrawContainer, GuiCickListener, GuiKeyDown, CharInput, ClientTickable, MouseScrollListener, MinecraftResize { @Override public void draw(int x, int y, float dunno, ContainerGui gui) { @@ -58,4 +58,9 @@ public class DrawContainerListener implements DrawContainer, GuiCickListener, Gu public void clientTick() { REIRenderHelper.tick(); } + + @Override + public void resize(int scaledWidth, int scaledHeight) { + REIRenderHelper.resize(scaledWidth, scaledHeight); + } } diff --git a/src/main/java/me/shedaniel/listeners/ResizeListener.java b/src/main/java/me/shedaniel/listeners/ResizeListener.java deleted file mode 100755 index 2d16e1ad1..000000000 --- a/src/main/java/me/shedaniel/listeners/ResizeListener.java +++ /dev/null @@ -1,14 +0,0 @@ -package me.shedaniel.listeners; - -import me.shedaniel.gui.REIRenderHelper; -import me.shedaniel.listenerdefinitions.MinecraftResize; - -/** - * Created by James on 7/28/2018. - */ -public class ResizeListener implements MinecraftResize { - @Override - public void resize(int scaledWidth, int scaledHeight) { - REIRenderHelper.resize(scaledWidth, scaledHeight); - } -} diff --git a/src/main/java/me/shedaniel/mixins/MixinMinecraftClient.java b/src/main/java/me/shedaniel/mixins/MixinMinecraftClient.java deleted file mode 100644 index 110ff5beb..000000000 --- a/src/main/java/me/shedaniel/mixins/MixinMinecraftClient.java +++ /dev/null @@ -1,33 +0,0 @@ -package me.shedaniel.mixins; - -import me.shedaniel.Core; -import me.shedaniel.listenerdefinitions.ClientTickable; -import me.shedaniel.listenerdefinitions.KeybindHandler; -import net.minecraft.class_3689; -import net.minecraft.client.MinecraftClient; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MinecraftClient.class) -public class MixinMinecraftClient { - - @Shadow - @Final - private class_3689 profiler; - - @Inject(method = "tick", at = @At("RETURN")) - private void onTick(CallbackInfo ci) { - profiler.begin("mods"); - for(ClientTickable tickable : Core.getListeners(ClientTickable.class)) { - profiler.begin(() -> tickable.getClass().getCanonicalName().replace('.', '/')); - tickable.clientTick(); - profiler.end(); - } - profiler.end(); - } - -} diff --git a/src/main/java/me/shedaniel/network/CheatPacket.java b/src/main/java/me/shedaniel/network/CheatPacket.java index ceeb9674f..007c121b2 100755 --- a/src/main/java/me/shedaniel/network/CheatPacket.java +++ b/src/main/java/me/shedaniel/network/CheatPacket.java @@ -5,6 +5,8 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.Packet; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sortme.ChatMessageType; +import net.minecraft.text.TranslatableTextComponent; import net.minecraft.util.PacketByteBuf; import java.io.IOException; @@ -39,7 +41,9 @@ public class CheatPacket implements Packet { public void apply(ServerPlayNetworkHandler iNetHandlerPlayServer) { ServerPlayNetworkHandler server = (ServerPlayNetworkHandler) iNetHandlerPlayServer; ServerPlayerEntity player = server.player; - player.inventory.addPickBlock(stack); + if (player.inventory.insertStack(stack.copy())) + player.sendChatMessage(new TranslatableTextComponent("text.rei.cheat_items", stack.getDisplayName().getFormattedText(), stack.getAmount(), player.getEntityName()), ChatMessageType.SYSTEM); + else player.sendChatMessage(new TranslatableTextComponent("text.rei.failed_cheat_items"), ChatMessageType.SYSTEM); } } 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..bb1a1a7f0 --- /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.block.Blocks; +import net.minecraft.item.ItemStack; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public class RandomRecipe implements IRecipe { + + private String id; + + public RandomRecipe(String id) { + this.id = id; + } + + @Override + public String getId() { + return id; + } + + @Override + public List getOutput() { + return new LinkedList<>(Arrays.asList(new ItemStack[]{new ItemStack(Blocks.BEETROOTS.getItem())})); + } + + @Override + public List> getInput() { + return new LinkedList<>(Arrays.asList(new LinkedList<>(Arrays.asList(new ItemStack[]{new ItemStack(Blocks.OAK_LOG.getItem())})))); + } +} \ No newline at end of file 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..2076fca19 --- /dev/null +++ b/src/main/java/me/shedaniel/plugin/TestRandomCategory.java @@ -0,0 +1,69 @@ +package me.shedaniel.plugin; + +import me.shedaniel.api.IDisplayCategory; +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.REISlot; +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class TestRandomCategory implements IDisplayCategory { + + private String id; + private List 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 setupDisplay(int number) { + return new LinkedList<>(); + } + + @Override + public boolean canDisplay(RandomRecipe recipe) { + return false; + } + + @Override + public void drawExtras() { + + } + + @Override + public void addWidget(List controls, int number) { + + } + + @Override + public ItemStack getCategoryIcon() { + return item; + } +} \ No newline at end of file diff --git a/src/main/java/me/shedaniel/plugin/VanillaPlugin.java b/src/main/java/me/shedaniel/plugin/VanillaPlugin.java index 74b734761..bd9d93e53 100755 --- a/src/main/java/me/shedaniel/plugin/VanillaPlugin.java +++ b/src/main/java/me/shedaniel/plugin/VanillaPlugin.java @@ -30,6 +30,8 @@ import net.minecraft.recipe.smelting.SmeltingRecipe; import net.minecraft.recipe.smelting.SmokingRecipe; import net.minecraft.util.registry.Registry; +import java.lang.reflect.Array; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; @@ -46,7 +48,15 @@ public class VanillaPlugin implements IREIPlugin, PotionCraftingAdder { List blastFurnaceRecipes = new LinkedList<>(); REIRecipeManager.instance().addDisplayAdapter(new VanillaCraftingCategory()); REIRecipeManager.instance().addDisplayAdapter(new VanillaFurnaceCategory()); + REIRecipeManager.instance().addDisplayAdapter(new VanillaSmokerCategory()); + REIRecipeManager.instance().addDisplayAdapter(new VanillaBlastFurnaceCategory()); REIRecipeManager.instance().addDisplayAdapter(new VanillaPotionCategory()); + REIRecipeManager.instance().addDisplayAdapter(new TestRandomCategory("a", new ItemStack(Items.ITEM_FRAME))); + REIRecipeManager.instance().addDisplayAdapter(new TestRandomCategory("b", new ItemStack(Items.ITEM_FRAME))); + REIRecipeManager.instance().addDisplayAdapter(new TestRandomCategory("c", new ItemStack(Items.ITEM_FRAME))); + REIRecipeManager.instance().addDisplayAdapter(new TestRandomCategory("d", new ItemStack(Items.ITEM_FRAME))); + REIRecipeManager.instance().addDisplayAdapter(new TestRandomCategory("e", new ItemStack(Items.ITEM_FRAME))); + for(Recipe recipe : REIRecipeManager.instance().recipeManager.values()) { if (recipe instanceof ShapelessRecipe) { @@ -80,11 +90,17 @@ public class VanillaPlugin implements IREIPlugin, PotionCraftingAdder { REIRecipeManager.instance().addRecipe("smoker", smokerRecipes); REIRecipeManager.instance().addRecipe("potion", potionRecipes.stream().distinct().collect(Collectors.toList())); REIRecipeManager.instance().addRecipe("blastingfurnace", blastFurnaceRecipes); + REIRecipeManager.instance().addRecipe("a", Arrays.asList(new RandomRecipe("a"))); + REIRecipeManager.instance().addRecipe("b", Arrays.asList(new RandomRecipe("b"))); + REIRecipeManager.instance().addRecipe("c", Arrays.asList(new RandomRecipe("c"))); + REIRecipeManager.instance().addRecipe("d", Arrays.asList(new RandomRecipe("d"))); + REIRecipeManager.instance().addRecipe("e", Arrays.asList(new RandomRecipe("e"))); } @Override public void addPotionRecipe(Potion inputType, Item reagent, Potion outputType) { + System.out.printf("%s%s%n", inputType.getName(""), outputType.getName("")); potionRecipes.add(new VanillaPotionRecipe(new ItemStack[]{PotionUtil.setPotion(new ItemStack(Items.POTION), inputType)}, Ingredient.ofItems(reagent).getStackArray(), new ItemStack[]{PotionUtil.setPotion(new ItemStack(Items.POTION), outputType)})); diff --git a/src/main/java/me/shedaniel/plugin/blastfurnace/VanillaBlastFurnaceCategory.java b/src/main/java/me/shedaniel/plugin/blastfurnace/VanillaBlastFurnaceCategory.java index 4ef67cbf9..159d274ae 100755 --- a/src/main/java/me/shedaniel/plugin/blastfurnace/VanillaBlastFurnaceCategory.java +++ b/src/main/java/me/shedaniel/plugin/blastfurnace/VanillaBlastFurnaceCategory.java @@ -80,7 +80,7 @@ public class VanillaBlastFurnaceCategory implements IDisplayCategory getFuel() { - return BlastFurnaceBlockEntity.getBurnTimeMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList()); + return BlastFurnaceBlockEntity.createBurnableMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList()); } @Override diff --git a/src/main/java/me/shedaniel/plugin/blastfurnace/VanillaBlastFurnaceRecipe.java b/src/main/java/me/shedaniel/plugin/blastfurnace/VanillaBlastFurnaceRecipe.java index 3eabdca66..6554420c3 100755 --- a/src/main/java/me/shedaniel/plugin/blastfurnace/VanillaBlastFurnaceRecipe.java +++ b/src/main/java/me/shedaniel/plugin/blastfurnace/VanillaBlastFurnaceRecipe.java @@ -41,7 +41,7 @@ public class VanillaBlastFurnaceRecipe implements IRecipe { List ingredients = Arrays.asList(ingredient.getStackArray()); input.add(ingredients); } - input.add(BlastFurnaceBlockEntity.getBurnTimeMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList())); + input.add(BlastFurnaceBlockEntity.createBurnableMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList())); return input; } } diff --git a/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java b/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java index 969ae4265..12e7d2324 100755 --- a/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java +++ b/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceCategory.java @@ -79,7 +79,7 @@ public class VanillaFurnaceCategory implements IDisplayCategory getFuel() { - return FurnaceBlockEntity.getBurnTimeMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList()); + return FurnaceBlockEntity.createBurnableMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList()); } @Override diff --git a/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceRecipe.java b/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceRecipe.java index 8023741b4..0e7d00dd5 100755 --- a/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceRecipe.java +++ b/src/main/java/me/shedaniel/plugin/furnace/VanillaFurnaceRecipe.java @@ -38,7 +38,7 @@ public class VanillaFurnaceRecipe implements IRecipe { List ingredients = Arrays.asList(ingredient.getStackArray()); input.add(ingredients); } - input.add(FurnaceBlockEntity.getBurnTimeMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList())); + input.add(FurnaceBlockEntity.createBurnableMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList())); return input; } } diff --git a/src/main/java/me/shedaniel/plugin/smoker/VanillaSmokerCategory.java b/src/main/java/me/shedaniel/plugin/smoker/VanillaSmokerCategory.java index 6bbb896d1..477578e6a 100755 --- a/src/main/java/me/shedaniel/plugin/smoker/VanillaSmokerCategory.java +++ b/src/main/java/me/shedaniel/plugin/smoker/VanillaSmokerCategory.java @@ -79,7 +79,7 @@ public class VanillaSmokerCategory implements IDisplayCategory getFuel() { - return SmokerBlockEntity.getBurnTimeMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList()); + return SmokerBlockEntity.createBurnableMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList()); } @Override diff --git a/src/main/java/me/shedaniel/plugin/smoker/VanillaSmokerRecipe.java b/src/main/java/me/shedaniel/plugin/smoker/VanillaSmokerRecipe.java index f05a01fc7..4eadd9db1 100755 --- a/src/main/java/me/shedaniel/plugin/smoker/VanillaSmokerRecipe.java +++ b/src/main/java/me/shedaniel/plugin/smoker/VanillaSmokerRecipe.java @@ -38,7 +38,7 @@ public class VanillaSmokerRecipe implements IRecipe { List ingredients = Arrays.asList(ingredient.getStackArray()); input.add(ingredients); } - input.add(SmokerBlockEntity.getBurnTimeMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList())); + input.add(SmokerBlockEntity.createBurnableMap().keySet().stream().map(Item::getDefaultStack).collect(Collectors.toList())); return input; } } diff --git a/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/src/main/resources/assets/roughlyenoughitems/lang/en_us.json index b751c348c..81e288f54 100755 --- a/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -18,5 +18,7 @@ "text.rei.config": "Config", "text.rei.listeningkey": "Listening Key", "text.rei.centre_searchbox": "Center Search Box: %s%b", - "text.rei.centre_searchbox.tooltip": "Please restart Minecraft after editing\nthis config to apply the changes" + "text.rei.centre_searchbox.tooltip": "Please restart Minecraft after editing\nthis config to apply the changes", + "text.rei.cheat_items": "Given [%s] x%d to %s.", + "text.rei.failed_cheat_items": "§cFailed to give items." } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index adb00b605..6dc51e92a 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -2,7 +2,7 @@ "id": "roughlyenoughitems", "name": "RoughlyEnoughItems", "description": "To allow players to view items and recipes.", - "version": "1.3", + "version": "1.4", "side": "client", "authors": [ "Danielshe" @@ -11,7 +11,7 @@ "me.shedaniel.Core" ], "requires": { - + "fabric": "*" }, "mixins": { "client": "roughlyenoughitems.client.json" diff --git a/src/main/resources/roughlyenoughitems.client.json b/src/main/resources/roughlyenoughitems.client.json index 90a581009..2b3fe6d26 100755 --- a/src/main/resources/roughlyenoughitems.client.json +++ b/src/main/resources/roughlyenoughitems.client.json @@ -9,8 +9,7 @@ "MixinMinecraftResize", "MixinKeyboardListener", "MixinRecipeManager", - "MixinCreativePlayerInventoryGui", - "MixinMinecraftClient" + "MixinCreativePlayerInventoryGui" ], "injectors": { "defaultRequire": 1 -- cgit