-
Notifications
You must be signed in to change notification settings - Fork 5
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
0 parents
commit b9f0db2
Showing
56 changed files
with
3,192 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
build/ | ||
*.ipr | ||
run/ | ||
*.iws | ||
out/ | ||
*.iml | ||
.gradle/ | ||
output/ | ||
bin/ | ||
libs/ | ||
|
||
.classpath | ||
.project | ||
.idea/ | ||
classes/ | ||
.metadata | ||
.vscode | ||
.settings | ||
*.launch | ||
|
||
dist/ |
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,59 @@ | ||
plugins { | ||
id "architectury-plugin" version "3.1-SNAPSHOT" | ||
id "forgified-fabric-loom" version "0.6-SNAPSHOT" apply false | ||
} | ||
|
||
architectury { | ||
minecraft = rootProject.minecraft_version | ||
} | ||
|
||
subprojects { | ||
apply plugin: "forgified-fabric-loom" | ||
|
||
loom { | ||
silentMojangMappingsLicense() | ||
mixinConfig "mixin.civmodern.json" | ||
} | ||
|
||
/*dependencies { | ||
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" | ||
// The following line declares the mojmap mappings, you may use other mappings as well | ||
mappings loom.officialMojangMappings() | ||
// The following line declares the yarn mappings you may select this one as well. | ||
// mappings "net.fabricmc:yarn:1.16.1+build.21" | ||
}*/ | ||
} | ||
|
||
allprojects { | ||
apply plugin: "java" | ||
apply plugin: "architectury-plugin" | ||
apply plugin: "maven-publish" | ||
|
||
archivesBaseName = rootProject.archives_base_name | ||
version = rootProject.mod_version | ||
group = rootProject.maven_group | ||
|
||
repositories { | ||
// Add repositories to retrieve artifacts from in here. | ||
// You should only use this when depending on other mods because | ||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically. | ||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html | ||
// for more information about repositories. | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.encoding = "UTF-8" | ||
|
||
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too | ||
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. | ||
// We'll use that if it's available, but otherwise we'll use the older option. | ||
def targetVersion = 8 | ||
if (JavaVersion.current().isJava9Compatible()) { | ||
options.release = targetVersion | ||
} | ||
} | ||
|
||
java { | ||
withSourcesJar() | ||
} | ||
} |
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,11 @@ | ||
# 1.1 | ||
|
||
- Add toggle to player pings | ||
- Minor bugfixes for hold left and right macros | ||
- Add option to rollback colours to presets | ||
- HSV colour picker starts with the current hue automatically selected | ||
- Add ice road macro (default key is backspace, can optionally snap to a cardinal or intercardinal direction) | ||
|
||
# 1.0.1 | ||
|
||
- Fix crash bug on 1.16.1 |
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,37 @@ | ||
dependencies { | ||
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies | ||
// Do NOT use other classes from fabric loader | ||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" | ||
// Remove the next line if you don't want to depend on the API | ||
//modApi "me.shedaniel:architectury:${rootProject.architectury_version}" | ||
|
||
minecraft "com.mojang:minecraft:1.16.5" | ||
mappings loom.officialMojangMappings() | ||
} | ||
|
||
architectury { | ||
injectInjectables = false | ||
common() | ||
} | ||
|
||
java { | ||
withSourcesJar() | ||
} | ||
|
||
publishing { | ||
publications { | ||
mavenCommon(MavenPublication) { | ||
artifactId = rootProject.archives_base_name | ||
// add all the jars that should be included when publishing to maven | ||
artifact remapJar | ||
artifact(sourcesJar) { | ||
builtBy remapSourcesJar | ||
} | ||
} | ||
} | ||
|
||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. | ||
repositories { | ||
// Add repositories to publish to here. | ||
} | ||
} |
206 changes: 206 additions & 0 deletions
206
common/src/main/java/sh/okx/civmodern/common/AbstractCivModernMod.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,206 @@ | ||
package sh.okx.civmodern.common; | ||
|
||
import com.mojang.blaze3d.platform.InputConstants.Type; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.lang.reflect.Field; | ||
import java.nio.file.Path; | ||
import java.util.Iterator; | ||
import java.util.Properties; | ||
import net.minecraft.client.KeyMapping; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.Options; | ||
import net.minecraft.client.gui.Gui; | ||
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; | ||
import net.minecraft.client.renderer.entity.ItemRenderer; | ||
import net.minecraft.core.NonNullList; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.world.item.CreativeModeTab; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.lwjgl.glfw.GLFW; | ||
import org.lwjgl.system.CallbackI.I; | ||
import sh.okx.civmodern.common.compat.CompatProvider; | ||
import sh.okx.civmodern.common.compat.v1_16_1.v1_16_1CompatProvider; | ||
import sh.okx.civmodern.common.compat.v1_16_5.v1_16_5CompatProvider; | ||
import sh.okx.civmodern.common.events.ClientTickEvent; | ||
import sh.okx.civmodern.common.events.EventBus; | ||
import sh.okx.civmodern.common.gui.screen.MainConfigScreen; | ||
import sh.okx.civmodern.common.macro.HoldKeyMacro; | ||
import sh.okx.civmodern.common.macro.IceRoadMacro; | ||
import sh.okx.civmodern.common.radar.Radar; | ||
|
||
public abstract class AbstractCivModernMod { | ||
|
||
private static AbstractCivModernMod INSTANCE; | ||
private static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
private final KeyMapping configBinding; | ||
private final KeyMapping holdLeftBinding; | ||
private final KeyMapping holdRightBinding; | ||
private final KeyMapping iceRoadBinding; | ||
private final CompatProvider compat; | ||
private CivMapConfig config; | ||
private Radar radar; | ||
|
||
private HoldKeyMacro leftMacro; | ||
private HoldKeyMacro rightMacro; | ||
private IceRoadMacro iceRoadMacro; | ||
|
||
private EventBus eventBus; | ||
|
||
public AbstractCivModernMod() { | ||
int version = Minecraft.getInstance().getGame().getVersion().getProtocolVersion(); | ||
if (version == 754) { | ||
this.compat = new v1_16_5CompatProvider(); | ||
} else { | ||
this.compat = new v1_16_1CompatProvider(); | ||
} | ||
|
||
this.configBinding = new KeyMapping( | ||
"key.civmodern.config", | ||
Type.KEYSYM, | ||
GLFW.GLFW_KEY_R, | ||
"category.civmodern" | ||
); | ||
this.holdLeftBinding = new KeyMapping( | ||
"key.civmodern.left", | ||
Type.KEYSYM, | ||
GLFW.GLFW_KEY_MINUS, | ||
"category.civmodern" | ||
); | ||
this.holdRightBinding = new KeyMapping( | ||
"key.civmodern.right", | ||
Type.KEYSYM, | ||
GLFW.GLFW_KEY_EQUAL, | ||
"category.civmodern" | ||
); | ||
this.iceRoadBinding = new KeyMapping( | ||
"key.civmodern.ice", | ||
Type.KEYSYM, | ||
GLFW.GLFW_KEY_BACKSPACE, | ||
"category.civmodern" | ||
); | ||
|
||
if (INSTANCE == null) { | ||
INSTANCE = this; | ||
} else { | ||
throw new IllegalStateException("AbstractCivModernMod initialised twice"); | ||
} | ||
} | ||
|
||
public final void enable() { | ||
this.eventBus = provideEventBus(); | ||
|
||
registerKeyBinding(this.configBinding); | ||
registerKeyBinding(this.holdLeftBinding); | ||
registerKeyBinding(this.holdRightBinding); | ||
registerKeyBinding(this.iceRoadBinding); | ||
|
||
loadConfig(); | ||
replaceItemRenderer(); | ||
|
||
this.eventBus.listen(ClientTickEvent.class, e -> this.tick()); | ||
|
||
Options options = Minecraft.getInstance().options; | ||
this.leftMacro = new HoldKeyMacro(this, this.holdLeftBinding, options.keyAttack); | ||
this.rightMacro = new HoldKeyMacro(this, this.holdRightBinding, options.keyUse); | ||
this.iceRoadMacro = new IceRoadMacro(this, config, this.iceRoadBinding); | ||
} | ||
|
||
public abstract EventBus provideEventBus(); | ||
public abstract void registerKeyBinding(KeyMapping mapping); | ||
|
||
private void onScroll() { | ||
if (this.leftMacro != null) this.leftMacro.onScroll(); | ||
if (this.rightMacro != null) this.rightMacro.onScroll(); | ||
} | ||
|
||
private void tick() { | ||
while (configBinding.consumeClick()) { | ||
Minecraft.getInstance().setScreen(new MainConfigScreen(this, config)); | ||
} | ||
} | ||
|
||
private void replaceItemRenderer() { | ||
// Look man, it's this or mixins | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
for (Field field : Minecraft.class.getDeclaredFields()) { | ||
if (field.getType() == ItemRenderer.class) { | ||
field.setAccessible(true); | ||
try { | ||
field.set(minecraft, new CustomItemRenderer(minecraft.getItemRenderer(), config)); | ||
replaceGuiItemRenderer(); | ||
return; | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
LOGGER.warn("Unable to replace item renderer"); | ||
} | ||
|
||
private void replaceGuiItemRenderer() { | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
Gui gui = minecraft.gui; | ||
for (Field field : Gui.class.getDeclaredFields()) { | ||
if (field.getType() == ItemRenderer.class) { | ||
field.setAccessible(true); | ||
try { | ||
field.set(gui, minecraft.getItemRenderer()); | ||
return; | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
LOGGER.warn("Unable to replace hotbar item renderer"); | ||
} | ||
|
||
private void loadConfig() { | ||
Properties properties = new Properties(); | ||
Path gameDir = Minecraft.getInstance().gameDirectory.toPath(); | ||
File configFile = gameDir.resolve("config").resolve("civmodern.properties").toFile(); | ||
try { | ||
if (!configFile.exists()) { | ||
InputStream resource = AbstractCivModernMod.class | ||
.getResourceAsStream("/civmodern.properties"); | ||
byte[] buffer = new byte[resource.available()]; | ||
resource.read(buffer); | ||
FileOutputStream fos = new FileOutputStream(configFile); | ||
fos.write(buffer); | ||
} | ||
|
||
FileInputStream input = new FileInputStream(configFile); | ||
properties.load(input); | ||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
} | ||
CivMapConfig config = new CivMapConfig(configFile, properties); | ||
|
||
this.config = config; | ||
|
||
this.radar = new Radar(config, eventBus, compat); | ||
this.radar.init(); | ||
} | ||
|
||
public EventBus getEventBus() { | ||
return eventBus; | ||
} | ||
|
||
public CompatProvider getCompat() { | ||
return compat; | ||
} | ||
|
||
public static void staticOnScroll() { | ||
if (INSTANCE != null) { | ||
INSTANCE.onScroll(); | ||
} | ||
} | ||
} |
Oops, something went wrong.