Skip to content

Commit

Permalink
Don't remember everything I did. Oh well!!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Nov 6, 2024
1 parent f12058c commit a22219e
Show file tree
Hide file tree
Showing 40 changed files with 545 additions and 182 deletions.
15 changes: 1 addition & 14 deletions src/main/java/com/floralquafloral/VoiceLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,17 @@ public enum VoiceLine {
}

public void play(MarioData data, long seed) {
MarioQuaMario.LOGGER.info("UWU: {}", SOUND_EVENTS.get(data.getCharacter()));

PlayerEntity mario = data.getMario();

if(mario.getWorld().isClient) {
ClientSoundPlayer.SOUND_MANAGER.stop(PLAYER_VOICE_LINES.get(mario));

// PositionedSoundInstance voiceSound = new PositionedSoundInstance(
// SOUND_EVENTS.get(data.getCharacter()),
// SoundCategory.VOICE,
// 1.0F,
// 1.0F,
// Random.create(seed),
// data.getMario().getX(),
// data.getMario().getY(),
// data.getMario().getZ()
// );
// ClientSoundPlayer.SOUND_MANAGER.play(voiceSound);
PLAYER_VOICE_LINES.put(mario, ClientSoundPlayer.playSound(
SOUND_EVENTS.get(data.getCharacter()),
SoundCategory.VOICE,
mario,
1.0F,
1.0F,
data.getPowerUp().VOICE_PITCH,
seed
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ private record SetActionC2SPayload(int newAction, long seed) implements CustomPa
);
public SetActionC2SPayload(@NotNull ParsedAction newAction, long seed) {
this(RegistryManager.ACTIONS.getRawIdOrThrow(newAction), seed);
MarioQuaMario.LOGGER.info("Made new SetActionC2S packet");
}
public static void registerReceiver() {
ServerPlayNetworking.registerGlobalReceiver(ID, (payload, context) ->
Expand Down
44 changes: 24 additions & 20 deletions src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.BlockSoundGroup;
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 org.joml.Vector2d;

import java.util.List;

public class MarioPlayerData implements MarioData {
private boolean enabled;
Expand Down Expand Up @@ -134,9 +128,9 @@ private void apply() {
// private double prevY;
public void tick() {
if(this.getMario().getWorld().isClient) {
this.action.otherClientsTick(this);
this.powerUp.otherClientsTick(this);
this.character.otherClientsTick(this);
this.action.clientTick(this, false);
this.powerUp.clientTick(this, false);
this.character.clientTick(this, false);
}
else {
this.action.serverTick(this);
Expand Down Expand Up @@ -165,12 +159,14 @@ public void tick() {

private class SkidSoundInstance extends MovingSoundInstance {
private final boolean IS_WALL;
private final boolean SPEED_SCALING;
private final SkidMaterial MATERIAL;
private int ticks;

protected SkidSoundInstance(boolean isWall, SkidMaterial material) {
protected SkidSoundInstance(boolean isWall, SkidMaterial material, boolean scaling) {
super(isWall ? MarioSFX.SKID_WALL : material.EVENT, SoundCategory.PLAYERS, SoundInstance.createRandom());
this.IS_WALL = isWall;
this.SPEED_SCALING = scaling;
this.MATERIAL = material;
this.updatePos();
this.repeat = true;
Expand Down Expand Up @@ -202,7 +198,7 @@ private enum SkidMaterial {
SkidMaterial newMaterial = getFloorSkidMaterial(getMario());
if(newMaterial != this.MATERIAL && !this.IS_WALL) {
MarioQuaMario.LOGGER.info("Switching skid material from {} to {}!", this.MATERIAL, newMaterial);
makeSkidSFX(false, newMaterial);
makeSkidSFX(false, newMaterial, this.SPEED_SCALING);

}
else this.updatePos();
Expand All @@ -215,9 +211,16 @@ private void updatePos() {
this.y = getMario().getY();
this.z = getMario().getZ();
if(this.IS_WALL) return;
float slidingSpeed = (float) getMario().getVelocity().horizontalLengthSquared();
this.volume = Math.min(1.0F, ((float) ticks) / 3.0F) * Math.min(1.0F, 0.7F * slidingSpeed);
this.pitch = 1.0F + Math.min(0.15F, 0.5F * slidingSpeed);
if(this.SPEED_SCALING) {
float slidingSpeed = (float) getMario().getVelocity().horizontalLengthSquared();
this.volume = Math.min(1.0F, ((float) ticks) / 3.0F) * Math.min(1.0F, 0.7F * slidingSpeed);
this.pitch = 1.0F + Math.min(0.15F, 0.5F * slidingSpeed);
}
else {
float slidingSpeed = (float) getMario().getVelocity().horizontalLengthSquared();
this.volume = Math.min(1.0F, ((float) ticks) / 3.0F) * Math.min(1.0F, 0.4F + 0.7F * slidingSpeed);
this.pitch = 1.0F + Math.min(0.15F, 0.5F * slidingSpeed);
}
}

@Override public boolean shouldAlwaysPlay() {
Expand All @@ -230,13 +233,13 @@ private void kill() {
}
}
private SkidSoundInstance skidSFX;
private void makeSkidSFX(boolean isWall, SkidSoundInstance.SkidMaterial material) {
private void makeSkidSFX(boolean isWall, SkidSoundInstance.SkidMaterial material, boolean scaling) {
if(this.skidSFX != null) this.skidSFX.kill();
this.skidSFX = new SkidSoundInstance(isWall, material);
this.skidSFX = new SkidSoundInstance(isWall, material, scaling);
MinecraftClient.getInstance().getSoundManager().playNextTick(this.skidSFX);
}
private void makeSkidSFX(boolean isWall) {
this.makeSkidSFX(isWall, SkidSoundInstance.getFloorSkidMaterial(this.getMario()));
private void makeSkidSFX(boolean isWall, boolean scaling) {
this.makeSkidSFX(isWall, SkidSoundInstance.getFloorSkidMaterial(this.getMario()), scaling);
}

@Override public void setAction(ParsedAction action, long seed) {
Expand All @@ -248,7 +251,7 @@ private void makeSkidSFX(boolean isWall) {
// Skid SFX
if(this.skidSFX != null) this.skidSFX.kill();
if(action.SLIDING_STATUS.doSlideSfx() || action.SLIDING_STATUS.doWallSlideSfx()) {
makeSkidSFX(action.SLIDING_STATUS.doWallSlideSfx());
makeSkidSFX(action.SLIDING_STATUS.doWallSlideSfx(), action.SLIDING_STATUS.doSpeedScaling());
}
}
else {
Expand All @@ -258,7 +261,8 @@ private void makeSkidSFX(boolean isWall) {
CPMIntegration.commonAPI.playAnimation(PlayerEntity.class, this.mario, action.ANIMATION, 1);
}
this.action = action;
MarioQuaMario.LOGGER.info("SFX? " + this.skidSFX);
this.mario.setPose(this.mario.getPose());

}
@Override public ParsedPowerUp getPowerUp() {
return powerUp;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/floralquafloral/mariodata/client/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public boolean isHeld() {
return this.isHeld;
}
public boolean isPressed() {
boolean result = this.isPressedNoUnbuffer();
if(result) this.unbuffer();
return result;
}
public boolean isPressedNoUnbuffer() {
return this.pressBuffer > 0;
}
public void unbuffer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ public MarioClientData(ClientPlayerEntity mario) {
public boolean travel(Vec3d movementInput) {
Input.updateDirections(movementInput.z, movementInput.x);

// TODO: Levitation effect functionality

getAction().attemptTransitions(this, TransitionPhase.PRE_TICK);
getAction().selfTick(this);
getAction().travelHook(this);
getAction().attemptTransitions(this, TransitionPhase.POST_TICK);

applyModifiedVelocity();
marioClient.move(MovementType.PLAYER, marioClient.getVelocity());
marioClient.move(MovementType.SELF, marioClient.getVelocity());
if(getAction().attemptTransitions(this, TransitionPhase.POST_MOVE))
applyModifiedVelocity();

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/floralquafloral/mixin/DamageSourceMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.floralquafloral.mixin;

import com.floralquafloral.registries.stomp.StompHandler;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.tag.TagKey;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(DamageSource.class)
public abstract class DamageSourceMixin {
@Shadow public abstract boolean isIn(TagKey<DamageType> tag);

@WrapOperation(method = "getDeathMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getMainHandStack()Lnet/minecraft/item/ItemStack;"))
protected ItemStack uwu(LivingEntity instance, Operation<ItemStack> original) {
if(isIn(StompHandler.USES_FEET_ITEM_TAG)) return instance.getEquippedStack(EquipmentSlot.FEET);
if(isIn(StompHandler.USES_LEGS_ITEM_TAG)) return instance.getEquippedStack(EquipmentSlot.LEGS);
return original.call(instance);
}
}
11 changes: 8 additions & 3 deletions src/main/java/com/floralquafloral/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ private void isInSneakingPose(CallbackInfoReturnable<Boolean> cir) {
@Inject(method = "setPose", at = @At("HEAD"), cancellable = true)
private void preventSettingSneakPose(EntityPose pose, CallbackInfo ci) {
if((Entity) (Object) this instanceof PlayerEntity player && pose == EntityPose.CROUCHING) {
if(MarioDataManager.getMarioData(player).getSneakProhibited())
// MarioQuaMario.LOGGER.info("setPose called on player! Pose == {}", pose);
if(MarioDataManager.getMarioData(player).getSneakProhibited()) {

if(player.getPose() == EntityPose.CROUCHING)
player.setPose(EntityPose.STANDING);
ci.cancel();
}
}
}

Expand All @@ -57,15 +62,15 @@ private void preventStepSounds(BlockPos pos, BlockState state, CallbackInfo ci)
@Unique
private static boolean shouldStompHook = true;

@Inject(method = "move", at = @At("HEAD"))
@Inject(method = "move", at = @At("HEAD"), cancellable = true)
private void executeStompsOnServer(MovementType movementType, Vec3d movement, CallbackInfo ci) {
if((Entity) (Object) this instanceof ServerPlayerEntity player && shouldStompHook) {
MarioData data = MarioDataManager.getMarioData(player);
if(data.useMarioPhysics()) {
ParsedAction action = data.getAction();
if(action.STOMP != null) {
shouldStompHook = false;
action.STOMP.attempt(data, movement);
if(action.STOMP.attempt(data, movement)) ci.cancel();
shouldStompHook = true;
}
}
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/com/floralquafloral/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@
import com.floralquafloral.registries.states.powerup.PowerUpDefinition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.client.util.Window;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.util.Colors;
import net.minecraft.util.Identifier;
import org.joml.Vector2d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Objects;

@Mixin(InGameHud.class)
public abstract class InGameHudMixin {
Expand All @@ -28,4 +43,47 @@ else if(hardcore) {
return data.getPowerUp().HEART.getTexture(half, blinking);
}
}

@Inject(method = "render", at = @At("TAIL"))
public void renderSpeedometerWithServerData(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
MinecraftClient client = MinecraftClient.getInstance();
PlayerEntity mario = client.player;
if(mario == null) return;

double horizontalSpeed = Vector2d.distance(mario.getX(), mario.getZ(), mario.prevX, mario.prevZ);
double verticalSpeed = mario.getY() - mario.prevY;

renderText(context, 3, "C: ", horizontalSpeed);
renderText(context, 1, "C(v): ", verticalSpeed);

IntegratedServer integratedServer = MinecraftClient.getInstance().getServer();
if(integratedServer == null) return;
Entity serverMario = Objects.requireNonNull(integratedServer.getWorld(mario.getWorld().getRegistryKey())).getEntityById(mario.getId());
if(serverMario == null) return;

renderText(context, 2, "S: ", serverMario.getVelocity().horizontalLength());
renderText(context, 0, "S(v): ", serverMario.getVelocity().y);

renderText(context, 6, mario.getHeight() + " VS " + mario.getHeight());
renderText(context, 5, mario.getPose() + " VS " + mario.getPose());
}

@Unique
private void renderText(DrawContext context, int linesFromBottom, String label, double value) {
renderText(context, linesFromBottom, String.format(label + "%.2f", value));
}

@Unique
private void renderText(DrawContext context, int linesFromBottom, String text) {
Window window = MinecraftClient.getInstance().getWindow();
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;

// String text = String.format(label + "%.2f", value);

int length = textRenderer.getWidth(text);
int x = window.getScaledWidth() - length - 2;
int y = window.getScaledHeight() - (linesFromBottom + 1) * (textRenderer.fontHeight + 3);

context.drawTextWithShadow(textRenderer, text, x, y, Colors.WHITE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
public interface MarioStateDefinition {
@NotNull Identifier getID();

void selfTick(MarioClientData data);
void otherClientsTick(MarioPlayerData data);
void clientTick(MarioPlayerData data, boolean isSelf);
void serverTick(MarioPlayerData data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ protected ParsedMarioState(MarioStateDefinition definition) {
this.DEFINITION = definition;
}

public void selfTick(MarioClientData data) {
this.DEFINITION.selfTick(data);
}
public void otherClientsTick(MarioPlayerData data) {
this.DEFINITION.otherClientsTick(data);
public void clientTick(MarioPlayerData data, boolean isSelf) {
this.DEFINITION.clientTick(data, isSelf);
}
public void serverTick(MarioPlayerData data) {
this.DEFINITION.serverTick(data);
Expand Down
Loading

0 comments on commit a22219e

Please sign in to comment.