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
50 changes: 25 additions & 25 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 @@ -14,45 +14,44 @@ repositories {
// for more information about repositories.

maven {
url "https://maven.terraformersmc.com/releases";
url = "https://maven.terraformersmc.com/releases"
}
maven { url "https://maven.shedaniel.me/" }
maven { url = "https://maven.shedaniel.me/" }
}

configurations {
modIncludeImplementation
includeImplementation

include.extendsFrom modIncludeImplementation
modImplementation.extendsFrom modIncludeImplementation
include.extendsFrom includeImplementation
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 @@ -61,16 +60,17 @@ base {
}

processResources {
inputs.property "version", project.version
def modVersion = project.version
inputs.property "version", modVersion

filesMatching("fabric.mod.json") {
expand "version": project.version
expand "version": modVersion
}
}

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 +79,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 Expand Up @@ -108,4 +108,4 @@ publishing {

loom {
accessWidenerPath = file("src/main/resources/clientsidenoteblocks.accesswidener")
}
}
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();
}
}
Loading