-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added MarioAuthoritativeData. Separated MarioClientSideData from its …
…implementations (although the implementations are still all default methods in an interface. GRRR!)
- Loading branch information
1 parent
7903a55
commit 96fdd8b
Showing
43 changed files
with
394 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/com/floralquafloral/mariodata/MarioAuthoritativeData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/com/floralquafloral/mariodata/MarioClientSideDataImplementation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
Oops, something went wrong.