forked from Clones/Controlify
rumble source
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package dev.isxander.controlify.rumble;
|
||||
|
||||
public interface RumbleCapable {
|
||||
boolean setRumble(float strongMagnitude, float weakMagnitude);
|
||||
boolean setRumble(float strongMagnitude, float weakMagnitude, RumbleSource source);
|
||||
|
||||
boolean canRumble();
|
||||
}
|
||||
|
@ -2,17 +2,22 @@ package dev.isxander.controlify.rumble;
|
||||
|
||||
public class RumbleManager {
|
||||
private final RumbleCapable controller;
|
||||
private RumbleEffect playingEffect;
|
||||
private RumbleEffectInstance playingEffect;
|
||||
|
||||
public RumbleManager(RumbleCapable controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void play(RumbleEffect effect) {
|
||||
play(RumbleSource.MASTER, effect);
|
||||
}
|
||||
|
||||
public void play(RumbleSource source, RumbleEffect effect) {
|
||||
if (!controller.canRumble())
|
||||
return;
|
||||
|
||||
playingEffect = effect;
|
||||
playingEffect = new RumbleEffectInstance(source, effect);
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
@ -23,7 +28,7 @@ public class RumbleManager {
|
||||
if (playingEffect == null)
|
||||
return;
|
||||
|
||||
controller.setRumble(0f, 0f);
|
||||
controller.setRumble(0f, 0f, RumbleSource.MASTER);
|
||||
playingEffect = null;
|
||||
}
|
||||
|
||||
@ -31,12 +36,15 @@ public class RumbleManager {
|
||||
if (playingEffect == null)
|
||||
return;
|
||||
|
||||
if (playingEffect.isFinished()) {
|
||||
if (playingEffect.effect().isFinished()) {
|
||||
stopCurrentEffect();
|
||||
return;
|
||||
}
|
||||
|
||||
RumbleState state = playingEffect.nextState();
|
||||
controller.setRumble(state.strong(), state.weak());
|
||||
RumbleState state = playingEffect.effect().nextState();
|
||||
controller.setRumble(state.strong(), state.weak(), playingEffect.source());
|
||||
}
|
||||
|
||||
private record RumbleEffectInstance(RumbleSource source, RumbleEffect effect) {
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
package dev.isxander.controlify.rumble;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class RumbleSource {
|
||||
private static final Map<ResourceLocation, RumbleSource> SOURCES = new LinkedHashMap<>();
|
||||
|
||||
public static final RumbleSource
|
||||
MASTER = register("master"),
|
||||
DAMAGE = register("damage"),
|
||||
BLOCK_DESTROY = register("block_destroy"),
|
||||
USE_ITEM = register("use_item"),
|
||||
ITEM_BREAK = register("item_break"),
|
||||
GUI = register("gui"),
|
||||
GLOBAL_EVENT = register("global_event");
|
||||
|
||||
private final ResourceLocation id;
|
||||
|
||||
private RumbleSource(ResourceLocation id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ResourceLocation id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Collection<RumbleSource> values() {
|
||||
return SOURCES.values();
|
||||
}
|
||||
|
||||
public static JsonObject getDefaultJson() {
|
||||
JsonObject object = new JsonObject();
|
||||
for (RumbleSource source : SOURCES.values()) {
|
||||
object.addProperty(source.id().toString(), 1f);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
public static RumbleSource register(ResourceLocation id) {
|
||||
var source = new RumbleSource(id);
|
||||
SOURCES.put(id, source);
|
||||
return source;
|
||||
}
|
||||
|
||||
public static RumbleSource register(String identifier, String path) {
|
||||
return register(new ResourceLocation(identifier, path));
|
||||
}
|
||||
|
||||
private static RumbleSource register(String path) {
|
||||
return register("controlify", path);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user