Skip to content

Commit

Permalink
feat(1.8.9-1.10-forge): 添加自动回正、按键滚动的功能
Browse files Browse the repository at this point in the history
refactor(1.8.9-1.10-forge): 重构代码
  • Loading branch information
flowerinsnowdh committed Nov 17, 2024
1 parent a9be86d commit 3befaad
Show file tree
Hide file tree
Showing 35 changed files with 799 additions and 1,217 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 8
distribution: temurin

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Build with Gradle Wrapper
run: |
cd 1.20.1-forge/
cd 1.8.9-1.10-forge/
chmod +x gradlew
./gradlew setupDecompWorkspace
./gradlew build
env:
GITHUB_USERNAME: ${{ secrets.GH_PKG_USERNAME }}
Expand All @@ -36,4 +37,4 @@ jobs:
- name: Release
uses: softprops/action-gh-release@v2
with:
files: 1.20.1-forge/build/libs/*.jar
files: 1.8.9-1.10-forge/build/libs/*.jar
69 changes: 45 additions & 24 deletions 1.8.9-1.10-forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ buildscript() {
classpath('org.spongepowered:mixingradle:0.6-SNAPSHOT')
}
}
apply('plugin' : 'net.minecraftforge.gradle.forge')
apply('plugin' : 'com.github.johnrengelman.shadow')
apply('plugin' : 'org.spongepowered.mixin')
apply('plugin': 'net.minecraftforge.gradle.forge')
apply('plugin': 'com.github.johnrengelman.shadow')
apply('plugin': 'org.spongepowered.mixin')

version = '1.3.0'
group= "online.flowerinsnow.greatscrollabletooltips"
version = '1.4.0'
group= "cn.flowerinsnow.greatscrollabletooltips"
archivesBaseName = "great-scrollable-tooltips"

minecraft() {
Expand All @@ -32,22 +32,36 @@ minecraft() {
}

repositories() {
mavenLocal()
mavenCentral()
maven {
url = 'https://repo.spongepowered.org/repository/maven-public/'

maven() {
url = 'https://maven.pkg.github.com/flowerinsnowdh/GreatScrollableTooltips'
credentials() {
username = "${System.getenv('GITHUB_USERNAME')}"
password = "${System.getenv('GITHUB_TOKEN')}"
}
}
maven {
url = 'https://repo.flowerinsnow.online/repository/maven-public/'

maven() {
url = 'https://repo.spongepowered.org/repository/maven-public/'
}
}

configurations() {
shade
compile.extendsFrom(shade)
}

dependencies() {
compile('online.flowerinsnow.fnml:fnml4j-core:1.0.3')
compile('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
exclude('module' : 'guava')
exclude('module' : 'commons-io')
exclude('module' : 'gson')
compile("cn.flowerinsnow.greatscrollabletooltips:common:${version_common_module}") {
exclude('module': 'core')
exclude('module': 'toml')
}
shade("com.electronwill.night-config:toml:${version_night_config}")
shade('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
exclude('module': 'guava')
exclude('module': 'commons-io')
exclude('module': 'gson')
}
}

Expand Down Expand Up @@ -80,31 +94,38 @@ tasks.withType(JavaCompile).configureEach() {
shadowJar() {
manifest() {
attributes([
'TweakClass': 'online.flowerinsnow.greatscrollabletooltips.tweaker.GreatScrollableTooltipsTweaker'
'TweakClass': 'cn.flowerinsnow.greatscrollabletooltips.tweaker.GreatScrollableTooltipsTweaker'
])
}

// configurations = [
// project.configurations.shade
// ]

dependencies() {
include(dependency('online.flowerinsnow.fnml:fnml4j-core:1.0.4'))
include(dependency("cn.flowerinsnow.greatscrollabletooltips:common:${version_common_module}"))
include(dependency("com.electronwill.night-config:core:${version_night_config}"))
include(dependency("com.electronwill.night-config:toml:${version_night_config}"))
include(dependency('org.spongepowered:mixin:0.7.11-SNAPSHOT'))
}
exclude('LICENSE.txt')
exclude('dummyThing')

ArrayList<String> packagesToLocate = [
'online.flowerinsnow.fnml4j.api',
'online.flowerinsnow.fnml4j.core'
ArrayList<String> packagesToRelocate = [
'com.electronwill.nightconfig.core',
'com.electronwill.nightconfig.toml'
]

packagesToLocate.forEach() {
relocate(it, "online.flowerinsnow.greatscrollabletooltips.shaded.$it")
packagesToRelocate.forEach() {
relocate(it, "cn.flowerinsnow.greatscrollabletooltips.shaded.$it")
}

classifier ''
classifier = ''
}

reobf() {
shadowJar {}
shadowJar() {
}
}

mixin() {
Expand Down
2 changes: 2 additions & 0 deletions 1.8.9-1.10-forge/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version_night_config=3.6.7
version_common_module=1.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package cn.flowerinsnow.greatscrollabletooltips;

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.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 net.minecraft.client.Minecraft;
import net.minecraft.crash.CrashReport;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.EventBus;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.io.File;
import java.io.InputStream;
import java.nio.file.Path;

@Mod(
modid = GreatScrollableTooltips.MODID,
name = GreatScrollableTooltips.NAME,
version = GreatScrollableTooltips.VERSION,
clientSideOnly = true,
guiFactory = "cn.flowerinsnow.greatscrollabletooltips.screen.GreatScrollableTooltipsGuiFactory"
)
@SideOnly(Side.CLIENT)
public class GreatScrollableTooltips {
public static final String MODID = "great-scrollable-tooltips";
public static final String NAME = "Great Scrollable Tooltips";
public static final String VERSION = "1.4.0";

private static GreatScrollableTooltips instance;

private GreatScrollableTooltipsConfig config;

private ScrollSession<ItemStack> scrollSession;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
GreatScrollableTooltips.instance = this;
this.scrollSession = new ScrollSession<>();
this.initConfig(new File(event.getModConfigurationDirectory(), GreatScrollableTooltips.MODID + ".toml").toPath());

}

@EventHandler
public void init(FMLInitializationEvent event) {
this.initListeners();
this.initKeyBindings();
}

private void initConfig(Path configFilePath) {
this.config = new GreatScrollableTooltipsConfig(new ModEnvironmentProvider() {
@Override
public InputStream getDefaultConfigAsStream() {
return GreatScrollableTooltips.class.getResourceAsStream("/config.toml");
}

@Override
public Path getConfigFile() {
return configFilePath;
}

@Override
public void crash(Throwable throwable, String msg) {
Minecraft.getMinecraft().crashed(CrashReport.makeCrashReport(throwable, msg));
}
});
this.config.saveDefaultConfig();
this.config.load();
}

private void initListeners() {
EventBus eventBus = MinecraftForge.EVENT_BUS;
eventBus.register(new EventTriggerListener());

// 鼠标滚动时
eventBus.register(new MouseScrollListener(this));

// 渲染物品提示时
eventBus.register(new ScrollingStatusListener(this));

// 按键滚动时
eventBus.register(new KeyScrollListener(this));
}

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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cn.flowerinsnow.greatscrollabletooltips.event;

import net.minecraftforge.fml.common.eventhandler.Event;

public class ClientTickEndEvent extends Event {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cn.flowerinsnow.greatscrollabletooltips.event;

import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Objects;

@SideOnly(Side.CLIENT)
public class PreScreenKeyPressedEvent extends Event {
private final GuiScreen screen;
private final char typedChar;
private final int keyCode;

public PreScreenKeyPressedEvent(GuiScreen screen, char typedChar, int keyCode) {
this.screen = screen;
this.typedChar = typedChar;
this.keyCode = keyCode;
}

public GuiScreen getScreen() {
return this.screen;
}

public char getTypedChar() {
return this.typedChar;
}

public int getKeyCode() {
return this.keyCode;
}

@Override
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
PreScreenKeyPressedEvent that = (PreScreenKeyPressedEvent) object;
return this.typedChar == that.typedChar && this.keyCode == that.keyCode && Objects.equals(this.screen, that.screen);
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + (this.screen != null ? this.screen.hashCode() : 0);
result = 31 * result + this.typedChar;
result = 31 * result + this.keyCode;
return result;
}

@Override
public String toString() {
return "PreScreenKeyPressedEvent{" +
"screen=" + this.screen +
", typedChar=" + this.typedChar +
", keyCode=" + this.keyCode +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cn.flowerinsnow.greatscrollabletooltips.event;

import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Objects;

@SideOnly(Side.CLIENT)
public class PreScreenMouseScrollEvent extends Event {
private final GuiScreen screen;
private final int amount;

public PreScreenMouseScrollEvent(GuiScreen screen, int amount) {
this.screen = screen;
this.amount = amount;
}

public GuiScreen getScreen() {
return this.screen;
}

public int getAmount() {
return this.amount;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PreScreenMouseScrollEvent that = (PreScreenMouseScrollEvent) o;
return this.amount == that.amount && Objects.equals(this.screen, that.screen);
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + (this.screen != null ? this.screen.hashCode() : 0);
result = 31 * result + this.amount;
return result;
}

@Override
public String toString() {
return "PreScreenMouseScrollEvent{" +
"screen=" + this.screen +
", amount=" + this.amount +
'}';
}
}
Loading

0 comments on commit 3befaad

Please sign in to comment.