-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c49164
commit 9da820d
Showing
32 changed files
with
566 additions
and
281 deletions.
There are no files selected for viewing
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
93 changes: 93 additions & 0 deletions
93
...fabric/src/main/java/cn/flowerinsnow/greatscrollabletooltips/GreatScrollableTooltips.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,93 @@ | ||
package cn.flowerinsnow.greatscrollabletooltips; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.crash.CrashReport; | ||
import cn.flowerinsnow.greatscrollabletooltips.common.config.GreatScrollableTooltipsConfig; | ||
import cn.flowerinsnow.greatscrollabletooltips.common.object.ScrollSession; | ||
import cn.flowerinsnow.greatscrollabletooltips.common.provider.ModEnvironmentProvider; | ||
import cn.flowerinsnow.greatscrollabletooltips.event.PreScreenKeyPressedEvent; | ||
import cn.flowerinsnow.greatscrollabletooltips.event.PreScreenMouseScrollEvent; | ||
import cn.flowerinsnow.greatscrollabletooltips.event.RenderTooltipEvent; | ||
import cn.flowerinsnow.greatscrollabletooltips.event.ScreenCloseEvent; | ||
import cn.flowerinsnow.greatscrollabletooltips.listener.EventTriggerListener; | ||
import cn.flowerinsnow.greatscrollabletooltips.listener.KeyScrollListener; | ||
import cn.flowerinsnow.greatscrollabletooltips.listener.MouseScrollListener; | ||
import cn.flowerinsnow.greatscrollabletooltips.listener.ScrollingStatusListener; | ||
import cn.flowerinsnow.greatscrollabletooltips.manager.KeyBindingManager; | ||
|
||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class GreatScrollableTooltips implements ClientModInitializer { | ||
public static final String MODID = "great-scrollable-tooltips"; | ||
|
||
private static GreatScrollableTooltips instance; | ||
|
||
private GreatScrollableTooltipsConfig config; | ||
|
||
private ScrollSession<ItemStack> scrollSession; | ||
|
||
@Override | ||
public void onInitializeClient() { | ||
GreatScrollableTooltips.instance = this; | ||
this.scrollSession = new ScrollSession<>(); | ||
|
||
this.initConfig(); | ||
this.initListeners(); | ||
this.initKeyBindings(); | ||
} | ||
|
||
private void initConfig() { | ||
this.config = new GreatScrollableTooltipsConfig(new ModEnvironmentProvider() { | ||
@Override | ||
public InputStream getDefaultConfigAsStream() { | ||
return GreatScrollableTooltips.class.getResourceAsStream("/config.toml"); | ||
} | ||
|
||
@Override | ||
public Path getConfigFile() { | ||
return FabricLoader.getInstance().getConfigDir().resolve(GreatScrollableTooltips.MODID + ".toml"); | ||
} | ||
|
||
@Override | ||
public void crash(Throwable throwable, String msg) { | ||
MinecraftClient.printCrashReport(CrashReport.create(throwable, msg)); | ||
} | ||
}); | ||
this.config.saveDefaultConfig(); | ||
this.config.load(); | ||
} | ||
|
||
private void initListeners() { | ||
ClientTickEvents.END_CLIENT_TICK.register(new EventTriggerListener()); | ||
PreScreenKeyPressedEvent.EVENT.register(new KeyScrollListener(this)); | ||
PreScreenMouseScrollEvent.EVENT.register(new MouseScrollListener(this)); | ||
ScrollingStatusListener scrollingStatusListener = new ScrollingStatusListener(this); | ||
RenderTooltipEvent.Pre.EVENT.register(scrollingStatusListener); | ||
RenderTooltipEvent.Miss.EVENT.register(scrollingStatusListener); | ||
ScreenCloseEvent.EVENT.register(scrollingStatusListener); | ||
} | ||
|
||
private void initKeyBindings() { | ||
KeyBindingManager.registerAll(); | ||
} | ||
|
||
public static GreatScrollableTooltips getInstance() { | ||
return GreatScrollableTooltips.instance; | ||
} | ||
|
||
public GreatScrollableTooltipsConfig getConfig() { | ||
return this.config; | ||
} | ||
|
||
public ScrollSession<ItemStack> getScrollSession() { | ||
return this.scrollSession; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...src/main/java/cn/flowerinsnow/greatscrollabletooltips/event/PreScreenKeyPressedEvent.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,20 @@ | ||
package cn.flowerinsnow.greatscrollabletooltips.event; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.util.ActionResult; | ||
|
||
public interface PreScreenKeyPressedEvent { | ||
Event<PreScreenKeyPressedEvent> EVENT = EventFactory.createArrayBacked(PreScreenKeyPressedEvent.class, listeners -> (screen, keyCode, scanCode, modifiers) -> { | ||
for (PreScreenKeyPressedEvent listener : listeners) { | ||
ActionResult actionResult = listener.preScreenKeyPressed(screen, keyCode, scanCode, modifiers); | ||
if (actionResult != ActionResult.PASS) { | ||
return actionResult; | ||
} | ||
} | ||
return ActionResult.PASS; | ||
}); | ||
|
||
ActionResult preScreenKeyPressed(HandledScreen<?> screen, int keyCode, int scanCode, int modifiers); | ||
} |
20 changes: 20 additions & 0 deletions
20
...rc/main/java/cn/flowerinsnow/greatscrollabletooltips/event/PreScreenMouseScrollEvent.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,20 @@ | ||
package cn.flowerinsnow.greatscrollabletooltips.event; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.util.ActionResult; | ||
|
||
public interface PreScreenMouseScrollEvent { | ||
Event<PreScreenMouseScrollEvent> EVENT = EventFactory.createArrayBacked(PreScreenMouseScrollEvent.class, listeners -> (screen, mouseX, mouseY, amount) -> { | ||
for (PreScreenMouseScrollEvent listener : listeners) { | ||
ActionResult actionResult = listener.preScreenMouseScrolled(screen, mouseX, mouseY, amount); | ||
if (actionResult != ActionResult.PASS) { | ||
return actionResult; | ||
} | ||
} | ||
return ActionResult.PASS; | ||
}); | ||
|
||
ActionResult preScreenMouseScrolled(HandledScreen<?> screen, double mouseX, double mouseY, double amount); | ||
} |
18 changes: 9 additions & 9 deletions
18
...bletooltips/event/RenderTooltipEvent.java → ...bletooltips/event/RenderTooltipEvent.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 |
---|---|---|
@@ -1,38 +1,38 @@ | ||
package online.flowerinsnow.greatscrollabletooltips.event; | ||
package cn.flowerinsnow.greatscrollabletooltips.event; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.util.ActionResult; | ||
|
||
public interface RenderTooltipEvent { | ||
interface Post { | ||
Event<Post> EVENT = EventFactory.createArrayBacked(Post.class, listeners -> (screen, matrices, stack, x, y) -> { | ||
for (Post listener : listeners) { | ||
ActionResult actionResult = listener.startDrawMouseoverTooltip(screen, matrices, stack, x, y); | ||
interface Pre { | ||
Event<Pre> EVENT = EventFactory.createArrayBacked(Pre.class, listeners -> (screen, matrices, x, y, focusedSlot) -> { | ||
for (Pre listener : listeners) { | ||
ActionResult actionResult = listener.preRenderTooltip(screen, matrices, x, y, focusedSlot); | ||
if (actionResult != ActionResult.PASS) { | ||
return actionResult; | ||
} | ||
} | ||
return ActionResult.PASS; | ||
}); | ||
|
||
ActionResult startDrawMouseoverTooltip(HandledScreen<?> screen, MatrixStack matrices, ItemStack stack, int x, int y); | ||
ActionResult preRenderTooltip(HandledScreen<?> screen, MatrixStack matrices, int x, int y, Slot focusedSlot); | ||
} | ||
|
||
interface Miss { | ||
Event<Miss> EVENT = EventFactory.createArrayBacked(Miss.class, listeners -> screen -> { | ||
for (Miss listener : listeners) { | ||
ActionResult actionResult = listener.onMiss(screen); | ||
ActionResult actionResult = listener.missRenderTooltip(screen); | ||
if (actionResult != ActionResult.PASS) { | ||
return actionResult; | ||
} | ||
} | ||
return ActionResult.PASS; | ||
}); | ||
|
||
ActionResult onMiss(HandledScreen<?> screen); | ||
ActionResult missRenderTooltip(HandledScreen<?> screen); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...-fabric/src/main/java/cn/flowerinsnow/greatscrollabletooltips/event/ScreenCloseEvent.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,20 @@ | ||
package cn.flowerinsnow.greatscrollabletooltips.event; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.util.ActionResult; | ||
|
||
public interface ScreenCloseEvent { | ||
Event<ScreenCloseEvent> EVENT = EventFactory.createArrayBacked(ScreenCloseEvent.class, listeners -> (screen) -> { | ||
for (ScreenCloseEvent event : listeners) { | ||
ActionResult actionResult = event.onScreenClose(screen); | ||
if (actionResult != ActionResult.PASS) { | ||
return actionResult; | ||
} | ||
} | ||
return ActionResult.PASS; | ||
}); | ||
|
||
ActionResult onScreenClose(Screen oldScreen); | ||
} |
4 changes: 2 additions & 2 deletions
4
...oltips/listener/EventTriggerListener.java → ...oltips/listener/EventTriggerListener.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
14 changes: 7 additions & 7 deletions
14
...etooltips/listener/KeyScrollListener.java → ...etooltips/listener/KeyScrollListener.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
Oops, something went wrong.