Sound fade

This commit is contained in:
paulevsGitch 2020-11-01 19:59:52 +03:00
parent d6d78925b7
commit 6362c2f85a
6 changed files with 128 additions and 25 deletions

View file

@ -0,0 +1,12 @@
package ru.betterend.mixin.client;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.client.sound.AbstractSoundInstance;
@Mixin(AbstractSoundInstance.class)
public interface AbstractSoundInstanceAccessor {
@Accessor("volume")
void setVolume(float volume);
}

View file

@ -0,0 +1,92 @@
package ru.betterend.mixin.client;
import java.util.Random;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
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 net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.AbstractSoundInstance;
import net.minecraft.client.sound.MusicTracker;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.sound.MusicSound;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
@Mixin(MusicTracker.class)
public class MusicTrackerMixin {
@Shadow
@Final
private MinecraftClient client;
@Shadow
@Final
private Random random;
@Shadow
private SoundInstance current;
@Shadow
private int timeUntilNextSong;
private static float volume = 1;
private static float srcVolume = 0;
private static long time;
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
public void beOnTick(CallbackInfo info) {
MusicSound musicSound = client.getMusicType();
if (volume > 0 && beIsInEnd() && beShouldChangeSound(musicSound)) {
if (volume > 0) {
if (srcVolume < 0) {
srcVolume = current.getVolume();
}
if (current instanceof AbstractSoundInstance) {
((AbstractSoundInstanceAccessor) current).setVolume(volume);
}
client.getSoundManager().updateSoundVolume(current.getCategory(), current.getVolume() * volume);
long t = System.currentTimeMillis();
if (volume == 1 && time == 0) {
time = t;
}
float delta = (t - time) * 0.0005F;
time = t;
volume -= delta;
if (volume < 0) {
volume = 0;
}
}
if (volume == 0) {
volume = 1;
time = 0;
srcVolume = -1;
this.client.getSoundManager().stop(this.current);
this.timeUntilNextSong = MathHelper.nextInt(this.random, 0, musicSound.getMinDelay() / 2);
this.current = null;
}
if (this.current == null && this.timeUntilNextSong-- <= 0) {
this.play(musicSound);
}
System.out.println(volume);
info.cancel();
}
else {
volume = 1;
}
}
private boolean beIsInEnd() {
return client.world != null && client.world.getRegistryKey().equals(World.END);
}
private boolean beShouldChangeSound(MusicSound musicSound) {
return current != null && !musicSound.getSound().getId().equals(this.current.getId()) && musicSound.shouldReplaceCurrentMusic();
}
@Shadow
public void play(MusicSound type) {}
}

View file

@ -47,7 +47,6 @@ public class TranslationHelper {
EndBiomes.getModBiomes().forEach((endBiome) -> { EndBiomes.getModBiomes().forEach((endBiome) -> {
if (endBiome.getID().getNamespace().equals(BetterEnd.MOD_ID)) { if (endBiome.getID().getNamespace().equals(BetterEnd.MOD_ID)) {
String name = "biome." + BetterEnd.MOD_ID + "." + endBiome.getID().getPath(); String name = "biome." + BetterEnd.MOD_ID + "." + endBiome.getID().getPath();
System.out.println(name);
if (!translationEn.has(name)) { if (!translationEn.has(name)) {
missingNamesEn.add(name); missingNamesEn.add(name);
} }

View file

@ -16,7 +16,6 @@ import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndTags; import ru.betterend.registry.EndTags;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
import ru.betterend.util.SplineHelper; import ru.betterend.util.SplineHelper;
import ru.betterend.util.sdf.PosInfo; import ru.betterend.util.sdf.PosInfo;
@ -125,13 +124,13 @@ public class PythadendronTreeFeature extends DefaultFeature {
}); });
sphere.fillRecursiveIgnore(world, pos.up(), IGNORE); sphere.fillRecursiveIgnore(world, pos.up(), IGNORE);
if (radius > 5) { /*if (radius > 5) {
int count = (int) (radius * 2.5F); int count = (int) (radius * 2.5F);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
BlockPos p = pos.add(random.nextGaussian() * 1.5, random.nextGaussian() * 1.5, random.nextGaussian() * 1.5); BlockPos p = pos.add(random.nextGaussian() * 1.5, random.nextGaussian() * 1.5, random.nextGaussian() * 1.5);
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.PYTHADENDRON.bark); BlocksHelper.setWithoutUpdate(world, p, EndBlocks.PYTHADENDRON.bark);
} }
} }*/
} }
static { static {

View file

@ -15,7 +15,6 @@ public class TerrainStructureProcessor extends StructureProcessor {
BlockPos bpos = structureBlockInfo2.pos; BlockPos bpos = structureBlockInfo2.pos;
if (structureBlockInfo2.state.isOf(Blocks.END_STONE) && worldView.isAir(bpos.up())) { if (structureBlockInfo2.state.isOf(Blocks.END_STONE) && worldView.isAir(bpos.up())) {
BlockState top = worldView.getBiome(structureBlockInfo2.pos).getGenerationSettings().getSurfaceConfig().getTopMaterial(); BlockState top = worldView.getBiome(structureBlockInfo2.pos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
System.out.println(top);
return new StructureBlockInfo(bpos, top, structureBlockInfo2.tag); return new StructureBlockInfo(bpos, top, structureBlockInfo2.tag);
} }
return structureBlockInfo2; return structureBlockInfo2;

View file

@ -1,20 +1,22 @@
{ {
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "ru.betterend.mixin.client", "package": "ru.betterend.mixin.client",
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_8",
"client": [ "client": [
"WorldRendererMixin", "AbstractSoundInstanceAccessor",
"BackgroundRendererMixin", "ClientPlayNetworkHandlerMixin",
"ClientRecipeBookMixin", "NamespaceResourceManagerMixin",
"ModelLoaderMixin", "DeserializationContextMixin",
"ModelVariantMapMixin", "BackgroundRendererMixin",
"DeserializationContextMixin", "ClientRecipeBookMixin",
"ClientPlayNetworkHandlerMixin", "ModelVariantMapMixin",
"NamespaceResourceManagerMixin", "MinecraftClientMixin",
"MinecraftClientMixin" "WorldRendererMixin",
], "MusicTrackerMixin",
"injectors": { "ModelLoaderMixin"
"defaultRequire": 1 ],
} "injectors": {
} "defaultRequire": 1
}
}