Skip to content

Commit

Permalink
Implemented Bump Handlers and camera dipping when bumping the floor d…
Browse files Browse the repository at this point in the history
…ownwards
  • Loading branch information
floral-qua-floral committed Nov 13, 2024
1 parent 3f95353 commit af1a736
Show file tree
Hide file tree
Showing 41 changed files with 904 additions and 165 deletions.
61 changes: 0 additions & 61 deletions src/main/java/com/floralquafloral/BlockBumping.java

This file was deleted.

41 changes: 41 additions & 0 deletions src/main/java/com/floralquafloral/MarioCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.floralquafloral;

import com.floralquafloral.bumping.BumpManager;
import com.floralquafloral.mariodata.MarioDataManager;
import com.floralquafloral.mariodata.MarioDataPackets;
import com.floralquafloral.mariodata.MarioPlayerData;
Expand All @@ -8,17 +9,23 @@
import com.floralquafloral.registries.stomp.ParsedStomp;
import com.floralquafloral.registries.stomp.StompHandler;
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 com.tom.cpm.shared.template.args.BoolArg;
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.CommandManager;
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;
Expand Down Expand Up @@ -75,6 +82,18 @@ public static void registerMarioCommand() {
)
)
)
.then(literal("bump")
.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))
)
)
)
);
}
Expand Down Expand Up @@ -126,4 +145,26 @@ private static int executeStomp(CommandContext<ServerCommandSource> context, boo

return sendFeedback(context, "Made " + stomper.getName().getString() + " perform a stomp of type " + stompType.ID + " on " + target.getName().getString());
}


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");

MarioServerData data = (MarioServerData) MarioDataManager.getMarioData(bumper);
BumpManager.bumpResponseCommon(data, data, bumper.getServerWorld(), bumper.getServerWorld().getBlockState(position), position, strength, strength, direction);

return sendFeedback(context, "Made " + bumper + " bump block " + direction + " with a strength " + strength);
}
private static LiteralArgumentBuilder<ServerCommandSource> 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))
)
);
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/floralquafloral/MarioPackets.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.floralquafloral;

import com.floralquafloral.bumping.BumpManager;
import com.floralquafloral.mariodata.MarioDataManager;
import com.floralquafloral.mariodata.MarioDataPackets;
import com.floralquafloral.registries.stomp.StompHandler;
import com.floralquafloral.util.JumpSoundPlayer;
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 @@ -24,7 +24,7 @@ public static void registerCommon() {
SyncUseCharacterStatsS2CPayload.register();
MarioDataPackets.registerCommon();
StompHandler.registerPackets();
BlockBumping.registerPackets();
BumpManager.registerPackets();


ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
Expand All @@ -35,7 +35,7 @@ public static void registerClient() {
SyncUseCharacterStatsS2CPayload.registerReceiver();
MarioDataPackets.registerClient();
StompHandler.registerPacketsClient();
BlockBumping.registerPacketsClient();
BumpManager.registerPacketsClient();
}

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

import com.floralquafloral.bumping.BumpManager;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioDataManager;
import com.floralquafloral.mariodata.MarioDataPackets;
Expand All @@ -16,7 +17,9 @@
import net.fabricmc.fabric.api.gamerule.v1.rule.DoubleRule;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -62,14 +65,16 @@ public class MarioQuaMario implements ModInitializer {
GameRuleRegistry.register("qua_mario:alwaysRevertToSmall", GameRules.Category.PLAYER,
GameRuleFactory.createBooleanRule(false));

public static final SimpleParticleType GAMER = FabricParticleTypes.simple();

@Override
public void onInitialize() {
LOGGER.info("MarioQuaMario.java loaded on environment type " + FabricLoader.getInstance().getEnvironmentType());
MarioDataManager.registerEventListeners();
BumpManager.registerEventListeners();

RegistryManager.register();


MarioPackets.registerCommon();

MarioCommand.registerMarioCommand();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/floralquafloral/MarioQuaMarioClient.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.floralquafloral;

import com.floralquafloral.bumping.BumpedBlockParticle;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.option.SimpleOption;
import net.minecraft.client.particle.FlameParticle;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import org.apache.commons.compress.utils.Lists;
Expand All @@ -25,5 +28,7 @@ public void onInitializeClient() {
ClientEntityEvents.ENTITY_UNLOAD.register((entity, world) -> SQUASHED_ENTITIES.remove(entity));
ClientTickEvents.END_WORLD_TICK.register((world) -> SQUASHED_ENTITIES.removeIf(squashedEntity ->
squashedEntity instanceof LivingEntity squashedLivingEntity && !squashedLivingEntity.isDead()));

ParticleFactoryRegistry.getInstance().register(MarioQuaMario.GAMER, new BumpedBlockParticle.Factory());
}
}
Loading

0 comments on commit af1a736

Please sign in to comment.