Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate forge event code from event handlers
- Loading branch information
Showing
18 changed files
with
299 additions
and
234 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.../common/gui/overlay/FilterTextSource.java → ...z/jei/common/filter/FilterTextSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...common/gui/overlay/IFilterTextSource.java → .../jei/common/filter/IFilterTextSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Common/src/main/java/mezz/jei/common/filter/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
package mezz.jei.common.filter; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
Common/src/main/java/mezz/jei/common/input/ClientInputHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package mezz.jei.common.input; | ||
|
||
import mezz.jei.common.input.handlers.CombinedInputHandler; | ||
import mezz.jei.core.util.ReflectionUtil; | ||
import net.minecraft.client.gui.components.EditBox; | ||
import net.minecraft.client.gui.screens.Screen; | ||
|
||
import java.util.List; | ||
|
||
public class ClientInputHandler { | ||
private final List<ICharTypedHandler> charTypedHandlers; | ||
private final CombinedInputHandler inputHandler; | ||
private final IKeyBindings keybindings; | ||
private final ReflectionUtil reflectionUtil = new ReflectionUtil(); | ||
|
||
public ClientInputHandler(List<ICharTypedHandler> charTypedHandlers, CombinedInputHandler inputHandler, IKeyBindings keybindings) { | ||
this.charTypedHandlers = charTypedHandlers; | ||
this.inputHandler = inputHandler; | ||
this.keybindings = keybindings; | ||
} | ||
|
||
public void onInitGui() { | ||
this.inputHandler.handleGuiChange(); | ||
} | ||
|
||
/** | ||
* When we have keyboard focus, use Pre | ||
*/ | ||
public boolean onKeyboardKeyPressedPre(Screen screen, UserInput input) { | ||
if (!isContainerTextFieldFocused(screen)) { | ||
return this.inputHandler.handleUserInput(screen, input, keybindings) | ||
.isPresent(); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Without keyboard focus, use Post | ||
*/ | ||
public boolean onKeyboardKeyPressed(Screen screen, UserInput input) { | ||
if (isContainerTextFieldFocused(screen)) { | ||
return this.inputHandler.handleUserInput(screen, input, keybindings) | ||
.isPresent(); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* When we have keyboard focus, use Pre | ||
*/ | ||
public boolean onKeyboardCharTypedPre(Screen screen, char codePoint, int modifiers) { | ||
if (!isContainerTextFieldFocused(screen)) { | ||
return handleCharTyped(codePoint, modifiers); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Without keyboard focus, use Post | ||
*/ | ||
public boolean onKeyboardCharTypedPost(Screen screen, char codePoint, int modifiers) { | ||
if (isContainerTextFieldFocused(screen)) { | ||
return handleCharTyped(codePoint, modifiers); | ||
} | ||
return false; | ||
} | ||
|
||
public boolean onGuiMouseClicked(Screen screen, UserInput input) { | ||
boolean handled = this.inputHandler.handleUserInput(screen, input, keybindings) | ||
.isPresent(); | ||
|
||
if (input.is(keybindings.getLeftClick())) { | ||
handled |= this.inputHandler.handleDragStart(screen, input) | ||
.isPresent(); | ||
} | ||
return handled; | ||
} | ||
|
||
public boolean onGuiMouseReleased(Screen screen, UserInput input) { | ||
boolean handled = this.inputHandler.handleUserInput(screen, input, keybindings) | ||
.isPresent(); | ||
|
||
if (input.is(keybindings.getLeftClick())) { | ||
handled |= this.inputHandler.handleDragComplete(screen, input) | ||
.isPresent(); | ||
} | ||
return handled; | ||
} | ||
|
||
public boolean onGuiMouseScroll(double mouseX, double mouseY, double scrollDelta) { | ||
return this.inputHandler.handleMouseScrolled(mouseX, mouseY, scrollDelta); | ||
} | ||
|
||
private boolean handleCharTyped(char codePoint, int modifiers) { | ||
return this.charTypedHandlers.stream() | ||
.filter(ICharTypedHandler::hasKeyboardFocus) | ||
.anyMatch(handler -> handler.onCharTyped(codePoint, modifiers)); | ||
} | ||
|
||
private boolean isContainerTextFieldFocused(Screen screen) { | ||
return reflectionUtil.getFieldWithClass(screen, EditBox.class) | ||
.anyMatch(textField -> textField.isActive() && textField.isFocused()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
Forge/src/main/java/mezz/jei/forge/events/EditModeToggleEvent.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.