diff --git a/build.gradle b/build.gradle index 19535bf..a9671f5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version "${loom_version}" + id 'net.fabricmc.fabric-loom' version "${loom_version}" id 'maven-publish' } @@ -20,39 +20,38 @@ repositories { } configurations { - modIncludeImplementation + includeImplementation - include.extendsFrom modIncludeImplementation - modImplementation.extendsFrom modIncludeImplementation + include.extendsFrom mincludeImplementation + implementation.extendsFrom includeImplementation } dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + implementation "net.fabricmc:fabric-loader:${project.loader_version}" // Fabric API. This is technically optional, but you probably want it anyway. - //modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modIncludeImplementation fabricApi.module("fabric-api-base", project.fabric_version) - modIncludeImplementation fabricApi.module("fabric-events-interaction-v0", project.fabric_version) - modIncludeImplementation fabricApi.module("fabric-key-binding-api-v1", project.fabric_version) - modIncludeImplementation fabricApi.module("fabric-lifecycle-events-v1", project.fabric_version) - modIncludeImplementation fabricApi.module("fabric-screen-api-v1", project.fabric_version) + //implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + implementation fabricApi.module("fabric-api-base", project.fabric_version) + implementation fabricApi.module("fabric-events-interaction-v0", project.fabric_version) + implementation fabricApi.module("fabric-key-mapping-api-v1", project.fabric_version) + implementation fabricApi.module("fabric-lifecycle-events-v1", project.fabric_version) + implementation fabricApi.module("fabric-screen-api-v1", project.fabric_version) // Uncomment the following line to enable the deprecated Fabric API modules. // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. - // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" + // implementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" - modCompileOnly("com.terraformersmc:modmenu:${project.modmenu_version}") { + compileOnly("com.terraformersmc:modmenu:${project.modmenu_version}") { exclude group: 'net.fabricmc.fabric-api', module: 'fabric-api' } - modIncludeImplementation("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") { + includeImplementation("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") { exclude(group: "net.fabricmc.fabric-api") } - modIncludeImplementation(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:0.4.1"))) + includeImplementation(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:0.4.1"))) } @@ -69,8 +68,8 @@ processResources { } tasks.withType(JavaCompile).configureEach { - // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. - it.options.release = 17 + // Minecraft 26.1 (26.1 snapshot 1) upwards uses Java 25. + it.options.release = 25 } java { @@ -79,8 +78,8 @@ java { // If you remove this line, sources will not be generated. withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_25 + targetCompatibility = JavaVersion.VERSION_25 } jar { diff --git a/gradle.properties b/gradle.properties index 07e7abe..b08a038 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,18 +4,17 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.10 -yarn_mappings=1.21.10+build.2 -loader_version=0.17.3 -loom_version=1.13-SNAPSHOT +minecraft_version=26.2 +loader_version=0.19.3 +loom_version=1.17-SNAPSHOT # Fabric API -fabric_version=0.138.3+1.21.10 +fabric_version=0.152.2+26.2 # Mod Properties -mod_version=2.12 +mod_version=2.13 maven_group=me.dacubeking archives_base_name=clientsidenoteblocks # https://linkie.shedaniel.dev/dependencies?loader=fabric -modmenu_version=16.0.0-rc.1 -cloth_config_version=20.0.149 +modmenu_version=20.0.0-beta.3 +cloth_config_version=26.2.155 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5c82cb0..f0f17c3 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 5b60df3..27e3d10 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { repositories { - jcenter() + mavenCentral() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' diff --git a/src/main/java/me/dacubeking/clientsidenoteblocks/client/ClientSideNoteblocksClient.java b/src/main/java/me/dacubeking/clientsidenoteblocks/client/ClientSideNoteblocksClient.java index b7e9fc4..0020752 100644 --- a/src/main/java/me/dacubeking/clientsidenoteblocks/client/ClientSideNoteblocksClient.java +++ b/src/main/java/me/dacubeking/clientsidenoteblocks/client/ClientSideNoteblocksClient.java @@ -1,7 +1,7 @@ package me.dacubeking.clientsidenoteblocks.client; import me.dacubeking.clientsidenoteblocks.expiringmap.SelfExpiringHashMap; -import me.dacubeking.clientsidenoteblocks.mixininterfaces.ClientWorldInterface; +import me.dacubeking.clientsidenoteblocks.mixininterfaces.ClientLevelInterface; import me.dacubeking.clientsidenoteblocks.mixininterfaces.NoteblockInterface; import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.serializer.GsonConfigSerializer; @@ -9,28 +9,29 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper; import net.fabricmc.fabric.api.event.player.AttackBlockCallback; -import net.minecraft.block.BlockState; -import net.minecraft.block.NoteBlock; -import net.minecraft.block.enums.NoteBlockInstrument; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvent; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.BlockPos; +import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.level.block.NoteBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; import org.lwjgl.glfw.GLFW; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Logger; -import static net.minecraft.block.NoteBlock.INSTRUMENT; -import static net.minecraft.block.NoteBlock.NOTE; +import static net.minecraft.world.level.block.NoteBlock.INSTRUMENT; +import static net.minecraft.world.level.block.NoteBlock.NOTE; + +import com.mojang.blaze3d.platform.InputConstants; @Environment(EnvType.CLIENT) public class ClientSideNoteblocksClient implements ClientModInitializer { @@ -59,7 +60,7 @@ public static boolean shouldCancelStraySounds() { public static String namespace = "clientsidenoteblocks"; - public static KeyBinding.Category keybindCategory = KeyBinding.Category.create(Identifier.of(namespace, "keybinds")); + public static KeyMapping.Category keybindCategory = KeyMapping.Category.register(Identifier.fromNamespaceAndPath(namespace, "keybinds")); @Override public void onInitializeClient() { AutoConfig.register(ModConfig.class, GsonConfigSerializer::new); @@ -68,20 +69,20 @@ public void onInitializeClient() { NOTEBLOCK_SOUNDS_TO_CANCEL = new SelfExpiringHashMap<>((long) (config.maxTimeToServerSound * 1000), 100); - KeyBinding toggleKeybind = KeyBindingHelper.registerKeyBinding(new KeyBinding("Toggle", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_BRACKET, keybindCategory)); + KeyMapping toggleKeybind = KeyMappingHelper.registerKeyMapping(new KeyMapping("Toggle", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_BRACKET, keybindCategory)); ClientTickEvents.END_CLIENT_TICK.register(client -> { - while (toggleKeybind.wasPressed()) { + while (toggleKeybind.consumeClick()) { if (client.player == null) return; config.enabled = !config.enabled; if (config.enabled) { - client.player.sendMessage(Text.translatableWithFallback("text.clientsidenoteblocks.chat.enabled", - "ClientSideNoteblocks is Enabled"), false); + client.player.sendSystemMessage(Component.translatableWithFallback("text.clientsidenoteblocks.chat.enabled", + "ClientSideNoteblocks is Enabled")); } else { - client.player.sendMessage(Text.translatableWithFallback("text.clientsidenoteblocks.chat.disabled", - "ClientSideNoteblocks is Disabled"), false); + client.player.sendSystemMessage(Component.translatableWithFallback("text.clientsidenoteblocks.chat.disabled", + "ClientSideNoteblocks is Disabled")); } } }); @@ -93,21 +94,21 @@ public void onInitializeClient() { LOGGER.info("Max time to server sound changed to " + lastMaxTimeToServerSound); } - if (!isEnabled()) return ActionResult.PASS; - if (world.isClient() && !player.isCreative() && !player.isSpectator() + if (!isEnabled()) return InteractionResult.PASS; + if (world.isClientSide() && !player.isCreative() && !player.isSpectator() && world.getBlockState(pos).getBlock().getClass() == NoteBlock.class) { BlockState state = world.getBlockState(pos); - if (MinecraftClient.getInstance().world != null && - (state.get(INSTRUMENT).isNotBaseBlock() || world.getBlockState(pos.up()).isAir())) { - ClientWorldInterface clientWorldInterface = ((ClientWorldInterface) MinecraftClient.getInstance().world); + if (Minecraft.getInstance().level != null && + (state.getValue(INSTRUMENT).worksAboveNoteBlock() || world.getBlockState(pos.above()).isAir())) { + ClientLevelInterface clientLevelInterface = ((ClientLevelInterface) Minecraft.getInstance().level); - RegistryEntry registryEntry; + Holder registryEntry; float f; - NoteBlockInstrument instrument = state.get(INSTRUMENT); - if (instrument.canBePitched()) { - int i = state.get(NOTE); - f = NoteBlock.getNotePitch(i); + NoteBlockInstrument instrument = state.getValue(INSTRUMENT); + if (instrument.isTunable()) { + int i = state.getValue(NOTE); + f = NoteBlock.getPitchFromNote(i); } else { f = 1.0f; } @@ -115,14 +116,14 @@ public void onInitializeClient() { if (instrument.hasCustomSound()) { Identifier identifier = ((NoteblockInterface) state.getBlock()).clientSideNoteblocks$getCustomSoundPublic(world, pos); if (identifier == null) { - return ActionResult.PASS; + return InteractionResult.PASS; } - registryEntry = RegistryEntry.of(SoundEvent.of(identifier)); + registryEntry = Holder.direct(SoundEvent.createVariableRangeEvent(identifier)); } else { - registryEntry = instrument.getSound(); + registryEntry = instrument.getSoundEvent(); } - clientWorldInterface.clientSideNoteblocks$bypassedPlaySound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, registryEntry, SoundCategory.RECORDS, 3.0f, f, world.random.nextLong()); + clientLevelInterface.clientSideNoteblocks$bypassedPlaySound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, registryEntry, SoundSource.RECORDS, 3.0f, f, world.getRandom().nextLong()); synchronized (NOTEBLOCK_SOUNDS_TO_CANCEL_LOCK) { @@ -136,7 +137,7 @@ public void onInitializeClient() { } - return ActionResult.PASS; + return InteractionResult.PASS; }); } } diff --git a/src/main/java/me/dacubeking/clientsidenoteblocks/client/ModMenu.java b/src/main/java/me/dacubeking/clientsidenoteblocks/client/ModMenu.java index be4f84b..b36def5 100644 --- a/src/main/java/me/dacubeking/clientsidenoteblocks/client/ModMenu.java +++ b/src/main/java/me/dacubeking/clientsidenoteblocks/client/ModMenu.java @@ -2,11 +2,13 @@ import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; -import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.AutoConfigClient; public class ModMenu implements ModMenuApi { @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return parent -> AutoConfig.getConfigScreen(ModConfig.class, parent).get(); + public ConfigScreenFactory getModConfigScreenFactory() + { + return parent -> AutoConfigClient + .getConfigScreen(ModConfig.class, parent).get(); } } diff --git a/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/ClientWorldMixin.java b/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/ClientLevelMixin.java similarity index 59% rename from src/main/java/me/dacubeking/clientsidenoteblocks/mixin/ClientWorldMixin.java rename to src/main/java/me/dacubeking/clientsidenoteblocks/mixin/ClientLevelMixin.java index 70b6953..e9d2384 100644 --- a/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/ClientWorldMixin.java +++ b/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/ClientLevelMixin.java @@ -1,22 +1,21 @@ package me.dacubeking.clientsidenoteblocks.mixin; import me.dacubeking.clientsidenoteblocks.client.ClientSideNoteblocksClient; -import me.dacubeking.clientsidenoteblocks.mixininterfaces.ClientWorldInterface; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.registry.DynamicRegistryManager; -import net.minecraft.registry.RegistryKey; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvent; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; -import net.minecraft.util.profiler.Profiler; -import net.minecraft.world.MutableWorldProperties; -import net.minecraft.world.World; -import net.minecraft.world.dimension.DimensionType; +import me.dacubeking.clientsidenoteblocks.mixininterfaces.ClientLevelInterface; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.core.RegistryAccess; +import net.minecraft.resources.ResourceKey; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundSource; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.storage.WritableLevelData; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -26,30 +25,29 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Supplier; import static me.dacubeking.clientsidenoteblocks.client.ClientSideNoteblocksClient.NOTEBLOCK_SOUNDS_TO_CANCEL; import static me.dacubeking.clientsidenoteblocks.client.ClientSideNoteblocksClient.NOTEBLOCK_SOUNDS_TO_CANCEL_LOCK; -@Mixin(ClientWorld.class) -public abstract class ClientWorldMixin extends World implements ClientWorldInterface { +@Mixin(ClientLevel.class) +public abstract class ClientLevelMixin extends Level implements ClientLevelInterface { @Final @Shadow - private MinecraftClient client; + private Minecraft minecraft; @Shadow @Final - private static double PARTICLE_Y_OFFSET; + private static double FLUID_PARTICLE_SPAWN_OFFSET; // Ignored by Mixin - protected ClientWorldMixin(MutableWorldProperties properties, RegistryKey registryRef, DynamicRegistryManager registryManager, RegistryEntry dimensionEntry, boolean isClient, boolean debugWorld, long seed, int maxChainedNeighborUpdates) { + protected ClientLevelMixin(WritableLevelData properties, ResourceKey registryRef, RegistryAccess registryManager, Holder dimensionEntry, boolean isClient, boolean debugWorld, long seed, int maxChainedNeighborUpdates) { super(properties, registryRef, registryManager, dimensionEntry, isClient, debugWorld, seed, maxChainedNeighborUpdates); } - @Inject(method = "playSound(DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FFZJ)V", at = @At("HEAD"), cancellable = true) - public void playSound(double x, double y, double z, SoundEvent event, SoundCategory category, float volume, float pitch, boolean useDistance, long seed, CallbackInfo ci) { + @Inject(method = "playSound(DDDLnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FFZJ)V", at = @At("HEAD"), cancellable = true) + public void playSound(double x, double y, double z, SoundEvent event, SoundSource category, float volume, float pitch, boolean useDistance, long seed, CallbackInfo ci) { BlockPos pos = new BlockPos((int) (x - 0.5), (int) (y - 0.5), (int) (z - 0.5)); if (ClientSideNoteblocksClient.isEnabled()) { @@ -81,21 +79,21 @@ public void playSound(double x, double y, double z, SoundEvent event, SoundCateg @Override public void clientSideNoteblocks$bypassedPlaySound( - @Nullable PlayerEntity except, + @Nullable Player except, double x, double y, double z, - RegistryEntry sound, - SoundCategory category, + Holder sound, + SoundSource category, float volume, float pitch, long seed) { if (ClientSideNoteblocksClient.isDebug()) { ClientSideNoteblocksClient.LOGGER.info("Bypassed played sound"); } - PositionedSoundInstance positionedSoundInstance = new PositionedSoundInstance(sound.value(), category, volume, pitch, Random.create(seed), x, y, z); + SimpleSoundInstance positionedSoundInstance = new SimpleSoundInstance(sound.value(), category, volume, pitch, RandomSource.create(seed), x, y, z); - this.client.getSoundManager().play(positionedSoundInstance); + this.minecraft.getSoundManager().play(positionedSoundInstance); } @Shadow - private void playSound(double x, double y, double z, SoundEvent event, SoundCategory category, float volume, float pitch, boolean useDistance, long seed) { + private void playSound(double x, double y, double z, SoundEvent event, SoundSource category, float volume, float pitch, boolean useDistance, long seed) { } } diff --git a/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/ClientPlayerInteractionManagerMixin.java b/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/ClientPlayerInteractionManagerMixin.java deleted file mode 100644 index d45f2eb..0000000 --- a/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/ClientPlayerInteractionManagerMixin.java +++ /dev/null @@ -1,50 +0,0 @@ -package me.dacubeking.clientsidenoteblocks.mixin; - -import me.dacubeking.clientsidenoteblocks.client.ClientSideNoteblocksClient; -import net.minecraft.block.Blocks; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.network.ClientPlayerInteractionManager; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.sound.SoundInstance; -import net.minecraft.client.sound.SoundManager; -import net.minecraft.client.sound.SoundSystem; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -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.Redirect; - -import static net.minecraft.block.NoteBlock.INSTRUMENT; - -@Mixin(ClientPlayerInteractionManager.class) -public abstract class ClientPlayerInteractionManagerMixin { - - @Final - @Shadow - private MinecraftClient client; - - @Shadow - @Final - private ClientPlayNetworkHandler networkHandler; - - @Redirect(method = "updateBlockBreakingProgress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/SoundManager;play(Lnet/minecraft/client/sound/SoundInstance;)Lnet/minecraft/client/sound/SoundSystem$PlayResult;")) - public SoundSystem.PlayResult cancelBlockBreakSound(SoundManager instance, SoundInstance sound, BlockPos pos, Direction direction) { - World world = this.client.world; - ClientPlayerEntity player = this.client.player; - if (!ClientSideNoteblocksClient.isEnabled() - || world == null || player == null - || player.isCreative() || player.isSpectator() - || world.getBlockState(pos).getBlock() != Blocks.NOTE_BLOCK - || (world.getBlockState(pos).get(INSTRUMENT).isNotBaseBlock() || !world.getBlockState(pos.up()).isAir())) { - this.client.getSoundManager().play(sound); - } else if (ClientSideNoteblocksClient.isDebug()) { - ClientSideNoteblocksClient.LOGGER.info("Cancelled block break sound"); - } - return null; - } -} diff --git a/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/MultiPlayerGameModeMixin.java b/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/MultiPlayerGameModeMixin.java new file mode 100644 index 0000000..23a625c --- /dev/null +++ b/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/MultiPlayerGameModeMixin.java @@ -0,0 +1,49 @@ +package me.dacubeking.clientsidenoteblocks.mixin; + +import me.dacubeking.clientsidenoteblocks.client.ClientSideNoteblocksClient; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.client.resources.sounds.SoundInstance; +import net.minecraft.client.sounds.SoundEngine; +import net.minecraft.client.sounds.SoundManager; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import org.spongepowered.asm.mixin.Final; +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.Redirect; + +import static net.minecraft.world.level.block.NoteBlock.INSTRUMENT; + +@Mixin(MultiPlayerGameMode.class) +public abstract class MultiPlayerGameModeMixin { + + @Final + @Shadow + private Minecraft minecraft; + + @Shadow + @Final + private ClientPacketListener connection; + + @Redirect(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;")) + public SoundEngine.PlayResult cancelBlockBreakSound(SoundManager instance, SoundInstance sound, BlockPos pos, Direction direction) { + Level world = this.minecraft.level; + LocalPlayer player = this.minecraft.player; + if (!ClientSideNoteblocksClient.isEnabled() + || world == null || player == null + || player.isCreative() || player.isSpectator() + || world.getBlockState(pos).getBlock() != Blocks.NOTE_BLOCK + || (world.getBlockState(pos).getValue(INSTRUMENT).worksAboveNoteBlock() || !world.getBlockState(pos.above()).isAir())) { + this.minecraft.getSoundManager().play(sound); + } else if (ClientSideNoteblocksClient.isDebug()) { + ClientSideNoteblocksClient.LOGGER.info("Cancelled block break sound"); + } + return null; + } +} diff --git a/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/NoteblockMixin.java b/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/NoteblockMixin.java index 16b419c..bdd855b 100644 --- a/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/NoteblockMixin.java +++ b/src/main/java/me/dacubeking/clientsidenoteblocks/mixin/NoteblockMixin.java @@ -1,28 +1,28 @@ package me.dacubeking.clientsidenoteblocks.mixin; import me.dacubeking.clientsidenoteblocks.mixininterfaces.NoteblockInterface; -import net.minecraft.block.Block; -import net.minecraft.block.NoteBlock; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.Identifier; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.NoteBlock; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @Mixin(NoteBlock.class) public abstract class NoteblockMixin extends Block implements NoteblockInterface { - public NoteblockMixin(Settings settings) { + public NoteblockMixin(Properties settings) { super(settings); } @Shadow @Nullable - protected abstract Identifier getCustomSound(World world, BlockPos pos); + protected abstract Identifier getCustomSoundId(Level world, BlockPos pos); @Override - public Identifier clientSideNoteblocks$getCustomSoundPublic(World world, BlockPos pos) { - return getCustomSound(world, pos); + public Identifier clientSideNoteblocks$getCustomSoundPublic(Level world, BlockPos pos) { + return getCustomSoundId(world, pos); } } diff --git a/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/ClientLevelInterface.java b/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/ClientLevelInterface.java new file mode 100644 index 0000000..fdbc6c9 --- /dev/null +++ b/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/ClientLevelInterface.java @@ -0,0 +1,13 @@ +package me.dacubeking.clientsidenoteblocks.mixininterfaces; + +import net.minecraft.core.Holder; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.Nullable; + +public interface ClientLevelInterface { + + + void clientSideNoteblocks$bypassedPlaySound(@Nullable Player except, double x, double y, double z, Holder sound, SoundSource category, float volume, float pitch, long seed); +} diff --git a/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/ClientWorldInterface.java b/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/ClientWorldInterface.java deleted file mode 100644 index b2efb8f..0000000 --- a/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/ClientWorldInterface.java +++ /dev/null @@ -1,13 +0,0 @@ -package me.dacubeking.clientsidenoteblocks.mixininterfaces; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvent; -import org.jetbrains.annotations.Nullable; - -public interface ClientWorldInterface { - - - void clientSideNoteblocks$bypassedPlaySound(@Nullable PlayerEntity except, double x, double y, double z, RegistryEntry sound, SoundCategory category, float volume, float pitch, long seed); -} diff --git a/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/NoteblockInterface.java b/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/NoteblockInterface.java index fecd326..f95783c 100644 --- a/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/NoteblockInterface.java +++ b/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/NoteblockInterface.java @@ -1,9 +1,9 @@ package me.dacubeking.clientsidenoteblocks.mixininterfaces; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.Identifier; +import net.minecraft.world.level.Level; public interface NoteblockInterface { - Identifier clientSideNoteblocks$getCustomSoundPublic(World world, BlockPos pos); + Identifier clientSideNoteblocks$getCustomSoundPublic(Level world, BlockPos pos); } diff --git a/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/SoundHandlerInterface.java b/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/SoundHandlerInterface.java index 854bc47..9275480 100644 --- a/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/SoundHandlerInterface.java +++ b/src/main/java/me/dacubeking/clientsidenoteblocks/mixininterfaces/SoundHandlerInterface.java @@ -1,6 +1,6 @@ package me.dacubeking.clientsidenoteblocks.mixininterfaces; -import net.minecraft.client.sound.SoundInstance; +import net.minecraft.client.resources.sounds.SoundInstance; public interface SoundHandlerInterface { void bypassedPlay(SoundInstance sound); diff --git a/src/main/resources/clientsidenoteblocks.accesswidener b/src/main/resources/clientsidenoteblocks.accesswidener index 0b8698b..33eaa64 100644 --- a/src/main/resources/clientsidenoteblocks.accesswidener +++ b/src/main/resources/clientsidenoteblocks.accesswidener @@ -1 +1 @@ -accessWidener v1 named +accessWidener v1 official diff --git a/src/main/resources/clientsidenoteblocks.mixins.json b/src/main/resources/clientsidenoteblocks.mixins.json index f27daa5..5f6fa6a 100644 --- a/src/main/resources/clientsidenoteblocks.mixins.json +++ b/src/main/resources/clientsidenoteblocks.mixins.json @@ -2,10 +2,10 @@ "required": true, "minVersion": "0.8", "package": "me.dacubeking.clientsidenoteblocks.mixin", - "compatibilityLevel": "JAVA_21", + "compatibilityLevel": "JAVA_25", "mixins": [ - "ClientPlayerInteractionManagerMixin", - "ClientWorldMixin", + "ClientLevelMixin", + "MultiPlayerGameModeMixin", "NoteblockMixin" ], "client": [ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e62a097..450d5cd 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,9 +27,9 @@ "clientsidenoteblocks.mixins.json" ], "depends": { - "fabricloader": ">=0.14.21", - "minecraft": "~1.21.10", - "java": ">=17" + "fabricloader": ">=0.19.3", + "minecraft": "~26.2", + "java": ">=25" }, "suggests": { "modmenu": ">=4.1.0"