Skip to content

Commit

Permalink
Update to support the breaking changes in forge (#2886)
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Jul 13, 2022
1 parent e5a34c9 commit 9669b94
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 80 deletions.
62 changes: 32 additions & 30 deletions Common/src/main/java/mezz/jei/common/config/KeyBindings.java
@@ -1,5 +1,6 @@
package mezz.jei.common.config;

import java.util.function.Consumer;
import mezz.jei.common.input.IKeyBindings;
import mezz.jei.common.input.keys.IJeiKeyMapping;
import mezz.jei.common.input.keys.IJeiKeyMappingCategoryBuilder;
Expand All @@ -8,6 +9,7 @@
import mezz.jei.common.platform.IPlatformInputHelper;
import mezz.jei.common.platform.Services;
import mezz.jei.common.util.Translator;
import net.minecraft.client.KeyMapping;
import org.lwjgl.glfw.GLFW;

import java.util.List;
Expand Down Expand Up @@ -55,7 +57,7 @@ public final class KeyBindings implements IKeyBindings {
private final IJeiKeyMapping rightClick;
private final List<IJeiKeyMapping> enterKey;

public KeyBindings() {
public KeyBindings(Consumer<KeyMapping> registerMethod) {
IPlatformInputHelper inputHelper = Services.PLATFORM.getInputHelper();

IJeiKeyMapping showRecipe1;
Expand Down Expand Up @@ -96,161 +98,161 @@ public KeyBindings() {
.setContext(JeiKeyConflictContext.GUI)
.setModifier(JeiKeyModifier.CONTROL_OR_COMMAND)
.buildKeyboardKey(GLFW.GLFW_KEY_O)
.register();
.register(registerMethod);

focusSearch = overlay.createMapping("key.jei.focusSearch")
.setContext(JeiKeyConflictContext.GUI)
.setModifier(JeiKeyModifier.CONTROL_OR_COMMAND)
.buildKeyboardKey(GLFW.GLFW_KEY_F)
.register();
.register(registerMethod);

previousPage = overlay.createMapping("key.jei.previousPage")
.setContext(JeiKeyConflictContext.GUI)
.buildUnbound()
.register();
.register(registerMethod);

nextPage = overlay.createMapping("key.jei.nextPage")
.setContext(JeiKeyConflictContext.GUI)
.buildUnbound()
.register();
.register(registerMethod);

toggleBookmarkOverlay = overlay.createMapping("key.jei.toggleBookmarkOverlay")
.setContext(JeiKeyConflictContext.GUI)
.buildUnbound()
.register();
.register(registerMethod);

// Mouse Hover
bookmark = mouseHover.createMapping("key.jei.bookmark")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER)
.buildKeyboardKey(GLFW.GLFW_KEY_A)
.register();
.register(registerMethod);

showRecipe1 = mouseHover.createMapping("key.jei.showRecipe")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER)
.buildKeyboardKey(GLFW.GLFW_KEY_R)
.register();
.register(registerMethod);

showRecipe2 = mouseHover.createMapping("key.jei.showRecipe2")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER)
.buildMouseLeft()
.register();
.register(registerMethod);

showUses1 = mouseHover.createMapping("key.jei.showUses")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER)
.buildKeyboardKey(GLFW.GLFW_KEY_U)
.register();
.register(registerMethod);

showUses2 = mouseHover.createMapping("key.jei.showUses2")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER)
.buildMouseRight()
.register();
.register(registerMethod);

// Search Bar
hoveredClearSearchBar = search.createMapping("key.jei.clearSearchBar")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER_SEARCH)
.buildMouseRight()
.register();
.register(registerMethod);

previousSearch = search.createMapping("key.jei.previousSearch")
.setContext(JeiKeyConflictContext.GUI)
.buildKeyboardKey(GLFW.GLFW_KEY_UP)
.register();
.register(registerMethod);

nextSearch = search.createMapping("key.jei.nextSearch")
.setContext(JeiKeyConflictContext.GUI)
.buildKeyboardKey(GLFW.GLFW_KEY_DOWN)
.register();
.register(registerMethod);

// Cheat Mode
toggleCheatMode = cheat.createMapping("key.jei.toggleCheatMode")
.setContext(JeiKeyConflictContext.GUI)
.buildUnbound()
.register();
.register(registerMethod);

cheatOneItem1 = cheat.createMapping("key.jei.cheatOneItem")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER_CHEAT_MODE)
.buildMouseLeft()
.register();
.register(registerMethod);

cheatOneItem2 = cheat.createMapping("key.jei.cheatOneItem2")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER_CHEAT_MODE)
.buildMouseRight()
.register();
.register(registerMethod);

cheatItemStack1 = cheat.createMapping("key.jei.cheatItemStack")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER_CHEAT_MODE)
.setModifier(JeiKeyModifier.SHIFT)
.buildMouseLeft()
.register();
.register(registerMethod);

cheatItemStack2 = cheat.createMapping("key.jei.cheatItemStack2")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER_CHEAT_MODE)
.buildMouseMiddle()
.register();
.register(registerMethod);

// Hovering over config button
toggleCheatModeConfigButton = hoverConfig.createMapping("key.jei.toggleCheatModeConfigButton")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER_CONFIG_BUTTON)
.setModifier(JeiKeyModifier.CONTROL_OR_COMMAND)
.buildMouseLeft()
.register();
.register(registerMethod);

// Edit Mode
toggleEditMode = editMode.createMapping("key.jei.toggleEditMode")
.setContext(JeiKeyConflictContext.GUI)
.buildUnbound()
.register();
.register(registerMethod);

toggleHideIngredient = editMode.createMapping("key.jei.toggleHideIngredient")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER)
.setModifier(JeiKeyModifier.CONTROL_OR_COMMAND)
.buildMouseLeft()
.register();
.register(registerMethod);

toggleWildcardHideIngredient = editMode.createMapping("key.jei.toggleWildcardHideIngredient")
.setContext(JeiKeyConflictContext.JEI_GUI_HOVER)
.setModifier(JeiKeyModifier.CONTROL_OR_COMMAND)
.buildMouseRight()
.register();
.register(registerMethod);

// Recipes
recipeBack = recipeCategory.createMapping("key.jei.recipeBack")
.setContext(JeiKeyConflictContext.GUI)
.buildKeyboardKey(GLFW.GLFW_KEY_BACKSPACE)
.register();
.register(registerMethod);

previousRecipePage = recipeCategory.createMapping("key.jei.previousRecipePage")
.setContext(JeiKeyConflictContext.GUI)
.buildKeyboardKey(GLFW.GLFW_KEY_PAGE_UP)
.register();
.register(registerMethod);

nextRecipePage = recipeCategory.createMapping("key.jei.nextRecipePage")
.setContext(JeiKeyConflictContext.GUI)
.buildKeyboardKey(GLFW.GLFW_KEY_PAGE_DOWN)
.register();
.register(registerMethod);

previousCategory = recipeCategory.createMapping("key.jei.previousCategory")
.setContext(JeiKeyConflictContext.GUI)
.setModifier(JeiKeyModifier.SHIFT)
.buildKeyboardKey(GLFW.GLFW_KEY_PAGE_UP)
.register();
.register(registerMethod);

nextCategory = recipeCategory.createMapping("key.jei.nextCategory")
.setContext(JeiKeyConflictContext.GUI)
.setModifier(JeiKeyModifier.SHIFT)
.buildKeyboardKey(GLFW.GLFW_KEY_PAGE_DOWN)
.register();
.register(registerMethod);

closeRecipeGui = recipeCategory.createMapping("key.jei.closeRecipeGui")
.setContext(JeiKeyConflictContext.GUI)
.buildKeyboardKey(GLFW.GLFW_KEY_ESCAPE)
.register();
.register(registerMethod);

// Dev Tools
copyRecipeId = devTools.createMapping("key.jei.copy.recipe.id")
.setContext(JeiKeyConflictContext.GUI)
.buildUnbound()
.register();
.register(registerMethod);

showRecipe = List.of(showRecipe1, showRecipe2);
showUses = List.of(showUses1, showUses2);
Expand Down
@@ -1,6 +1,8 @@
package mezz.jei.common.input.keys;

import com.mojang.blaze3d.platform.InputConstants;
import java.util.function.Consumer;
import net.minecraft.client.KeyMapping;
import net.minecraft.network.chat.Component;

public interface IJeiKeyMapping {
Expand All @@ -10,5 +12,5 @@ public interface IJeiKeyMapping {

Component getTranslatedKeyMessage();

IJeiKeyMapping register();
IJeiKeyMapping register(Consumer<KeyMapping> registerMethod);
}
@@ -1,9 +1,11 @@
package mezz.jei.fabric.input;

import com.mojang.blaze3d.platform.InputConstants;
import java.util.function.Consumer;
import mezz.jei.common.input.keys.IJeiKeyMapping;
import mezz.jei.common.input.keys.JeiKeyConflictContext;
import mezz.jei.common.input.keys.JeiKeyModifier;
import net.minecraft.client.KeyMapping;
import net.minecraft.network.chat.Component;

public class FabricJeiKeyMapping implements IJeiKeyMapping {
Expand Down Expand Up @@ -52,7 +54,7 @@ public Component getTranslatedKeyMessage() {
}

@Override
public IJeiKeyMapping register() {
public IJeiKeyMapping register(Consumer<KeyMapping> registerMethod) {
return this;
}
}
Expand Up @@ -37,7 +37,7 @@ public ClientLifecycleHandler(Textures textures, IServerConfig serverConfig) {
Path jeiConfigDir = configDir.resolve(ModIds.JEI_ID);

IConnectionToServer serverConnection = new ConnectionToServer();
KeyBindings keyBindings = new KeyBindings();
KeyBindings keyBindings = new KeyBindings(keyMapping -> {});

ConfigData configData = ConfigData.create(
serverConnection,
Expand Down
@@ -1,10 +1,10 @@
package mezz.jei.forge.input;

import com.mojang.blaze3d.platform.InputConstants;
import java.util.function.Consumer;
import mezz.jei.common.input.keys.IJeiKeyMapping;
import net.minecraft.client.KeyMapping;
import net.minecraft.network.chat.Component;
import net.minecraftforge.client.ClientRegistry;

public class ForgeJeiKeyMapping implements IJeiKeyMapping {
private final KeyMapping keyMapping;
Expand All @@ -29,8 +29,8 @@ public Component getTranslatedKeyMessage() {
}

@Override
public IJeiKeyMapping register() {
ClientRegistry.registerKeyBinding(keyMapping);
public IJeiKeyMapping register(Consumer<KeyMapping> registerMethod) {
registerMethod.accept(keyMapping);
return this;
}
}
6 changes: 3 additions & 3 deletions Forge/src/main/java/mezz/jei/forge/input/ForgeUserInput.java
Expand Up @@ -11,15 +11,15 @@
public final class ForgeUserInput {
private ForgeUserInput() {}

public static UserInput fromEvent(ScreenEvent.KeyboardKeyEvent keyEvent) {
public static UserInput fromEvent(ScreenEvent.KeyPressed keyEvent) {
InputConstants.Key input = InputConstants.getKey(keyEvent.getKeyCode(), keyEvent.getScanCode());
double mouseX = MouseUtil.getX();
double mouseY = MouseUtil.getY();
int modifiers = keyEvent.getModifiers();
return new UserInput(input, mouseX, mouseY, modifiers, InputType.IMMEDIATE);
}

public static Optional<UserInput> fromEvent(ScreenEvent.MouseClickedEvent event) {
public static Optional<UserInput> fromEvent(ScreenEvent.MouseButtonPressed event) {
int button = event.getButton();
if (button < 0) {
return Optional.empty();
Expand All @@ -29,7 +29,7 @@ public static Optional<UserInput> fromEvent(ScreenEvent.MouseClickedEvent event)
return Optional.of(userInput);
}

public static Optional<UserInput> fromEvent(ScreenEvent.MouseReleasedEvent event) {
public static Optional<UserInput> fromEvent(ScreenEvent.MouseButtonReleased event) {
int button = event.getButton();
if (button < 0) {
return Optional.empty();
Expand Down
4 changes: 2 additions & 2 deletions Forge/src/main/java/mezz/jei/forge/platform/ConfigHelper.java
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraftforge.client.ConfigGuiHandler;
import net.minecraftforge.client.ConfigScreenHandler;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModList;

Expand All @@ -21,7 +21,7 @@ public Optional<Screen> getConfigScreen() {
return ModList.get()
.getModContainerById(ModIds.JEI_ID)
.map(ModContainer::getModInfo)
.flatMap(ConfigGuiHandler::getGuiFactoryFor)
.flatMap(ConfigScreenHandler::getScreenFactoryFor)
.map(f -> f.apply(minecraft, minecraft.screen));
}

Expand Down
9 changes: 4 additions & 5 deletions Forge/src/main/java/mezz/jei/forge/platform/FluidHelper.java
Expand Up @@ -14,8 +14,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.client.IFluidTypeRenderProperties;
import net.minecraftforge.client.RenderProperties;
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidType;
import org.jetbrains.annotations.Nullable;
Expand All @@ -41,8 +40,8 @@ public IIngredientRenderer<FluidStack> createRenderer(long capacity, boolean sho
@Override
public int getColorTint(FluidStack ingredient) {
Fluid fluid = ingredient.getFluid();
IFluidTypeRenderProperties renderProperties = RenderProperties.get(fluid);
return renderProperties.getColorTint(ingredient);
IClientFluidTypeExtensions renderProperties = IClientFluidTypeExtensions.of(fluid);
return renderProperties.getTintColor(ingredient);
}

@Override
Expand All @@ -63,7 +62,7 @@ public long bucketVolume() {
@Override
public TextureAtlasSprite getStillFluidSprite(FluidStack fluidStack) {
Fluid fluid = fluidStack.getFluid();
IFluidTypeRenderProperties renderProperties = RenderProperties.get(fluid);
IClientFluidTypeExtensions renderProperties = IClientFluidTypeExtensions.of(fluid);
ResourceLocation fluidStill = renderProperties.getStillTexture(fluidStack);

Minecraft minecraft = Minecraft.getInstance();
Expand Down

0 comments on commit 9669b94

Please sign in to comment.