Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ modrinth {
projectId = "prefixes"
versionNumber = project.version.toString()
versionName = "Prefixes ${project.version}"
versionType = "alpha"
versionType = "release"
uploadFile = jar
gameVersions = [project.minecraft_version]
loaders = ["fabric"]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ loader_version=0.19.3
loom_version=1.17-SNAPSHOT

# Mod Properties
mod_version=1.0.7
mod_version=1.0.8
maven_group=dev.badtz.prefixes

# Dependencies
Expand Down
23 changes: 23 additions & 0 deletions src/client/java/dev/badtz/prefixes/client/PrefixClientSounds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.badtz.prefixes.client;

import dev.badtz.prefixes.PrefixApplier;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.item.ItemStack;

public final class PrefixClientSounds {
private PrefixClientSounds() {}

public static void playMiningSound(Minecraft minecraft, BlockPos pos, ItemStack stack) {
PrefixApplier.getHitSound(stack)
.ifPresent(sound -> BuiltInRegistries.SOUND_EVENT.get(sound.id())
.ifPresent(soundEvent -> minecraft.getSoundManager()
.play(new SimpleSoundInstance(soundEvent.value(),
SoundSource.PLAYERS, sound.volume(), sound.pitch(),
SoundInstance.createUnseededRandom(), pos))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,34 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.llamalad7.mixinextras.sugar.Local;
import dev.badtz.prefixes.PrefixApplier;
import dev.badtz.prefixes.PrefixManager;
import dev.badtz.prefixes.client.PrefixClientSounds;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.SoundType;

@Mixin(MultiPlayerGameMode.class)
public class MultiPlayerGameModeMixin {
@Shadow
@Final
private Minecraft minecraft;
@Shadow
@Final
private Minecraft minecraft;

@Shadow
private ItemStack destroyingItem;
@Shadow
private ItemStack destroyingItem;

@Inject(method = "continueDestroyBlock", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/sounds/SoundManager;play(Lnet/minecraft/client/resources/sounds/SoundInstance;)Lnet/minecraft/client/sounds/SoundEngine$PlayResult;"))
private void injectBlockBreakSound(BlockPos pos, Direction direction,
CallbackInfoReturnable<Boolean> cir, @Local(name = "soundType") SoundType soundType) {
PrefixApplier.getPrefix(destroyingItem).ifPresent(prefix -> {
if (prefix.type() != PrefixManager.PrefixType.TOOL) {
return;
}
@Inject(method = "continueDestroyBlock", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/sounds/SoundManager;play(Lnet/minecraft/client/resources/sounds/SoundInstance;)Lnet/minecraft/client/sounds/SoundEngine$PlayResult;"))
private void injectBlockBreakSound(BlockPos pos, Direction direction,
CallbackInfoReturnable<Boolean> cir) {
PrefixApplier.getPrefix(destroyingItem).ifPresent(prefix -> {
if (prefix.type() != PrefixManager.PrefixType.TOOL) {
return;
}

PrefixApplier.getHitSound(destroyingItem)
.ifPresent(sound -> BuiltInRegistries.SOUND_EVENT.get(sound.id())
.ifPresent(soundEvent -> minecraft.getSoundManager()
.play(new SimpleSoundInstance(soundEvent.value(),
SoundSource.PLAYERS,
((soundType.getVolume() + 1.0F) / 6.0F)
* sound.volume(),
soundType.getPitch() * sound.pitch(),
SoundInstance.createUnseededRandom(), pos))));
});
}
PrefixClientSounds.playMiningSound(minecraft, pos, destroyingItem);
});
}
}
10 changes: 10 additions & 0 deletions src/main/java/dev/badtz/prefixes/PrefixApplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
Expand Down Expand Up @@ -115,6 +118,13 @@ public static Optional<PrefixManager.PrefixSound> getHitSound(ItemStack stack) {
.filter(sound -> sound != null);
}

public static void playHitSound(ServerLevel level, Entity target, ItemStack stack) {
getHitSound(stack).ifPresent(sound -> BuiltInRegistries.SOUND_EVENT.get(sound.id())
.ifPresent(soundEvent -> level.playSound(null, target.getX(), target.getY(),
target.getZ(), soundEvent.value(), SoundSource.PLAYERS, sound.volume(),
sound.pitch())));
}

private static boolean hasPlayerCustomName(ItemStack stack,
PrefixManager.PrefixDefinition oldPrefix) {
Component customName = stack.get(DataComponents.CUSTOM_NAME);
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/dev/badtz/prefixes/mixin/KineticWeaponMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.badtz.prefixes.mixin;

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;
import dev.badtz.prefixes.PrefixApplier;
import dev.badtz.prefixes.PrefixManager;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.KineticWeapon;

@Mixin(KineticWeapon.class)
public abstract class KineticWeaponMixin {
@Inject(method = "damageEntities", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/level/Level;broadcastEntityEvent(Lnet/minecraft/world/entity/Entity;B)V"))
private void prefixes$playPrefixKineticHitSound(ItemStack stack, int ticksRemaining,
LivingEntity attacker, EquipmentSlot equipmentSlot, CallbackInfo ci) {
if (!(attacker.level() instanceof ServerLevel level)) {
return;
}

PrefixApplier.getPrefix(stack).ifPresent(prefix -> {
if (prefix.type() == PrefixManager.PrefixType.WEAPON) {
PrefixApplier.playHitSound(level, attacker, stack);
}
});
}
}
33 changes: 33 additions & 0 deletions src/main/java/dev/badtz/prefixes/mixin/PiercingWeaponMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.badtz.prefixes.mixin;

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;
import dev.badtz.prefixes.PrefixApplier;
import dev.badtz.prefixes.PrefixManager;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.PiercingWeapon;

@Mixin(PiercingWeapon.class)
public abstract class PiercingWeaponMixin {
@Inject(method = "attack", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/item/component/PiercingWeapon;makeHitSound(Lnet/minecraft/world/entity/Entity;)V"))
private void prefixes$playPrefixPiercingHitSound(LivingEntity attacker, EquipmentSlot hand,
CallbackInfo ci) {
if (!(attacker.level() instanceof ServerLevel level)) {
return;
}

ItemStack stack = attacker.getItemBySlot(hand);

PrefixApplier.getPrefix(stack).ifPresent(prefix -> {
if (prefix.type() == PrefixManager.PrefixType.WEAPON) {
PrefixApplier.playHitSound(level, attacker, stack);
}
});
}
}
8 changes: 1 addition & 7 deletions src/main/java/dev/badtz/prefixes/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import dev.badtz.prefixes.PrefixApplier;
import dev.badtz.prefixes.PrefixManager;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand All @@ -30,11 +28,7 @@ public abstract class PlayerMixin {
return;
}

PrefixApplier.getHitSound(stack)
.ifPresent(sound -> BuiltInRegistries.SOUND_EVENT.get(sound.id())
.ifPresent(soundEvent -> level.playSound(null, target.getX(),
target.getY(), target.getZ(), soundEvent.value(),
SoundSource.PLAYERS, sound.volume(), sound.pitch())));
PrefixApplier.playHitSound(level, target, stack);
});
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": 1,
"id": "prefixes",
"version": "${version}",
"name": "prefixes",
"name": "Prefixes",
"description": "prefixes for tools and weapons with a fun reforging mechanic",
"authors": [
"kamo.moe, chromadeline"
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/prefixes.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"CrafterBlockMixin",
"PlayerMixin",
"AbstractContainerMenuAccessor",
"InventoryMenuMixin"
"InventoryMenuMixin",
"PiercingWeaponMixin",
"KineticWeaponMixin"
],
"client": [],
"injectors": {
Expand Down