Skip to content

Commit

Permalink
Open a SmyLib screen on Fabric 1.20.1
Browse files Browse the repository at this point in the history
Nothing renders and inputs aren't processed, but that's already something.
  • Loading branch information
SmylerMC committed Jun 8, 2024
1 parent cdc0a1a commit 2d4c136
Show file tree
Hide file tree
Showing 18 changed files with 638 additions and 18 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "unspecified"
version = project.version
description = "Core code shared by all versions"

dependencies {
Expand Down
17 changes: 7 additions & 10 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

version = project.mod_version
group = project.mod_group
mod_id = project.mod_id

base {
archivesName = project.archives_base_name
}

dependencies {
// To change the versions see the gradle.properties file
// Terramap modules
implementation project(":core") // Shared implementation of Terramap
implementation project(":smylib:core") // Shared implementation of SmyLib
implementation project(path: ":smylib:fabric", configuration: "namedElements") // Fabric backend for SmyLib, https://fabricmc.net/wiki/documentation:fabric_loom

// Fabric
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
}

Expand All @@ -35,10 +38,4 @@ processResources {
filesMatching("fabric.mod.json") {
expand properties
}
}

jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package net.smyler.terramap;

import net.fabricmc.api.ModInitializer;
import net.minecraft.client.Minecraft;
import net.smyler.smylib.SmyLib;
import net.smyler.smylib.game.WrappedMinecraft;
import org.apache.logging.log4j.Logger;

import static org.apache.logging.log4j.LogManager.getLogger;
Expand All @@ -11,6 +14,7 @@ public class TerramapFabricMod implements ModInitializer {
@Override
public void onInitialize() {
LOGGER.info("Initializing Terramap");
SmyLib.initializeGameClient(new WrappedMinecraft(Minecraft.getInstance()), LOGGER);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.smyler.terramap.mixins;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.smyler.smylib.gui.screen.TestScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static net.smyler.smylib.SmyLib.getGameClient;

@Mixin(Minecraft.class)
public class ShowTestScreenMixin {

@Inject(method = "setScreen(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD"), cancellable = true)
private void onSetScreen(Screen screen, CallbackInfo ci) {
if (screen instanceof TitleScreen) {
getGameClient().displayScreen(new TestScreen(null));
ci.cancel();
}
}

}
3 changes: 2 additions & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
]
},
"mixins": [
"${mod_id}.fabric.mixins.json"
"${mod_id}.fabric.mixins.json",
"smylib.fabric.mixins.json"
],
"depends": {
"fabricloader": ">=${fabric_loader_version}",
Expand Down
3 changes: 2 additions & 1 deletion fabric/src/main/resources/terramap.fabric.mixins.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.smyler.terramap.mixin",
"package": "net.smyler.terramap.mixins",
"refmap": "${mod_id}.refmap.json",
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [
"ShowTestScreenMixin"
],
"server": [],
"injectors": {
Expand Down
12 changes: 7 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}

rootProject.name = 'Terramap'

include 'core'
//include "forge"
include 'fabric'
include 'smylib'
include 'smylib:core'
findProject(':smylib:core')?.name = 'core'
//findProject(':smylib:core')?.name = 'core'
//include 'smylib:forge'
//findProject(':smylib:forge')?.name = 'forge'
include 'smylib:fabric'
//findProject(':smylib:fabric')?.name = 'fabric'
include 'smylib:testing'
findProject(':smylib:testing')?.name = 'testing'
include 'fabric'
//findProject(':smylib:testing')?.name = 'testing'

46 changes: 46 additions & 0 deletions smylib/fabric/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# IDE
.idea
eclipse
.classpath
.location
.project
0.tree
.settings

# Run files
run/*

# Build files
build/*
out/*
.gradle/*
*.launch
*.xcf

# Compiled class file
*.class

# Log file
*.log
*.log.gz

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
# *.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/bin/
/.gradle/
/build/
12 changes: 12 additions & 0 deletions smylib/fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
}

dependencies {
implementation project(":smylib:core")
testImplementation project(":smylib:testing")

minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.smyler.smylib.game;

import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHandler;

public class Lwjgl3Mouse implements Mouse {

private final Minecraft vanilla;

public Lwjgl3Mouse(Minecraft vanilla) {
this.vanilla = vanilla;
}

@Override
public float x() {
return (float) this.vanilla.mouseHandler.xpos();
}

@Override
public float y() {
return (float) this.vanilla.mouseHandler.ypos();
}

@Override
public int getButtonCount() {
return 3; //FIXME Hard-coded mouse button count
}

@Override
public boolean hasWheel() {
return false; //FIXME hard-coded mouse wheel
}

@Override
public boolean isButtonPressed(int button) throws IllegalArgumentException {
return false; //FIXME hard-coded mouse is button pressed
}

@Override
public String getButtonName(int button) throws IllegalArgumentException {
return "Mouse button"; //FIXME hard-coded mouse get button name
}

@Override
public int getButtonByName(String name) throws IllegalArgumentException {
return 0; //FIXME hard-coded mouse get button by name
}

}
Loading

0 comments on commit 2d4c136

Please sign in to comment.