Skip to content

Commit

Permalink
Added MarioAuthoritativeData. Separated MarioClientSideData from its …
Browse files Browse the repository at this point in the history
…implementations (although the implementations are still all default methods in an interface. GRRR!)
  • Loading branch information
floral-qua-floral committed Nov 19, 2024
1 parent 7903a55 commit 96fdd8b
Show file tree
Hide file tree
Showing 43 changed files with 394 additions and 231 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.floralquafloral.bumping;

import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.mariodata.MarioClientSideDataImplementation;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.moveable.MarioTravelData;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.block.BlockState;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
Expand Down Expand Up @@ -43,7 +42,7 @@ public interface BlockBumpCallback {
);

BlockBumpResult bump(
MarioData marioData, @Nullable MarioClientSideData marioClientData, @Nullable MarioTravelData marioTravelData,
MarioData marioData, @Nullable MarioClientSideDataImplementation marioClientData, @Nullable MarioTravelData marioTravelData,
World world, BlockPos blockPos, BlockState blockState,
int strength, int modifier, Direction direction
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.floralquafloral.bumping;

import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.mariodata.MarioClientSideDataImplementation;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.moveable.MarioTravelData;
import net.minecraft.block.Block;
Expand All @@ -10,11 +10,9 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.crash.CrashException;
import net.minecraft.util.crash.CrashReport;
import net.minecraft.util.crash.CrashReportSection;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
Expand All @@ -39,7 +37,7 @@ public class BlockBumpHandler {
public static final Set<ForcedSignalSpot> FORCED_SIGNALS_DATA = new HashSet<>();

public static BlockBumpResult processBumpResult(
MarioData marioData, @Nullable MarioClientSideData marioClientData, @Nullable MarioTravelData marioTravelData,
MarioData marioData, @Nullable MarioClientSideDataImplementation marioClientData, @Nullable MarioTravelData marioTravelData,
World world, BlockPos blockPos, BlockState blockState,
int strength, int modifier, Direction direction
) {
Expand Down Expand Up @@ -70,7 +68,7 @@ else if(result == BlockBumpResult.DISPLACE) {
private static class InvalidBumpResultException extends RuntimeException {}

private static BlockBumpResult getBumpResult(
MarioData marioData, @Nullable MarioClientSideData marioClientData, @Nullable MarioTravelData marioTravelData,
MarioData marioData, @Nullable MarioClientSideDataImplementation marioClientData, @Nullable MarioTravelData marioTravelData,
World world, BlockPos blockPos, BlockState blockState,
int strength, int modifier, Direction direction
) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/floralquafloral/bumping/BumpManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import com.floralquafloral.MarioPackets;
import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.mariodata.MarioClientSideDataImplementation;
import com.floralquafloral.mariodata.MarioDataManager;
import com.floralquafloral.mariodata.moveable.MarioMainClientData;
import com.floralquafloral.mariodata.moveable.MarioServerData;
import com.floralquafloral.registries.RegistryManager;
import com.floralquafloral.util.MarioSFX;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
Expand Down Expand Up @@ -157,7 +156,7 @@ public static void attemptBumpBlocks(
}

public static Set<BlockPos> bumpBlocksClient(
MarioClientSideData marioClientData, @Nullable MarioMainClientData marioMainClientData,
MarioClientSideDataImplementation marioClientData, @Nullable MarioMainClientData marioMainClientData,
ClientWorld world, Iterable<BlockPos> positions,
int strength, Direction direction
) {
Expand Down Expand Up @@ -276,7 +275,7 @@ private record BumpS2CPayload(int player, Set<BlockPos> positions, Direction dir
);
public static void registerReceiver() {
ClientPlayNetworking.registerGlobalReceiver(ID, (payload, context) -> {
MarioClientSideData data = (MarioClientSideData) MarioDataManager.getMarioData(context.player());
MarioClientSideDataImplementation data = (MarioClientSideDataImplementation) MarioDataManager.getMarioData(context.player());
bumpBlocksClient(
data, null,
context.player().clientWorld, payload.positions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.floralquafloral.mariodata;

import com.floralquafloral.mariodata.moveable.MarioTravelData;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

/**
* Represents server-sided MarioData. The functions defined in this interface are networked to the player who this data
* belongs to, and anyone who's tracking them.
*/
public interface MarioAuthoritativeData extends MarioTravelData {
@Override
ServerPlayerEntity getMario();

/**
* @param isEnabled Whether the player should have access to Mario abilities.
*/
void setEnabled(boolean isEnabled);

/**
* @param id The namespaced ID of the Character to switch to.
*/
void setCharacter(Identifier id);
void setCharacter(String id);

/**
* Changes Mario's currently-equipped power-up. This won't trigger transition-related sound effects or animations.
* @param id The namespaced ID of the Power-up to switch to.
*/
void setPowerUp(Identifier id);
void setPowerUp(String id);

/**
* Changes Mario's action. This will trigger whatever Action Transition the current action has which leads
* into the target action.
* <p>
* If no transition is found, the behavior of this method call depends on the rejectInvalidActionTransitions
* gamerule. If the gamerule is true, then the change is rejected and Mario remains in his current action. If
* it's false, then the change is allowed and Mario will be switched to the new action without any transitions
* occurring. See also: {@linkplain #setActionTransitionless}
* @param id The namespaced ID of the Action to transition to.
* @return True if Mario's action was changed, false otherwise.
*/
boolean setAction(Identifier id);
boolean setAction(String id);

/**
* Changes Mario's action. Action Transitions will not be checked for or executed.
* @param id The namespaced ID of the Action to switch to.
*/
void setActionTransitionless(Identifier id);
void setActionTransitionless(String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,36 @@
import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.registries.RegistryManager;
import com.floralquafloral.registries.states.character.ParsedCharacter;
import com.floralquafloral.util.JumpSoundPlayer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.random.Random;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
* This is supposedly an interface but every method is implemented because that's the closest i can get to multiple
* inheritance. endless pains and agonies for ever & ever!
* An instance of MarioData on the client-side. Mostly used for playing sound effects, especially voice sounds.
* This isn't necessarily for the main client!
*/
@SuppressWarnings("UnusedReturnValue")
public interface MarioClientSideData extends MarioData {
SoundManager SOUND_MANAGER = MinecraftClient.getInstance().getSoundManager();

default PositionedSoundInstance playSoundEvent(
PositionedSoundInstance playSoundEvent(
SoundEvent event, SoundCategory category,
double x, double y, double z,
float pitch, float volume, long seed
) {
PositionedSoundInstance sound = new PositionedSoundInstance(
event, category,
volume, pitch,
Random.create(seed),
x, y, z
);
SOUND_MANAGER.play(sound);
return sound;
}

default PositionedSoundInstance playSoundEvent(SoundEvent event, long seed) {
PlayerEntity mario = this.getMario();
return playSoundEvent(
event, SoundCategory.PLAYERS,
mario.getX(), mario.getY(), mario.getZ(),
1.0F, 1.0F, seed
);
}

default PositionedSoundInstance playSoundEvent(SoundEvent event, float pitch, float volume, long seed) {
PlayerEntity mario = this.getMario();
return playSoundEvent(
event, SoundCategory.PLAYERS,
mario.getX(), mario.getY(), mario.getZ(),
pitch, volume, seed
);
}

default PositionedSoundInstance playSoundEvent(SoundEvent event, Entity entity, SoundCategory category, long seed) {
return playSoundEvent(
event, category,
entity.getX(), entity.getY(), entity.getZ(),
1.0F, 1.0F, seed
);
}

default PositionedSoundInstance voice(VoiceLine line, long seed) {
PlayerEntity mario = this.getMario();
);

SOUND_MANAGER.stop(VoiceLine.MARIO_VOICE_LINES.get(this));
PositionedSoundInstance playSoundEvent(SoundEvent event, long seed);
PositionedSoundInstance playSoundEvent(SoundEvent event, float pitch, float volume, long seed);
PositionedSoundInstance playSoundEvent(SoundEvent event, Entity entity, SoundCategory category, long seed);

PositionedSoundInstance newSoundInstance = this.playSoundEvent(
line.SOUND_EVENTS.get(this.getCharacter()), SoundCategory.VOICE,
mario.getX(), mario.getY(), mario.getZ(),
this.getPowerUp().VOICE_PITCH, 1.0F,
seed
);
VoiceLine.MARIO_VOICE_LINES.put(this, newSoundInstance);
void playJumpSound(long seed);

return newSoundInstance;
}

default void playJumpSound(long seed) {
JumpSoundPlayer.playJumpSfx(this, seed);
}
PositionedSoundInstance voice(VoiceLine line, long seed);

enum VoiceLine {
SELECT,
Expand All @@ -110,11 +54,9 @@ enum VoiceLine {
FIREBALL,
GET_STAR;

private static final Map<MarioClientSideData, PositionedSoundInstance> MARIO_VOICE_LINES = new HashMap<>();
public static void staticInitialize() {

}

private final Map<ParsedCharacter, SoundEvent> SOUND_EVENTS;
VoiceLine() {
SOUND_EVENTS = new HashMap<>();
Expand All @@ -127,5 +69,8 @@ public static void staticInitialize() {
SOUND_EVENTS.put(character, event);
}
}
public SoundEvent getSoundEvent(ParsedCharacter character) {
return SOUND_EVENTS.get(character);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.floralquafloral.mariodata;

import com.floralquafloral.util.JumpSoundPlayer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.random.Random;

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

/**
* This is supposedly an interface but every method is implemented because that's the closest i can get to multiple
* inheritance. endless pains and agonies for ever & ever!
*/
@SuppressWarnings("UnusedReturnValue")
public interface MarioClientSideDataImplementation extends MarioClientSideData {
SoundManager SOUND_MANAGER = MinecraftClient.getInstance().getSoundManager();

@Override
default PositionedSoundInstance playSoundEvent(
SoundEvent event, SoundCategory category,
double x, double y, double z,
float pitch, float volume, long seed
) {
PositionedSoundInstance sound = new PositionedSoundInstance(
event, category,
volume, pitch,
Random.create(seed),
x, y, z
);
SOUND_MANAGER.play(sound);
return sound;
}

@Override
default PositionedSoundInstance playSoundEvent(SoundEvent event, long seed) {
PlayerEntity mario = this.getMario();
return playSoundEvent(
event, SoundCategory.PLAYERS,
mario.getX(), mario.getY(), mario.getZ(),
1.0F, 1.0F, seed
);
}

@Override
default PositionedSoundInstance playSoundEvent(SoundEvent event, float pitch, float volume, long seed) {
PlayerEntity mario = this.getMario();
return playSoundEvent(
event, SoundCategory.PLAYERS,
mario.getX(), mario.getY(), mario.getZ(),
pitch, volume, seed
);
}

@Override
default PositionedSoundInstance playSoundEvent(SoundEvent event, Entity entity, SoundCategory category, long seed) {
return playSoundEvent(
event, category,
entity.getX(), entity.getY(), entity.getZ(),
1.0F, 1.0F, seed
);
}

Map<MarioClientSideDataImplementation, PositionedSoundInstance> MARIO_VOICE_LINES = new HashMap<>();

@Override
default PositionedSoundInstance voice(MarioClientSideData.VoiceLine line, long seed) {
PlayerEntity mario = this.getMario();

SOUND_MANAGER.stop(MARIO_VOICE_LINES.get(this));

PositionedSoundInstance newSoundInstance = this.playSoundEvent(
line.getSoundEvent(this.getCharacter()), SoundCategory.VOICE,
mario.getX(), mario.getY(), mario.getZ(),
this.getPowerUp().VOICE_PITCH, 1.0F,
seed
);
MARIO_VOICE_LINES.put(this, newSoundInstance);

return newSoundInstance;
}

@Override
default void playJumpSound(long seed) {
JumpSoundPlayer.playJumpSfx(this, seed);
}

}
Loading

0 comments on commit 96fdd8b

Please sign in to comment.