Skip to content

Commit

Permalink
Fixed AW bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jun 14, 2024
1 parent d631de5 commit 6979aed
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public void registerTypeWrappers(TypeWrapperRegistry registry) {

@Override
public void generateLang(LangKubeEvent event) {
event.add(KubeJS.MOD_ID, "key.kubejs.gui", "KubeJS (GUI)");
event.add(KubeJS.MOD_ID, "key.kubejs.in_game", "KubeJS (In-Game)");
event.add(KubeJS.MOD_ID, "key.kubejs", "KubeJS Info");

if (ModList.get().isLoaded("jade")) {
for (var mod : PlatformWrapper.getMods().values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import java.util.concurrent.CompletableFuture;

public class KubeJSClient extends KubeJSCommon {
public static KeyMapping guiKey;
public static KeyMapping inGameKey;
public static KeyMapping key;
public static boolean keyDown = false;

@Override
public void reloadClientInternal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent;
import net.neoforged.neoforge.client.event.RenderGuiEvent;
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
import net.neoforged.neoforge.client.event.ScreenEvent;
import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -131,15 +133,34 @@ public static void loggingOut(ClientPlayerNetworkEvent.LoggingOut event) {
}

@SubscribeEvent
public static void onRenderGuiPost(RenderGuiEvent.Post event) {
public static void hudPostDraw(RenderGuiEvent.Post event) {
Painter.getGlobal().inGameScreenDraw(event.getGuiGraphics(), event.getPartialTick());
}

@SubscribeEvent
public static void onRenderPost(ScreenEvent.Render.Post event) {
public static void screenPostDraw(ScreenEvent.Render.Post event) {
Painter.getGlobal().guiScreenDraw(event.getScreen(), event.getGuiGraphics(), event.getMouseX(), event.getMouseY(), event.getPartialTick());
}

@SubscribeEvent
public static void clientTick(ClientTickEvent.Post event) {
var mc = Minecraft.getInstance();
boolean prevKeyDown = KubeJSClient.keyDown;

KubeJSClient.keyDown = mc.level != null && mc.player != null && KubeJSClient.key != null && !mc.isPaused() && mc.kjs$isKeyMappingDown(KubeJSClient.key);

if (prevKeyDown != KubeJSClient.keyDown) {
// KubeJS.LOGGER.info("AAAA");
}
}

@SubscribeEvent
public static void worldRender(RenderLevelStageEvent event) {
if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) {
// noop
}
}

@Nullable
public static Screen setScreen(Screen screen) {
if (screen instanceof TitleScreen && !ConsoleJS.STARTUP.errors.isEmpty() && CommonProperties.get().startupErrorGUI) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/dev/latvian/mods/kubejs/core/MinecraftClientKJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import dev.latvian.mods.kubejs.util.ConsoleJS;
import dev.latvian.mods.rhino.util.HideFromJS;
import dev.latvian.mods.rhino.util.RemapPrefixForJS;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;

@SuppressWarnings("resource")
@RemapPrefixForJS("kjs$")
Expand Down Expand Up @@ -71,6 +73,18 @@ public interface MinecraftClientKJS extends MinecraftEnvironmentKJS {
return InputConstants.isKeyDown(kjs$self().getWindow().getWindow(), key);
}

default boolean kjs$isKeyMappingDown(KeyMapping key) {
if (!key.isUnbound() && key.isConflictContextAndModifierActive()) {
if (key.getKey().getType() == InputConstants.Type.KEYSYM) {
return kjs$isKeyDown(key.getKey().getValue());
} else if (key.getKey().getType() == InputConstants.Type.MOUSE) {
return GLFW.glfwGetMouseButton(kjs$self().getWindow().getWindow(), key.getKey().getValue()) == GLFW.GLFW_TRUE;
}
}

return false;
}

default boolean kjs$isShiftDown() {
return Screen.hasShiftDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public static void registerMenuScreens(RegisterMenuScreensEvent event) {

@SubscribeEvent
public static void registerKeyMappings(RegisterKeyMappingsEvent event) {
event.register(KubeJSClient.guiKey = new KeyMapping("key.kubejs.gui", KeyConflictContext.GUI, KeyModifier.NONE, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, KeyMapping.CATEGORY_MISC));
event.register(KubeJSClient.inGameKey = new KeyMapping("key.kubejs.in_game", KeyConflictContext.IN_GAME, KeyModifier.NONE, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, KeyMapping.CATEGORY_MISC));
event.register(KubeJSClient.key = new KeyMapping("key.kubejs", KeyConflictContext.UNIVERSAL, KeyModifier.NONE, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, KeyMapping.CATEGORY_MISC));
}
}
2 changes: 1 addition & 1 deletion src/main/resources/kubejs.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ transitive-extendable class net/minecraft/world/item/crafting/Ingredient$Value
accessible field net/minecraft/world/item/crafting/ShapedRecipe pattern Lnet/minecraft/world/item/crafting/ShapedRecipePattern;
accessible field net/minecraft/world/item/crafting/ShapedRecipe result Lnet/minecraft/world/item/ItemStack;
accessible field net/minecraft/world/item/crafting/ShapedRecipe showNotification Z
accessible method net/minecraft/world/item/crafting/ShapedRecipePattern matches (Lnet/minecraft/world/inventory/CraftingContainer;IIZ)Z
# accessible method net/minecraft/world/item/crafting/ShapedRecipePattern matches (Lnet/minecraft/world/inventory/CraftingContainer;IIZ)Z

accessible field net/minecraft/server/level/ServerPlayerGameMode isDestroyingBlock Z
accessible method net/minecraft/server/commands/TeleportCommand performTeleport (Lnet/minecraft/commands/CommandSourceStack;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/server/level/ServerLevel;DDDLjava/util/Set;FFLnet/minecraft/server/commands/TeleportCommand$LookAt;)V
Expand Down

0 comments on commit 6979aed

Please sign in to comment.