From 799ebb9fa057580b3ab05367607bb3228797d777 Mon Sep 17 00:00:00 2001 From: Violet-Scarelli <33497956+Violet-Scarelli@users.noreply.github.com> Date: Fri, 27 May 2022 16:14:45 -0700 Subject: [PATCH 1/2] Fixed the mouse button problems with the linked controller. (#3069) * Fixed the mouse button problems with the linked controller. (Closes #2807) * Now with added elegance * I'm here I might as well tie up some loose ends * Compacting out some spaces * This was probably the way it was for a good reason --- src/main/java/com/simibubi/create/AllKeys.java | 6 ++++++ .../logistics/item/LinkedControllerClientHandler.java | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/AllKeys.java b/src/main/java/com/simibubi/create/AllKeys.java index 58ad25fdf..8010fe460 100644 --- a/src/main/java/com/simibubi/create/AllKeys.java +++ b/src/main/java/com/simibubi/create/AllKeys.java @@ -63,6 +63,12 @@ public enum AllKeys { .getWindow(), key) != 0; } + public static boolean isMouseButtonDown(int button){ + return GLFW.glfwGetMouseButton(Minecraft.getInstance() + .getWindow() + .getWindow(), button) != 0; + } + public static boolean ctrlDown() { return Screen.hasControlDown(); } diff --git a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerClientHandler.java b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerClientHandler.java index 1c3452d7f..1671bda41 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerClientHandler.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerClientHandler.java @@ -6,6 +6,8 @@ import java.util.HashSet; import java.util.List; import java.util.Vector; +import com.simibubi.create.AllKeys; + import org.lwjgl.glfw.GLFW; import com.mojang.blaze3d.platform.InputConstants; @@ -116,11 +118,10 @@ public class LinkedControllerClientHandler { } protected static boolean isActuallyPressed(KeyMapping kb) { - return InputConstants.isKeyDown(Minecraft.getInstance() - .getWindow() - .getWindow(), - kb.getKey() - .getValue()); + if(kb.matchesMouse(kb.getKey().getValue())) + return AllKeys.isMouseButtonDown(kb.getKey().getValue()); + else + return AllKeys.isKeyDown(kb.getKey().getValue()); } public static void tick() { From 97da6be27fc7f4422531fbd298d998ab32a19090 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Fri, 27 May 2022 17:58:56 -0700 Subject: [PATCH 2/2] Add wrench to wrench tag - Fix stress capacity tooltip --- src/generated/resources/.cache/cache | 1 + .../data/forge/tags/items/tools/wrench.json | 6 ++++++ src/main/java/com/simibubi/create/AllItems.java | 1 + src/main/java/com/simibubi/create/AllKeys.java | 12 +++++++----- src/main/java/com/simibubi/create/AllTags.java | 3 ++- .../item/LinkedControllerClientHandler.java | 13 +++++++------ .../create/foundation/item/ItemDescription.java | 16 +++++++--------- 7 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 src/generated/resources/data/forge/tags/items/tools/wrench.json diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 9692f8b06..2e8dc473b 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -5258,6 +5258,7 @@ dc96331cded39b2d2f24853f4dd6c1f6f3863115 data/forge/tags/items/raw_materials/zin ff1900963bc4cd8ceffa78d58ef1952ceacb2fb7 data/forge/tags/items/storage_blocks/brass.json 823d05187626797205381d4620a84abda3bc8f89 data/forge/tags/items/storage_blocks/raw_zinc.json 7f71a774800111e50b42de0e6159ed2d2a807d32 data/forge/tags/items/storage_blocks/zinc.json +e002dfedc5e8762de0f97ea1f3fa546e92e748ae data/forge/tags/items/tools/wrench.json 2db7759fe036160c14c6ed19a68604ca16f4de60 data/minecraft/tags/blocks/azalea_root_replaceable.json 9f7a428085b1aac66da32a43e9d51c7efc1f0d81 data/minecraft/tags/blocks/beacon_base_blocks.json 2db7759fe036160c14c6ed19a68604ca16f4de60 data/minecraft/tags/blocks/dripstone_replaceable_blocks.json diff --git a/src/generated/resources/data/forge/tags/items/tools/wrench.json b/src/generated/resources/data/forge/tags/items/tools/wrench.json new file mode 100644 index 000000000..bfa16b91b --- /dev/null +++ b/src/generated/resources/data/forge/tags/items/tools/wrench.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "create:wrench" + ] +} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index 41147d22c..1f7d0c2f5 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -274,6 +274,7 @@ public class AllItems { public static final ItemEntry WRENCH = REGISTRATE.item("wrench", WrenchItem::new) .properties(p -> p.stacksTo(1)) .model(AssetLookup.itemModelWithPartials()) + .tag(AllItemTags.WRENCH.tag) .register(); public static final ItemEntry MINECART_CONTRAPTION = diff --git a/src/main/java/com/simibubi/create/AllKeys.java b/src/main/java/com/simibubi/create/AllKeys.java index 8010fe460..8da43a2c8 100644 --- a/src/main/java/com/simibubi/create/AllKeys.java +++ b/src/main/java/com/simibubi/create/AllKeys.java @@ -2,6 +2,8 @@ package com.simibubi.create; import org.lwjgl.glfw.GLFW; +import com.mojang.blaze3d.platform.InputConstants; + import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; @@ -58,15 +60,15 @@ public enum AllKeys { } public static boolean isKeyDown(int key) { - return GLFW.glfwGetKey(Minecraft.getInstance() + return InputConstants.isKeyDown(Minecraft.getInstance() .getWindow() - .getWindow(), key) != 0; + .getWindow(), key); } - public static boolean isMouseButtonDown(int button){ + public static boolean isMouseButtonDown(int button) { return GLFW.glfwGetMouseButton(Minecraft.getInstance() - .getWindow() - .getWindow(), button) != 0; + .getWindow() + .getWindow(), button) == 1; } public static boolean ctrlDown() { diff --git a/src/main/java/com/simibubi/create/AllTags.java b/src/main/java/com/simibubi/create/AllTags.java index 9a0536f1e..b77061fa4 100644 --- a/src/main/java/com/simibubi/create/AllTags.java +++ b/src/main/java/com/simibubi/create/AllTags.java @@ -201,7 +201,8 @@ public class AllTags { VALVE_HANDLES, BEACON_PAYMENT(FORGE), - PLATES(FORGE) + PLATES(FORGE), + WRENCH(FORGE, "tools/wrench") ; diff --git a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerClientHandler.java b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerClientHandler.java index 1671bda41..1995c6f58 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerClientHandler.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerClientHandler.java @@ -6,14 +6,13 @@ import java.util.HashSet; import java.util.List; import java.util.Vector; -import com.simibubi.create.AllKeys; - import org.lwjgl.glfw.GLFW; import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; +import com.simibubi.create.AllKeys; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.item.TooltipHelper; @@ -118,10 +117,12 @@ public class LinkedControllerClientHandler { } protected static boolean isActuallyPressed(KeyMapping kb) { - if(kb.matchesMouse(kb.getKey().getValue())) - return AllKeys.isMouseButtonDown(kb.getKey().getValue()); - else - return AllKeys.isKeyDown(kb.getKey().getValue()); + InputConstants.Key key = kb.getKey(); + if (key.getType() == InputConstants.Type.MOUSE) { + return AllKeys.isMouseButtonDown(key.getValue()); + } else { + return AllKeys.isKeyDown(key.getValue()); + } } public static void tick() { diff --git a/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java b/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java index 47992e3c7..4c2f7a935 100644 --- a/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java +++ b/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java @@ -107,9 +107,8 @@ public class ItemDescription { boolean hasStressCapacity = StressImpact.isEnabled() && BlockStressValues.hasCapacity(block); if (hasSpeedRequirement) { - int index = minimumRequiredSpeedLevel.ordinal(); MutableComponent level = - new TextComponent(makeProgressBar(3, index)).withStyle(minimumRequiredSpeedLevel.getTextColor()); + new TextComponent(makeProgressBar(3, minimumRequiredSpeedLevel.ordinal())).withStyle(minimumRequiredSpeedLevel.getTextColor()); if (hasGoggles) level.append(String.valueOf(minimumRequiredSpeedLevel.getSpeedValue())) @@ -127,9 +126,8 @@ public class ItemDescription { double impact = BlockStressValues.getImpact(block); StressImpact impactId = impact >= config.highStressImpact.get() ? StressImpact.HIGH : (impact >= config.mediumStressImpact.get() ? StressImpact.MEDIUM : StressImpact.LOW); - int index = impactId.ordinal(); MutableComponent level = - new TextComponent(makeProgressBar(3, index + 1)).withStyle(impactId.getAbsoluteColor()); + new TextComponent(makeProgressBar(3, impactId.ordinal() + 1)).withStyle(impactId.getAbsoluteColor()); if (hasGoggles) level.append(impact + "x ") @@ -144,17 +142,17 @@ public class ItemDescription { if (hasStressCapacity) { double capacity = BlockStressValues.getCapacity(block); - StressImpact impactId = capacity >= config.highCapacity.get() ? StressImpact.LOW - : (capacity >= config.mediumCapacity.get() ? StressImpact.MEDIUM : StressImpact.HIGH); - int index = StressImpact.values().length - 2 - impactId.ordinal(); + StressImpact impactId = capacity >= config.highCapacity.get() ? StressImpact.HIGH + : (capacity >= config.mediumCapacity.get() ? StressImpact.MEDIUM : StressImpact.LOW); + StressImpact opposite = StressImpact.values()[StressImpact.values().length - 2 - impactId.ordinal()]; MutableComponent level = - new TextComponent(makeProgressBar(3, index + 1)).withStyle(impactId.getAbsoluteColor()); + new TextComponent(makeProgressBar(3, impactId.ordinal() + 1)).withStyle(opposite.getAbsoluteColor()); if (hasGoggles) level.append(capacity + "x ") .append(rpmUnit); else - level.append(Lang.translate("tooltip.capacityProvided." + Lang.asId(impactId.name()))); + level.append(Lang.translate("tooltip.capacityProvided." + Lang.asId(opposite.name()))); // if (!isEngine && ((IRotate) block).showCapacityWithAnnotation()) // level +=