Skip to content

Commit

Permalink
init: add files
Browse files Browse the repository at this point in the history
  • Loading branch information
wiidotmom committed May 1, 2022
0 parents commit 434e9b7
Show file tree
Hide file tree
Showing 28 changed files with 891 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
build/
*.ipr
run/
*.iws
out/
*.iml
.gradle/
output/
bin/
libs/

.classpath
.project
.idea/
classes/
.metadata
.vscode
.settings
*.launch
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 🐢 Take it Slow

A Fabric/Quilt/Forge mod that disables sprinting and, optionally, swimming

Who needed sprinting anyways?

### Dependencies
- Cloth Config v6
- (Optional, Fabric/Quilt) Mod Menu

*Mod icon taken from Twemoji under the [Creative Commons Attribution 4.0 International license](https://github.com/twitter/twemoji/blob/master/LICENSE-GRAPHICS)*
54 changes: 54 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "0.11.0-SNAPSHOT" apply false
}

architectury {
minecraft = rootProject.minecraft_version
}

subprojects {
apply plugin: "dev.architectury.loom"

loom {
silentMojangMappingsLicense()
}

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.18.2+build.3:v2"
}
}

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.
maven {
url "https://maven.terraformersmc.com/"
}
}

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = 17
}

java {
withSourcesJar()
}
}
28 changes: 28 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
architectury {
common(rootProject.enabled_platforms.split(","))
}

loom {

}

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}"
modImplementation "me.shedaniel.cloth:cloth-config:${rootProject.cloth_version}"
}

publishing {
publications {
mavenCommon(MavenPublication) {
artifactId = rootProject.archives_base_name
from components.java
}
}

// 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.
}
}
21 changes: 21 additions & 0 deletions common/src/main/java/dev/igalaxy/takeitslow/TakeItSlow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.igalaxy.takeitslow;

import dev.igalaxy.takeitslow.config.TakeItSlowConfig;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TakeItSlow {
private static final Logger logger = LoggerFactory.getLogger("Take It Slow");

public static void onInitialize() {
AutoConfig.register(TakeItSlowConfig.class, JanksonConfigSerializer::new);

logger.info("Remember to take it slow!");
}

public static TakeItSlowConfig getConfig() {
return AutoConfig.getConfigHolder(TakeItSlowConfig.class).getConfig();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.igalaxy.takeitslow.config;

import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;

@Config(name = "takeitslow")
public class TakeItSlowConfig implements ConfigData {
@ConfigEntry.Category("Movement")
public boolean allowSwimming = true;

@ConfigEntry.Category("Movement")
public boolean allowCreative = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.igalaxy.takeitslow.mixin;

import dev.igalaxy.takeitslow.TakeItSlow;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.level.GameType;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LocalPlayer.class)
public abstract class LocalPlayerMixin {
@Shadow @Final protected Minecraft minecraft;
@Shadow public abstract boolean isUnderWater();
@Shadow public abstract void setSprinting(boolean bl);

@ModifyVariable(method = "setSprinting(Z)V", at = @At("HEAD"))
private boolean modifySetSprinting(boolean bl) {
GameType localPlayerMode = ((MultiPlayerGameModeAccessor)this.minecraft.gameMode).getLocalPlayerMode();

boolean allowSwimming = TakeItSlow.getConfig().allowSwimming;
boolean allowCreative = TakeItSlow.getConfig().allowCreative;

boolean isUnderwater = this.isUnderWater();
boolean isCreative = localPlayerMode == GameType.CREATIVE;
boolean isSpectator = localPlayerMode == GameType.SPECTATOR;

return (isUnderwater && bl && allowSwimming) || (isCreative && bl && allowCreative) || (isSpectator && bl && allowCreative);
}

@Inject(method = "updateIsUnderwater", at = @At("TAIL"))
private void modifyUpdateIsUnderwater(CallbackInfoReturnable<Boolean> cir) {
GameType localPlayerMode = ((MultiPlayerGameModeAccessor)this.minecraft.gameMode).getLocalPlayerMode();

boolean isUnderwater = this.isUnderWater();
boolean isCreative = localPlayerMode == GameType.CREATIVE;
boolean isSpectator = localPlayerMode == GameType.SPECTATOR;

if (!isUnderwater && !isCreative && !isSpectator) {
this.setSprinting(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.igalaxy.takeitslow.mixin;

import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.world.level.GameType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(MultiPlayerGameMode.class)
public interface MultiPlayerGameModeAccessor {
@Accessor
GameType getLocalPlayerMode();
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions common/src/main/resources/assets/takeitslow/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"text.autoconfig.takeitslow.title": "Take it Slow Config",
"text.autoconfig.takeitslow.option.allowSwimming": "Allow Swimming",
"text.autoconfig.takeitslow.option.allowCreative": "Allow in Creative/Spectator Mode"
}
14 changes: 14 additions & 0 deletions common/src/main/resources/takeitslow-common.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"package": "dev.igalaxy.takeitslow.mixin",
"compatibilityLevel": "JAVA_16",
"client": [
"LocalPlayerMixin",
"MultiPlayerGameModeAccessor"
],
"mixins": [
],
"injectors": {
"defaultRequire": 1
}
}
78 changes: 78 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
}

architectury {
platformSetupLoomIde()
fabric()
}

configurations {
common
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentFabric.extendsFrom common
}

dependencies {
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }

modImplementation("me.shedaniel.cloth:cloth-config-fabric:${rootProject.cloth_version}") { exclude module: "fabric-api" }
modImplementation("com.terraformersmc:modmenu:3.+")
}

processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

shadowJar {
exclude "architectury.common.json"

configurations = [project.configurations.shadowCommon]
classifier "dev-shadow"
}

remapJar {
input.set shadowJar.archiveFile
dependsOn shadowJar
classifier null
}

jar {
classifier "dev"
}

sourcesJar {
def commonSources = project(":common").sourcesJar
dependsOn commonSources
from commonSources.archiveFile.map { zipTree(it) }
}

components.java {
withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
skip()
}
}

publishing {
publications {
mavenFabric(MavenPublication) {
artifactId = rootProject.archives_base_name + "-" + project.name
from components.java
}
}

// 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.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.igalaxy.takeitslow.fabric;

import dev.igalaxy.takeitslow.TakeItSlow;
import net.fabricmc.api.ModInitializer;

public class FabricEntrypoint implements ModInitializer {
@Override
public void onInitialize() {
TakeItSlow.onInitialize();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.igalaxy.takeitslow.fabric;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import dev.igalaxy.takeitslow.config.TakeItSlowConfig;
import me.shedaniel.autoconfig.AutoConfig;

public class ModMenuIntegration implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> AutoConfig.getConfigScreen(TakeItSlowConfig.class, parent).get();
}
}
38 changes: 38 additions & 0 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"schemaVersion": 1,
"id": "takeitslow",
"version": "${version}",
"name": "Take it Slow",
"description": "Who needs sprinting anyways?",
"authors": [
"iGalaxy"
],
"contact": {
"homepage": "https://github.com/iGalaxyYT/take-it-slow",
"sources": "https://github.com/iGalaxyYT/take-it-slow"
},
"license": "MIT",
"icon": "assets/takeitslow/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"dev.igalaxy.takeitslow.fabric.FabricEntrypoint"
],
"modmenu": [
"dev.igalaxy.takeitslow.fabric.ModMenuIntegration"
]
},
"mixins": [
"takeitslow.mixins.json",
"takeitslow-common.mixins.json"
],
"depends": {
"fabric": "*",
"minecraft": ">=1.18.2",
"java": ">=17",
"cloth-config2": ">=6.0.0"
},
"suggests": {
"modmenu": ">=3.0.0"
}
}
12 changes: 12 additions & 0 deletions fabric/src/main/resources/takeitslow.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": true,
"package": "dev.igalaxy.takeitslow.fabric.mixin",
"compatibilityLevel": "JAVA_16",
"client": [
],
"mixins": [
],
"injectors": {
"defaultRequire": 1
}
}
Loading

0 comments on commit 434e9b7

Please sign in to comment.