From 9d4c307fcb45fef4f6cf47d1e34cabaccce959c5 Mon Sep 17 00:00:00 2001 From: Floral <49110090+floral-qua-floral@users.noreply.github.com> Date: Thu, 5 Dec 2024 18:34:36 -0500 Subject: [PATCH] Implementing MarioDatas --- .../fqf/mario_qua_mario/MarioQuaMarioAPI.java | 7 + .../mariodata/IMarioAuthoritativeData.java | 17 ++ .../mariodata/IMarioClientData.java | 50 ++++++ .../mario_qua_mario/mariodata/IMarioData.java | 25 +++ .../mariodata/IMarioTravelData.java | 37 ++++ .../fqf/mario_qua_mario/util/CharaStat.java | 36 ++++ .../mario_qua_mario/util/StatCategory.java | 39 ++++ mod/build.gradle | 1 + .../mariodata/IMarioClientDataImpl.java | 113 ++++++++++++ .../mariodata/MarioMainClientData.java | 28 ++- .../mariodata/MarioOtherClientData.java | 18 +- .../ClientPlayerEntityMarioDataMixin.java | 2 +- ...OtherClientPlayerEntityMarioDataMixin.java | 2 +- .../com/fqf/mario_qua_mario/MarioCommand.java | 169 ++++++++++++++++++ .../fqf/mario_qua_mario/MarioQuaMario.java | 2 + .../mariodata/MarioPlayerData.java | 53 +++++- .../registries/RegistryManager.java | 58 ++++++ 17 files changed, 650 insertions(+), 7 deletions(-) create mode 100644 api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioAuthoritativeData.java create mode 100644 api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioClientData.java create mode 100644 api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioData.java create mode 100644 api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioTravelData.java create mode 100644 api/src/main/java/com/fqf/mario_qua_mario/util/CharaStat.java create mode 100644 api/src/main/java/com/fqf/mario_qua_mario/util/StatCategory.java create mode 100644 mod/src/client/java/com/fqf/mario_qua_mario/mariodata/IMarioClientDataImpl.java create mode 100644 mod/src/main/java/com/fqf/mario_qua_mario/MarioCommand.java create mode 100644 mod/src/main/java/com/fqf/mario_qua_mario/registries/RegistryManager.java diff --git a/api/src/main/java/com/fqf/mario_qua_mario/MarioQuaMarioAPI.java b/api/src/main/java/com/fqf/mario_qua_mario/MarioQuaMarioAPI.java index d4320d1..b5a10cd 100644 --- a/api/src/main/java/com/fqf/mario_qua_mario/MarioQuaMarioAPI.java +++ b/api/src/main/java/com/fqf/mario_qua_mario/MarioQuaMarioAPI.java @@ -1,5 +1,7 @@ package com.fqf.mario_qua_mario; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.api.ModInitializer; import org.slf4j.Logger; @@ -13,4 +15,9 @@ public class MarioQuaMarioAPI implements ModInitializer { public void onInitialize() { LOGGER.info("Mario qua Mario API initializing!"); } + + @Environment(EnvType.CLIENT) + private void testasaur() { + + } } \ No newline at end of file diff --git a/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioAuthoritativeData.java b/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioAuthoritativeData.java new file mode 100644 index 0000000..73718ac --- /dev/null +++ b/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioAuthoritativeData.java @@ -0,0 +1,17 @@ +package com.fqf.mario_qua_mario.mariodata; + +import net.minecraft.util.Identifier; + +public interface IMarioAuthoritativeData { + boolean setAction(Identifier actionID); + boolean setAction(String actionID); + + boolean setActionTransitionless(Identifier actionID); + boolean setActionTransitionless(String actionID); + + boolean setPowerUp(Identifier powerUpID); + boolean setPowerUp(String powerUpID); + + boolean setCharacter(Identifier characterID); + boolean setCharacter(String characterID); +} diff --git a/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioClientData.java b/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioClientData.java new file mode 100644 index 0000000..d098998 --- /dev/null +++ b/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioClientData.java @@ -0,0 +1,50 @@ +package com.fqf.mario_qua_mario.mariodata; + +import net.minecraft.entity.Entity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; + +public interface IMarioClientData extends IMarioData { + SoundInstanceWrapper playSound( + SoundEvent event, SoundCategory category, + double x, double y, double z, + float pitch, float volume, long seed + ); + + SoundInstanceWrapper playSound(SoundEvent event, long seed); + SoundInstanceWrapper playSound(SoundEvent event, float pitch, float volume, long seed); + SoundInstanceWrapper playSound(SoundEvent event, Entity entity, SoundCategory category, long seed); + + void playJumpSound(long seed); + void fadeJumpSound(); + + SoundInstanceWrapper voice(VoiceLine line, long seed); + float getVoicePitch(); + + void storeSound(SoundInstanceWrapper instance); + void stopStoredSound(SoundEvent event); + + enum VoiceLine { + SELECT, + DUCK, + + DOUBLE_JUMP, + TRIPLE_JUMP, + GYMNAST_SALUTE, + + DUCK_JUMP, + LONG_JUMP, + BACKFLIP, + SIDEFLIP, + WALL_JUMP, + + REVERT, + BURNT, + + FIREBALL, + GET_STAR + } + + interface SoundInstanceWrapper { + } +} diff --git a/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioData.java b/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioData.java new file mode 100644 index 0000000..4dbb4a2 --- /dev/null +++ b/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioData.java @@ -0,0 +1,25 @@ +package com.fqf.mario_qua_mario.mariodata; + +import com.fqf.mario_qua_mario.util.CharaStat; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Identifier; + +import java.util.HashSet; +import java.util.Set; + +public interface IMarioData { + PlayerEntity getMario(); + boolean isClient(); + + double getStat(CharaStat stat); + double getStatMultiplier(CharaStat stat); + int getBumpStrengthModifier(); + + boolean canSneak(); + boolean canSprint(); + + boolean isEnabled(); + Identifier getActionID(); + Identifier getPowerUpID(); + Identifier getCharacterID(); +} diff --git a/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioTravelData.java b/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioTravelData.java new file mode 100644 index 0000000..b615305 --- /dev/null +++ b/api/src/main/java/com/fqf/mario_qua_mario/mariodata/IMarioTravelData.java @@ -0,0 +1,37 @@ +package com.fqf.mario_qua_mario.mariodata; + +public interface IMarioTravelData extends IMarioData { + double getForwardVel(); + double getStrafeVel(); + double getYVel(); + + void setForwardVel(double forward); + void setStrafeVel(double strafe); + default void setForwardStrafeVel(double forward, double strafe) { + this.setForwardVel(forward); + this.setStrafeVel(strafe); + } + void setYVel(double vertical); + + abstract class MarioInputs { + public final MarioButton JUMP; + public final MarioButton DUCK; + public final MarioButton SPIN; + + public abstract double getForwardInput(); + public abstract double getStrafeInput(); + + public abstract boolean isReal(); + + public interface MarioButton { + boolean isPressed(); + boolean isHeld(); + } + + protected MarioInputs(MarioButton jump, MarioButton duck, MarioButton spin) { + JUMP = jump; + DUCK = duck; + SPIN = spin; + } + } +} diff --git a/api/src/main/java/com/fqf/mario_qua_mario/util/CharaStat.java b/api/src/main/java/com/fqf/mario_qua_mario/util/CharaStat.java new file mode 100644 index 0000000..6551546 --- /dev/null +++ b/api/src/main/java/com/fqf/mario_qua_mario/util/CharaStat.java @@ -0,0 +1,36 @@ +package com.fqf.mario_qua_mario.util; + +import com.fqf.mario_qua_mario.mariodata.IMarioData; + +import java.util.Set; + +/** + * Represents a numerical value that might vary depending on character and power-up form. + * This is used for movement, speed thresholds, and damage calculations. + */ +public class CharaStat { + public final double BASE; + public final Set CATEGORIES; + + public CharaStat(double base, StatCategory... categories) { + this(base, Set.of(categories)); + } + public CharaStat variate(double multiplier) { + return new CharaStat(this.BASE * multiplier, this.CATEGORIES); + } + + private CharaStat(double base, Set categorySet) { + this.BASE = base; + this.CATEGORIES = categorySet; + } + + public double get(IMarioData data) { + return data.getStat(this); + } + public double getAsThreshold(IMarioData data) { + return this.get(data) * 0.96; + } + public double getAsLimit(IMarioData data) { + return this.get(data) * 1.015; + } +} diff --git a/api/src/main/java/com/fqf/mario_qua_mario/util/StatCategory.java b/api/src/main/java/com/fqf/mario_qua_mario/util/StatCategory.java new file mode 100644 index 0000000..0de5378 --- /dev/null +++ b/api/src/main/java/com/fqf/mario_qua_mario/util/StatCategory.java @@ -0,0 +1,39 @@ +package com.fqf.mario_qua_mario.util; + +public enum StatCategory { + WALKING, + RUNNING, + P_RUNNING, + DUCKING, + + DRIFTING, // Airborne + + SWIMMING, // Aquatic + + ACCELERATION, + OVERSPEED_CORRECTION, // Used INSTEAD OF acceleration for overwalk, overrun, etc. type stats. + SPEED, + REDIRECTION, + THRESHOLD, + + FORWARD, + BACKWARD, + STRAFE, + + DRAG, + FRICTION, // Mostly for Luigi? + WATER_DRAG, + + JUMP_VELOCITY, + JUMP_CAP, + + JUMPING_GRAVITY, + NORMAL_GRAVITY, + AQUATIC_GRAVITY, + TERMINAL_VELOCITY, + AQUATIC_TERMINAL_VELOCITY, + + STOMP_BASE_DAMAGE, + STOMP_ARMOR_MULTIPLIER, + STOMP_BOUNCE +} diff --git a/mod/build.gradle b/mod/build.gradle index 803171a..fec1a47 100644 --- a/mod/build.gradle +++ b/mod/build.gradle @@ -38,6 +38,7 @@ fabricApi { dependencies { implementation(project(path: ':api', configuration: "namedElements")) + runtimeOnly(project(path: ':content', configuration: "namedElements")) // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" diff --git a/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/IMarioClientDataImpl.java b/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/IMarioClientDataImpl.java new file mode 100644 index 0000000..52f2229 --- /dev/null +++ b/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/IMarioClientDataImpl.java @@ -0,0 +1,113 @@ +package com.fqf.mario_qua_mario.mariodata; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.client.sound.SoundInstance; +import net.minecraft.entity.Entity; +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 java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; + +public interface IMarioClientDataImpl extends IMarioClientData { + @Override + default boolean isClient() { + return true; + } + + @Override + default SoundInstanceWrapperImpl playSound( + SoundEvent event, SoundCategory category, + double x, double y, double z, + float pitch, float volume, long seed + ) { + SoundInstance sound = new PositionedSoundInstance( + event, category, + volume, pitch, + Random.create(seed), + x, y, z + ); + MinecraftClient.getInstance().getSoundManager().play(sound); + return new SoundInstanceWrapperImpl(sound); + } + + @Override + default SoundInstanceWrapperImpl playSound(SoundEvent event, long seed) { + return this.playSound(event, 1F, 1F, seed); + } + + @Override + default SoundInstanceWrapperImpl playSound(SoundEvent event, float pitch, float volume, long seed) { + Vec3d marioPos = this.getMario().getPos(); + return this.playSound(event, SoundCategory.PLAYERS, marioPos.x, marioPos.y, marioPos.z, 1F, 1F, seed); + } + + @Override + default SoundInstanceWrapperImpl playSound(SoundEvent event, Entity entity, SoundCategory category, long seed) { + return this.playSound(event, category, entity.getX(), entity.getY(), entity.getZ(), 1F, 1F, seed); + } + + @Override + default void playJumpSound(long seed) { + + } + + @Override + default void fadeJumpSound() { + + } + + Map MARIO_VOICE_LINES = new HashMap<>(); + + @Override + default SoundInstanceWrapperImpl voice(VoiceLine line, long seed) { + MinecraftClient.getInstance().getSoundManager().stop(MARIO_VOICE_LINES.get(this)); + Vec3d marioPos = this.getMario().getPos(); + SoundInstanceWrapperImpl newVoiceSound = this.playSound( + VOICE_SOUND_EVENTS.get(line).get(this.getCharacterID()), SoundCategory.VOICE, + marioPos.x, marioPos.y, marioPos.z, + this.getVoicePitch(), 1.0F, + seed + ); + + MARIO_VOICE_LINES.put(this, newVoiceSound.SOUND); + + return newVoiceSound; + } + + @Override + default float getVoicePitch() { +// return ((MarioPlayerData) this).getPowerUp().; + return 1; + } + + Map> STORED_SOUNDS = new HashMap<>(); + + @Override + default void storeSound(SoundInstanceWrapper instance) { + STORED_SOUNDS.putIfAbsent(this, new HashMap<>()); + SoundInstance sound = ((SoundInstanceWrapperImpl) instance).SOUND; + STORED_SOUNDS.get(this).put(sound.getId(), sound); + } + + @Override + default void stopStoredSound(SoundEvent event) { + if(STORED_SOUNDS.containsKey(this)) { + + } + } + + class SoundInstanceWrapperImpl implements SoundInstanceWrapper { + private final SoundInstance SOUND; + public SoundInstanceWrapperImpl(SoundInstance sound) { + this.SOUND = sound; + } + } + + EnumMap> VOICE_SOUND_EVENTS = new EnumMap<>(VoiceLine.class); +} diff --git a/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/MarioMainClientData.java b/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/MarioMainClientData.java index 62f5797..d7272db 100644 --- a/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/MarioMainClientData.java +++ b/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/MarioMainClientData.java @@ -1,5 +1,31 @@ package com.fqf.mario_qua_mario.mariodata; -public class MarioMainClientData extends MarioPlayerData { +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.entity.player.PlayerEntity; +import org.jetbrains.annotations.Nullable; +public class MarioMainClientData extends MarioPlayerData 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) { + this.mario = mario; + instance = this; + } + + @Override + public ClientPlayerEntity getMario() { + return mario; + } + + @Override + public void setMario(PlayerEntity mario) { + this.mario = (ClientPlayerEntity) mario; + } } diff --git a/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/MarioOtherClientData.java b/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/MarioOtherClientData.java index 7e61f11..1c23f58 100644 --- a/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/MarioOtherClientData.java +++ b/mod/src/client/java/com/fqf/mario_qua_mario/mariodata/MarioOtherClientData.java @@ -1,5 +1,21 @@ package com.fqf.mario_qua_mario.mariodata; -public class MarioOtherClientData extends MarioPlayerData { +import net.minecraft.client.network.OtherClientPlayerEntity; +import net.minecraft.entity.player.PlayerEntity; +public class MarioOtherClientData extends MarioPlayerData implements IMarioClientDataImpl { + private OtherClientPlayerEntity mario; + public MarioOtherClientData(OtherClientPlayerEntity mario) { + this.mario = mario; + } + + @Override + public void setMario(PlayerEntity mario) { + this.mario = (OtherClientPlayerEntity) mario; + } + + @Override + public OtherClientPlayerEntity getMario() { + return this.mario; + } } diff --git a/mod/src/client/java/com/fqf/mario_qua_mario/mixin/client/ClientPlayerEntityMarioDataMixin.java b/mod/src/client/java/com/fqf/mario_qua_mario/mixin/client/ClientPlayerEntityMarioDataMixin.java index 44b7502..8fbc66b 100644 --- a/mod/src/client/java/com/fqf/mario_qua_mario/mixin/client/ClientPlayerEntityMarioDataMixin.java +++ b/mod/src/client/java/com/fqf/mario_qua_mario/mixin/client/ClientPlayerEntityMarioDataMixin.java @@ -23,7 +23,7 @@ public class ClientPlayerEntityMarioDataMixin extends PlayerEntityMarioDataMixin @Inject(method = "", at = @At("RETURN")) private void constructorHook(MinecraftClient client, ClientWorld world, ClientPlayNetworkHandler networkHandler, StatHandler stats, ClientRecipeBook recipeBook, boolean lastSneaking, boolean lastSprinting, CallbackInfo ci) { - mqm$setMarioData(new MarioMainClientData()); + mqm$setMarioData(new MarioMainClientData((ClientPlayerEntity) (Object) this)); } @Override diff --git a/mod/src/client/java/com/fqf/mario_qua_mario/mixin/client/OtherClientPlayerEntityMarioDataMixin.java b/mod/src/client/java/com/fqf/mario_qua_mario/mixin/client/OtherClientPlayerEntityMarioDataMixin.java index 8cf94f2..4107dd1 100644 --- a/mod/src/client/java/com/fqf/mario_qua_mario/mixin/client/OtherClientPlayerEntityMarioDataMixin.java +++ b/mod/src/client/java/com/fqf/mario_qua_mario/mixin/client/OtherClientPlayerEntityMarioDataMixin.java @@ -20,7 +20,7 @@ public class OtherClientPlayerEntityMarioDataMixin extends PlayerEntityMarioData @Inject(method = "", at = @At("RETURN")) private void constructorHook(ClientWorld clientWorld, GameProfile gameProfile, CallbackInfo ci) { - this.marioData = new MarioOtherClientData(); + this.marioData = new MarioOtherClientData((OtherClientPlayerEntity) (Object) this); } @Override diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/MarioCommand.java b/mod/src/main/java/com/fqf/mario_qua_mario/MarioCommand.java new file mode 100644 index 0000000..ea5a6d4 --- /dev/null +++ b/mod/src/main/java/com/fqf/mario_qua_mario/MarioCommand.java @@ -0,0 +1,169 @@ +package com.fqf.mario_qua_mario; + +import com.fqf.mario_qua_mario.registries.RegistryManager; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.command.argument.BlockPosArgumentType; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.command.argument.RegistryEntryReferenceArgumentType; +import net.minecraft.entity.Entity; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.random.RandomSeed; + +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class MarioCommand { + public static void registerMarioCommand() { + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> + dispatcher.register(literal("mario") + .then(literal("setEnabled") + .then(argument("enabled", BoolArgumentType.bool()) + .executes(context -> setEnabled(context, false)) + .then(argument("target", EntityArgumentType.player()) + .requires(source -> source.hasPermissionLevel(2)) + .executes(context -> setEnabled(context, true)) + ) + ) + ) + .then(literal("setAction") + .requires(source -> source.hasPermissionLevel(2)) + .then(argument("action", RegistryEntryReferenceArgumentType.registryEntry(registryAccess, RegistryManager.ACTIONS_KEY)) + .executes(context -> setAction(context, false)) + .then(argument("target", EntityArgumentType.player()) + .executes(context -> setAction(context, true)) + ) + ) + ) + .then(literal("setPowerUp") + .requires(source -> source.hasPermissionLevel(2)) + .then(argument("power", RegistryEntryReferenceArgumentType.registryEntry(registryAccess, RegistryManager.POWER_UPS_KEY)) + .executes(context -> setPowerUp(context, false)) + .then(argument("target", EntityArgumentType.player()) + .executes(context -> setPowerUp(context, true)) + ) + ) + ) + .then(literal("setCharacter") + .requires(source -> source.hasPermissionLevel(2)) + .then(argument("character", RegistryEntryReferenceArgumentType.registryEntry(registryAccess, RegistryManager.CHARACTERS_KEY)) + .executes(context -> setCharacter(context, false)) + .then(argument("target", EntityArgumentType.player()) + .executes(context -> setCharacter(context, true)) + ) + ) + ) + .then(literal("executeStomp") + .requires(source -> source.hasPermissionLevel(2)) + .then(argument("stomp", RegistryEntryReferenceArgumentType.registryEntry(registryAccess, RegistryManager.STOMP_TYPES_KEY)) + .then(argument("goomba", EntityArgumentType.entity()) + .executes(context -> executeStomp(context, false)) + .then(argument("target", EntityArgumentType.player()) + .executes(context -> executeStomp(context, true)) + ) + ) + ) + ) + .then(literal("executeBump") + .requires(source -> source.hasPermissionLevel(2)) + .then(argument("position", BlockPosArgumentType.blockPos()) + .executes(context -> executeBump(context, false, Direction.UP, 4)) + .then(makeBumpDirectionFork("up", Direction.UP)) + .then(makeBumpDirectionFork("down", Direction.DOWN)) + .then(makeBumpDirectionFork("north", Direction.NORTH)) + .then(makeBumpDirectionFork("south", Direction.SOUTH)) + .then(makeBumpDirectionFork("east", Direction.EAST)) + .then(makeBumpDirectionFork("west", Direction.WEST)) + ) + ) + ) + ); + } + + private static int sendFeedback(CommandContext context, String feedback) { + context.getSource().sendFeedback(() -> Text.literal(feedback), true); + return 1; + } + + private static ServerPlayerEntity getPlayerFromCmd(CommandContext context, boolean playerArgumentGiven) throws CommandSyntaxException { + return playerArgumentGiven ? EntityArgumentType.getPlayer(context, "target") : context.getSource().getPlayerOrThrow(); + } + + private static int setEnabled(CommandContext context, boolean playerArgumentGiven) throws CommandSyntaxException { +// return sendFeedback(context, MarioDataPackets.setMarioEnabled( +// getPlayerFromCmd(context, playerArgumentGiven), +// BoolArgumentType.getBool(context, "enabled") +// )); + return 0; + } + + private static int setAction(CommandContext context, boolean playerArgumentGiven) throws CommandSyntaxException { +// return sendFeedback(context, MarioDataPackets.forceSetMarioAction( +// getPlayerFromCmd(context, playerArgumentGiven), +// RegistryEntryReferenceArgumentType.getRegistryEntry(context, "action", RegistryManager.ACTIONS_KEY).value() +// )); + return 0; + } + + private static int setPowerUp(CommandContext context, boolean playerArgumentGiven) throws CommandSyntaxException { +// return sendFeedback(context, MarioDataPackets.setMarioPowerUp( +// getPlayerFromCmd(context, playerArgumentGiven), +// RegistryEntryReferenceArgumentType.getRegistryEntry(context, "power", RegistryManager.POWER_UPS_KEY).value() +// )); + return 0; + } + + private static int setCharacter(CommandContext context, boolean playerArgumentGiven) throws CommandSyntaxException { +// return sendFeedback(context, MarioDataPackets.setMarioCharacter( +// getPlayerFromCmd(context, playerArgumentGiven), +// RegistryEntryReferenceArgumentType.getRegistryEntry(context, "character", RegistryManager.CHARACTERS_KEY).value() +// )); + return 0; + } + + private static int executeStomp(CommandContext 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(); +// +// 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 0; + } + + + private static int executeBump(CommandContext 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"); +// +// 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 0; + } + private static LiteralArgumentBuilder makeBumpDirectionFork(String name, Direction direction) { + return literal(name) + .executes(context -> executeBump(context, false, direction, 4)) + .then(argument("strength", IntegerArgumentType.integer()) + .executes(context -> executeBump(context, false, direction, null)) + .then(argument("target", EntityArgumentType.player()) + .executes(context -> executeBump(context, true, direction, null)) + ) + ); + } +} diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/MarioQuaMario.java b/mod/src/main/java/com/fqf/mario_qua_mario/MarioQuaMario.java index 91aac9c..da82782 100644 --- a/mod/src/main/java/com/fqf/mario_qua_mario/MarioQuaMario.java +++ b/mod/src/main/java/com/fqf/mario_qua_mario/MarioQuaMario.java @@ -12,5 +12,7 @@ public class MarioQuaMario implements ModInitializer { @Override public void onInitialize() { LOGGER.info("Mario qua Mario initializing..."); + + MarioCommand.registerMarioCommand(); } } \ No newline at end of file diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/mariodata/MarioPlayerData.java b/mod/src/main/java/com/fqf/mario_qua_mario/mariodata/MarioPlayerData.java index 725ca0f..14c6c8b 100644 --- a/mod/src/main/java/com/fqf/mario_qua_mario/mariodata/MarioPlayerData.java +++ b/mod/src/main/java/com/fqf/mario_qua_mario/mariodata/MarioPlayerData.java @@ -1,10 +1,57 @@ package com.fqf.mario_qua_mario.mariodata; +import com.fqf.mario_qua_mario.util.CharaStat; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Identifier; + /** * The most advanced form of MarioData that can be applied for all players. */ -public abstract class MarioPlayerData { - public String getValue() { - return "Abstract data"; +public abstract class MarioPlayerData implements IMarioData { + public abstract void setMario(PlayerEntity mario); + + @Override + public double getStat(CharaStat stat) { + return 0; + } + + @Override + public double getStatMultiplier(CharaStat stat) { + return 0; + } + + @Override + public int getBumpStrengthModifier() { + return 0; + } + + @Override + public boolean canSneak() { + return false; + } + + @Override + public boolean canSprint() { + return false; + } + + @Override + public boolean isEnabled() { + return false; + } + + @Override + public Identifier getActionID() { + return null; + } + + @Override + public Identifier getPowerUpID() { + return null; + } + + @Override + public Identifier getCharacterID() { + return null; } } diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/registries/RegistryManager.java b/mod/src/main/java/com/fqf/mario_qua_mario/registries/RegistryManager.java new file mode 100644 index 0000000..abedad8 --- /dev/null +++ b/mod/src/main/java/com/fqf/mario_qua_mario/registries/RegistryManager.java @@ -0,0 +1,58 @@ +package com.fqf.mario_qua_mario.registries; + +import com.fqf.mario_qua_mario.MarioQuaMario; +import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; +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.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.util.Identifier; + +import java.util.List; + +public class RegistryManager { + public static void register() { + Registry.register(STOMP_TYPES, Identifier.of(MarioQuaMario.MOD_ID, "stomp"), "BOING!"); + Registry.register(STOMP_TYPES, Identifier.of(MarioQuaMario.MOD_ID, "ground_pound"), "POW!"); + + Registry.register(ACTIONS, Identifier.of(MarioQuaMario.MOD_ID, "debug"), "float..."); + Registry.register(ACTIONS, Identifier.of(MarioQuaMario.MOD_ID, "debug_alt"), "zoom!"); + + Registry.register(POWER_UPS, Identifier.of(MarioQuaMario.MOD_ID, "super"), "wahoo!"); + Registry.register(POWER_UPS, Identifier.of(MarioQuaMario.MOD_ID, "small"), "owch!"); + + Registry.register(CHARACTERS, Identifier.of(MarioQuaMario.MOD_ID, "mario"), "yippee!"); + Registry.register(CHARACTERS, Identifier.of(MarioQuaMario.MOD_ID, "toadette"), "nice!"); + } + + public static final RegistryKey> STOMP_TYPES_KEY = RegistryKey.ofRegistry( + Identifier.of(MarioQuaMario.MOD_ID, "stomp_types")); + public static final Registry STOMP_TYPES = FabricRegistryBuilder.createSimple(STOMP_TYPES_KEY) + .attribute(RegistryAttribute.SYNCED) + .buildAndRegister(); + + public static final RegistryKey> ACTIONS_KEY = RegistryKey.ofRegistry( + Identifier.of(MarioQuaMario.MOD_ID, "actions")); + public static final Registry ACTIONS = FabricRegistryBuilder.createSimple(ACTIONS_KEY) + .attribute(RegistryAttribute.SYNCED) + .buildAndRegister(); + + public static final RegistryKey> POWER_UPS_KEY = RegistryKey.ofRegistry( + Identifier.of(MarioQuaMario.MOD_ID, "power_ups")); + public static final Registry POWER_UPS = FabricRegistryBuilder.createSimple(POWER_UPS_KEY) + .attribute(RegistryAttribute.SYNCED) + .buildAndRegister(); + + public static final RegistryKey> CHARACTERS_KEY = RegistryKey.ofRegistry( + Identifier.of(MarioQuaMario.MOD_ID, "characters")); + public static final Registry CHARACTERS = FabricRegistryBuilder.createSimple(CHARACTERS_KEY) + .attribute(RegistryAttribute.SYNCED) + .buildAndRegister(); + + public static List getEntrypoints(String key, Class clazz) { + return FabricLoader.getInstance().getEntrypointContainers(key, clazz).stream().map(EntrypointContainer::getEntrypoint).toList(); + } + + +}