Skip to content

Commit

Permalink
Port to Minecraft 1.20.2 and add support for NeoForge.
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkhax committed Nov 15, 2023
1 parent b9e04d5 commit 640daa2
Show file tree
Hide file tree
Showing 20 changed files with 280 additions and 169 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ build
# other
eclipse
run
runs
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ buildscript {
}

plugins {
id 'fabric-loom' version '1.2-SNAPSHOT' apply(false)
id 'net.minecraftforge.gradle' version '[6.0,6.2)' apply(false)
id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' apply(false)
id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' apply(false)
id 'net.darkhax.curseforgegradle' version '1.1.16' apply(false)
id 'com.modrinth.minotaur' version '2.8.0' apply(false)
id 'net.darkhax.curseforgegradle' version '1.1.17' apply(false)
id 'com.modrinth.minotaur' version '2.8.5' apply(false)
id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7"
}

apply from: 'gradle/property_loader.gradle'
Expand Down Expand Up @@ -101,6 +98,11 @@ task postDiscord() {
downloadSources.add("<:fabric:916233929722314763> [Fabric](${project(':fabric').findProperty('curse_file_url')})")
}

if (project(':neoforge').hasProperty('curse_file_url')) {

downloadSources.add("<:neoforge:1173939148806176779> [NeoForge](${project(':neoforge').findProperty('curse_file_url')})")
}

// Add Curseforge DL link if available.
def downloadString = downloadSources.toString()

Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.spongepowered.gradle.vanilla'
id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT'
}
apply from: '../gradle/property_helper.gradle'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.google.gson.annotations.SerializedName;
import net.darkhax.attributefix.Constants;
import net.darkhax.attributefix.mixin.AccessorRangedAttribute;
import net.darkhax.attributefix.temp.RegistryHelper;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.Attributes;
Expand All @@ -23,17 +23,16 @@ public class AttributeConfig {
@Expose
private Map<String, Entry> attributes = new HashMap<>();

public void applyChanges(RegistryHelper<Attribute> registry) {

public void applyChanges() {

Constants.LOG.info("Applying changes for {} attributes.", attributes.size());
for (Map.Entry<String, Entry> configEntry : attributes.entrySet()) {

final ResourceLocation attributeId = ResourceLocation.tryParse(configEntry.getKey());

if (attributeId != null && registry.exists(attributeId)) {
if (attributeId != null && BuiltInRegistries.ATTRIBUTE.containsKey(attributeId)) {

final Attribute attribute = registry.get(attributeId);
final Attribute attribute = BuiltInRegistries.ATTRIBUTE.get(attributeId);

if (attribute instanceof RangedAttribute ranged) {

Expand All @@ -46,7 +45,7 @@ public void applyChanges(RegistryHelper<Attribute> registry) {
continue;
}

final AccessorRangedAttribute accessor = (AccessorRangedAttribute)(Object)attribute;
final AccessorRangedAttribute accessor = (AccessorRangedAttribute) (Object) attribute;

if (minValue != ranged.getMinValue()) {

Expand All @@ -64,16 +63,16 @@ public void applyChanges(RegistryHelper<Attribute> registry) {
}
}

public static AttributeConfig load(File configFile, RegistryHelper<Attribute> registry) {
public static AttributeConfig load(File configFile) {

final AttributeConfig config = new AttributeConfig();

// Load/Generate the default values.
for (Attribute attribute : registry.getValues()) {
for (Attribute attribute : BuiltInRegistries.ATTRIBUTE) {

if (attribute instanceof RangedAttribute ranged) {

final ResourceLocation id = registry.getId(attribute);
final ResourceLocation id = BuiltInRegistries.ATTRIBUTE.getKey(attribute);
config.attributes.put(id.toString(), new Entry(id, ranged));
}
}
Expand All @@ -96,7 +95,7 @@ public static AttributeConfig load(File configFile, RegistryHelper<Attribute> re
Constants.LOG.error("Attribute ID '{}' is not a valid. This entry will be ignored.", configEntry.getKey());
}

else if (!registry.exists(attributeId)) {
else if (!BuiltInRegistries.ATTRIBUTE.containsKey(attributeId)) {

Constants.LOG.error("Attribute ID '{}' does not belong to a known attribute. This entry will be ignored.", configEntry.getKey());
}
Expand Down Expand Up @@ -143,8 +142,8 @@ else if (!registry.exists(attributeId)) {
}

/**
* Map of Attributes to new default values.<br>
* Any attribute not in this map will retain the declared default value, but can still be changed via config.
* Map of Attributes to new default values.<br> Any attribute not in this map will retain the declared default
* value, but can still be changed via config.
*/
private static final Map<Attribute, Double> NEW_DEFAULT_VALUES = ImmutableMap.of(
Attributes.MAX_HEALTH, 1_000_000D,
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'net.darkhax.curseforgegradle'
id 'com.modrinth.minotaur'
id 'idea'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package net.darkhax.attributefix;

import net.darkhax.attributefix.config.AttributeConfig;
import net.darkhax.attributefix.temp.RegistryHelper;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.world.entity.ai.attributes.Attribute;

public class AttributeFixFabricClient implements ClientModInitializer {

@Override
public void onInitializeClient() {


ClientLifecycleEvents.CLIENT_STARTED.register(mc -> {

RegistryHelper<Attribute> registry = new AttributeRegistryHelper();
AttributeConfig.load(FabricLoader.getInstance().getConfigDir().resolve(Constants.MOD_ID + ".json").toFile(), registry).applyChanges(registry);
});
ClientLifecycleEvents.CLIENT_STARTED.register(mc -> AttributeConfig.load(FabricLoader.getInstance().getConfigDir().resolve(Constants.MOD_ID + ".json").toFile()).applyChanges());
}
}

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"${mod_id}.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.21",
"fabricloader": ">=0.14.24",
"fabric": "*",
"minecraft": "1.20.1",
"minecraft": "${minecraft_version}",
"java": ">=17"
},
"custom": {
Expand Down
4 changes: 2 additions & 2 deletions forge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
id 'net.minecraftforge.gradle'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'org.spongepowered.mixin' version '0.7-SNAPSHOT'
id 'net.darkhax.curseforgegradle'
id 'com.modrinth.minotaur'
id 'org.spongepowered.mixin'
}

apply from: '../gradle/patreon.gradle'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package net.darkhax.attributefix;

import net.darkhax.attributefix.config.AttributeConfig;
import net.darkhax.attributefix.temp.RegistryHelper;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
Expand All @@ -15,7 +13,6 @@ public class AttributeFixForge {
@SubscribeEvent
public static void onLoadComplete(FMLLoadCompleteEvent event) {

RegistryHelper<Attribute> registry = new AttributeRegistryHelper();
AttributeConfig.load(FMLPaths.CONFIGDIR.get().resolve(Constants.MOD_ID + ".json").toFile(), registry).applyChanges(registry);
AttributeConfig.load(FMLPaths.CONFIGDIR.get().resolve(Constants.MOD_ID + ".json").toFile()).applyChanges();
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modLoader="javafml"
loaderVersion="[47,)"
loaderVersion="[48,)"
license="${mod_license}"
issueTrackerURL="${mod_issues}"

Expand Down
14 changes: 9 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# Project
version=21.0
version=22.0
group=net.darkhax.attributefix

# Common
minecraft_version=1.20.1
minecraft_version=1.20.2

# Forge
forge_version=47.1.44
forge_version=48.0.37

# NeoForge
neoforge_version=20.2.47-beta
neoforge_version_range=20.2,

# Fabric
fabric_version=0.87.0+1.20.1
fabric_loader_version=0.14.22
fabric_version=0.90.7+1.20.2
fabric_loader_version=0.14.24

# Mod options
mod_name=AttributeFix
Expand Down
Loading

0 comments on commit 640daa2

Please sign in to comment.