Skip to content

Commit

Permalink
Started implementing packets; more Actions work
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Dec 16, 2024
1 parent 440968c commit 4b3671b
Show file tree
Hide file tree
Showing 29 changed files with 304 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,24 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CameraAnimationSet {
public CameraAnimationSet(
@NotNull CameraAnimation authentic,
@Nullable CameraAnimation gentle,
@Nullable CameraAnimation minimal
public record CameraAnimationSet(
@NotNull CameraAnimation authentic,
@Nullable CameraAnimation gentle,
@Nullable CameraAnimation minimal
) {
public record CameraAnimation(
boolean looping,
float durationSeconds,
CameraAnimation.rotationalOffsetCalculator calculator
) {
this.AUTHENTIC_ANIMATION = authentic;
this.GENTLE_ANIMATION = gentle == null ? authentic : gentle;
this.MINIMAL_ANIMATION = minimal;
}

public static class CameraAnimation {
@FunctionalInterface
public interface rotationalOffsetCalculator {
void setRotationalOffsets(float progress, float[] offsets);
void setRotationalOffsets(float progress, CameraOffsets offsets);
}

public CameraAnimation(
boolean looping,
float durationSeconds,
CameraAnimation.rotationalOffsetCalculator calculator
) {
this.SHOULD_LOOP = looping;
this.DURATION_TICKS = durationSeconds * 20;
this.CALCULATOR = calculator;
public static class CameraOffsets {
public float pitch, yaw, roll;
public float x, y, z;
}

public final boolean SHOULD_LOOP;
public final float DURATION_TICKS;
public final CameraAnimation.rotationalOffsetCalculator CALCULATOR;
}

@NotNull
public final CameraAnimation AUTHENTIC_ANIMATION;
@NotNull
public final CameraAnimation GENTLE_ANIMATION;
@Nullable
public final CameraAnimation MINIMAL_ANIMATION;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fqf.mario_qua_mario.definitions.actions.util;

public enum EvaluatorContext {
public enum EvaluatorEnvironment {
CLIENT_ONLY,
SERVER_ONLY,
COMMON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
public record TransitionDefinition(
@NotNull Identifier targetID,
@NotNull Evaluator evaluator, @NotNull EvaluatorContext context,
@NotNull Evaluator evaluator, @NotNull EvaluatorEnvironment environment,
@Nullable TravelExecutor travelExecutor,
@Nullable ClientsExecutor clientsExecutor
) {
/**
* Alternate constructor provided for convenience
*/
public TransitionDefinition(@NotNull Identifier targetID, @NotNull Evaluator evaluator, @NotNull EvaluatorContext context) {
public TransitionDefinition(@NotNull Identifier targetID, @NotNull Evaluator evaluator, @NotNull EvaluatorEnvironment context) {
this(targetID, evaluator, context, null, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
public interface IMarioAuthoritativeData extends IMarioData {
@Override ServerPlayerEntity getMario();

boolean setEnabled(boolean enable);
void setEnabled(boolean enable);

boolean setAction(Identifier actionID);
boolean setAction(String actionID);

boolean setActionTransitionless(Identifier actionID);
boolean setActionTransitionless(String actionID);
void setActionTransitionless(Identifier actionID);
void setActionTransitionless(String actionID);

boolean setPowerUp(Identifier powerUpID);
boolean setPowerUp(String powerUpID);
void setPowerUp(Identifier powerUpID);
void setPowerUp(String powerUpID);

boolean setCharacter(Identifier characterID);
boolean setCharacter(String characterID);
void setCharacter(Identifier characterID);
void setCharacter(String characterID);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class Debug implements GenericActionDefinition {
return List.of(
new TransitionDefinition(
MarioQuaMarioContent.makeID("debug_sprint"),
data -> data.getMario().isSprinting(), EvaluatorContext.CLIENT_ONLY,
data -> data.getMario().isSprinting(), EvaluatorEnvironment.CLIENT_ONLY,
null,
(data, isSelf, seed) -> data.playSound(SoundEvents.ENTITY_VEX_CHARGE, seed)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class DebugSprint extends Debug {
return List.of(
new TransitionDefinition(
MarioQuaMarioContent.makeID("debug"),
data -> !data.getMario().isSprinting(), EvaluatorContext.CLIENT_ONLY,
data -> !data.getMario().isSprinting(), EvaluatorEnvironment.CLIENT_ONLY,
null,
(data, isSelf, seed) -> data.playSound(SoundEvents.ENTITY_ALLAY_AMBIENT_WITH_ITEM, seed)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.fqf.mario_qua_mario.actions.grounded;

import com.fqf.mario_qua_mario.MarioQuaMarioContent;
import com.fqf.mario_qua_mario.definitions.actions.AirborneActionDefinition;
import com.fqf.mario_qua_mario.definitions.actions.GenericActionDefinition;
import com.fqf.mario_qua_mario.definitions.actions.GroundedActionDefinition;
import com.fqf.mario_qua_mario.definitions.actions.util.*;
import com.fqf.mario_qua_mario.mariodata.IMarioAuthoritativeData;
import com.fqf.mario_qua_mario.mariodata.IMarioClientData;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.OtherClientPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;

public class MarioQuaMarioClient implements ClientModInitializer {
// This is in the client sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,10 @@
import org.jetbrains.annotations.Nullable;

public class MarioMainClientData extends MarioMoveableData implements IMarioClientDataImpl {
private static MarioMainClientData instance;
public static @Nullable MarioMainClientData getInstance() {
return instance;
}
public static void clearInstance() {
instance = null;
}

private ClientPlayerEntity mario;
public MarioMainClientData(ClientPlayerEntity mario) {
super();
this.mario = mario;
instance = this;
}
@Override public ClientPlayerEntity getMario() {
return mario;
Expand All @@ -36,9 +27,14 @@ public void tick() {
@Override
public boolean travelHook(double forwardInput, double strafeInput) {
this.INPUTS.updateAnalog(forwardInput, strafeInput);

this.getAction().travelHook(this);


this.applyModifiedVelocity();
this.getMario().move(MovementType.SELF, this.getMario().getVelocity());

this.getMario().updateLimbs(false);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
import org.jetbrains.annotations.NotNull;

public interface MarioMainClientDataHolder extends MarioDataHolder {
@Override @NotNull MarioMainClientData mqm$getMarioData();
@SuppressWarnings("DataFlowIssue") @Override
default @NotNull MarioMainClientData mqm$getMarioData() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
import org.jetbrains.annotations.NotNull;

public interface MarioOtherClientDataHolder extends MarioDataHolder {
@Override @NotNull MarioOtherClientData mqm$getMarioData();
@SuppressWarnings("DataFlowIssue") @Override
default @NotNull MarioOtherClientData mqm$getMarioData() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientPlayerEntity.class)
public class ClientPlayerEntityMarioDataMixin extends PlayerEntityMarioDataMixin implements MarioMainClientDataHolder {
public class ClientPlayerEntityMarioDataMixin implements MarioMainClientDataHolder {
@Unique private MarioMainClientData marioData;

@Inject(method = "<init>", at = @At("RETURN"))
Expand All @@ -34,5 +34,6 @@ private void constructorHook(MinecraftClient client, ClientWorld world, ClientPl
@Override
public void mqm$setMarioData(MarioPlayerData replacementData) {
this.marioData = (MarioMainClientData) replacementData;
replacementData.setMario((ClientPlayerEntity) (Object) this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(OtherClientPlayerEntity.class)
public class OtherClientPlayerEntityMarioDataMixin extends PlayerEntityMarioDataMixin implements MarioOtherClientDataHolder {
public class OtherClientPlayerEntityMarioDataMixin implements MarioOtherClientDataHolder {
@Unique private MarioOtherClientData marioData;

@Inject(method = "<init>", at = @At("RETURN"))
Expand All @@ -31,5 +31,6 @@ private void constructorHook(ClientWorld clientWorld, GameProfile gameProfile, C
@Override
public void mqm$setMarioData(MarioPlayerData replacementData) {
this.marioData = (MarioOtherClientData) replacementData;
replacementData.setMario((OtherClientPlayerEntity) (Object) this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.fqf.mario_qua_mario.packets;

import com.fqf.mario_qua_mario.mariodata.MarioPlayerData;
import com.fqf.mario_qua_mario.registries.RegistryManager;
import com.fqf.mario_qua_mario.registries.actions.AbstractParsedAction;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.entity.player.PlayerEntity;

import java.util.Objects;

public class MarioClientPacketReceivers {
public static void registerClientReceivers() {
// SetActionS2CPayload Receiver
ClientPlayNetworking.registerGlobalReceiver(MarioDataPackets.SetActionS2CPayload.ID, (payload, context) -> {
MarioPlayerData data = getMarioFromID(context, payload.marioID()).mqm$getMarioData();
AbstractParsedAction action = RegistryManager.ACTIONS.get(payload.newAction());
if(payload.doTransition()) data.setActionInternal(action, payload.seed(), true);
else data.setActionTransitionlessInternal(action);
});
}

public static PlayerEntity getMarioFromID(ClientPlayNetworking.Context context, int marioID) {
return (PlayerEntity) Objects.requireNonNull(context.player().getWorld().getEntityById(marioID));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.fqf.mario_qua_mario;

public abstract class MarioAbstractClientHelper {
public static MarioAbstractClientHelper instance = new MarioAbstractClientHelper() {
};
public static MarioAbstractClientHelper instance = null;
}
52 changes: 31 additions & 21 deletions mod/src/main/java/com/fqf/mario_qua_mario/MarioCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.fqf.mario_qua_mario;

import com.fqf.mario_qua_mario.mariodata.MarioServerPlayerData;
import com.fqf.mario_qua_mario.packets.MarioDataPackets;
import com.fqf.mario_qua_mario.registries.RegistryManager;
import com.fqf.mario_qua_mario.registries.actions.AbstractParsedAction;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
Expand All @@ -10,6 +13,7 @@
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.argument.RegistryEntryReferenceArgumentType;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -102,60 +106,66 @@ private static ServerPlayerEntity getPlayerFromCmd(CommandContext<ServerCommandS
}

private static int setEnabled(CommandContext<ServerCommandSource> context, boolean playerArgumentGiven) throws CommandSyntaxException {
// return sendFeedback(context, MarioDataPackets.setMarioEnabled(
// getPlayerFromCmd(context, playerArgumentGiven),
// BoolArgumentType.getBool(context, "enabled")
// return sendFeedback(environment, MarioDataPackets.setMarioEnabled(
// getPlayerFromCmd(environment, playerArgumentGiven),
// BoolArgumentType.getBool(environment, "enabled")
// ));
return 0;
}

private static int setAction(CommandContext<ServerCommandSource> context, boolean playerArgumentGiven) throws CommandSyntaxException {
// return sendFeedback(context, MarioDataPackets.forceSetMarioAction(
// getPlayerFromCmd(context, playerArgumentGiven),
// RegistryEntryReferenceArgumentType.getRegistryEntry(context, "action", RegistryManager.ACTIONS_KEY).value()
// return sendFeedback(environment, MarioDataPackets.forceSetMarioAction(
// getPlayerFromCmd(environment, playerArgumentGiven),
// RegistryEntryReferenceArgumentType.getRegistryEntry(environment, "action", RegistryManager.ACTIONS_KEY).value()
// ));
return 0;
ServerPlayerEntity mario = getPlayerFromCmd(context, playerArgumentGiven);
RegistryEntry<AbstractParsedAction> actionEntry =
RegistryEntryReferenceArgumentType.getRegistryEntry(context, "action", RegistryManager.ACTIONS_KEY);
mario.mqm$getMarioData().setActionTransitionlessInternal(actionEntry.value());
MarioDataPackets.setActionS2C(mario, true, actionEntry.value(), false, 0);

return sendFeedback(context, "Changed " + mario.getName().getString() + "'s action to " + actionEntry.value().ID + ".");
}

private static int setPowerUp(CommandContext<ServerCommandSource> context, boolean playerArgumentGiven) throws CommandSyntaxException {
// return sendFeedback(context, MarioDataPackets.setMarioPowerUp(
// getPlayerFromCmd(context, playerArgumentGiven),
// RegistryEntryReferenceArgumentType.getRegistryEntry(context, "power", RegistryManager.POWER_UPS_KEY).value()
// return sendFeedback(environment, MarioDataPackets.setMarioPowerUp(
// getPlayerFromCmd(environment, playerArgumentGiven),
// RegistryEntryReferenceArgumentType.getRegistryEntry(environment, "power", RegistryManager.POWER_UPS_KEY).value()
// ));
return 0;
}

private static int setCharacter(CommandContext<ServerCommandSource> context, boolean playerArgumentGiven) throws CommandSyntaxException {
// return sendFeedback(context, MarioDataPackets.setMarioCharacter(
// getPlayerFromCmd(context, playerArgumentGiven),
// RegistryEntryReferenceArgumentType.getRegistryEntry(context, "character", RegistryManager.CHARACTERS_KEY).value()
// return sendFeedback(environment, MarioDataPackets.setMarioCharacter(
// getPlayerFromCmd(environment, playerArgumentGiven),
// RegistryEntryReferenceArgumentType.getRegistryEntry(environment, "character", RegistryManager.CHARACTERS_KEY).value()
// ));
return 0;
}

private static int executeStomp(CommandContext<ServerCommandSource> context, boolean playerArgumentGiven) throws CommandSyntaxException {
// ServerPlayerEntity stomper = getPlayerFromCmd(context, playerArgumentGiven);
// Entity target = EntityArgumentType.getEntity(context, "goomba");
// ParsedStomp stompType = RegistryEntryReferenceArgumentType.getRegistryEntry(context, "stomp", RegistryManager.STOMP_TYPES_KEY).value();
// ServerPlayerEntity stomper = getPlayerFromCmd(environment, playerArgumentGiven);
// Entity target = EntityArgumentType.getEntity(environment, "goomba");
// ParsedStomp stompType = RegistryEntryReferenceArgumentType.getRegistryEntry(environment, "stomp", RegistryManager.STOMP_TYPES_KEY).value();
//
// stomper.teleport((ServerWorld) target.getWorld(), target.getX(), target.getY() + target.getHeight(), target.getZ(), target.getPitch(), target.getYaw());
// stompType.executeServer((MarioServerData) MarioDataManager.getMarioData(stomper), target, true, RandomSeed.getSeed());
//
// return sendFeedback(context, "Made " + stomper.getName().getString() + " perform a stomp of type " + stompType.ID + " on " + target.getName().getString());
// return sendFeedback(environment, "Made " + stomper.getName().getString() + " perform a stomp of type " + stompType.ID + " on " + target.getName().getString());
return 0;
}


private static int executeBump(CommandContext<ServerCommandSource> context, boolean playerArgumentGiven, Direction direction, Integer strength) throws CommandSyntaxException {
// ServerPlayerEntity bumper = getPlayerFromCmd(context, playerArgumentGiven);
// if(strength == null) strength = IntegerArgumentType.getInteger(context, "strength");
// BlockPos position = BlockPosArgumentType.getBlockPos(context, "position");
// ServerPlayerEntity bumper = getPlayerFromCmd(environment, playerArgumentGiven);
// if(strength == null) strength = IntegerArgumentType.getInteger(environment, "strength");
// BlockPos position = BlockPosArgumentType.getBlockPos(environment, "position");
//
// MarioServerData data = (MarioServerData) MarioDataManager.getMarioData(bumper);
//// BumpManager.bumpBlockServer(data, bumper.getServerWorld(), position, strength, strength, direction, true, true);
//// BumpManager.bumpResponseCommon(data, data, bumper.getServerWorld(), bumper.getServerWorld().getBlockState(position), position, strength, strength, direction);
//
// return sendFeedback(context, "Made " + bumper.getName().getString() + " bump block " + direction + " with a strength " + strength);
// return sendFeedback(environment, "Made " + bumper.getName().getString() + " bump block " + direction + " with a strength " + strength);

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions mod/src/main/java/com/fqf/mario_qua_mario/MarioQuaMario.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fqf.mario_qua_mario.registries.RegistryManager;
import net.fabricmc.api.ModInitializer;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Loading

0 comments on commit 4b3671b

Please sign in to comment.