diff --git a/mod/src/main/java/com/floralquafloral/MarioQuaMario.java b/mod/src/main/java/com/floralquafloral/MarioQuaMario.java index ac12612..2088433 100644 --- a/mod/src/main/java/com/floralquafloral/MarioQuaMario.java +++ b/mod/src/main/java/com/floralquafloral/MarioQuaMario.java @@ -4,6 +4,7 @@ import com.floralquafloral.mariodata.MarioData; import com.floralquafloral.mariodata.MarioDataManager; import com.floralquafloral.mariodata.MarioDataPackets; +import com.floralquafloral.mariodata.MarioPlayerData; import com.floralquafloral.registries.RegistryManager; import com.floralquafloral.util.ModConfig; import com.floralquafloral.util.MarioSFX; @@ -84,7 +85,7 @@ public void onInitialize() { // Mario can't be damaged by a mob that he's high enough to stomp on ServerLivingEntityEvents.ALLOW_DAMAGE.register((livingEntity, damageSource, amount) -> { if(livingEntity instanceof PlayerEntity player && damageSource.getSource() instanceof LivingEntity sourceEntity && sourceEntity.equals(damageSource.getAttacker())) { - MarioData data = MarioDataManager.getMarioData(player); + MarioPlayerData data = MarioDataManager.getMarioData(player); if(data.isEnabled() && livingEntity.getY() >= sourceEntity.getY() + sourceEntity.getHeight() && data.getAction().STOMP != null) { LOGGER.info("Prevented Mario from taking damage against {} due to stomp eligibility.", sourceEntity); return false; @@ -95,7 +96,7 @@ public void onInitialize() { ServerLivingEntityEvents.ALLOW_DEATH.register((livingEntity, damageSource, amount) -> { if(livingEntity instanceof ServerPlayerEntity player) { - MarioData data = MarioDataManager.getMarioData(player); + MarioPlayerData data = MarioDataManager.getMarioData(player); if(data.isEnabled()) { // Revert if possible Identifier revertTargetID = data.getPowerUp().REVERT_TARGET; diff --git a/mod/src/main/java/com/floralquafloral/bumping/BumpManager.java b/mod/src/main/java/com/floralquafloral/bumping/BumpManager.java index 3809180..d09b9c6 100644 --- a/mod/src/main/java/com/floralquafloral/bumping/BumpManager.java +++ b/mod/src/main/java/com/floralquafloral/bumping/BumpManager.java @@ -161,7 +161,7 @@ public static Set bumpBlocksClient( int strength, Direction direction ) { boolean playBumpSound = false; - int modifier = marioClientData.getPowerUp().BUMP_STRENGTH_MODIFIER + marioClientData.getCharacter().BUMP_STRENGTH_MODIFIER; + int modifier = marioClientData.getBumpStrengthModifier(); Set blocksBumped = new HashSet<>(); Set soundGroups = new HashSet<>(); @@ -212,7 +212,7 @@ public static void bumpBlocksServer( int strength, Direction direction, boolean networkToBumper ) { boolean canRepeatBump = false; - int modifier = marioServerData.getPowerUp().BUMP_STRENGTH_MODIFIER + marioServerData.getCharacter().BUMP_STRENGTH_MODIFIER; + int modifier = marioServerData.getBumpStrengthModifier(); Set bumpedPositions = new HashSet<>(); for(BlockPos pos : positions) { diff --git a/mod/src/main/java/com/floralquafloral/mariodata/MarioClientSideData.java b/mod/src/main/java/com/floralquafloral/mariodata/MarioClientSideData.java index 125cd1a..7d6b2f3 100644 --- a/mod/src/main/java/com/floralquafloral/mariodata/MarioClientSideData.java +++ b/mod/src/main/java/com/floralquafloral/mariodata/MarioClientSideData.java @@ -2,7 +2,9 @@ import com.floralquafloral.MarioQuaMario; import com.floralquafloral.registries.RegistryManager; +import com.floralquafloral.registries.states.action.ParsedAction; import com.floralquafloral.registries.states.character.ParsedCharacter; +import com.floralquafloral.registries.states.powerup.ParsedPowerUp; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.entity.Entity; import net.minecraft.registry.Registries; @@ -19,6 +21,7 @@ * 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 { PositionedSoundInstance playSoundEvent( SoundEvent event, SoundCategory category, @@ -33,6 +36,7 @@ PositionedSoundInstance playSoundEvent( void playJumpSound(long seed); PositionedSoundInstance voice(VoiceLine line, long seed); + float getVoicePitch(); enum VoiceLine { SELECT, @@ -52,25 +56,6 @@ enum VoiceLine { BURNT, FIREBALL, - GET_STAR; - - public static void staticInitialize() { - - } - private final Map SOUND_EVENTS; - VoiceLine() { - SOUND_EVENTS = new HashMap<>(); - - for(ParsedCharacter character : RegistryManager.CHARACTERS) { - Identifier id = Identifier.of(character.ID.getNamespace(), "voice." + character.ID.getPath() + "." + this.name().toLowerCase(Locale.ROOT)); - MarioQuaMario.LOGGER.info("Automatically registering VoiceLine sound event {}...", id); - SoundEvent event = SoundEvent.of(id); - Registry.register(Registries.SOUND_EVENT, id, event); - SOUND_EVENTS.put(character, event); - } - } - public SoundEvent getSoundEvent(ParsedCharacter character) { - return SOUND_EVENTS.get(character); - } + GET_STAR } } diff --git a/mod/src/main/java/com/floralquafloral/mariodata/MarioClientSideDataImplementation.java b/mod/src/main/java/com/floralquafloral/mariodata/MarioClientSideDataImplementation.java index bbee34c..c685b85 100644 --- a/mod/src/main/java/com/floralquafloral/mariodata/MarioClientSideDataImplementation.java +++ b/mod/src/main/java/com/floralquafloral/mariodata/MarioClientSideDataImplementation.java @@ -1,16 +1,24 @@ package com.floralquafloral.mariodata; +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.util.Identifier; import net.minecraft.util.math.random.Random; +import java.util.EnumMap; import java.util.HashMap; +import java.util.Locale; import java.util.Map; /** @@ -75,9 +83,9 @@ default PositionedSoundInstance voice(MarioClientSideData.VoiceLine line, long s SOUND_MANAGER.stop(MARIO_VOICE_LINES.get(this)); PositionedSoundInstance newSoundInstance = this.playSoundEvent( - line.getSoundEvent(this.getCharacter()), SoundCategory.VOICE, + VOICE_SOUND_EVENTS.get(line).get(this.getCharacterID()), SoundCategory.VOICE, mario.getX(), mario.getY(), mario.getZ(), - this.getPowerUp().VOICE_PITCH, 1.0F, + this.getVoicePitch(), 1.0F, seed ); MARIO_VOICE_LINES.put(this, newSoundInstance); @@ -90,4 +98,21 @@ default void playJumpSound(long seed) { JumpSoundPlayer.playJumpSfx(this, seed); } + EnumMap> VOICE_SOUND_EVENTS = new EnumMap<>(VoiceLine.class); + class VoiceSoundEventInitializer { + public static void initialize() { + for(MarioClientSideData.VoiceLine voiceLine : MarioClientSideData.VoiceLine.values()) { + Map soundEvents = new HashMap<>(); + VOICE_SOUND_EVENTS.put(voiceLine, soundEvents); + + for(ParsedCharacter character : RegistryManager.CHARACTERS) { + Identifier id = Identifier.of(character.ID.getNamespace(), "voice." + character.ID.getPath() + "." + voiceLine.name().toLowerCase(Locale.ROOT)); + MarioQuaMario.LOGGER.info("Automatically registering VoiceLine sound event {}...", id); + SoundEvent event = SoundEvent.of(id); + Registry.register(Registries.SOUND_EVENT, id, event); + soundEvents.put(character.ID, event); + } + } + } + } } diff --git a/mod/src/main/java/com/floralquafloral/mariodata/MarioData.java b/mod/src/main/java/com/floralquafloral/mariodata/MarioData.java index d5485d8..d3ad96f 100644 --- a/mod/src/main/java/com/floralquafloral/mariodata/MarioData.java +++ b/mod/src/main/java/com/floralquafloral/mariodata/MarioData.java @@ -1,18 +1,24 @@ package com.floralquafloral.mariodata; -import com.floralquafloral.registries.states.action.ParsedAction; -import com.floralquafloral.registries.states.character.ParsedCharacter; -import com.floralquafloral.registries.states.powerup.ParsedPowerUp; +import com.floralquafloral.stats.CharaStat; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Identifier; public interface MarioData { PlayerEntity getMario(); boolean isClient(); boolean useMarioPhysics(); + double getStat(CharaStat stat); + double getStatMultiplier(CharaStat stat); + int getBumpStrengthModifier(); + boolean isSneakProhibited(); + + + boolean isEnabled(); - ParsedAction getAction(); - boolean getSneakProhibited(); - ParsedPowerUp getPowerUp(); - ParsedCharacter getCharacter(); + Identifier getActionID(); + Identifier getPowerUpID(); + Identifier getCharacterID(); + } diff --git a/mod/src/main/java/com/floralquafloral/mariodata/MarioDataPackets.java b/mod/src/main/java/com/floralquafloral/mariodata/MarioDataPackets.java index 265042c..4be90f6 100644 --- a/mod/src/main/java/com/floralquafloral/mariodata/MarioDataPackets.java +++ b/mod/src/main/java/com/floralquafloral/mariodata/MarioDataPackets.java @@ -58,7 +58,7 @@ public static void registerClient() { } public static void sendAllData(ServerPlayerEntity toWho, PlayerEntity aboutWho) { - MarioData data = getMarioData(aboutWho); + MarioPlayerData data = getMarioData(aboutWho); // am I supposed to send one packet with all this data or is this fine???? ServerPlayNetworking.send(toWho, new SetEnabledS2CPayload(aboutWho, data.isEnabled())); ServerPlayNetworking.send(toWho, new SetActionS2CPayload(aboutWho, data.getAction(), true, 0)); diff --git a/mod/src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java b/mod/src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java index 8d39ebb..d330fac 100644 --- a/mod/src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java +++ b/mod/src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java @@ -6,6 +6,7 @@ import com.floralquafloral.registries.states.character.ParsedCharacter; import com.floralquafloral.registries.states.powerup.ParsedPowerUp; import com.floralquafloral.stats.CharaStat; +import com.floralquafloral.stats.StatCategory; import com.floralquafloral.util.MarioSFX; import net.minecraft.block.BlockState; import net.minecraft.client.MinecraftClient; @@ -66,13 +67,54 @@ public MarioPlayerData(PlayerEntity mario) { @Override public boolean useMarioPhysics() { return( isEnabled() - && !mario.getAbilities().flying - && !mario.isFallFlying() + && !this.mario.getAbilities().flying + && !this.mario.isFallFlying() // && !mario.hasVehicle() // && !mario.isClimbing() ); } + private static final double MOVEMENT_SPEED_MULTIPLIER = 1.0 / 0.10000000149011612; + private static final double MOVEMENT_SPEED_MULTIPLIER_SPRINTING = 1.0 / 0.13000000312924387; + + @Override + public double getStat(CharaStat stat) { + double modifiedBase = stat.BASE * this.getStatMultiplier(stat); + + double attributeFactor = 1.0; + double attributeAddend = 0.0; + + if(stat.CATEGORIES.contains(StatCategory.SPEED) && ( + stat.CATEGORIES.contains(StatCategory.WALKING) + || stat.CATEGORIES.contains(StatCategory.RUNNING) + || stat.CATEGORIES.contains(StatCategory.P_RUNNING) + || stat.CATEGORIES.contains(StatCategory.DUCKING) + )) { + attributeFactor = this.mario.getAttributes().getValue(EntityAttributes.GENERIC_MOVEMENT_SPEED) + * (this.mario.isSprinting() ? MOVEMENT_SPEED_MULTIPLIER_SPRINTING : MOVEMENT_SPEED_MULTIPLIER); + } + + if(stat.CATEGORIES.contains(StatCategory.JUMP_VELOCITY)) { + attributeAddend = this.mario.getJumpBoostVelocityModifier(); + } + + return attributeFactor * modifiedBase + attributeAddend; + } + + @Override + public double getStatMultiplier(CharaStat stat) { + return this.powerUp.getStatMultiplier(stat) * this.character.getStatMultiplier(stat); + } + + @Override + public int getBumpStrengthModifier() { + return this.powerUp.BUMP_STRENGTH_MODIFIER + this.character.BUMP_STRENGTH_MODIFIER; + } + + public float getVoicePitch() { + return this.powerUp.VOICE_PITCH; + } + public boolean attemptDismount = false; public abstract void tick(); @@ -90,10 +132,13 @@ public void setEnabledInternal(boolean enabled) { attackSpeedAttributeInstance.removeModifier(ATTACK_SLOWDOWN_ID); attackSpeedAttributeInstance.addPersistentModifier(ATTACK_SLOWDOWN); } - @Override public ParsedAction getAction() { + public ParsedAction getAction() { return action; } - @Override public boolean getSneakProhibited() { + @Override public Identifier getActionID() { + return action.ID; + } + @Override public boolean isSneakProhibited() { return useMarioPhysics() && getAction().SNEAK_LEGALITY.prohibitSneak(); } @@ -199,9 +244,12 @@ public void setActionTransitionless(ParsedAction action) { this.mario.setPose(this.mario.getPose()); } - @Override public ParsedPowerUp getPowerUp() { + public ParsedPowerUp getPowerUp() { return powerUp; } + @Override public Identifier getPowerUpID() { + return powerUp.ID; + } public void setPowerUp(ParsedPowerUp powerUp) { MarioQuaMario.LOGGER.info("Set Power-up to {}", powerUp.ID); this.powerUp.losePower(this); @@ -209,14 +257,15 @@ public void setPowerUp(ParsedPowerUp powerUp) { this.mario.setHealth(this.mario.getMaxHealth()); this.powerUp = powerUp; this.mario.calculateDimensions(); - CharaStat.invalidateCache(); } - @Override public ParsedCharacter getCharacter() { + public ParsedCharacter getCharacter() { return character; } + @Override public Identifier getCharacterID() { + return character.ID; + } public void setCharacter(ParsedCharacter character) { this.character = character; this.mario.calculateDimensions(); - CharaStat.invalidateCache(); } } diff --git a/mod/src/main/java/com/floralquafloral/mariodata/moveable/MarioTravelData.java b/mod/src/main/java/com/floralquafloral/mariodata/moveable/MarioTravelData.java index 68dba2b..3a34367 100644 --- a/mod/src/main/java/com/floralquafloral/mariodata/moveable/MarioTravelData.java +++ b/mod/src/main/java/com/floralquafloral/mariodata/moveable/MarioTravelData.java @@ -1,6 +1,9 @@ package com.floralquafloral.mariodata.moveable; import com.floralquafloral.mariodata.MarioData; +import com.floralquafloral.registries.states.action.ParsedAction; +import com.floralquafloral.registries.states.character.ParsedCharacter; +import com.floralquafloral.registries.states.powerup.ParsedPowerUp; import org.jetbrains.annotations.NotNull; public interface MarioTravelData extends MarioData { diff --git a/mod/src/main/java/com/floralquafloral/mixin/ClientPlayerEntityMixin.java b/mod/src/main/java/com/floralquafloral/mixin/ClientPlayerEntityMixin.java index d87b994..a2d002b 100644 --- a/mod/src/main/java/com/floralquafloral/mixin/ClientPlayerEntityMixin.java +++ b/mod/src/main/java/com/floralquafloral/mixin/ClientPlayerEntityMixin.java @@ -1,6 +1,5 @@ package com.floralquafloral.mixin; -import com.floralquafloral.mariodata.MarioData; import com.floralquafloral.mariodata.MarioDataManager; import net.minecraft.client.network.ClientPlayerEntity; import org.spongepowered.asm.mixin.Mixin; @@ -18,7 +17,7 @@ private void preventSlowDown(CallbackInfoReturnable cir) { @Inject(method = "isInSneakingPose", at = @At("HEAD"), cancellable = true) private void preventSneakPose(CallbackInfoReturnable cir) { - if(MarioDataManager.getMarioData(this).getSneakProhibited()) + if(MarioDataManager.getMarioData(this).isSneakProhibited()) cir.setReturnValue(false); } } diff --git a/mod/src/main/java/com/floralquafloral/mixin/EntityMixin.java b/mod/src/main/java/com/floralquafloral/mixin/EntityMixin.java index 840b6f3..6a34c90 100644 --- a/mod/src/main/java/com/floralquafloral/mixin/EntityMixin.java +++ b/mod/src/main/java/com/floralquafloral/mixin/EntityMixin.java @@ -1,7 +1,6 @@ package com.floralquafloral.mixin; import com.floralquafloral.MarioQuaMario; -import com.floralquafloral.mariodata.MarioData; import com.floralquafloral.mariodata.MarioDataManager; import com.floralquafloral.mariodata.MarioPlayerData; import com.floralquafloral.mariodata.moveable.MarioServerData; @@ -40,7 +39,7 @@ private void setSwimming(boolean swimming, CallbackInfo ci) { @Inject(at = @At("HEAD"), method = "isInSneakingPose", cancellable = true) private void isInSneakingPose(CallbackInfoReturnable cir) { if((Entity) (Object) this instanceof PlayerEntity player) { - if(MarioDataManager.getMarioData(player).getSneakProhibited()) + if(MarioDataManager.getMarioData(player).isSneakProhibited()) cir.setReturnValue(false); } } @@ -49,7 +48,7 @@ private void isInSneakingPose(CallbackInfoReturnable cir) { private void preventSettingSneakPose(EntityPose pose, CallbackInfo ci) { if((Entity) (Object) this instanceof PlayerEntity player && pose == EntityPose.CROUCHING) { // MarioQuaMario.LOGGER.info("setPose called on player! Pose == {}", pose); - if(MarioDataManager.getMarioData(player).getSneakProhibited()) { + if(MarioDataManager.getMarioData(player).isSneakProhibited()) { if(player.getPose() == EntityPose.CROUCHING) player.setPose(EntityPose.STANDING); @@ -61,7 +60,7 @@ private void preventSettingSneakPose(EntityPose pose, CallbackInfo ci) { @Inject(method = "playStepSounds", at = @At("HEAD"), cancellable = true) private void preventStepSounds(BlockPos pos, BlockState state, CallbackInfo ci) { if(((Entity) (Object) this) instanceof PlayerEntity player) { - MarioData data = MarioDataManager.getMarioData(player); + MarioPlayerData data = MarioDataManager.getMarioData(player); if(!data.getAction().SLIDING_STATUS.doFootsteps()) ci.cancel(); } @@ -73,7 +72,7 @@ private void preventStepSounds(BlockPos pos, BlockState state, CallbackInfo ci) @Inject(method = "move", at = @At("HEAD"), cancellable = true) private void executeStompsOnServer(MovementType movementType, Vec3d movement, CallbackInfo ci) { if((Entity) (Object) this instanceof ServerPlayerEntity mario && shouldStompHook) { - MarioData data = MarioDataManager.getMarioData(mario); + MarioPlayerData data = MarioDataManager.getMarioData(mario); if(data.useMarioPhysics()) { ParsedAction action = data.getAction(); if(action.STOMP != null) { diff --git a/mod/src/main/java/com/floralquafloral/mixin/InGameHudMixin.java b/mod/src/main/java/com/floralquafloral/mixin/InGameHudMixin.java index 25e557e..1de058d 100644 --- a/mod/src/main/java/com/floralquafloral/mixin/InGameHudMixin.java +++ b/mod/src/main/java/com/floralquafloral/mixin/InGameHudMixin.java @@ -3,6 +3,7 @@ import com.floralquafloral.MarioQuaMario; import com.floralquafloral.mariodata.MarioData; import com.floralquafloral.mariodata.MarioDataManager; +import com.floralquafloral.mariodata.MarioPlayerData; import com.floralquafloral.mariodata.moveable.MarioMainClientData; import com.floralquafloral.registries.states.powerup.PowerUpDefinition; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; @@ -34,29 +35,29 @@ public abstract class InGameHudMixin { @Shadow @Final private MinecraftClient client; - @WrapOperation(method = "drawHeart", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud$HeartType;getTexture(ZZZ)Lnet/minecraft/util/Identifier;")) - public Identifier usePowerUpHeart(InGameHud.HeartType instance, boolean hardcore, boolean half, boolean blinking, Operation original) { - // Cancel if the power-up hearts are disabled in the config or if this is a special heart - if(!MarioQuaMario.CONFIG.shouldUsePowerUpHearts() || (instance != InGameHud.HeartType.CONTAINER && instance != InGameHud.HeartType.NORMAL)) - return original.call(instance, hardcore, half, blinking); - - MarioMainClientData data = MarioMainClientData.getInstance(); - // Cancel if there's no Mario Client Data or if the player isn't Mario - if(data == null || !data.isEnabled()) - return original.call(instance, hardcore, half, blinking); - - if(instance == InGameHud.HeartType.CONTAINER) { - PowerUpDefinition.PowerHeart heartContainer = data.getPowerUp().HEART_EMPTY; - if(heartContainer == null) return original.call(instance, hardcore, half, blinking); - else return heartContainer.getTexture(half, blinking); - } - else if(hardcore) { - return data.getPowerUp().HEART_HARDCORE.getTexture(half, blinking); - } - else { - return data.getPowerUp().HEART.getTexture(half, blinking); - } - } +// @WrapOperation(method = "drawHeart", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud$HeartType;getTexture(ZZZ)Lnet/minecraft/util/Identifier;")) +// public Identifier usePowerUpHeart(InGameHud.HeartType instance, boolean hardcore, boolean half, boolean blinking, Operation original) { +// // Cancel if the power-up hearts are disabled in the config or if this is a special heart +// if(!MarioQuaMario.CONFIG.shouldUsePowerUpHearts() || (instance != InGameHud.HeartType.CONTAINER && instance != InGameHud.HeartType.NORMAL)) +// return original.call(instance, hardcore, half, blinking); +// +// MarioMainClientData data = MarioMainClientData.getInstance(); +// // Cancel if there's no Mario Client Data or if the player isn't Mario +// if(data == null || !data.isEnabled()) +// return original.call(instance, hardcore, half, blinking); +// +// if(instance == InGameHud.HeartType.CONTAINER) { +// PowerUpDefinition.PowerHeart heartContainer = data.getPowerUp().HEART_EMPTY; +// if(heartContainer == null) return original.call(instance, hardcore, half, blinking); +// else return heartContainer.getTexture(half, blinking); +// } +// else if(hardcore) { +// return data.getPowerUp().HEART_HARDCORE.getTexture(half, blinking); +// } +// else { +// return data.getPowerUp().HEART.getTexture(half, blinking); +// } +// } @Inject(method = "render", at = @At("TAIL")) public void renderSpeedometerWithServerData(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) { @@ -76,7 +77,7 @@ public void renderSpeedometerWithServerData(DrawContext context, RenderTickCount if(integratedServer == null) return; Entity serverMario = Objects.requireNonNull(integratedServer.getWorld(clientMario.getWorld().getRegistryKey())).getEntityById(clientMario.getId()); if(serverMario == null) return; - MarioData serverData = MarioDataManager.getMarioData(serverMario); + MarioPlayerData serverData = MarioDataManager.getMarioData(serverMario); renderText(context, 0, "S: ", serverMario.getVelocity().horizontalLength(), serverMario.getVelocity().y); diff --git a/mod/src/main/java/com/floralquafloral/mixin/PlayerEntityMixin.java b/mod/src/main/java/com/floralquafloral/mixin/PlayerEntityMixin.java index e237d06..bb5008b 100644 --- a/mod/src/main/java/com/floralquafloral/mixin/PlayerEntityMixin.java +++ b/mod/src/main/java/com/floralquafloral/mixin/PlayerEntityMixin.java @@ -1,14 +1,10 @@ package com.floralquafloral.mixin; -import com.floralquafloral.MarioQuaMario; -import com.floralquafloral.bumping.BumpManager; -import com.floralquafloral.mariodata.MarioData; import com.floralquafloral.mariodata.MarioDataManager; import com.floralquafloral.mariodata.MarioPlayerData; import com.floralquafloral.mariodata.moveable.MarioMoveableData; import com.floralquafloral.registries.states.character.ParsedCharacter; import com.floralquafloral.registries.states.powerup.ParsedPowerUp; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityPose; import net.minecraft.entity.player.PlayerEntity; @@ -42,10 +38,10 @@ private void preventVanillaJumpingSwimming(CallbackInfoReturnable cir) @Inject(at = @At("TAIL"), method = "getBaseDimensions(Lnet/minecraft/entity/EntityPose;)Lnet/minecraft/entity/EntityDimensions;", cancellable = true) private void getBaseDimensions(EntityPose pose, CallbackInfoReturnable cir) { - MarioData data = MarioDataManager.getMarioData(this); + MarioPlayerData data = MarioDataManager.getMarioData(this); if(data.isEnabled()) { // Returns the standing hitbox if being used by Mario while he can't sneak - if(data.getSneakProhibited() && pose == EntityPose.CROUCHING) { + if(data.isSneakProhibited() && pose == EntityPose.CROUCHING) { cir.setReturnValue(data.getMario().getBaseDimensions(EntityPose.STANDING)); return; } @@ -77,7 +73,7 @@ private void getBaseDimensions(EntityPose pose, CallbackInfoReturnable cir) { - MarioData data = MarioDataManager.getMarioData(this); + MarioPlayerData data = MarioDataManager.getMarioData(this); if(data.useMarioPhysics() && data.getAction().SNEAK_LEGALITY.slipOffLedges()) { cir.setReturnValue(false); } @@ -85,7 +81,7 @@ public void slideOffLedges(CallbackInfoReturnable cir) { @Inject(method = "tickMovement", at = @At("TAIL")) public void preventViewBobbing(CallbackInfo ci) { - MarioData data = MarioDataManager.getMarioData(this); + MarioPlayerData data = MarioDataManager.getMarioData(this); if(data.isClient() && !data.getAction().SLIDING_STATUS.doViewBobbing()) { strideDistance = prevStrideDistance * 0.6F; } diff --git a/mod/src/main/java/com/floralquafloral/registries/RegistryManager.java b/mod/src/main/java/com/floralquafloral/registries/RegistryManager.java index a6a9778..80b2995 100644 --- a/mod/src/main/java/com/floralquafloral/registries/RegistryManager.java +++ b/mod/src/main/java/com/floralquafloral/registries/RegistryManager.java @@ -2,6 +2,7 @@ import com.floralquafloral.MarioQuaMario; import com.floralquafloral.mariodata.MarioClientSideData; +import com.floralquafloral.mariodata.MarioClientSideDataImplementation; import com.floralquafloral.registries.states.action.ActionDefinition; import com.floralquafloral.registries.states.action.AirborneActionDefinition; import com.floralquafloral.registries.states.action.GroundedActionDefinition; @@ -17,14 +18,13 @@ import net.fabricmc.fabric.api.event.registry.RegistryAttribute; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; +import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; +import net.minecraft.sound.SoundEvent; import net.minecraft.util.Identifier; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class RegistryManager { public static void register() { @@ -34,7 +34,8 @@ public static void register() { registerCharacters(); MarioSFX.staticInitialize(); - MarioClientSideData.VoiceLine.staticInitialize(); + + MarioClientSideDataImplementation.VoiceSoundEventInitializer.initialize(); } public static final RegistryKey> STOMP_TYPES_KEY = RegistryKey.ofRegistry( diff --git a/mod/src/main/java/com/floralquafloral/registries/states/ParsedMajorMarioState.java b/mod/src/main/java/com/floralquafloral/registries/states/ParsedMajorMarioState.java index 958c01a..e860384 100644 --- a/mod/src/main/java/com/floralquafloral/registries/states/ParsedMajorMarioState.java +++ b/mod/src/main/java/com/floralquafloral/registries/states/ParsedMajorMarioState.java @@ -1,5 +1,6 @@ package com.floralquafloral.registries.states; +import com.floralquafloral.stats.CharaStat; import com.floralquafloral.stats.StatCategory; import java.util.EnumMap; @@ -13,6 +14,21 @@ public abstract class ParsedMajorMarioState extends ParsedMarioState { public final float HEIGHT_FACTOR; public final Map, Double> STAT_MODIFIERS; + private final Map STAT_MULTIPLIERS_CACHE = new HashMap<>(); + + public double getStatMultiplier(CharaStat stat) { + if(this.STAT_MULTIPLIERS_CACHE.containsKey(stat)) return this.STAT_MULTIPLIERS_CACHE.get(stat); + + double combinedModifier = 1.0; + for(Map.Entry, Double> entry : this.STAT_MODIFIERS.entrySet()) { + if(stat.CATEGORIES.containsAll(entry.getKey())) + combinedModifier *= entry.getValue(); + } + + this.STAT_MULTIPLIERS_CACHE.put(stat, combinedModifier); + return combinedModifier; + } + protected ParsedMajorMarioState(MarioMajorStateDefinition definition) { super(definition); diff --git a/mod/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckSlide.java b/mod/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckSlide.java index f2146aa..1a8fcec 100644 --- a/mod/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckSlide.java +++ b/mod/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckSlide.java @@ -119,7 +119,7 @@ public List getTransitionInjections() { return data.getInputs().DUCK.isHeld() && Vector2d.lengthSquared(data.getForwardVel(), data.getStrafeVel()) > threshold * threshold - && !data.getAction().ID.equals(getID()); + && !data.getActionID().equals(getID()); }, GroundedTransitions.DUCK_WADDLE.EXECUTOR_TRAVELLERS, GroundedTransitions.DUCK_WADDLE.EXECUTOR_CLIENTS @@ -142,7 +142,7 @@ public List getTransitionInjections() { && MathHelper.approximatelyEquals(data.getInputs().getStrafeInput(), 0))) ) && Vector2d.lengthSquared(data.getForwardVel(), data.getStrafeVel()) > threshold * threshold - && !data.getAction().ID.equals(getID()); + && !data.getActionID().equals(getID()); }, null, null diff --git a/mod/src/main/java/com/floralquafloral/registries/states/character/ParsedCharacter.java b/mod/src/main/java/com/floralquafloral/registries/states/character/ParsedCharacter.java index 14232b3..4743bce 100644 --- a/mod/src/main/java/com/floralquafloral/registries/states/character/ParsedCharacter.java +++ b/mod/src/main/java/com/floralquafloral/registries/states/character/ParsedCharacter.java @@ -1,13 +1,21 @@ package com.floralquafloral.registries.states.character; +import com.floralquafloral.mariodata.MarioDataManager; import com.floralquafloral.registries.states.ParsedMajorMarioState; +import com.floralquafloral.stats.CharaStat; +import com.floralquafloral.stats.StatCategory; + +import java.util.Map; +import java.util.Set; public class ParsedCharacter extends ParsedMajorMarioState { public ParsedCharacter(CharacterDefinition definition) { super(definition); } -// public double getStatFactor(BaseStats stat) { -// -// } + @Override + public double getStatMultiplier(CharaStat stat) { + if(MarioDataManager.useCharacterStats) return super.getStatMultiplier(stat); + else return 1.0; + } } diff --git a/mod/src/main/java/com/floralquafloral/registries/states/powerup/ParsedPowerUp.java b/mod/src/main/java/com/floralquafloral/registries/states/powerup/ParsedPowerUp.java index cad0a36..6474c23 100644 --- a/mod/src/main/java/com/floralquafloral/registries/states/powerup/ParsedPowerUp.java +++ b/mod/src/main/java/com/floralquafloral/registries/states/powerup/ParsedPowerUp.java @@ -2,12 +2,17 @@ import com.floralquafloral.mariodata.MarioData; import com.floralquafloral.registries.states.ParsedMajorMarioState; +import com.floralquafloral.stats.CharaStat; +import com.floralquafloral.stats.StatCategory; import com.floralquafloral.util.MarioSFX; import net.minecraft.sound.SoundEvent; import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Map; +import java.util.Set; + public class ParsedPowerUp extends ParsedMajorMarioState { public final int VALUE; diff --git a/mod/src/main/java/com/floralquafloral/stats/CharaStat.java b/mod/src/main/java/com/floralquafloral/stats/CharaStat.java index 286dc08..651b8a9 100644 --- a/mod/src/main/java/com/floralquafloral/stats/CharaStat.java +++ b/mod/src/main/java/com/floralquafloral/stats/CharaStat.java @@ -10,62 +10,23 @@ import java.util.*; public class CharaStat { - private final double BASE; - private final Set CATEGORIES; - - private static final Map CACHE = new HashMap<>(); - - public static void invalidateCache() { - CACHE.clear(); - } + public final double BASE; + public final Set CATEGORIES; public CharaStat(double base, StatCategory... categories) { this(base, Set.of(categories)); } - private CharaStat(double base, Set categorySet) { - this.BASE = base; - this.CATEGORIES = categorySet; - } - public CharaStat variate(double multiplier) { return new CharaStat(this.BASE * multiplier, this.CATEGORIES); } - private static final double MOVEMENT_SPEED_MULTIPLIER = 1.0 / 0.10000000149011612; - private static final double MOVEMENT_SPEED_MULTIPLIER_SPRINTING = 1.0 / 0.13000000312924387; + private CharaStat(double base, Set categorySet) { + this.BASE = base; + this.CATEGORIES = categorySet; + } public double get(MarioData data) { - double modifiedBase; - - if(data.getMario().isMainPlayer()) { // Only cache stat values for the client-side player - Double value = CACHE.get(this); - if(value == null) { - value = this.BASE * this.getMultiplier(data); - CACHE.put(this, value); - } - - modifiedBase = value; - } - else modifiedBase = this.BASE * this.getMultiplier(data); - - double attributeFactor = 1.0; - double attributeAddend = 0.0; - - if(this.CATEGORIES.contains(StatCategory.SPEED) && ( - this.CATEGORIES.contains(StatCategory.WALKING) - || this.CATEGORIES.contains(StatCategory.RUNNING) - || this.CATEGORIES.contains(StatCategory.P_RUNNING) - || this.CATEGORIES.contains(StatCategory.DUCKING) - )) { - attributeFactor = data.getMario().getAttributes().getValue(EntityAttributes.GENERIC_MOVEMENT_SPEED) - * (data.getMario().isSprinting() ? MOVEMENT_SPEED_MULTIPLIER_SPRINTING : MOVEMENT_SPEED_MULTIPLIER); - } - - if(this.CATEGORIES.contains(StatCategory.JUMP_VELOCITY)) { - attributeAddend = data.getMario().getJumpBoostVelocityModifier(); - } - - return attributeFactor * modifiedBase + attributeAddend; + return data.getStat(this); } public double getAsThreshold(MarioData data) { return this.get(data) * 0.96; @@ -73,21 +34,4 @@ public double getAsThreshold(MarioData data) { public double getAsLimit(MarioData data) { return this.get(data) * 1.015; } - - public double getMultiplier(MarioData data) { - double multiplier = getSpecificMultiplier(data.getPowerUp()); - if(MarioDataManager.useCharacterStats) - multiplier *= getSpecificMultiplier(data.getCharacter()); - return multiplier; - } - - private double getSpecificMultiplier(ParsedMajorMarioState state) { - double combinedModifier = 1.0; - for(Map.Entry, Double> entry : state.STAT_MODIFIERS.entrySet()) { - if(CATEGORIES.containsAll(entry.getKey())) - combinedModifier *= entry.getValue(); - } - - return combinedModifier; - } } diff --git a/settings.gradle b/settings.gradle index 0bc969a..32303d9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -9,5 +9,5 @@ pluginManagement { } } -rootProject.name = 'mario-qua-mario' +rootProject.name = 'qua_mario' include 'api', 'mod' \ No newline at end of file