Skip to content

Commit

Permalink
Working on implementing stomps
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Oct 20, 2024
1 parent cd18d8d commit 4f73be1
Show file tree
Hide file tree
Showing 43 changed files with 525 additions and 120 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/floralquafloral/MarioPackets.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.floralquafloral;

import com.floralquafloral.mariodata.MarioDataPackets;
import com.floralquafloral.registries.stomp.StompHandler;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
Expand All @@ -20,6 +21,7 @@ public class MarioPackets {
public static void registerCommon() {
SyncUseCharacterStatsS2CPayload.register();
MarioDataPackets.registerCommon();
StompHandler.registerPackets();

ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
MarioQuaMario.LOGGER.info("");
Expand All @@ -28,6 +30,7 @@ public static void registerCommon() {
public static void registerClient() {
SyncUseCharacterStatsS2CPayload.registerReceiver();
MarioDataPackets.registerClient();
StompHandler.registerPacketsClient();
}

public static PlayerEntity getPlayerFromInt(ClientPlayNetworking.Context context, int playerID) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/floralquafloral/MarioQuaMario.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.floralquafloral;

import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioDataManager;
import com.floralquafloral.registries.RegistryManager;
import com.floralquafloral.util.ModConfig;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.GsonConfigSerializer;
import net.fabricmc.api.ModInitializer;

import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.fabricmc.fabric.api.gamerule.v1.rule.DoubleRule;
Expand Down Expand Up @@ -59,6 +61,7 @@ public class MarioQuaMario implements ModInitializer {
public void onInitialize() {
LOGGER.info("MarioQuaMario.java loaded on environment type " + FabricLoader.getInstance().getEnvironmentType());
MarioDataManager.wipePlayerData();
MarioDataManager.registerEventListeners();

RegistryManager.register();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/floralquafloral/VoiceLine.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.floralquafloral;

import com.floralquafloral.registries.RegistryManager;
import com.floralquafloral.registries.character.ParsedCharacter;
import com.floralquafloral.registries.states.character.ParsedCharacter;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.Registries;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/floralquafloral/mariodata/MarioData.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.floralquafloral.mariodata;

import com.floralquafloral.registries.action.ParsedAction;
import com.floralquafloral.registries.character.ParsedCharacter;
import com.floralquafloral.registries.powerup.ParsedPowerUp;
import com.floralquafloral.registries.states.action.ParsedAction;
import com.floralquafloral.registries.states.character.ParsedCharacter;
import com.floralquafloral.registries.states.powerup.ParsedPowerUp;
import net.minecraft.entity.player.PlayerEntity;

public interface MarioData {
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/floralquafloral/mariodata/MarioDataManager.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.floralquafloral.mariodata;

import com.floralquafloral.MarioPackets;
import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.client.MarioClientData;
import com.floralquafloral.mixin.PlayerEntityMixin;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.EntityTrackingEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -16,6 +22,34 @@ public class MarioDataManager {
private static final Map<PlayerEntity, MarioData> SERVER_PLAYERS_DATA = new HashMap<>();
private static final Map<PlayerEntity, MarioData> CLIENT_PLAYERS_DATA = new HashMap<>();

public static void registerEventListeners() {
ServerTickEvents.START_SERVER_TICK.register((server) -> {
for(Map.Entry<PlayerEntity, MarioData> entry : SERVER_PLAYERS_DATA.entrySet()) {
ServerPlayerEntity player = (ServerPlayerEntity) entry.getKey();
if(player.isDisconnected()) {
SERVER_PLAYERS_DATA.remove(player);
continue;
}

((MarioPlayerData) entry.getValue()).tick();
}
});

ClientTickEvents.START_CLIENT_TICK.register((client) -> {
for(Map.Entry<PlayerEntity, MarioData> entry : CLIENT_PLAYERS_DATA.entrySet()) {
((MarioPlayerData) entry.getValue()).tick();
}
});



// ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
//
// });


}

public static void wipePlayerData() {
SERVER_PLAYERS_DATA.clear();
CLIENT_PLAYERS_DATA.clear();
Expand Down
32 changes: 28 additions & 4 deletions src/main/java/com/floralquafloral/mariodata/MarioDataPackets.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import com.floralquafloral.MarioPackets;
import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.registries.RegistryManager;
import com.floralquafloral.registries.action.ParsedAction;
import com.floralquafloral.registries.character.ParsedCharacter;
import com.floralquafloral.registries.powerup.ParsedPowerUp;
import com.floralquafloral.registries.states.action.ParsedAction;
import com.floralquafloral.registries.states.character.ParsedCharacter;
import com.floralquafloral.registries.states.powerup.ParsedPowerUp;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.EntityTrackingEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
Expand All @@ -32,6 +33,20 @@ public static void registerCommon() {
// C2S
SetActionC2SPayload.register();
SetActionC2SPayload.registerReceiver();

// Listeners
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
sendAllData(handler.player, handler.player);
ServerPlayNetworking.send(handler.player,
new MarioPackets.SyncUseCharacterStatsS2CPayload(
handler.player.getWorld().getGameRules().getBoolean(MarioQuaMario.USE_CHARACTER_STATS)));
});

EntityTrackingEvents.START_TRACKING.register((trackingTarget, tracker) -> {
if(trackingTarget instanceof PlayerEntity trackingPlayer) {
sendAllData(tracker, trackingPlayer);
}
});
}
public static void registerClient() {
SetEnabledS2CPayload.registerReceiver();
Expand All @@ -40,6 +55,15 @@ public static void registerClient() {
SetCharacterS2CPayload.registerReceiver();
}

private static void sendAllData(ServerPlayerEntity toWho, PlayerEntity aboutWho) {
MarioData 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));
ServerPlayNetworking.send(toWho, new SetPowerUpS2CPayload(aboutWho, data.getPowerUp()));
ServerPlayNetworking.send(toWho, new SetCharacterS2CPayload(aboutWho, data.getCharacter()));
}

public static String setMarioEnabled(ServerPlayerEntity player, boolean enabled) {
getMarioData(player).setEnabled(enabled);
MarioPackets.sendPacketToTrackers(player, new MarioDataPackets.SetEnabledS2CPayload(player, enabled));
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.registries.RegistryManager;
import com.floralquafloral.registries.action.ParsedAction;
import com.floralquafloral.registries.character.ParsedCharacter;
import com.floralquafloral.registries.powerup.ParsedPowerUp;
import com.floralquafloral.registries.states.action.ParsedAction;
import com.floralquafloral.registries.states.character.ParsedCharacter;
import com.floralquafloral.registries.states.powerup.ParsedPowerUp;
import com.floralquafloral.util.CPMIntegration;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -86,7 +86,8 @@ private void apply() {
return this.VELOCITIES.ensure().strafe;
}
@Override public double getYVel() {
return this.VELOCITIES.ensure().vertical;
if(this.VELOCITIES.isGenerated) return this.VELOCITIES.vertical;
else return this.MARIO.getVelocity().y;
}
@Override public void setForwardVel(double forward) {
VELOCITIES.ensureDirty().forward = forward;
Expand All @@ -95,7 +96,11 @@ private void apply() {
this.VELOCITIES.ensureDirty().strafe = strafe;
}
@Override public void setYVel(double vertical) {
this.VELOCITIES.ensureDirty().vertical = vertical;
if(this.VELOCITIES.isGenerated) this.VELOCITIES.ensureDirty().vertical = vertical;
else {
Vec3d oldVel = this.MARIO.getVelocity();
this.MARIO.setVelocity(oldVel.x, vertical, oldVel.y);
}
}
@Override public void applyModifiedVelocity() {
this.VELOCITIES.apply();
Expand All @@ -107,12 +112,16 @@ public void tick() {
if(this.getMario().getWorld().isClient) {
this.action.otherClientsTick(this);
this.powerUp.otherClientsTick(this);
// this.character.otherClientsTick(this);
this.character.otherClientsTick(this);
}
else {
this.action.serverTick(this);
this.powerUp.serverTick(this);
// this.character.serverTick(this);
this.character.serverTick(this);

if(this.action.STOMP != null) this.action.STOMP.attempt(this);

this.applyModifiedVelocity();
}
}

Expand Down Expand Up @@ -150,11 +159,13 @@ public void tick() {
powerUp.acquirePower(this);
this.MARIO.setHealth(this.MARIO.getMaxHealth());
this.powerUp = powerUp;
this.MARIO.calculateDimensions();
}
@Override public ParsedCharacter getCharacter() {
return character;
}
@Override public void setCharacter(ParsedCharacter character) {
this.character = character;
this.MARIO.calculateDimensions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.MarioPlayerData;
import com.floralquafloral.registries.action.ParsedAction;
import com.floralquafloral.registries.action.TransitionPhase;
import com.floralquafloral.registries.states.action.ParsedAction;
import com.floralquafloral.registries.states.action.TransitionPhase;
import com.floralquafloral.util.CPMIntegration;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector2d;

public class MarioClientData extends MarioPlayerData {
Expand Down Expand Up @@ -50,17 +47,12 @@ public MarioClientData(ClientPlayerEntity mario) {
}

public boolean travel(Vec3d movementInput) {
tick();
Input.updateDirections(movementInput.z, movementInput.x);

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

// MarioVelocityContainer cachedVelocities = getVelocities();
// this.clearCachedVelocities();
// setVelocities(cachedVelocities);

applyModifiedVelocity();
MARIO_CLIENT.move(MovementType.PLAYER, MARIO_CLIENT.getVelocity());
if(getAction().attemptTransitions(this, TransitionPhase.POST_MOVE))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.floralquafloral.mixin;

import com.floralquafloral.MarioQuaMarioClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
Expand All @@ -13,7 +14,7 @@ public abstract class ClientPlayNetworkHandlerMixin {
@Redirect(method = "onEntityDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;onDamaged(Lnet/minecraft/entity/damage/DamageSource;)V"))
private void onDamaged(Entity instance, DamageSource damageSource) {
// if(damageSource.isIn(StompHandler.FLATTENS_ENTITIES_TAG)) {
// MarioQuaMarioClient.SQUASHED_ENTITIES.add(instance);
MarioQuaMarioClient.SQUASHED_ENTITIES.add(instance);
// }
instance.onDamaged(damageSource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.floralquafloral.MarioQuaMarioClient;
import com.floralquafloral.mariodata.client.MarioClientData;
import com.floralquafloral.registries.action.ActionDefinition;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.SimpleOption;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.floralquafloral.mixin;

import com.floralquafloral.mariodata.client.MarioClientData;
import com.floralquafloral.registries.powerup.PowerUpDefinition;
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.gui.hud.InGameHud;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.floralquafloral.mixin;

import com.floralquafloral.MarioQuaMarioClient;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(LivingEntityRenderer.class)
public abstract class LivingEntityRendererMixin<T extends LivingEntity, M extends EntityModel<T>> {

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/LivingEntityRenderer;getLyingAngle(Lnet/minecraft/entity/LivingEntity;)F"), method = "setupTransforms", cancellable = true)
private void squashedDeathAnimation(T entity, MatrixStack matrices, float animationProgress, float bodyYaw, float tickDelta, float scale, CallbackInfo ci) {
if(MarioQuaMarioClient.SQUASHED_ENTITIES.contains(entity)) {
matrices.scale(1.4F, 0.25F, 1.4F);
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.client.MarioClientData;
import com.floralquafloral.mariodata.MarioDataManager;
import com.floralquafloral.registries.action.ActionDefinition;
import com.floralquafloral.registries.character.ParsedCharacter;
import com.floralquafloral.registries.powerup.ParsedPowerUp;
import com.floralquafloral.registries.states.character.ParsedCharacter;
import com.floralquafloral.registries.states.powerup.ParsedPowerUp;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.player.PlayerEntity;
Expand Down
Loading

0 comments on commit 4f73be1

Please sign in to comment.