Skip to content

Commit

Permalink
Implementing MarioDatas
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Dec 5, 2024
1 parent f524518 commit 9d4c307
Show file tree
Hide file tree
Showing 17 changed files with 650 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.fqf.mario_qua_mario;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.api.ModInitializer;

import org.slf4j.Logger;
Expand All @@ -13,4 +15,9 @@ public class MarioQuaMarioAPI implements ModInitializer {
public void onInitialize() {
LOGGER.info("Mario qua Mario API initializing!");
}

@Environment(EnvType.CLIENT)
private void testasaur() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.fqf.mario_qua_mario.mariodata;

import net.minecraft.util.Identifier;

public interface IMarioAuthoritativeData {
boolean setAction(Identifier actionID);
boolean setAction(String actionID);

boolean setActionTransitionless(Identifier actionID);
boolean setActionTransitionless(String actionID);

boolean setPowerUp(Identifier powerUpID);
boolean setPowerUp(String powerUpID);

boolean setCharacter(Identifier characterID);
boolean setCharacter(String characterID);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.fqf.mario_qua_mario.mariodata;

import net.minecraft.entity.Entity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;

public interface IMarioClientData extends IMarioData {
SoundInstanceWrapper playSound(
SoundEvent event, SoundCategory category,
double x, double y, double z,
float pitch, float volume, long seed
);

SoundInstanceWrapper playSound(SoundEvent event, long seed);
SoundInstanceWrapper playSound(SoundEvent event, float pitch, float volume, long seed);
SoundInstanceWrapper playSound(SoundEvent event, Entity entity, SoundCategory category, long seed);

void playJumpSound(long seed);
void fadeJumpSound();

SoundInstanceWrapper voice(VoiceLine line, long seed);
float getVoicePitch();

void storeSound(SoundInstanceWrapper instance);
void stopStoredSound(SoundEvent event);

enum VoiceLine {
SELECT,
DUCK,

DOUBLE_JUMP,
TRIPLE_JUMP,
GYMNAST_SALUTE,

DUCK_JUMP,
LONG_JUMP,
BACKFLIP,
SIDEFLIP,
WALL_JUMP,

REVERT,
BURNT,

FIREBALL,
GET_STAR
}

interface SoundInstanceWrapper {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.fqf.mario_qua_mario.mariodata;

import com.fqf.mario_qua_mario.util.CharaStat;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;

import java.util.HashSet;
import java.util.Set;

public interface IMarioData {
PlayerEntity getMario();
boolean isClient();

double getStat(CharaStat stat);
double getStatMultiplier(CharaStat stat);
int getBumpStrengthModifier();

boolean canSneak();
boolean canSprint();

boolean isEnabled();
Identifier getActionID();
Identifier getPowerUpID();
Identifier getCharacterID();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.fqf.mario_qua_mario.mariodata;

public interface IMarioTravelData extends IMarioData {
double getForwardVel();
double getStrafeVel();
double getYVel();

void setForwardVel(double forward);
void setStrafeVel(double strafe);
default void setForwardStrafeVel(double forward, double strafe) {
this.setForwardVel(forward);
this.setStrafeVel(strafe);
}
void setYVel(double vertical);

abstract class MarioInputs {
public final MarioButton JUMP;
public final MarioButton DUCK;
public final MarioButton SPIN;

public abstract double getForwardInput();
public abstract double getStrafeInput();

public abstract boolean isReal();

public interface MarioButton {
boolean isPressed();
boolean isHeld();
}

protected MarioInputs(MarioButton jump, MarioButton duck, MarioButton spin) {
JUMP = jump;
DUCK = duck;
SPIN = spin;
}
}
}
36 changes: 36 additions & 0 deletions api/src/main/java/com/fqf/mario_qua_mario/util/CharaStat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.fqf.mario_qua_mario.util;

import com.fqf.mario_qua_mario.mariodata.IMarioData;

import java.util.Set;

/**
* Represents a numerical value that might vary depending on character and power-up form.
* This is used for movement, speed thresholds, and damage calculations.
*/
public class CharaStat {
public final double BASE;
public final Set<StatCategory> CATEGORIES;

public CharaStat(double base, StatCategory... categories) {
this(base, Set.of(categories));
}
public CharaStat variate(double multiplier) {
return new CharaStat(this.BASE * multiplier, this.CATEGORIES);
}

private CharaStat(double base, Set<StatCategory> categorySet) {
this.BASE = base;
this.CATEGORIES = categorySet;
}

public double get(IMarioData data) {
return data.getStat(this);
}
public double getAsThreshold(IMarioData data) {
return this.get(data) * 0.96;
}
public double getAsLimit(IMarioData data) {
return this.get(data) * 1.015;
}
}
39 changes: 39 additions & 0 deletions api/src/main/java/com/fqf/mario_qua_mario/util/StatCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.fqf.mario_qua_mario.util;

public enum StatCategory {
WALKING,
RUNNING,
P_RUNNING,
DUCKING,

DRIFTING, // Airborne

SWIMMING, // Aquatic

ACCELERATION,
OVERSPEED_CORRECTION, // Used INSTEAD OF acceleration for overwalk, overrun, etc. type stats.
SPEED,
REDIRECTION,
THRESHOLD,

FORWARD,
BACKWARD,
STRAFE,

DRAG,
FRICTION, // Mostly for Luigi?
WATER_DRAG,

JUMP_VELOCITY,
JUMP_CAP,

JUMPING_GRAVITY,
NORMAL_GRAVITY,
AQUATIC_GRAVITY,
TERMINAL_VELOCITY,
AQUATIC_TERMINAL_VELOCITY,

STOMP_BASE_DAMAGE,
STOMP_ARMOR_MULTIPLIER,
STOMP_BOUNCE
}
1 change: 1 addition & 0 deletions mod/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fabricApi {

dependencies {
implementation(project(path: ':api', configuration: "namedElements"))
runtimeOnly(project(path: ':content', configuration: "namedElements"))

// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.fqf.mario_qua_mario.mariodata;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.entity.Entity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;

public interface IMarioClientDataImpl extends IMarioClientData {
@Override
default boolean isClient() {
return true;
}

@Override
default SoundInstanceWrapperImpl playSound(
SoundEvent event, SoundCategory category,
double x, double y, double z,
float pitch, float volume, long seed
) {
SoundInstance sound = new PositionedSoundInstance(
event, category,
volume, pitch,
Random.create(seed),
x, y, z
);
MinecraftClient.getInstance().getSoundManager().play(sound);
return new SoundInstanceWrapperImpl(sound);
}

@Override
default SoundInstanceWrapperImpl playSound(SoundEvent event, long seed) {
return this.playSound(event, 1F, 1F, seed);
}

@Override
default SoundInstanceWrapperImpl playSound(SoundEvent event, float pitch, float volume, long seed) {
Vec3d marioPos = this.getMario().getPos();
return this.playSound(event, SoundCategory.PLAYERS, marioPos.x, marioPos.y, marioPos.z, 1F, 1F, seed);
}

@Override
default SoundInstanceWrapperImpl playSound(SoundEvent event, Entity entity, SoundCategory category, long seed) {
return this.playSound(event, category, entity.getX(), entity.getY(), entity.getZ(), 1F, 1F, seed);
}

@Override
default void playJumpSound(long seed) {

}

@Override
default void fadeJumpSound() {

}

Map<IMarioClientDataImpl, SoundInstance> MARIO_VOICE_LINES = new HashMap<>();

@Override
default SoundInstanceWrapperImpl voice(VoiceLine line, long seed) {
MinecraftClient.getInstance().getSoundManager().stop(MARIO_VOICE_LINES.get(this));
Vec3d marioPos = this.getMario().getPos();
SoundInstanceWrapperImpl newVoiceSound = this.playSound(
VOICE_SOUND_EVENTS.get(line).get(this.getCharacterID()), SoundCategory.VOICE,
marioPos.x, marioPos.y, marioPos.z,
this.getVoicePitch(), 1.0F,
seed
);

MARIO_VOICE_LINES.put(this, newVoiceSound.SOUND);

return newVoiceSound;
}

@Override
default float getVoicePitch() {
// return ((MarioPlayerData) this).getPowerUp().;
return 1;
}

Map<IMarioClientDataImpl, Map<Identifier, SoundInstance>> STORED_SOUNDS = new HashMap<>();

@Override
default void storeSound(SoundInstanceWrapper instance) {
STORED_SOUNDS.putIfAbsent(this, new HashMap<>());
SoundInstance sound = ((SoundInstanceWrapperImpl) instance).SOUND;
STORED_SOUNDS.get(this).put(sound.getId(), sound);
}

@Override
default void stopStoredSound(SoundEvent event) {
if(STORED_SOUNDS.containsKey(this)) {

}
}

class SoundInstanceWrapperImpl implements SoundInstanceWrapper {
private final SoundInstance SOUND;
public SoundInstanceWrapperImpl(SoundInstance sound) {
this.SOUND = sound;
}
}

EnumMap<VoiceLine, Map<Identifier, SoundEvent>> VOICE_SOUND_EVENTS = new EnumMap<>(VoiceLine.class);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
package com.fqf.mario_qua_mario.mariodata;

public class MarioMainClientData extends MarioPlayerData {
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
import org.jetbrains.annotations.Nullable;

public class MarioMainClientData extends MarioPlayerData implements IMarioClientDataImpl {
private static MarioMainClientData instance;
public static @Nullable MarioMainClientData getInstance() {
return instance;
}
public static void clearInstance() {
instance = null;
}

private ClientPlayerEntity mario;
public MarioMainClientData(ClientPlayerEntity mario) {
this.mario = mario;
instance = this;
}

@Override
public ClientPlayerEntity getMario() {
return mario;
}

@Override
public void setMario(PlayerEntity mario) {
this.mario = (ClientPlayerEntity) mario;
}
}
Loading

0 comments on commit 9d4c307

Please sign in to comment.