1
0
forked from Clones/Controlify

vibration conflict support - multiple vibrations can play at once

This commit is contained in:
isXander
2023-04-05 21:15:52 +01:00
parent a3583ab5c8
commit 2f4cbfa099
9 changed files with 180 additions and 68 deletions

View File

@ -53,18 +53,13 @@ public class MultiPlayerGameModeMixin {
}
private void startRumble(BlockState state) {
ContinuousRumbleEffect effect = new ContinuousRumbleEffect(tick ->
new RumbleState(
var effect = ContinuousRumbleEffect.builder()
.byTick(tick -> new RumbleState(
0.02f + Easings.easeInQuad(Math.min(1, state.getBlock().defaultDestroyTime() / 20f)) * 0.25f,
0.01f
)
){
@Override
public boolean isFinished() {
// insta-break blocks will stop the same tick it starts, so it must not stop until 1 tick has played
return super.isFinished() && currentTick() > 0;
}
};
))
.minTime(1)
.build();
blockBreakRumble = effect;
ControlifyApi.get().currentController().rumbleManager().play(RumbleSource.BLOCK_DESTROY, effect);

View File

@ -1,4 +1,4 @@
package dev.isxander.controlify.mixins.feature.rumble.sounds;
package dev.isxander.controlify.mixins.feature.rumble.levelevents;
import dev.isxander.controlify.api.ControlifyApi;
import dev.isxander.controlify.rumble.BasicRumbleEffect;
@ -40,7 +40,7 @@ public class LevelRendererMixin {
float easeOutQuad = Easings.easeOutQuad(t);
return new RumbleState(1 - easeOutQuad, 1 - easeOutQuad);
}, 63)
)
).prioritised(10)
);
case LevelEvent.SOUND_WITHER_BOSS_SPAWN -> rumble(
RumbleSource.GLOBAL_EVENT,
@ -51,7 +51,7 @@ public class LevelRendererMixin {
float easeOutQuad = 1 - (1 - t) * (1 - t);
return new RumbleState(0f, 1 - easeOutQuad);
}, 56)
)
).prioritised(10)
);
}
}

View File

@ -8,6 +8,7 @@ import dev.isxander.controlify.rumble.RumbleState;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.BowItem;
import net.minecraft.world.item.CrossbowItem;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@ -20,22 +21,37 @@ public abstract class LocalPlayerMixin extends LivingEntityMixin {
@Override
protected void onStartUsingItem(InteractionHand hand, CallbackInfo ci, ItemStack stack) {
switch (stack.getUseAnimation()) {
case BOW, CROSSBOW, SPEAR ->
startRumble(new ContinuousRumbleEffect(tick ->
new RumbleState(tick % 7 <= 3 && tick > BowItem.MAX_DRAW_DURATION ? 0.1f : 0f, BowItem.getPowerForTime(tick))
));
case BLOCK, SPYGLASS ->
startRumble(new ContinuousRumbleEffect(tick ->
new RumbleState(0f, tick % 4 / 4f * 0.12f + 0.05f)
));
case EAT, DRINK ->
startRumble(new ContinuousRumbleEffect(tick ->
new RumbleState(0.05f, 0.1f)
));
case TOOT_HORN ->
startRumble(new ContinuousRumbleEffect(tick ->
new RumbleState(Math.min(1f, tick / 10f), 0.25f)
));
case BOW -> startRumble(ContinuousRumbleEffect.builder()
.byTick(tick -> new RumbleState(
tick % 7 <= 3 && tick > BowItem.MAX_DRAW_DURATION ? 0.1f : 0f,
BowItem.getPowerForTime(tick)
))
.build());
case CROSSBOW -> {
int chargeDuration = CrossbowItem.getChargeDuration(stack);
startRumble(ContinuousRumbleEffect.builder()
.byTick(tick -> new RumbleState(
0f,
(float) tick / chargeDuration
))
.timeout(chargeDuration)
.build());
}
case BLOCK, SPYGLASS -> startRumble(ContinuousRumbleEffect.builder()
.byTick(tick -> new RumbleState(
0f,
tick % 4 / 4f * 0.12f + 0.05f
))
.build());
case EAT, DRINK -> startRumble(ContinuousRumbleEffect.builder()
.constant(0.05f, 0.1f)
.build());
case TOOT_HORN -> startRumble(ContinuousRumbleEffect.builder()
.byTick(tick -> new RumbleState(
Math.min(1f, tick / 10f),
0.25f
))
.build());
}
}