Skip to content

Commit

Permalink
feat: iron man step sound
Browse files Browse the repository at this point in the history
  • Loading branch information
Duzos committed Aug 28, 2024
1 parent 3932202 commit be175d6
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private void genSounds(FabricDataGenerator.Pack pack) {

provider.addSound("thruster", Register.Sounds.THRUSTER);
provider.addSound("mark5_noises", Register.Sounds.MARK5_NOISES);
provider.addSound("ironman_step", Register.Sounds.IRONMAN_STEP);

return provider;
})));
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/mc/duzo/timeless/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package mc.duzo.timeless.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.BlockPos;

import mc.duzo.timeless.suit.Suit;

@Mixin(Entity.class)
public abstract class EntityMixin {
@Shadow public abstract void playSound(SoundEvent sound, float volume, float pitch);

@Inject(method="playStepSound", at=@At("HEAD"))
private void timeless$playStepSound(BlockPos pos, BlockState state, CallbackInfo ci) {
Entity entity = (Entity)(Object)this;
if (!(entity instanceof PlayerEntity player)) return;

Suit suit = Suit.findSuit(player).orElse(null);
if (suit == null) return;

this.playSound(suit.getStepSound(), 1f, 1f);
}
}
5 changes: 2 additions & 3 deletions src/main/java/mc/duzo/timeless/power/impl/FlightPower.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mc.duzo.timeless.power.impl;

import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes;
Expand All @@ -15,6 +14,7 @@
import mc.duzo.timeless.network.Network;
import mc.duzo.timeless.network.s2c.UpdateFlyingStatusS2CPacket;
import mc.duzo.timeless.power.Power;
import mc.duzo.timeless.suit.Suit;
import mc.duzo.timeless.suit.ironman.IronManSuit;
import mc.duzo.timeless.suit.item.SuitItem;
import mc.duzo.timeless.util.ServerKeybind;
Expand Down Expand Up @@ -130,8 +130,7 @@ private static void setIsFlying(PlayerEntity player, boolean val) {
}

public static IronManSuit getSuit(PlayerEntity player) { // todo not assume IronManSuit
if (!(player.getEquippedStack(EquipmentSlot.CHEST).getItem() instanceof SuitItem item)) return null;
if (!(item.getSuit() instanceof IronManSuit suit)) return null;
if (!(Suit.findSuit(player).orElse(null) instanceof IronManSuit suit)) return null;

return suit;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mc/duzo/timeless/registry/Register.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static void init() {
public static class Sounds {
public static final SoundEvent THRUSTER = register("thruster");
public static final SoundEvent MARK5_NOISES = register("mark5_noises");
public static final SoundEvent IRONMAN_STEP = register("ironman_step");

private static SoundEvent register(String name) {
return register(new Identifier(Timeless.MOD_ID, name));
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/mc/duzo/timeless/suit/Suit.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
package mc.duzo.timeless.suit;

import java.util.Optional;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.sound.SoundEvent;

import mc.duzo.timeless.datagen.provider.lang.Translatable;
import mc.duzo.timeless.power.PowerList;
import mc.duzo.timeless.registry.Identifiable;
import mc.duzo.timeless.suit.client.ClientSuit;
import mc.duzo.timeless.suit.client.ClientSuitRegistry;
import mc.duzo.timeless.suit.item.SuitItem;
import mc.duzo.timeless.suit.set.SuitSet;

public abstract class Suit implements Identifiable, Translatable {
public static Optional<Suit> findSuit(LivingEntity entity) {
if (!(entity.getEquippedStack(EquipmentSlot.CHEST).getItem() instanceof SuitItem item)) return Optional.empty();
return Optional.ofNullable(item.getSuit());
}

public abstract boolean isBinding();
public abstract SuitSet getSet();
public abstract PowerList getPowers();
public abstract SoundEvent getStepSound();

@Override
public String getTranslationKey() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/mc/duzo/timeless/suit/ironman/IronManSuit.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package mc.duzo.timeless.suit.ironman;

import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;

import mc.duzo.timeless.Timeless;
import mc.duzo.timeless.datagen.provider.lang.AutomaticEnglish;
import mc.duzo.timeless.registry.Register;
import mc.duzo.timeless.suit.Suit;

public abstract class IronManSuit extends Suit implements AutomaticEnglish {
Expand Down Expand Up @@ -34,6 +36,11 @@ public Identifier id() {
return this.id;
}

@Override
public SoundEvent getStepSound() {
return Register.Sounds.IRONMAN_STEP;
}

public abstract int getVerticalFlightModifier(boolean isSprinting);
public abstract int getHorizontalFlightModifier(boolean isSprinting);
}
Binary file not shown.
29 changes: 15 additions & 14 deletions src/main/resources/timeless.mixins.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"required": true,
"package": "mc.duzo.timeless.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"EnchantmentHelperMixin"
],
"client": [
"client.ArmorFeatureRendererMixin",
"client.PlayerEntityRendererMixin",
"client.PlayerEntityModelMixin",
"client.PerspectiveMixin"
],
"injectors": {
"defaultRequire": 1
"required": true,
"package": "mc.duzo.timeless.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"EnchantmentHelperMixin",
"EntityMixin"
],
"client": [
"client.ArmorFeatureRendererMixin",
"client.PerspectiveMixin",
"client.PlayerEntityModelMixin",
"client.PlayerEntityRendererMixin"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit be175d6

Please sign in to comment.