Skip to content

Commit

Permalink
Add Mixin to update banner patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
legobmw99 committed Jun 27, 2024
1 parent 2ecc1fd commit 82d830d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.151'
id 'net.neoforged.gradle.mixin' version '7.0.151'
}

tasks.named('wrapper', Wrapper).configure {
Expand Down Expand Up @@ -103,6 +104,14 @@ repositories {
}
}

mixin {
// add sourceSets.main, "${mod_id}.refmap.json"
// Sets up the mixin config; this gets added to run configurations and the manifest in the final jar
config "${mod_id}.mixins.json"

// Enables exporting mixin-changed classes to .mixin.out in the run folder
// debug.export = true
}

dependencies {
// Specify the version of Minecraft to use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public static void fillVial(ItemStack stack, FlakeStorage storage) {
/**
* TEMPORARY: Used to port pre-1.20.5 worlds to post.
* Loads custom NBT data and convets it to the data component.
* TODO: Remove in future version once worlds have updated
*/
@Override
public void verifyComponentsAfterLoad(ItemStack pStack) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.legobmw99.allomancy.modules.extras.mixin;

import com.legobmw99.allomancy.Allomancy;
import com.legobmw99.allomancy.api.enums.Metal;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.datafix.fixes.BannerPatternFormatFix;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
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.HashMap;
import java.util.Locale;
import java.util.Map;


/**
* TEMPORARY: Used to port 1.20 banners to 1.21
* TODO: Remove in future version once worlds have updated
*/
@Mixin(BannerPatternFormatFix.class)
public class BannerDFUMixin {
@Mutable
@Final
@Shadow
private static Map<String, String> PATTERN_ID_MAP;

@Inject(at = @At("RETURN"), method = "<clinit>")
private static void onConstruct(CallbackInfo info) {

Allomancy.LOGGER.info("Injecting to banner DFU");
var patternMap = new HashMap<>(PATTERN_ID_MAP);

for (Metal mt : Metal.values()) {
String name = mt.getName();
Allomancy.LOGGER.info("Redirecting banner pattern for {}", name);
patternMap.put("ALLOMANCY" + name.toUpperCase(Locale.ROOT),
ResourceLocation.fromNamespaceAndPath(Allomancy.MODID, name).toString());
}

PATTERN_ID_MAP = patternMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private CommonEventHandler() {}
/**
* TEMPORARY: Used to port Forge worlds to Neoforged.
* Loads the player's data file and sees if they have an old forge Capability stored.
* TODO: Remove in future version once worlds have updated
*/
@SubscribeEvent
public static void onPlayerLoad(final PlayerEvent.LoadFromFile event) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ authors = "${mod_authors}" #optional

# The description text for the mod (multi line!) (#mandatory)
description = '''${mod_description}'''

# The [[mixins]] block allows you to declare your mixin config to FML so that it gets loaded.
[[mixins]]
config="${mod_id}.mixins.json"

# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.${ mod_id }]] #optional
# the modid of the dependency
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/allomancy.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.legobmw99.allomancy.modules.extras.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": ["BannerDFUMixin"],
"client": [],
"server": [],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 82d830d

Please sign in to comment.