Skip to content

Commit

Permalink
port to multiloader
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Oct 6, 2024
1 parent 07e74fe commit f447272
Show file tree
Hide file tree
Showing 26 changed files with 660 additions and 251 deletions.
174 changes: 83 additions & 91 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,115 +1,107 @@
plugins {
id "fabric-loom" version "1.6+"
id "com.github.johnrengelman.shadow" version "8.1+"
id "maven-publish"
id "me.modmuss50.mod-publish-plugin" version "0.5.2"
id 'idea'
id 'maven-publish'
id 'me.modmuss50.mod-publish-plugin' version '0.7.4' apply false
id 'net.neoforged.moddev' version '2.0.34-beta' apply false
}

version = project.mod_version
version = "${project.mod_version}+mc${project.minecraft_version}"
group = project.maven_group

repositories {
maven { url = "https://maven.quiltmc.org/repository/release/" }
maven { url = "https://maven.terraformersmc.com/releases/" }
maven { url = "https://repo.sleeping.town/" }
}

configurations {
shadow
api.extendsFrom shadow
}

dependencies {
minecraft("com.mojang:minecraft:${project.minecraft_version}")
mappings("org.quiltmc:quilt-mappings:${project.minecraft_version}+build.${project.quilt_mappings}:intermediary-v2")
modImplementation("net.fabricmc:fabric-loader:${project.loader_version}")
modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}")

implementation("folk.sisby:kaleido-config:${project.kaleido_config_version}")
include("folk.sisby:kaleido-config:${project.kaleido_config_version}")

modRuntimeOnly("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
}

processResources {
inputs.property "version", project.version
inputs.property "minecraft_version", project.minecraft_version
inputs.property "loader_version", project.loader_version
filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
expand "version": project.version,
"minecraft_version": project.minecraft_version,
"loader_version": project.loader_version
def targetJavaVersion = 21

subprojects {
apply plugin: 'java-library'
project.group = rootProject.group
project.version = rootProject.version

repositories {
maven { url = 'https://maven.quiltmc.org/repository/release' }
maven { url = 'https://maven.terraformersmc.com/releases' }
maven { url = 'https://repo.sleeping.town' }
maven {
name = "ParchmentMC"
url = "https://maven.parchmentmc.org"
content {
includeGroupAndSubgroups "org.parchmentmc"
}
}
}
}

publishMods {
displayName = "ramel ${project.version}"
file = remapJar.archiveFile
changelog = rootProject.file("CHANGELOG.md").getText()
type = STABLE

modLoaders.add("quilt")
modLoaders.add("fabric")

dryRun = !providers.environmentVariable("MODRINTH_TOKEN").isPresent()
|| !providers.environmentVariable("CURSEFORGE_TOKEN").isPresent()
|| property("pub.should_publish") == "false"
dryRun = false

var mcVersions = [project.minecraft_version]
mcVersions.addAll(property("pub.additional_versions").toString().split(" ").findAll { !it.empty })

modrinth {
projectId = "4Uw92C2y"
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
mcVersions.forEach(minecraftVersions::add)
java {
withSourcesJar()
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
}

requires("fabric-api")
optional("modmenu")
tasks.withType(JavaCompile).configureEach {
it.options.encoding = 'UTF-8'
it.options.release = targetJavaVersion
}

curseforge {
accessToken = providers.environmentVariable("CURSEFORGE_TOKEN")
projectId = "877074"
mcVersions.forEach(minecraftVersions::add)
javadoc {
// need this so javadoc doesnt complain about mixin's @reason
options.tags = ['reason']
}

clientRequired = true
serverRequired = false
base {
archivesName = "${rootProject.archives_base_name}-${project.name}"
}

requires("fabric-api")
optional("modmenu")
jar {
from('LICENSE') {
rename { "LICENSE_${rootProject.archives_base_name}"}
}
}
}

def targetJavaVersion = 17
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release = targetJavaVersion
sourcesJar {
from('LICENSE') {
rename { "LICENSE_${rootProject.archives_base_name}" }
}
}
}

java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
processResources {
filteringCharset 'UTF-8'

def expandProps = [
'version': version,
'minecraft_version': project.minecraft_version,
'mod_id': project.mod_id,
'maven_group_id': project.maven_group,
'website_url': project.website_url,
'sources_url': project.sources_url,
'issue_tracker_url': project.issue_tracker_url,
'discord_url': project.discord_url,

'fabric_loader_version': project.fabric_loader_version,
'neoforge_version': project.neoforge_version,
'java_version': targetJavaVersion
]

filesMatching(['pack.mcmeta', '*.mod.json', 'META-INF/*mods.toml', '*.mixins.json']) {
expand expandProps
}
inputs.properties(expandProps)
}
archivesBaseName = project.archives_base_name
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
publishing {
publications {
"mavenJava_${project.name}"(MavenPublication) {
artifactId base.archivesName.get()
from components.java
}
}
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
allprojects {
// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
idea {
module {
downloadSources = true
downloadJavadoc = true
}
}
}
21 changes: 21 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id 'net.neoforged.moddev'
}

dependencies {
compileOnly("org.jetbrains:annotations:${project.jetbrains_annotations_version}")
compileOnly("net.fabricmc:sponge-mixin:${project.mixin_version}")
compileOnly("io.github.llamalad7:mixinextras-common:${project.mixin_extras_version}")
annotationProcessor("io.github.llamalad7:mixinextras-common:${project.mixin_extras_version}")

compileOnly("folk.sisby:kaleido-config:${project.kaleido_config_version}")
}

neoForge {
neoFormVersion = project.neoform_version

parchment {
minecraftVersion = project.parchment_minecraft_version
mappingsVersion = project.parchment_mappings_version
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
import folk.sisby.kaleido.api.ReflectiveConfig;
import folk.sisby.kaleido.lib.quiltconfig.api.annotations.Comment;
import folk.sisby.kaleido.lib.quiltconfig.api.annotations.FloatRange;
import folk.sisby.kaleido.lib.quiltconfig.api.serializers.TomlSerializer;
import folk.sisby.kaleido.lib.quiltconfig.api.values.TrackedValue;
import folk.sisby.kaleido.lib.quiltconfig.implementor_api.ConfigEnvironment;
import net.fabricmc.loader.api.FabricLoader;
import io.ix0rai.ramel.service.ConfigProvider;

public class Config extends ReflectiveConfig {
private static final String FORMAT = "toml";
private static final String FAMILY = "ramel";
private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(FabricLoader.getInstance().getConfigDir(), FORMAT, TomlSerializer.INSTANCE);
public static final Config INSTANCE = create(ENVIRONMENT, FAMILY, "ramel", Config.class);
private static final String FAMILY = Ramel.MODID;
public static final Config INSTANCE = create(ConfigProvider.load().createConfigEnvironment(), FAMILY, "ramel", Config.class);

@Comment("The amount of extra range beyond the camel's normal hitbox, in blocks, that the ramming effect will apply.")
@Comment("Value will be halved for baby camels.")
Expand Down
6 changes: 6 additions & 0 deletions common/src/main/java/io/ix0rai/ramel/Ramel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.ix0rai.ramel;

public class Ramel {

public static final String MODID = "ramel";
}
49 changes: 49 additions & 0 deletions common/src/main/java/io/ix0rai/ramel/client/RamelConfigScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.ix0rai.ramel.client;

import com.mojang.serialization.Codec;
import folk.sisby.kaleido.lib.quiltconfig.api.Constraint;
import folk.sisby.kaleido.lib.quiltconfig.api.values.TrackedValue;
import io.ix0rai.ramel.Config;
import net.minecraft.client.Minecraft;
import net.minecraft.client.OptionInstance;
import net.minecraft.client.Options;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.options.OptionsSubScreen;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.Nullable;

import java.util.stream.StreamSupport;

public class RamelConfigScreen extends OptionsSubScreen {
public RamelConfigScreen(@Nullable Screen parent) {
super(parent, Minecraft.getInstance().options, Component.translatable("ramel.config.title"));
}

@Override
@SuppressWarnings({"unchecked", "DataFlowIssue"})
protected void addOptions() {
this.list.addSmall(StreamSupport.stream(Config.INSTANCE.values().spliterator(), false)
.map(value -> createOptional((TrackedValue<Float>) value)).toArray(OptionInstance[]::new));
}

private static OptionInstance<Float> createOptional(TrackedValue<Float> trackedValue) {
Constraint.Range<Float> range = null;

for (Constraint<Float> c : trackedValue.constraints()) {
if (c instanceof Constraint.Range<Float> constraintRange) {
range = constraintRange;
}
}

String stringValue = trackedValue.key().toString();

if (range == null) {
throw new RuntimeException("value must have float range constraint: " + stringValue);
}

float min = range.min();
float max = range.max();

return new OptionInstance<>("ramel.config." + stringValue, OptionInstance.cachedConstantTooltip(Component.translatable("ramel.config.tooltip." + stringValue)), (text, value) -> Options.genericValueLabel(text, Component.translatable("ramel.config.value." + stringValue, value)), (new OptionInstance.IntRange((int) (min * 10), (int) (max * 10))).xmap((intValue) -> intValue / 10.0F, (doubleValue) -> (int) (doubleValue * 10.0D)), Codec.floatRange(min, max), trackedValue.value(), trackedValue::setValue);
}
}
66 changes: 66 additions & 0 deletions common/src/main/java/io/ix0rai/ramel/mixin/CamelEntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.ix0rai.ramel.mixin;

import com.google.common.base.MoreObjects;
import io.ix0rai.ramel.Config;
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.camel.Camel;
import net.minecraft.world.level.Level;
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.callback.CallbackInfo;

import java.util.Objects;

@Mixin(Camel.class)
public abstract class CamelEntityMixin extends LivingEntity {
@Shadow public abstract boolean isDashing();

private CamelEntityMixin(EntityType<? extends Camel> entityType, Level level) {
super(entityType, level);
throw new UnsupportedOperationException();
}

@Inject(method = "tick", at = @At("HEAD"))
private void inject$tick(CallbackInfo ci) {
if (!this.isDashing() || this.level().isClientSide()) {
return;
}

int speedEffectModifier = this.hasEffect(MobEffects.MOVEMENT_SPEED) ? Objects.requireNonNull(this.getEffect(MobEffects.MOVEMENT_SPEED)).getAmplifier() + 1 : 0;
int slowEffectModifier = this.hasEffect(MobEffects.MOVEMENT_SLOWDOWN) ? Objects.requireNonNull(this.getEffect(MobEffects.MOVEMENT_SLOWDOWN)).getAmplifier() + 1 : 0;
double speedAdjustedImpact = Mth.clamp(this.getSpeed() * 1.65, .2, 3.0) + .25 * (speedEffectModifier - slowEffectModifier);

float rammingRange = Config.INSTANCE.additionalRammingRange.value() * (isBaby() ? 0.5F : 1.0F);
float rammingDamage = Config.INSTANCE.rammingDamage.value() * (isBaby() ? 0.5F : 1.0F);
float knockBackMultiplier = Config.INSTANCE.knockbackMultiplier.value() * (isBaby() ? 0.5F : 1.0F);

DamageSource source = this.damageSources().mobAttack(MoreObjects.firstNonNull(this.getControllingPassenger(), this));

this.level().getEntities(this, this.getBoundingBox().inflate(rammingRange), Entity::isAlive).stream()
.filter(e -> e instanceof LivingEntity && !this.getPassengers().contains(e))
.forEach(e -> {
LivingEntity entity = (LivingEntity) e;

entity.playSound(SoundEvents.PLAYER_ATTACK_KNOCKBACK);
entity.hurt(source, rammingDamage);
final double blockedImpact = entity.isDamageSourceBlocked(source) ? .5 : 1.0;

entity.knockback(blockedImpact * speedAdjustedImpact * knockBackMultiplier,
Mth.sin(this.getXRot() * (Mth.PI / 180.0F)), -Mth.cos(this.getXRot() * (Mth.PI / 180.0F)));
if (entity instanceof ServerPlayer player) {
// The player won't feel any effects if we don't update the velocity
player.connection.send(new ClientboundSetEntityMotionPacket(player));
}
});
}
}
20 changes: 20 additions & 0 deletions common/src/main/java/io/ix0rai/ramel/service/ConfigProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.ix0rai.ramel.service;

import folk.sisby.kaleido.lib.quiltconfig.api.serializers.TomlSerializer;
import folk.sisby.kaleido.lib.quiltconfig.implementor_api.ConfigEnvironment;

import java.nio.file.Path;
import java.util.ServiceLoader;

public interface ConfigProvider {

Path getConfigDir();

default ConfigEnvironment createConfigEnvironment() {
return new ConfigEnvironment(getConfigDir(), "toml", TomlSerializer.INSTANCE);
}

static ConfigProvider load() {
return ServiceLoader.load(ConfigProvider.class).findFirst().orElseThrow(() -> new IllegalStateException("No platform implementation found for " + ConfigProvider.class.getCanonicalName()));
}
}
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required": true,
"minVersion": "0.8",
"package": "io.ix0rai.ramel.mixin",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"mixins": [
"CamelEntityMixin"
],
Expand Down
Loading

0 comments on commit f447272

Please sign in to comment.