Skip to content

Commit

Permalink
Fix Computer Craft speaker (#889)
Browse files Browse the repository at this point in the history
* speaker sound fix

* readme

* em
  • Loading branch information
xiewuzhiying authored Jul 21, 2024
1 parent a22ebde commit 1c62ccc
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 101 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.valkyrienskies.mod.fabric.mixin.compat.cc_restitched;

import dan200.computercraft.client.sound.SpeakerSound;
import dan200.computercraft.shared.peripheral.speaker.SpeakerPosition;
import net.minecraft.client.resources.sounds.AbstractSoundInstance;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.spongepowered.asm.mixin.Mixin;
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.callback.CallbackInfo;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.mod.client.audio.VelocityTickableSoundInstance;
import org.valkyrienskies.mod.common.VSGameUtilsKt;

@Mixin(SpeakerSound.class)
public abstract class MixinSpeakerSound extends AbstractSoundInstance implements VelocityTickableSoundInstance {
@Unique private SpeakerPosition speakerPosition;
@Unique private Ship ship;

protected MixinSpeakerSound(ResourceLocation arg, SoundSource arg2) {
super(arg, arg2);
}

@Inject(
method = "setPosition",
at = @At("RETURN"),
remap = false
)
private void isOnShip(SpeakerPosition position, CallbackInfo ci) {
this.speakerPosition = position;
this.ship = VSGameUtilsKt.getShipManagingPos(position.level(), position.position());
if (this.ship != null) {
Vec3 worldPos = VSGameUtilsKt.toWorldCoordinates(speakerPosition.level(), speakerPosition.position());
x = worldPos.x;
y = worldPos.y;
z = worldPos.z;
}
}

@Inject(
method = "tick",
at = @At("HEAD")
)
private void updateWorldPos(CallbackInfo ci) {
if (this.ship != null) {
Vec3 worldPos = VSGameUtilsKt.toWorldCoordinates(speakerPosition.level(), speakerPosition.position());
x = worldPos.x;
y = worldPos.y;
z = worldPos.z;
}
}

@NotNull
@Override
public Vector3dc getVelocity() {
return ship != null ? ship.getVelocity() : new Vector3d();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Minimal ComputerCraft Compatibility Mixins

- MixinSpeakerPosition
- MixinSpeakerSound
- Fixes Speakers on Ships not playing sounds in worldspace but in Shipyard
- MixinTurtleBrain
- Fails Movement if the turtle is in worldspace and the target position is a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_8",
"plugin": "org.valkyrienskies.mod.fabric.mixin.ValkyrienFabricMixinConfigPlugin",
"mixins": [
"compat.cc_restitched.MixinSpeakerPosition",
"compat.cc_restitched.MixinTurtleBrain",
"compat.cc_restitched.MixinTurtleMoveCommand",
"compat.cc_restitched.MixinWirelessNetwork",
Expand All @@ -18,6 +17,7 @@
"world.level.block.FireMixin"
],
"client": [
"compat.cc_restitched.MixinSpeakerSound",
"compat.create.client.MixinContraptionHandlerClient",
"compat.create.client.MixinContraptionRenderInfo",
"compat.create.client.MixinCullingBlockEntityIterator",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.valkyrienskies.mod.forge.mixin.compat.cc_tweaked;

import dan200.computercraft.client.sound.SpeakerSound;
import dan200.computercraft.shared.peripheral.speaker.SpeakerPosition;
import net.minecraft.client.resources.sounds.AbstractSoundInstance;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.spongepowered.asm.mixin.Mixin;
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.callback.CallbackInfo;
import org.valkyrienskies.core.api.ships.Ship;
import org.valkyrienskies.mod.client.audio.VelocityTickableSoundInstance;
import org.valkyrienskies.mod.common.VSGameUtilsKt;

@Mixin(SpeakerSound.class)
public abstract class MixinSpeakerSound extends AbstractSoundInstance implements VelocityTickableSoundInstance {
@Unique private SpeakerPosition speakerPosition;
@Unique private Ship ship;

protected MixinSpeakerSound(ResourceLocation arg, SoundSource arg2) {
super(arg, arg2);
}

@Inject(
method = "setPosition",
at = @At("RETURN"),
remap = false
)
private void isOnShip(SpeakerPosition position, CallbackInfo ci) {
this.speakerPosition = position;
this.ship = VSGameUtilsKt.getShipManagingPos(position.level(), position.position());
if (this.ship != null) {
Vec3 worldPos = VSGameUtilsKt.toWorldCoordinates(speakerPosition.level(), speakerPosition.position());
x = worldPos.x;
y = worldPos.y;
z = worldPos.z;
}
}

@Inject(
method = "tick",
at = @At("HEAD")
)
private void updateWorldPos(CallbackInfo ci) {
if (this.ship != null) {
Vec3 worldPos = VSGameUtilsKt.toWorldCoordinates(speakerPosition.level(), speakerPosition.position());
x = worldPos.x;
y = worldPos.y;
z = worldPos.z;
}
}

@NotNull
@Override
public Vector3dc getVelocity() {
return ship != null ? ship.getVelocity() : new Vector3d();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Minimal ComputerCraft Compatibility Mixins

- MixinSpeakerPosition
- MixinSpeakerSound
- Fixes Speakers on Ships not playing sounds in worldspace but in Shipyard
- MixinTurtleBrain
- Fails Movement if the turtle is in worldspace and the target position is a
Expand Down
6 changes: 3 additions & 3 deletions forge/src/main/resources/valkyrienskies-forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_17",
"plugin": "org.valkyrienskies.mod.forge.mixin.ValkyrienForgeMixinConfigPlugin",
"mixins": [
"compat.cc_tweaked.MixinSpeakerPosition",
"compat.cc_tweaked.MixinTurtleBrain",
"compat.cc_tweaked.MixinTurtleMoveCommand",
"compat.cc_tweaked.MixinWirelessNetwork",
Expand All @@ -23,14 +22,15 @@
],
"client": [
"client.render.MixinLevelRenderer",
"compat.cc_tweaked.MixinSpeakerSound",
"compat.create.client.MixinContraptionHandlerClient",
"compat.create.client.MixinContraptionRenderInfo",
"compat.create.client.MixinFlwContraption",
"compat.create.client.MixinSuperGlueSelectionHandler",
"compat.create.client.MixinTrackBlockOutline",
"compat.sodium.MixinRenderSectionManager",
"compat.tis3d.MixinCasingTileEntityRender",
"compat.tis3d.MixinRenderContextImpl",
"compat.create.client.MixinTrackBlockOutline"
"compat.tis3d.MixinRenderContextImpl"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 1c62ccc

Please sign in to comment.