forked from ChomeNS/chipmunkmod
ADD SUPPOR TFOR SOUNDS OVER AND LOWER THE OCTAVE
IT TOOK AGES IM SO DUMB :(((((((((((((((((((( :(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( HELP ME
This commit is contained in:
parent
b231e5e3d6
commit
80d67f17f8
3 changed files with 56 additions and 9 deletions
|
@ -4,24 +4,30 @@ import io.netty.channel.ChannelHandlerContext;
|
|||
import io.netty.handler.codec.DecoderException;
|
||||
import land.chipmunk.chipmunkmod.listeners.Listener;
|
||||
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.network.listener.PacketListener;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket;
|
||||
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
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 java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Mixin(net.minecraft.network.ClientConnection.class)
|
||||
public class ClientConnectionMixin {
|
||||
@Unique
|
||||
private static final Pattern CUSTOM_PITCH_PATTERN = Pattern.compile(".*\\.pitch\\.(.*)");
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "disconnect", cancellable = true)
|
||||
public void disconnect (Text disconnectReason, CallbackInfo ci) {
|
||||
if (disconnectReason == ClientPlayNetworkHandlerAccessor.chatValidationFailedText()) {
|
||||
|
@ -52,17 +58,40 @@ public class ClientConnectionMixin {
|
|||
ci.cancel();
|
||||
}
|
||||
} else if (packet instanceof PlaySoundS2CPacket t_packet) {
|
||||
if (t_packet.getVolume() != 1) return;
|
||||
try {
|
||||
final SoundEvent soundEvent = t_packet.getSound().value();
|
||||
|
||||
final Optional<RegistryKey<SoundEvent>> event = t_packet.getSound().getKey();
|
||||
final Identifier sound = soundEvent.getId();
|
||||
|
||||
if (event.isEmpty()) return;
|
||||
final Matcher matcher = CUSTOM_PITCH_PATTERN.matcher(sound.getPath());
|
||||
|
||||
final Identifier sound = event.get().getValue();
|
||||
if (!matcher.find()) return;
|
||||
|
||||
if (!sound.getPath().equals("entity.enderman.scream")) return;
|
||||
try {
|
||||
final String stringPitch = matcher.group(1);
|
||||
|
||||
final float pitch = Float.parseFloat(stringPitch);
|
||||
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
final ClientWorld world = client.world;
|
||||
|
||||
if (world == null) return;
|
||||
|
||||
// huge mess
|
||||
final SoundEvent newSound = SoundEvent.of(new Identifier(sound.getNamespace(), sound.getPath().substring(0, sound.getPath().length() - (".pitch." + stringPitch).length())));
|
||||
|
||||
world.playSound(client.player, t_packet.getX(), t_packet.getY(), t_packet.getZ(), newSound, t_packet.getCategory(), t_packet.getVolume(), pitch, t_packet.getSeed());
|
||||
|
||||
ci.cancel();
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (t_packet.getVolume() == 1 && sound.getPath().equals("entity.enderman.scream")) ci.cancel();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package land.chipmunk.chipmunkmod.mixin;
|
||||
|
||||
import net.minecraft.client.sound.SoundInstance;
|
||||
import net.minecraft.client.sound.SoundSystem;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(SoundSystem.class)
|
||||
public class SoundSystemMixin {
|
||||
@Inject(method = "getAdjustedPitch", at = @At("HEAD"), cancellable = true)
|
||||
private void getAdjustedPitch (SoundInstance sound, CallbackInfoReturnable<Float> cir) {
|
||||
cir.setReturnValue(sound.getPitch());
|
||||
cir.cancel();
|
||||
}
|
||||
}
|
|
@ -23,7 +23,8 @@
|
|||
"PlayerListEntryAccessor",
|
||||
"SharedConstantsMixin",
|
||||
"TextSerializerMixin",
|
||||
"CommandDispatcherMixin"
|
||||
"CommandDispatcherMixin",
|
||||
"SoundSystemMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in a new issue