Skip to content
Open
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
39 changes: 19 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version "${loom_version}"
id 'net.fabricmc.fabric-loom' version "${loom_version}"
id 'maven-publish'
}

Expand All @@ -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")))

}

Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
15 changes: 7 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginManagement {
repositories {
jcenter()
mavenCentral()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
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;
import net.fabricmc.api.ClientModInitializer;
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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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"));
}
}
});
Expand All @@ -93,36 +94,36 @@ 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<SoundEvent> registryEntry;
Holder<SoundEvent> 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;
}

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) {
Expand All @@ -136,7 +137,7 @@ public void onInitializeClient() {


}
return ActionResult.PASS;
return InteractionResult.PASS;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<World> registryRef, DynamicRegistryManager registryManager, RegistryEntry<DimensionType> dimensionEntry, boolean isClient, boolean debugWorld, long seed, int maxChainedNeighborUpdates) {
protected ClientLevelMixin(WritableLevelData properties, ResourceKey<Level> registryRef, RegistryAccess registryManager, Holder<DimensionType> 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()) {
Expand Down Expand Up @@ -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<SoundEvent> sound,
SoundCategory category,
Holder<SoundEvent> 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) {

}
}
Loading