Skip to content

Commit

Permalink
Sounds are now part of a StompDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Oct 23, 2024
1 parent 85ce505 commit 9ab2978
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void applyDrag(
deltaVelocities.y, 0,
forwardAngleContribution,
strafeAngleContribution,
redirection
redirection * slipFactor
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public List<ActionTransitionDefinition> getPreTickTransitions() {
new ActionTransitionDefinition("qua_mario:p_run",
(data) -> data.getForwardVel() >= RUN_SPEED.getAsThreshold(data),
(data, isSelf, seed) -> {
if(isSelf) data.setForwardVel(P_SPEED.get(data));
if(isSelf) data.setForwardVel(Math.max(P_SPEED.get(data), data.getForwardVel()));
},
(data, seed) -> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public List<ActionTransitionInjection> getTransitionInjections() {
double threshold = DUCK_SLIDE_THRESHOLD.get(data);
return
Input.DUCK.isHeld()
&& data.getMario().isOnGround()
&& !data.getAction().ID.equals(getID())
&& Vector2d.lengthSquared(data.getForwardVel(), data.getStrafeVel()) > threshold * threshold;
}
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@
import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioPlayerData;
import com.floralquafloral.registries.RegistryManager;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.component.type.ItemEnchantmentsComponent;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.Saddleable;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.vehicle.VehicleEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
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.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.RandomSeed;
import net.minecraft.world.World;

import java.util.List;

Expand All @@ -39,6 +38,7 @@ public class ParsedStomp {
private final boolean HITS_NONLIVING_ENTITIES;

private final RegistryKey<DamageType> DAMAGE_TYPE;
private final RegistryEntry<SoundEvent> SOUND_ENTRY;
private final Identifier POST_STOMP_ACTION;

public ParsedStomp(StompDefinition definition) {
Expand All @@ -51,10 +51,7 @@ public ParsedStomp(StompDefinition definition) {
this.HITS_NONLIVING_ENTITIES = definition.canHitNonLiving();

this.DAMAGE_TYPE = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, definition.getDamageType());
MarioQuaMario.LOGGER.info("Parsing:"
+ "\ndef damagetype: " + definition.getDamageType()
+ "\ndamagetype: " + this.DAMAGE_TYPE
);
this.SOUND_ENTRY = Registries.SOUND_EVENT.getEntry(definition.getSoundEvent());
this.POST_STOMP_ACTION = definition.getPostStompAction();
}

Expand All @@ -76,8 +73,21 @@ public void executeServer(MarioPlayerData data, Entity target, boolean harmless,

this.DEFINITION.executeServer(target.getWorld(), data, target, harmless, seed);
}
public void executeClient(World world, MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) {
this.DEFINITION.executeClient(world, data, isSelf, target, harmless, seed);
public void executeClient(PlayerEntity hearingPlayer, MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) {
if(this.SOUND_ENTRY != null) {
target.getWorld().playSound(
hearingPlayer,
target.getX(),
target.getY(),
target.getZ(),
this.SOUND_ENTRY,
SoundCategory.PLAYERS,
1.0F,
1.0F,
seed
);
}
this.DEFINITION.executeClient(hearingPlayer.getWorld(), data, isSelf, target, harmless, seed);
data.applyModifiedVelocity();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
Expand All @@ -19,6 +20,7 @@ public interface StompDefinition {
boolean canHitNonLiving();

@NotNull Identifier getDamageType();
@Nullable SoundEvent getSoundEvent();
@Nullable Identifier getPostStompAction();

boolean canStompTarget(MarioData data, Entity target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void registerReceiver() {
+ "\nareEqual2: " + (context.player().getWorld().equals(mario.getWorld()))
+ "\nmarioDataMarioWorld: " + getMarioData(mario).getMario().getWorld()
);
stompType.executeClient(context.player().getWorld(), (MarioPlayerData) getMarioData(mario), mario.isMainPlayer(), target, payload.harmless, payload.seed);
stompType.executeClient(context.player(), (MarioPlayerData) getMarioData(mario), mario.isMainPlayer(), target, payload.harmless, payload.seed);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import com.floralquafloral.mariodata.MarioPlayerData;
import com.floralquafloral.registries.stomp.StompDefinition;
import com.floralquafloral.registries.stomp.StompHandler;
import com.floralquafloral.util.MarioSFX;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MovementType;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
Expand Down Expand Up @@ -46,6 +49,9 @@ public class JumpStomp implements StompDefinition {
@Override public @NotNull Identifier getDamageType() {
return Identifier.of(MarioQuaMario.MOD_ID, "stomp");
}
@Override public @Nullable SoundEvent getSoundEvent() {
return MarioSFX.STOMP;
}

@Override public @Nullable Identifier getPostStompAction() {
return null;
Expand Down Expand Up @@ -73,16 +79,8 @@ public void executeServer(World world, MarioPlayerData data, Entity target, bool
@Override
public void executeClient(World world, MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) {
executeCommon(data, target);
// world.playSound(
// target.getX(),
// target.getY(),
// target.getZ(),
// SoundEvents.ENTITY_SKELETON_DEATH,
// SoundCategory.PLAYERS,
// 1.0F,
// 1.0F,
// false
// );

// world.playSoundFromEntity(null, target, Registries.SOUND_EVENT.getEntry(MarioSFX.STOMP), SoundCategory.PLAYERS, 1.0F, 1.0F, seed);
}

private void executeCommon(MarioPlayerData data, Entity target) {
Expand Down

0 comments on commit 9ab2978

Please sign in to comment.