Skip to content

Commit

Permalink
Port Apron, Audiomod and Forge mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Jan 1, 2025
1 parent 8c5ebd5 commit 6f41441
Show file tree
Hide file tree
Showing 48 changed files with 410 additions and 479 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public String getModLoaderMPVersion() {

@Override
public String translate(String key) {
return TranslationStorage.getInstance().translate(key);
return TranslationStorage.getInstance().get(key);
}

@Override
public String translate(String key, Object... args) {
return TranslationStorage.getInstance().translate(key, args);
return TranslationStorage.getInstance().get(key, args);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import net.fabricmc.loader.impl.FabricLoaderImpl;
import org.jetbrains.annotations.Nullable;

import net.minecraft.client.resource.language.Internationalization;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
Expand All @@ -27,7 +26,7 @@ public final class ApronServerImpl implements ApronApi {
MinecraftServer server = (MinecraftServer) getGame();

if (server != null) {
return server.getWorld(0);
return server.method_2157(0);
}

return null;
Expand All @@ -39,7 +38,7 @@ public List<PlayerEntity> getPlayers() {
MinecraftServer server = (MinecraftServer) getGame();

if (server != null) {
return server.serverPlayerConnectionManager.players;
return server.field_2842.field_578;
}

return null;
Expand All @@ -65,12 +64,12 @@ public String getModLoaderMPVersion() {

@Override
public String translate(String key) {
return Internationalization.translate(key);
return I18n.getTranslation(key);
}

@Override
public String translate(String key, Object... args) {
return Internationalization.translate(key, args);
return I18n.getTranslation(key, args);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ default Item asItem() {
if (((Object)this) instanceof ItemStack) return ((ItemStack) (Object) this).getItem();
if (this instanceof Item) return ((Item) this);
if (this instanceof ItemEntity) return ((ItemConvertible)(Object)((ItemEntity) this).stack).asItem();
if (this instanceof Block) return Item.byId[((Block) this).id];
if (this instanceof Block) return Item.ITEMS[((Block) this).id];

return Item.byId[0];
return Item.ITEMS[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
@Mixin(Entity.class)
public interface EntityAccessor {
@Accessor
void setFallDistance(float distance);
void setField_1636(float distance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
@Mixin(World.class)
public interface WorldAccessor {
@Accessor
void setAutoSaveInterval(int interval);
void setField_212(int interval);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiElement;
import net.minecraft.client.gui.InGameHud;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;

@Environment(EnvType.CLIENT)
@Mixin(InGameHud.class)
public abstract class InGameHudMixin extends GuiElement {
public abstract class InGameHudMixin extends DrawContext {
@Shadow
private Minecraft client;
private Minecraft minecraft;

@ModifyConstant(method = "render(FZII)V", constant = @Constant(stringValue = "Minecraft Beta 1.7.3 ("))
private String apron$replaceVersionString(String constant) {
Expand All @@ -37,7 +37,7 @@ public abstract class InGameHudMixin extends GuiElement {
y = 106;
}

this.drawTextWithShadow(this.client.textRenderer,
this.drawTextWithShadow(this.minecraft.textRenderer,
String.format("M: %s, %s", rmlModsLoaded(), fabricModsLoaded()), 2, y, 0xE0_E0_E0);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package io.github.betterthanupdates.apron.mixin.client;

import net.minecraft.client.sound.SoundManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import paulscode.sound.SoundSystem;

import net.minecraft.client.sound.SoundHelper;

@Mixin(SoundHelper.class)
@Mixin(SoundManager.class)
public interface SoundHelperAccessor {
@Accessor
int getSoundUID();
int getField_2671();
@Accessor
void setMusicCountdown(int countdown);
void setField_2675(int countdown);

@Accessor
static SoundSystem getSoundSystem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.menu.TitleScreen;
import net.minecraft.client.gui.screen.TitleScreen;

//import io.github.betterthanupdates.apron.Apron;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.class_266;
import net.minecraft.class_267;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import paulscode.sound.SoundSystem;
import paulscode.sound.SoundSystemConfig;
import paulscode.sound.codecs.CodecIBXM;

import net.minecraft.client.Minecraft;
import net.minecraft.client.options.GameOptions;
import net.minecraft.client.sound.SoundEntry;
import net.minecraft.client.sound.SoundHelper;
import net.minecraft.client.sound.SoundMap;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.util.math.MathHelper;

import io.github.betterthanupdates.apron.api.ApronApi;
Expand All @@ -34,42 +33,40 @@
*
* @see paulscode.sound.codecs.CodecIBXM
*/
@Mixin(SoundHelper.class)
@Mixin(SoundManager.class)
public abstract class SoundHelperMixin {
@Shadow
private Random rand;
private Random field_2674;
@Shadow
private int musicCountdown;

@Shadow
private SoundMap sounds;
private int field_2675;
@Shadow
private SoundMap streaming;
private class_266 field_2668;
@Shadow
private SoundMap music;
private class_266 field_2669;
@Shadow
private static boolean initialized;
private class_266 field_2670;

@Shadow
private static SoundSystem soundSystem;

// AudioMod Fields
@Unique
private final SoundMap cave = new SoundMap();
private final class_266 cave = new class_266();
@Unique
private Minecraft client;
@Unique
private static final int MUSIC_INTERVAL = 6000;

@Inject(method = "<init>", at = @At("RETURN"))
private void audiomod$ctr(CallbackInfo ci) {
this.musicCountdown = this.rand.nextInt(MUSIC_INTERVAL);
this.field_2675 = this.field_2674.nextInt(MUSIC_INTERVAL);
}

@Inject(method = "acceptOptions", at = @At("RETURN"))
@Inject(method = "method_2012", at = @At("RETURN"))
private void audiomod$acceptOptions(GameOptions options, CallbackInfo ci) {
loadModAudio("./resources/mod/sound", this.sounds);
loadModAudio("./resources/mod/streaming", this.streaming);
loadModAudio("./resources/mod/music", this.music);
loadModAudio("./resources/mod/sound", this.field_2668);
loadModAudio("./resources/mod/streaming", this.field_2669);
loadModAudio("./resources/mod/music", this.field_2670);
loadModAudio("./resources/mod/cavemusic", this.cave);

this.client = (Minecraft) ApronApi.getInstance().getGame();
Expand All @@ -78,7 +75,7 @@ public abstract class SoundHelperMixin {
/**
* @author Risugami
*/
private static void loadModAudio(String folder, SoundMap array) {
private static void loadModAudio(String folder, class_266 array) {
File base = new File(FabricLoader.getInstance().getGameDir().toFile(), folder);

walkFolder(base, base, array);
Expand All @@ -87,7 +84,7 @@ private static void loadModAudio(String folder, SoundMap array) {
/**
* @author Risugami
*/
private static void walkFolder(File root, File folder, SoundMap sounds) {
private static void walkFolder(File root, File folder, class_266 sounds) {
if (folder.exists() || folder.mkdirs()) {
File[] files = folder.listFiles();

Expand All @@ -102,7 +99,7 @@ private static void walkFolder(File root, File folder, SoundMap sounds) {
} else if (f.isRegularFile()) {
String path = file.getPath().substring(root.getPath().length() + 1)
.replace('\\', '/');
sounds.addSound(path, file);
sounds.method_959(path, file);
}
} catch (IOException ignored) {
// Simply don't load the file.
Expand All @@ -117,7 +114,7 @@ private static void walkFolder(File root, File folder, SoundMap sounds) {
* @author Risugami
* @reason IBXM audio codec for Paul's SoundSystem
*/
@Inject(method = "setLibsAndCodecs", at = @At(value = "INVOKE", ordinal = 2, shift = At.Shift.AFTER, remap = false,
@Inject(method = "method_2019", at = @At(value = "INVOKE", ordinal = 2, shift = At.Shift.AFTER, remap = false,
target = "Lpaulscode/sound/SoundSystemConfig;setCodec(Ljava/lang/String;Ljava/lang/Class;)V"))
private void audiomod$setLibsAndCodecs(CallbackInfo ci) {
SoundSystemConfig.setCodec("xm", CodecIBXM.class);
Expand All @@ -129,71 +126,71 @@ private static void walkFolder(File root, File folder, SoundMap sounds) {
* @author Risugami
* @reason AudioMod patches
*/
@Redirect(method = "updateMusicVolume", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundHelper;initialized:Z", ordinal = 1))
public boolean updateMusicVolume() {
return initialized && soundSystem != null;
@WrapOperation(method = "method_2008", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundManager;field_2673:Z", ordinal = 1))
public boolean updateMusicVolume(Operation<Boolean> original) {
return original.call() && soundSystem != null;
}

/**
* @author Risugami
* @reason AudioMod patches
*/
@Redirect(method = "handleBackgroundMusic", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundHelper;initialized:Z"))
public boolean handleBackgroundMusic() {
return initialized && soundSystem != null;
@WrapOperation(method = "method_2017", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundManager;field_2673:Z"))
public boolean handleBackgroundMusic(Operation<Boolean> original) {
return original.call() && soundSystem != null;
}

/**
* @author Risugami
* @reason AudioMod patches
*/
@WrapOperation(method = "handleBackgroundMusic", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/SoundMap;getRandomSound()Lnet/minecraft/client/sound/SoundEntry;"))
public SoundEntry handleBackgroundMusic(SoundMap instance, Operation<SoundEntry> operation) {
@WrapOperation(method = "method_2017", at = @At(value = "INVOKE", target = "Lnet/minecraft/class_266;method_957()Lnet/minecraft/class_267;"))
public class_267 handleBackgroundMusic(class_266 instance, Operation<class_267> operation) {
if (this.client != null
&& this.client.player != null
&& !this.client
.player
.world
.isAboveGroundCached(MathHelper.floor(this.client.player.x), MathHelper.floor(this.client.player.y), MathHelper.floor(this.client.player.z))) {
.method_249(MathHelper.floor(this.client.player.x), MathHelper.floor(this.client.player.y), MathHelper.floor(this.client.player.z))) {
return operation.call(this.cave);
} else {
return operation.call(this.music);
return operation.call(this.field_2670);
}
}

/**
* @author Risugami
* @reason AudioMod patches
*/
@Redirect(method = "setSoundPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundHelper;initialized:Z"))
public boolean setSoundPosition() {
return initialized && soundSystem != null;
@WrapOperation(method = "method_2013", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundManager;field_2673:Z"))
public boolean setSoundPosition(Operation<Boolean> original) {
return original.call() && soundSystem != null;
}

/**
* @author Risugami
* @reason AudioMod patches
*/
@Redirect(method = "playStreaming", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundHelper;initialized:Z"))
public boolean playSound() {
return initialized && soundSystem != null;
@WrapOperation(method = "method_2010", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundManager;field_2673:Z"))
public boolean playSound(Operation<Boolean> original) {
return original.call() && soundSystem != null;
}

/**
* @author Risugami
* @reason AudioMod patches
*/
@Redirect(method = "playSound(Ljava/lang/String;FFFFF)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundHelper;initialized:Z"))
public boolean playSound$1() {
return initialized && soundSystem != null;
@WrapOperation(method = "method_2015", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundManager;field_2673:Z"))
public boolean playSound$1(Operation<Boolean> original) {
return original.call() && soundSystem != null;
}

/**
* @author Risugami
* @reason AudioMod patches
*/
@Redirect(method = "playSound(Ljava/lang/String;FF)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundHelper;initialized:Z"))
public boolean playSound$2() {
return initialized && soundSystem != null;
@WrapOperation(method = "method_2009", at = @At(value = "FIELD", target = "Lnet/minecraft/client/sound/SoundManager;field_2673:Z"))
public boolean playSound$2(Operation<Boolean> original) {
return original.call() && soundSystem != null;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.betterthanupdates.forge.client.particle;

import net.minecraft.block.Block;
import net.minecraft.client.entity.particle.DiggingParticleEntity;
import net.minecraft.client.particle.BlockParticle;

public interface ForgeParticleManager {
void addDigParticleEffect(DiggingParticleEntity dig_effect, Block block);
void addDigParticleEffect(BlockParticle dig_effect, Block block);
}
Loading

0 comments on commit 6f41441

Please sign in to comment.