Skip to content

Commit

Permalink
Use mixin instead of access transform
Browse files Browse the repository at this point in the history
  • Loading branch information
IONayrus committed Jan 24, 2025
1 parent 59948bb commit 7496c15
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod_name=Note Block Master
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GNU GPLv3
# The mod version. See https://semver.org/
mod_version=0.7.1
mod_version=0.7.2
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.nayrus.noteblockmaster.mixin;

import net.minecraft.client.particle.ParticleEngine;
import net.minecraft.client.particle.SpriteSet;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.nayrus.noteblockmaster.setup.SpriteAccessor;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Map;

@Mixin(ParticleEngine.class)
public abstract class ParticleEnginePatch implements SpriteAccessor {

@Shadow @Final private Map<ResourceLocation, ?> spriteSets;

@SuppressWarnings("AddedMixinMembersNamePattern")
@Override
public SpriteSet getRegisteredSprite(ParticleType<?> type) {
return (SpriteSet) this.spriteSets.get(BuiltInRegistries.PARTICLE_TYPE.getKey(type));
}
}
7 changes: 3 additions & 4 deletions src/main/java/net/nayrus/noteblockmaster/setup/Registry.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package net.nayrus.noteblockmaster.setup;

import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.SpriteSet;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.BlockItem;
Expand Down Expand Up @@ -90,7 +88,8 @@ public static void registerClientExtensions(RegisterClientExtensionsEvent event)
}

public static void registerParticles(RegisterParticleProvidersEvent event) {
SpriteSet vanillaNote = Minecraft.getInstance().particleEngine.spriteSets.get(BuiltInRegistries.PARTICLE_TYPE.getKey(ParticleTypes.NOTE));
event.registerSpecial(SUSTAINED_NOTE.get(), new SustainedNoteParticle.Provider(vanillaNote));
if(!(Minecraft.getInstance().particleEngine instanceof SpriteAccessor vanillaSprites)) return;

event.registerSpecial(SUSTAINED_NOTE.get(), new SustainedNoteParticle.Provider(vanillaSprites.getRegisteredSprite(ParticleTypes.NOTE)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.nayrus.noteblockmaster.setup;

import net.minecraft.client.particle.SpriteSet;
import net.minecraft.core.particles.ParticleType;

public interface SpriteAccessor {
SpriteSet getRegisteredSprite(ParticleType<?> type);
}
9 changes: 5 additions & 4 deletions src/main/resources/noteblockmaster.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"required": true,
"package": "net.nayrus.noteblockmaster.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"SoundEnginePatch"
],
"injectors": {
"defaultRequire": 1
}
},
"client": [
"SoundEnginePatch",
"ParticleEnginePatch"
]
}
1 change: 0 additions & 1 deletion src/main/templates/META-INF/accesstransformer.cfg

This file was deleted.

0 comments on commit 7496c15

Please sign in to comment.