From f0b9c30ef514a1489430d606316236347e8d8d32 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Thu, 18 Jul 2019 10:24:36 +0200 Subject: [PATCH] Jar Fixes - Fixed ScrollFixer not working in built jar - updated mods.toml - moved TreeFertilizer to item package --- build.gradle | 4 +-- .../java/com/simibubi/create/AllItems.java | 2 +- src/main/java/com/simibubi/create/Create.java | 4 --- .../java/com/simibubi/create/ScrollFixer.java | 36 +++++++++---------- .../create/gui/BlueprintHotbarOverlay.java | 2 +- .../ItemTreeFertilizer.java | 5 ++- .../schematic/BlueprintAndQuillHandler.java | 15 +++++--- .../create/schematic/BlueprintHandler.java | 10 ++++++ src/main/resources/META-INF/mods.toml | 12 ++----- 9 files changed, 46 insertions(+), 44 deletions(-) rename src/main/java/com/simibubi/create/{supertree => item}/ItemTreeFertilizer.java (97%) diff --git a/build.gradle b/build.gradle index af8cd416c..163c3ce42 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ minecraft { // stable_# Stables are built at the discretion of the MCP team. // Use non-default mappings at your own risk. they may not always work. // Simply re-run your setup task after changing the mappings to update your workspace. - mappings channel: 'snapshot', version: '20190621-1.14.2' + mappings channel: 'snapshot', version: '20190717-1.14.3' // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. // accessTransformer = file('build/resources/main/META-INF/accesstransformer.cfg') @@ -89,7 +89,7 @@ dependencies { // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied. // The userdev artifact is a special name and will get all sorts of transformations applied to it. - minecraft 'net.minecraftforge:forge:1.14.3-27.0.43' + minecraft 'net.minecraftforge:forge:1.14.3-27.0.57' // You may put jars on which you depend on in ./libs or you may define them like so.. // compile "some.group:artifact:version:classifier" diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index d2f367a64..28c3175cd 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -2,8 +2,8 @@ package com.simibubi.create; import com.simibubi.create.item.ItemBlueprint; import com.simibubi.create.item.ItemBlueprintAndQuill; +import com.simibubi.create.item.ItemTreeFertilizer; import com.simibubi.create.item.ItemWandSymmetry; -import com.simibubi.create.supertree.ItemTreeFertilizer; import net.minecraft.item.Item; import net.minecraft.item.Item.Properties; diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index df42b7308..fd3e6d797 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -5,7 +5,6 @@ import org.apache.logging.log4j.Logger; import com.simibubi.create.gui.Keyboard; import com.simibubi.create.networking.Packets; -import com.simibubi.create.schematic.BlueprintAndQuillHandler; import com.simibubi.create.schematic.BlueprintHandler; import com.simibubi.create.schematic.SchematicHologram; @@ -63,9 +62,6 @@ public class Create { new SchematicHologram(); new BlueprintHandler(); ScrollFixer.init(); - ScrollFixer.addMouseWheelListener(BlueprintHandler.instance::onScroll); - ScrollFixer.addMouseWheelListener(BlueprintAndQuillHandler::onScroll); - TOOL_MENU = new KeyBinding("Tool Menu (Hold)", Keyboard.LALT, NAME); ClientRegistry.registerKeyBinding(TOOL_MENU); }); diff --git a/src/main/java/com/simibubi/create/ScrollFixer.java b/src/main/java/com/simibubi/create/ScrollFixer.java index d896a94c3..691392d22 100644 --- a/src/main/java/com/simibubi/create/ScrollFixer.java +++ b/src/main/java/com/simibubi/create/ScrollFixer.java @@ -2,49 +2,45 @@ package com.simibubi.create; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Predicate; import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFWScrollCallback; import net.minecraft.client.Minecraft; import net.minecraft.client.MouseHelper; +import net.minecraftforge.client.event.GuiScreenEvent.MouseScrollEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.ObfuscationReflectionHelper; public class ScrollFixer { - private static List> listeners; - public static void init() { - listeners = new ArrayList<>(); - Method method; try { MouseHelper mouseHelper = Minecraft.getInstance().mouseHelper; - method = mouseHelper.getClass().getDeclaredMethod("scrollCallback", Long.TYPE, + Method method = ObfuscationReflectionHelper.findMethod(mouseHelper.getClass(), "func_198020_a", Long.TYPE, Double.TYPE, Double.TYPE); - method.setAccessible(true); - GLFW.glfwSetScrollCallback(Minecraft.getInstance().mainWindow.getHandle(), new GLFWScrollCallback() { + + GLFWScrollCallback callback = new GLFWScrollCallback() { @Override public void invoke(long win, double dx, double dy) { - for (Predicate consumer : listeners) { - if (consumer.test(dy)) - return; - } + MouseScrollEvent.Post event = new MouseScrollEvent.Post(null, mouseHelper.getMouseX(), + mouseHelper.getMouseY(), dy); + boolean canceled = MinecraftForge.EVENT_BUS.post(event); + if (canceled) + return; + try { method.invoke(mouseHelper, win, dx, dy); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); } } - }); - } catch (NoSuchMethodException | SecurityException e1) { + }; + + GLFW.glfwSetScrollCallback(Minecraft.getInstance().mainWindow.getHandle(), callback); + } catch (SecurityException e1) { e1.printStackTrace(); } } - public static void addMouseWheelListener(Predicate callback) { - listeners.add(callback); - } - } diff --git a/src/main/java/com/simibubi/create/gui/BlueprintHotbarOverlay.java b/src/main/java/com/simibubi/create/gui/BlueprintHotbarOverlay.java index a5712f38e..5a876abdc 100644 --- a/src/main/java/com/simibubi/create/gui/BlueprintHotbarOverlay.java +++ b/src/main/java/com/simibubi/create/gui/BlueprintHotbarOverlay.java @@ -12,9 +12,9 @@ public class BlueprintHotbarOverlay extends AbstractGui { MainWindow mainWindow = Minecraft.getInstance().mainWindow; int x = mainWindow.getScaledWidth() / 2 - 92; int y = mainWindow.getScaledHeight() - 23; - GlStateManager.enableBlend(); GlStateManager.enableAlphaTest(); GuiResources.BLUEPRINT_SLOT.draw(this, x + 20 * slot, y); + GlStateManager.disableAlphaTest(); } } diff --git a/src/main/java/com/simibubi/create/supertree/ItemTreeFertilizer.java b/src/main/java/com/simibubi/create/item/ItemTreeFertilizer.java similarity index 97% rename from src/main/java/com/simibubi/create/supertree/ItemTreeFertilizer.java rename to src/main/java/com/simibubi/create/item/ItemTreeFertilizer.java index 32d8cc348..b817395e8 100644 --- a/src/main/java/com/simibubi/create/supertree/ItemTreeFertilizer.java +++ b/src/main/java/com/simibubi/create/item/ItemTreeFertilizer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.supertree; +package com.simibubi.create.item; import java.util.Collections; import java.util.HashMap; @@ -68,6 +68,9 @@ public class ItemTreeFertilizer extends Item { context.getWorld().setBlockState(actualPos, world.getBlockState(pos)); } + + if (!context.getPlayer().isCreative()) + context.getItem().shrink(1); return ActionResultType.SUCCESS; } diff --git a/src/main/java/com/simibubi/create/schematic/BlueprintAndQuillHandler.java b/src/main/java/com/simibubi/create/schematic/BlueprintAndQuillHandler.java index 6dfb49f5a..db1ddbcdb 100644 --- a/src/main/java/com/simibubi/create/schematic/BlueprintAndQuillHandler.java +++ b/src/main/java/com/simibubi/create/schematic/BlueprintAndQuillHandler.java @@ -35,6 +35,7 @@ import net.minecraft.util.math.RayTraceResult.Type; import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.gen.feature.template.Template; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.GuiScreenEvent.MouseScrollEvent; import net.minecraftforge.client.event.InputEvent.MouseInputEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -58,13 +59,17 @@ public class BlueprintAndQuillHandler { && Minecraft.getInstance().currentScreen == null && !Minecraft.getInstance().player.isSneaking(); } - public static boolean onScroll(double delta) { + @SubscribeEvent + // TODO: This is a fabricated event call by ScrollFixer until a proper event exists + public static void onMouseScrolled(MouseScrollEvent.Post event) { + if (event.getGui() != null) + return; if (!active()) - return false; + return; if (!Keyboard.isKeyDown(GLFW.GLFW_KEY_LEFT_CONTROL)) - return false; - range = (int) MathHelper.clamp(range + delta, 1, 100); - return true; + return; + range = (int) MathHelper.clamp(range + event.getScrollDelta(), 1, 100); + event.setCanceled(true); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/schematic/BlueprintHandler.java b/src/main/java/com/simibubi/create/schematic/BlueprintHandler.java index 2170d9a7f..89e163c85 100644 --- a/src/main/java/com/simibubi/create/schematic/BlueprintHandler.java +++ b/src/main/java/com/simibubi/create/schematic/BlueprintHandler.java @@ -37,6 +37,7 @@ import net.minecraftforge.client.event.InputEvent.KeyInputEvent; import net.minecraftforge.client.event.InputEvent.MouseInputEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.client.event.GuiScreenEvent.MouseScrollEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; @@ -215,6 +216,15 @@ public class BlueprintHandler { toolSelection.focused = true; } + @SubscribeEvent + // TODO: This is a fabricated event call by ScrollFixer until a proper event exists + public static void onMouseScrolled(MouseScrollEvent.Post event) { + if (event.getGui() != null) + return; + if (instance.onScroll(event.getScrollDelta())) + event.setCanceled(true); + } + public boolean onScroll(double delta) { if (!active) return false; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 24fd5fc78..a90935318 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -14,26 +14,18 @@ loaderVersion="[26,)" #mandatory (26 is current forge version) # The modid of the mod modId="create" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it -version="${file.jarVersion}" #mandatory +version="0.0.1" #mandatory # A display name for the mod displayName="Create" #mandatory # A URL to query for updates for this mod. See the JSON update specification #updateJSONURL=""#optional # A URL for the "homepage" for this mod, displayed in the mod UI -displayURL="http://example.com/" #optional # A file name (in the root of the mod JAR) containing a logo for display -logoFile="examplemod.png" #optional -# A text field displayed in the mod UI -credits="Thanks for this example mod goes to Java" #optional # A text field displayed in the mod UI authors="simibubi" #optional # The description text for the mod (multi line!) (#mandatory) description=''' -This is a long form description of the mod. You can write whatever you want here - -Have some lorem ipsum. - -Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis lacinia magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis luctus odio eu tempus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque volutpat ligula eget lacus auctor sagittis. In hac habitasse platea dictumst. Nunc gravida elit vitae sem vehicula efficitur. Donec mattis ipsum et arcu lobortis, eleifend sagittis sem rutrum. Cras pharetra quam eget posuere fermentum. Sed id tincidunt justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. +A handful of additions to aid the creative survivalist. ''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. [[dependencies.examplemod]] #optional