Skip to content

Commit

Permalink
Footstep sounds no longer play when Mario's current action is a Slidi…
Browse files Browse the repository at this point in the history
…ng action. Game event is also not emitted (so no triggering things like Sculk Sensors with nonexistent footsteps).
  • Loading branch information
floral-qua-floral committed Dec 19, 2024
1 parent 8730945 commit a427a07
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 33 deletions.
2 changes: 1 addition & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
// withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.fqf.mario_qua_mario.interfaces;

import com.fqf.mario_qua_mario.mariodata.IMarioAuthoritativeData;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.Saddleable;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
import net.minecraft.entity.vehicle.MinecartEntity;
import net.minecraft.entity.vehicle.VehicleEntity;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;

/**
* An entity can implement this interface and override its methods to change Stomp attacks interact with it.
*/
public interface IStompableEntity {
default StompResult mqm$getStompResult(
IMarioAuthoritativeData mario,
Identifier stompType,
boolean canMount,
DamageSource damageSource,
float amount
) {
// Only entities can be stomped.
if(!(this instanceof Entity entity)) return StompResult.FAIL;

// Mario can mount some entities by falling onto them from above, like how he mounts Yoshi in most games.
if(canMount && this.mqm$isStompMountable() && mario.getMario().startRiding(entity, false))
return StompResult.MOUNT;

// Various datapack-tag-driven interactions
if(entity.getType().isIn(UNSTOMPABLE_ENTITIES)) return StompResult.FAIL;
if(entity.getType().isIn(HURTS_TO_STOMP_ENTITIES)) return StompResult.PAINFUL;
if(entity.getType().isIn(IMMUNE_TO_BASIC_STOMP_ENTITIES) && damageSource.isIn(BASIC_STOMPS)) return StompResult.FAIL;

// Attempt to apply the damage from the stomp to the entity.
// If the damage goes through, then Mario should do a normal stomp.
// If it doesn't, that means the entity is probably immune for whatever reason, and Mario should do a Resisted stomp.
boolean damaged = entity.damage(damageSource, amount);

if(damaged) return StompResult.NORMAL;
else return StompResult.RESISTED;
}

default boolean mqm$isStompMountable() {
if(this instanceof VehicleEntity vehicle) {
// If we're a vehicle, then:
// - If we're a Minecart, then return true if we're an empty minecart (as opposed to, i.e., a Chest Minecart)
// - If we're not a Minecart, then return true
return !(vehicle instanceof MinecartEntity minecart) || minecart.getMinecartType() != AbstractMinecartEntity.Type.RIDEABLE;
}
if(this instanceof Saddleable saddleable) {
// If we're something that can be saddled, then:
// - If we're saddled, then return true
// - If we're not saddled, then return false
return saddleable.isSaddled();
}

// If we're neither a vehicle nor saddleable, then return false.
return false;
}

TagKey<EntityType<?>> UNSTOMPABLE_ENTITIES =
TagKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("mario_qua_mario:unstompable"));
TagKey<EntityType<?>> HURTS_TO_STOMP_ENTITIES =
TagKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("mario_qua_mario:hurts_to_stomp"));
TagKey<EntityType<?>> IMMUNE_TO_BASIC_STOMP_ENTITIES =
TagKey.of(RegistryKeys.ENTITY_TYPE, Identifier.of("mario_qua_mario:immune_to_basic_stomp"));

TagKey<DamageType> BASIC_STOMPS =
TagKey.of(RegistryKeys.DAMAGE_TYPE, Identifier.of("mario_qua_mario:basic_stomps"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.fqf.mario_qua_mario.interfaces;

public enum StompResult {
NORMAL,
PAINFUL,
GLANCING,
RESISTED,
FAIL,
MOUNT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.fqf.mario_qua_mario.mixin;

import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(Entity.class)
public abstract class EntityMixin {

}
15 changes: 0 additions & 15 deletions api/src/main/java/com/fqf/mario_qua_mario/mixin/ExampleMixin.java

This file was deleted.

2 changes: 1 addition & 1 deletion api/src/main/resources/mario_qua_mario_api.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"package": "com.fqf.mario_qua_mario.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"ExampleMixin"
"EntityMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
2 changes: 1 addition & 1 deletion content/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
// withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public void onInitialize() {
public static Identifier makeID(String path) {
return Identifier.of("mqm", path);
}
public static Identifier makeResID(String path) {
return Identifier.of("mario_qua_mario", path);
}
}
22 changes: 10 additions & 12 deletions content/src/main/java/com/fqf/mario_qua_mario/powerups/Small.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,21 @@ public class Small implements PowerUpDefinition {
}

@Override public @NotNull PowerHeart getPowerHeart(PowerHeartHelper helper) {
String namespace = "mario_qua_mario";

return new PowerUpDefinition.PowerHeart(
Identifier.of(namespace, "hud/power_hearts/small/full"),
Identifier.of(namespace, "hud/power_hearts/small/full_blinking"),
MarioQuaMarioContent.makeResID("hud/power_hearts/small/full"),
MarioQuaMarioContent.makeResID("hud/power_hearts/small/full_blinking"),

Identifier.of(namespace, "hud/power_hearts/small/half"),
Identifier.of(namespace, "hud/power_hearts/small/half_blinking"),
MarioQuaMarioContent.makeResID("hud/power_hearts/small/half"),
MarioQuaMarioContent.makeResID("hud/power_hearts/small/half_blinking"),

Identifier.of(namespace, "hud/power_hearts/small/hardcore/full"),
Identifier.of(namespace, "hud/power_hearts/small/hardcore/full_blinking"),
MarioQuaMarioContent.makeResID("hud/power_hearts/small/hardcore/full"),
MarioQuaMarioContent.makeResID("hud/power_hearts/small/hardcore/full_blinking"),

Identifier.of(namespace, "hud/power_hearts/small/hardcore/half"),
Identifier.of(namespace, "hud/power_hearts/small/hardcore/half_blinking"),
MarioQuaMarioContent.makeResID("hud/power_hearts/small/hardcore/half"),
MarioQuaMarioContent.makeResID("hud/power_hearts/small/hardcore/half_blinking"),

Identifier.of(namespace, "hud/power_hearts/small/container"),
Identifier.of(namespace, "hud/power_hearts/small/container_blinking")
MarioQuaMarioContent.makeResID("hud/power_hearts/small/container"),
MarioQuaMarioContent.makeResID("hud/power_hearts/small/container_blinking")
);
}

Expand Down
3 changes: 3 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 @@ -25,4 +25,7 @@ public void onInitialize() {
public static Identifier makeID(String path) {
return Identifier.of("mqm", path);
}
public static Identifier makeResID(String path) {
return Identifier.of(MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@

import com.fqf.mario_qua_mario.mariodata.MarioMoveableData;
import com.fqf.mario_qua_mario.mariodata.injections.MarioDataHolder;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
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(PlayerEntity.class)
public abstract class PlayerEntityMixin implements MarioDataHolder {
public abstract class PlayerEntityMixin extends LivingEntity implements MarioDataHolder {
private PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world) {
super(entityType, world);
}

@Inject(method = "tick", at = @At("HEAD"))
private void tickHook(CallbackInfo ci) {
this.mqm$getMarioData().tick();
Expand All @@ -22,4 +32,20 @@ private void travelHook(Vec3d movementInput, CallbackInfo ci) {
&& moveableData.travelHook(movementInput.z, movementInput.x))
ci.cancel();
}

@Override
protected boolean stepOnBlock(BlockPos pos, BlockState state, boolean playSound, boolean emitEvent, Vec3d movement) {
return switch (this.mqm$getMarioData().getAction().SLIDING_STATUS) {
case SLIDING, SLIDING_SILENT, SKIDDING -> false;
default -> super.stepOnBlock(pos, state, playSound, emitEvent, movement);
};
}

@Override
protected void playStepSounds(BlockPos pos, BlockState state) {
switch (this.mqm$getMarioData().getAction().SLIDING_STATUS) {
case SLIDING, SLIDING_SILENT, SKIDDING -> {}
default -> super.playStepSounds(pos, state);
};
}
}
4 changes: 3 additions & 1 deletion mod/src/main/resources/mario_qua_mario.accesswidener
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
accessWidener v2 named

accessible class net/minecraft/client/gui/hud/InGameHud$HeartType
accessible class net/minecraft/client/gui/hud/InGameHud$HeartType
extendable method net/minecraft/entity/Entity stepOnBlock (Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;ZZLnet/minecraft/util/math/Vec3d;)Z
extendable method net/minecraft/entity/Entity playStepSounds (Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V
1 change: 0 additions & 1 deletion mod/src/main/resources/mario_qua_mario.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"package": "com.fqf.mario_qua_mario.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"ExampleMixin",
"PlayerEntityMarioDataMixin",
"PlayerEntityMixin",
"ServerPlayerMarioDataMixin"
Expand Down

0 comments on commit a427a07

Please sign in to comment.