Skip to content

Commit

Permalink
Stomp collisions now use a move() mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Oct 21, 2024
1 parent c426954 commit cb88e0c
Show file tree
Hide file tree
Showing 31 changed files with 197 additions and 124 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/floralquafloral/MarioCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private static int executeStomp(CommandContext<ServerCommandSource> context, boo
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.getZ(), target.getPitch(), target.getYaw());
stomper.teleport((ServerWorld) target.getWorld(), target.getX(), target.getY() + target.getHeight(), target.getZ(), target.getPitch(), target.getYaw());
long seed = RandomSeed.getSeed();
StompHandler.networkStomp(stomper, target, stompType, false, seed);
stompType.executeServer((MarioPlayerData) MarioDataManager.getMarioData(stomper), target, false, seed);
Expand Down
41 changes: 24 additions & 17 deletions src/main/java/com/floralquafloral/MarioQuaMario.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

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

import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
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;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.world.GameRules;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -64,26 +67,30 @@ public void onInitialize() {
MarioDataManager.registerEventListeners();

RegistryManager.register();
MarioSFX.staticInitialize();

MarioPackets.registerCommon();

MarioCommand.registerMarioCommand();

// ServerLivingEntityEvents.ALLOW_DEATH.register((livingEntity, damageSource, damageAmount) -> {
// if(livingEntity instanceof ServerPlayerEntity player) {
// MarioData data = MarioDataManager.getMarioData(player);
// if(data.isEnabled()) {
// // Revert if possible
// boolean canRevert = player.isOnGround();
// if(canRevert) {
// player.playSound(RegistryManager.POWER_UP_SFX);
// data.setYVel(0.5);
// player.setHealth(20.0F);
// return false;
// }
// }
// }
// return true;
// });
ServerLivingEntityEvents.ALLOW_DEATH.register((livingEntity, damageSource, damageAmount) -> {
if(livingEntity instanceof ServerPlayerEntity player) {
MarioData data = MarioDataManager.getMarioData(player);
if(data.isEnabled()) {
// Revert if possible
Identifier revertTargetID = data.getPowerUp().REVERT_TARGET;
if(revertTargetID != null) {
MarioDataPackets.setMarioPowerUp(player, RegistryManager.POWER_UPS.get(revertTargetID));

player.playSound(MarioSFX.REVERT);

data.setYVel(0.5);
player.setHealth(player.getMaxHealth());
return false;
}
}
}
return true;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static void registerEventListeners() {

ClientEntityEvents.ENTITY_LOAD.register((entity, world) -> {
if(entity instanceof ClientPlayerEntity clientPlayer) {
MarioClientData data = (MarioClientData) getMarioData(clientPlayer);
MarioClientData data = MarioClientData.getInstance();
if(data == null) return;
CLIENT_PLAYERS_DATA.remove(clientPlayer);
CLIENT_PLAYERS_DATA.remove(data.getMario());
data.setMario(clientPlayer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.floralquafloral.registries.states.powerup.ParsedPowerUp;
import com.floralquafloral.util.CPMIntegration;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;

Expand Down Expand Up @@ -118,6 +119,7 @@ private void apply() {
this.VELOCITIES.isGenerated = false;
}

// private double prevY;
public void tick() {
if(this.getMario().getWorld().isClient) {
this.action.otherClientsTick(this);
Expand All @@ -129,7 +131,8 @@ public void tick() {
this.powerUp.serverTick(this);
this.character.serverTick(this);

if(this.action.STOMP != null) this.action.STOMP.attempt(this);
// if(this.action.STOMP != null) this.action.STOMP.attempt(this, prevY);
// prevY = getMario().getY();

this.applyModifiedVelocity();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.floralquafloral.mixin;

import com.floralquafloral.MarioQuaMarioClient;
import com.floralquafloral.registries.stomp.StompHandler;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
Expand All @@ -13,9 +14,9 @@ public abstract class ClientPlayNetworkHandlerMixin {
// Code stolen from FlatteringAnvils by ItsFelix5
@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)) {
if(damageSource.isIn(StompHandler.FLATTENS_ENTITIES_TAG)) {
MarioQuaMarioClient.SQUASHED_ENTITIES.add(instance);
// }
}
instance.onDamaged(damageSource);
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/floralquafloral/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioDataManager;
import com.floralquafloral.registries.states.action.ParsedAction;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand Down Expand Up @@ -47,4 +52,22 @@ private void preventStepSounds(BlockPos pos, BlockState state, CallbackInfo ci)
ci.cancel();
}
}

@Unique
private static boolean shouldStompHook = true;

@Inject(method = "move", at = @At("HEAD"))
private void executeStompsOnServer(MovementType movementType, Vec3d movement, CallbackInfo ci) {
if((Entity) (Object) this instanceof ServerPlayerEntity player && shouldStompHook) {
MarioData data = MarioDataManager.getMarioData(player);
if(data.useMarioPhysics()) {
ParsedAction action = data.getAction();
if(action.STOMP != null) {
shouldStompHook = false;
action.STOMP.attempt(data, movement);
shouldStompHook = true;
}
}
}
}
}
20 changes: 0 additions & 20 deletions src/main/java/com/floralquafloral/registries/RegistryManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.floralquafloral.registries;

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.registries.states.MarioStateDefinition;
import com.floralquafloral.registries.states.action.ActionDefinition;
import com.floralquafloral.registries.states.action.GroundedActionDefinition;
import com.floralquafloral.registries.states.action.ParsedAction;
Expand All @@ -15,12 +14,8 @@
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
Expand All @@ -36,21 +31,6 @@ public static void register() {
registerCharacters();
}

public static final SoundEvent JUMP_SFX = makeAndRegisterSound("sfx.jump");

public static final SoundEvent STOMP_SFX = makeAndRegisterSound("sfx.stomp");

public static final SoundEvent POWER_UP_SFX = makeAndRegisterSound("sfx.power_up_wii");

private static SoundEvent makeAndRegisterSound(String id) {
Identifier identifier = Identifier.of(MarioQuaMario.MOD_ID, id);
SoundEvent event = SoundEvent.of(identifier);

Registry.register(Registries.SOUND_EVENT, identifier, event);

return event;
}

public static final RegistryKey<Registry<ParsedStomp>> STOMP_TYPES_KEY = RegistryKey.ofRegistry(
Identifier.of(MarioQuaMario.MOD_ID, "stomp_types"));
public static final Registry<ParsedStomp> STOMP_TYPES = FabricRegistryBuilder.createSimple(STOMP_TYPES_KEY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.client.Input;
import com.floralquafloral.mariodata.client.MarioClientData;
import com.floralquafloral.util.MarioSFX;
import net.minecraft.util.math.BlockPos;
import org.joml.Vector2d;

Expand All @@ -27,6 +28,7 @@ protected abstract static class GroundedTransitions {
(data) -> Input.DUCK.isHeld(),
(data, isSelf, seed) -> {
// Play duck voiceline
data.getMario().playSound(MarioSFX.DUCK);
LOGGER.info("Ducking voiceline with seed {}", seed);
},
(data, seed) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public ParsedAction(ActionDefinition definition) {
this.ANIMATION = definition.getAnimationName();
this.SNEAK_LEGALITY = definition.getSneakLegalityRule();
this.SLIDING_STATUS = definition.getConstantSlidingStatus();
this.STOMP = RegistryManager.STOMP_TYPES.get(definition.getStompType());
Identifier stompID = definition.getStompType();
this.STOMP = stompID == null ? null : RegistryManager.STOMP_TYPES.get(stompID);

this.TRANSITION_LISTS = new EnumMap<>(TransitionPhase.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.registries.states.ParsedMajorMarioState;
import com.floralquafloral.registries.RegistryManager;
import com.floralquafloral.util.MarioSFX;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
Expand All @@ -24,7 +24,7 @@ public ParsedPowerUp(PowerUpDefinition definition) {

this.VALUE = definition.getValue();
SoundEvent acquisitionSound = definition.getAcquisitionSound();
this.ACQUISITION_SOUND = acquisitionSound == null ? RegistryManager.POWER_UP_SFX : acquisitionSound;
this.ACQUISITION_SOUND = acquisitionSound == null ? MarioSFX.NORMAL_POWER : acquisitionSound;
this.REVERT_TARGET = definition.getRevertTarget();

this.HEART = definition.getHeart();
Expand Down
64 changes: 36 additions & 28 deletions src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.EntityTypeTags;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.RandomSeed;

import java.util.List;
Expand Down Expand Up @@ -77,47 +79,53 @@ public void executeClient(MarioPlayerData data, boolean isSelf, Entity target, b
this.DEFINITION.executeClient(data, isSelf, target, harmless, seed);
}

public void attempt(MarioData data) {
public void attempt(MarioData data, Vec3d movement) {
ServerPlayerEntity mario = (ServerPlayerEntity) data.getMario();
double yVel = data.getYVel();
if(this.MUST_FALL_ON_TARGET && yVel > 0) return;
List<Entity> targets = mario.getWorld().getOtherEntities(mario, mario.getBoundingBox().stretch(movement));

List<Entity> targets = mario.getWorld().getOtherEntities(mario, mario.getBoundingBox());

boolean enteredStompAction = false;
long seed = RandomSeed.getSeed();
for(Entity target : targets) {
if(attemptOnTarget(mario, data, target, seed)) break;
}
}

if(target.getType().isIn(StompHandler.UNSTOMPABLE_TAG)) continue;
private boolean attemptOnTarget(ServerPlayerEntity mario, MarioData data, Entity target, long seed) {
if(target.getType().isIn(StompHandler.UNSTOMPABLE_TAG)) return false;

if(this.MUST_FALL_ON_TARGET && target.getY() + target.getHeight() > mario.getY() - yVel) continue;
if(this.MUST_FALL_ON_TARGET && target.getY() + target.getHeight() > mario.getY()) return false;

if(this.SHOULD_ATTEMPT_MOUNTING) {
if((target instanceof Saddleable saddleableTarget && saddleableTarget.isSaddled())
|| target instanceof VehicleEntity) {
if(mario.startRiding(target)) return;
}
if(this.SHOULD_ATTEMPT_MOUNTING) {
if((target instanceof Saddleable saddleableTarget && saddleableTarget.isSaddled())
|| target instanceof VehicleEntity) {
if(mario.startRiding(target)) return false;
}
}

if(!(target instanceof LivingEntity livingTarget && !livingTarget.isDead())) continue;
if(!this.DEFINITION.canStompTarget(data, target)) continue;
livingTarget.isDead();

boolean targetHurtsToStomp = target.getType().isIn(StompHandler.HURTS_TO_STOMP_TAG);
if(this.PAINFUL_STOMP_RESPONSE == StompDefinition.PainfulStompResponse.INJURY && targetHurtsToStomp) {
// Hurt Mario
mario.damage(makeDamageSource(mario.getServerWorld(), DamageTypes.THORNS, target), 2.8F);
return;
}
if(!(target instanceof LivingEntity livingTarget && !livingTarget.isDead())) return false;
if(!this.DEFINITION.canStompTarget(data, target)) return false;
livingTarget.isDead();

boolean targetHurtsToStomp = target.getType().isIn(StompHandler.HURTS_TO_STOMP_TAG);
MarioQuaMario.LOGGER.info("hurts:"
+ "\ntarget type: " + target.getType()
+ "\ntag: " + StompHandler.HURTS_TO_STOMP_TAG
+ "\ninTag: " + target.getType().isIn(StompHandler.HURTS_TO_STOMP_TAG)
+ "\ninVanillaTag: " + target.getType().isIn(EntityTypeTags.AQUATIC)
+ "\nresponse: " + this.PAINFUL_STOMP_RESPONSE
);
if(this.PAINFUL_STOMP_RESPONSE == StompDefinition.PainfulStompResponse.INJURY && targetHurtsToStomp) {
// Hurt Mario
mario.damage(makeDamageSource(mario.getServerWorld(), DamageTypes.THORNS, target), 2.8F);
return false;
}



boolean harmless = targetHurtsToStomp && this.PAINFUL_STOMP_RESPONSE == StompDefinition.PainfulStompResponse.BOUNCE;
StompHandler.networkStomp(mario, target, this, harmless, seed);
executeServer((MarioPlayerData) data, target, true, seed);
boolean harmless = targetHurtsToStomp && this.PAINFUL_STOMP_RESPONSE == StompDefinition.PainfulStompResponse.BOUNCE;
StompHandler.networkStomp(mario, target, this, harmless, seed);
executeServer((MarioPlayerData) data, target, true, seed);

return;
}
return true;
}

private static DamageSource makeDamageSource(ServerWorld world, RegistryKey<DamageType> key, Entity attacker) {
Expand Down
Loading

0 comments on commit cb88e0c

Please sign in to comment.