Skip to content

Commit

Permalink
Add Config
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeF53 committed Nov 16, 2021
1 parent 614f286 commit dfc6037
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 31 deletions.
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.9-SNAPSHOT'
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -16,6 +16,12 @@ repositories {
// 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.

// Cloth Config
maven { url "https://maven.shedaniel.me/" }

// Mod Menu
maven { url "https://maven.terraformersmc.com/" }
}

dependencies {
Expand All @@ -27,6 +33,12 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Cloth Config
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}")

// Mod Menu
modImplementation("com.terraformersmc:modmenu:${project.mod_menu_version}")

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
}
Expand All @@ -47,6 +59,7 @@ tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"

// Minecraft 1.17 (21w19a) upwards uses Java 16.
// Minecraft 1.18 (1.18-pre18) upwards uses Java 17.
it.options.release = 16
}

Expand Down
8 changes: 5 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.63
loader_version=0.11.7
yarn_mappings=1.17.1+build.64
loader_version=0.12.5

# Mod Properties
mod_version = 1.0.0
mod_version = 1.1.0
maven_group = com.HorseBuff
archives_base_name = HorseBuff

# Dependencies
fabric_version=0.41.0+1.17
cloth_config_version=5.0.38
mod_menu_version=2.0.14
6 changes: 6 additions & 0 deletions src/main/java/net/F53/HorseBuff/HorseBuffInit.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package net.F53.HorseBuff;

import net.fabricmc.api.ModInitializer;

import net.F53.HorseBuff.config.ModConfig;

import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -17,5 +22,6 @@ public void onInitialize() {
// Proceed with mild caution.

LOGGER.info("Horse Buff Initialized");
AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new);
}
}
8 changes: 8 additions & 0 deletions src/main/java/net/F53/HorseBuff/ModInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.F53.HorseBuff;



public final class ModInfo {
public static final String MODID = "HorseBuff";
public static final double VERSION = 1.1;
}
19 changes: 19 additions & 0 deletions src/main/java/net/F53/HorseBuff/config/ModConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.F53.HorseBuff.config;

import net.F53.HorseBuff.ModInfo;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.*;


@Config(name = ModInfo.MODID)
public class ModConfig implements ConfigData{
// Config Structure
// Saddled Horse Don't Wander
// Breeding Changes

@ConfigEntry.Gui.Tooltip
public static boolean noWander = true;

@ConfigEntry.Gui.Tooltip
public static boolean fairBreeds = true;
}
15 changes: 15 additions & 0 deletions src/main/java/net/F53/HorseBuff/config/ModMenuIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.F53.HorseBuff.config;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import me.shedaniel.autoconfig.AutoConfig;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
public class ModMenuIntegration implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> AutoConfig.getConfigScreen(ModConfig.class, parent).get();
}
}
5 changes: 1 addition & 4 deletions src/main/java/net/F53/HorseBuff/mixin/BreakSpeed.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.HorseBaseEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import net.minecraft.entity.passive.HorseBaseEntity;

// Disable breakspeed debuff
@Mixin(PlayerEntity.class)
Expand Down
36 changes: 20 additions & 16 deletions src/main/java/net/F53/HorseBuff/mixin/FairBreeds.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static net.F53.HorseBuff.config.ModConfig.fairBreeds;

// Make breeding fair
@Mixin(HorseBaseEntity.class)
abstract class HorseChildAttributeMixin extends AnimalEntity {
Expand All @@ -21,22 +23,24 @@ protected HorseChildAttributeMixin(EntityType<? extends AnimalEntity> entityType

@Inject(method = "setChildAttributes", at = @At(value = "TAIL"))
protected void onSetChildAttributes(PassiveEntity mate, HorseBaseEntity child, CallbackInfo ci) {
// Logic - Set stat to average parent stat, +/- some random amount, limited to vanilla min/max values

// Health
// 15-30
double Health = Logic(this.getAttributeBaseValue(EntityAttributes.GENERIC_MAX_HEALTH), mate.getAttributeBaseValue(EntityAttributes.GENERIC_MAX_HEALTH), 15, 30);
child.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH).setBaseValue(Health);

// Jump
// 0.4-1.0
double JumpStrength = Logic(this.getAttributeBaseValue(EntityAttributes.HORSE_JUMP_STRENGTH), mate.getAttributeBaseValue(EntityAttributes.HORSE_JUMP_STRENGTH), 0.4, 1.0);
child.getAttributeInstance(EntityAttributes.HORSE_JUMP_STRENGTH).setBaseValue(JumpStrength);

// Movement
// 0.1125 - 0.3375
double MovementSpeed = Logic(this.getAttributeBaseValue(EntityAttributes.GENERIC_MOVEMENT_SPEED), mate.getAttributeBaseValue(EntityAttributes.GENERIC_MOVEMENT_SPEED), 0.1125, 0.3375);
child.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED).setBaseValue(MovementSpeed);
if (fairBreeds) {
// Logic - Set stat to average parent stat, +/- some random amount, limited to vanilla min/max values

// Health
// 15-30
double Health = Logic(this.getAttributeBaseValue(EntityAttributes.GENERIC_MAX_HEALTH), mate.getAttributeBaseValue(EntityAttributes.GENERIC_MAX_HEALTH), 15, 30);
child.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH).setBaseValue(Health);

// Jump
// 0.4-1.0
double JumpStrength = Logic(this.getAttributeBaseValue(EntityAttributes.HORSE_JUMP_STRENGTH), mate.getAttributeBaseValue(EntityAttributes.HORSE_JUMP_STRENGTH), 0.4, 1.0);
child.getAttributeInstance(EntityAttributes.HORSE_JUMP_STRENGTH).setBaseValue(JumpStrength);

// Movement
// 0.1125 - 0.3375
double MovementSpeed = Logic(this.getAttributeBaseValue(EntityAttributes.GENERIC_MOVEMENT_SPEED), mate.getAttributeBaseValue(EntityAttributes.GENERIC_MOVEMENT_SPEED), 0.1125, 0.3375);
child.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED).setBaseValue(MovementSpeed);
}
}

private double Logic(double A, double B, double min, double max){
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/net/F53/HorseBuff/mixin/NoWander.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package net.F53.HorseBuff.mixin;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.HorseBaseEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import net.minecraft.entity.passive.HorseBaseEntity;

import static net.F53.HorseBuff.config.ModConfig.noWander;

// Lower wander speed for saddled horses
@Mixin(HorseBaseEntity.class)
public abstract class NoWander {
public abstract class NoWander extends MobEntity {
protected NoWander(EntityType<? extends MobEntity> entityType, World world) {
super(entityType, world);
}

@Shadow public abstract boolean isSaddled();

@ModifyArg(method = "travel(Lnet/minecraft/util/math/Vec3d;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/AnimalEntity;travel(Lnet/minecraft/util/math/Vec3d;)V", ordinal = 0))
private Vec3d lowerWanderSpeed(Vec3d input) {
if (isSaddled())
if (noWander && isSaddled() && this.getHoldingEntity() == null)
return(Vec3d.ZERO);
return input;
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/assets/horsebuff/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"text.autoconfig.HorseBuff.title": "Horse Buff Config",
"text.autoconfig.HorseBuff.option.noWander": "No Horse Wandering",
"text.autoconfig.HorseBuff.option.noWander.@Tooltip": "Yes - saddled horses wont wander.\nNo - saddled horses will wander",
"text.autoconfig.HorseBuff.option.fairBreeds": "Breeding Changes",
"text.autoconfig.HorseBuff.option.fairBreeds.@Tooltip": "Yes - game uses alternate breeding algorithm.\nNo - game uses vanilla breeding algorithm"
}
18 changes: 17 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"entrypoints": {
"main": [
"net.F53.HorseBuff.HorseBuffInit"
],
"modmenu": [
"net.F53.HorseBuff.config.ModMenuIntegration"
]
},
"mixins": [
Expand All @@ -30,9 +33,22 @@
"fabricloader": ">=0.11.3",
"fabric": "*",
"minecraft": "1.17.x",
"java": ">=16"
"java": ">=16",
"cloth-config2": ">=5.0.38",
"modmenu": ">=2.0.14"
},
"suggests": {
"another-mod": "*"
},

"custom": {
"modmenu": {
"parent": {
"id": "horsebuff",
"name": "HorseBuff",
"description": "QOL tweaks for horses",
"icon": "assets/horsebuff/icon.png"
}
}
}
}

0 comments on commit dfc6037

Please sign in to comment.