From c0727fccba191ff1c41740ae7b55eb6c7d39f2cc Mon Sep 17 00:00:00 2001 From: StavWasPlayZ Date: Fri, 10 Nov 2023 01:16:10 +0200 Subject: [PATCH] Update mod to GI v3.4, mod to v2.2 --- .gitignore | 1 + build.gradle | 7 +- gradle.properties | 4 +- .../block/blockentity/LooperBlockEntity.java | 653 +++++++++--------- .../NoteBlockInstrumentScreen.java | 11 +- .../gui/instrument/violin/ViolinScreen.java | 2 +- .../evenmoreinstruments/sound/ModSounds.java | 43 +- .../evenmoreinstruments/util/LooperUtil.java | 247 ++++--- .../instrument/guitar/instrument_style.json | 10 +- .../instrument/keyboard/instrument_style.json | 11 +- .../instrument/trombone/instrument_style.json | 8 +- .../instrument/violin/instrument_style.json | 9 +- src/main/resources/fabric.mod.json | 2 +- 13 files changed, 524 insertions(+), 484 deletions(-) diff --git a/.gitignore b/.gitignore index c476faf..2b006c4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ build/ out/ classes/ +libs/ # eclipse diff --git a/build.gradle b/build.gradle index b9a8253..722642c 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,10 @@ repositories { maven { url 'https://maven.terraformersmc.com/releases/' } } + flatDir { + dir 'libs' + } + exclusiveContent { forRepository { maven { @@ -53,7 +57,8 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation "maven.modrinth:genshin-instruments:${project.genshinstrument_version}" +// modImplementation "maven.modrinth:genshin-instruments:${project.genshinstrument_version}" + modImplementation "idc:genshinstrument-fabric:${project.minecraft_version}-${project.genshinstrument_version}" modImplementation "curse.maven:forge-config-api-port-fabric-547434:${project.forge_config_api_port_version}" modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}" diff --git a/gradle.properties b/gradle.properties index d41db29..56df29e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,12 +9,12 @@ parchment_mappings=1.20.1:2023.07.02 loader_version=0.14.21 # Mod Properties -mod_version=b2.1 +mod_version=2.2 maven_group=com.cstav.evenmoreinstruments archives_base_name=evenmoreinstruments # Dependencies fabric_version=0.90.0+1.20.1 modmenu_version=7.1.0 -genshinstrument_version=fabric-1.20+1.20.1-3.3.1 +genshinstrument_version=3.4 forge_config_api_port_version=4583000 \ No newline at end of file diff --git a/src/main/java/com/cstav/evenmoreinstruments/block/blockentity/LooperBlockEntity.java b/src/main/java/com/cstav/evenmoreinstruments/block/blockentity/LooperBlockEntity.java index 1132185..b8611b5 100644 --- a/src/main/java/com/cstav/evenmoreinstruments/block/blockentity/LooperBlockEntity.java +++ b/src/main/java/com/cstav/evenmoreinstruments/block/blockentity/LooperBlockEntity.java @@ -1,331 +1,322 @@ -// package com.cstav.evenmoreinstruments.block.blockentity; - -// import java.util.ArrayList; -// import java.util.HashSet; -// import java.util.Optional; -// import java.util.UUID; - -// import org.slf4j.Logger; - -// import com.cstav.evenmoreinstruments.Main; -// import com.cstav.evenmoreinstruments.block.IDoubleBlock; -// import com.cstav.evenmoreinstruments.block.LooperBlock; -// import com.cstav.evenmoreinstruments.block.ModBlocks; -// import com.cstav.evenmoreinstruments.gamerule.ModGameRules; -// import com.cstav.evenmoreinstruments.util.CommonUtil; -// import com.cstav.evenmoreinstruments.util.LooperUtil; -// import com.cstav.genshinstrument.event.InstrumentPlayedEvent; -// import com.cstav.genshinstrument.sound.NoteSound; -// import com.cstav.genshinstrument.util.ServerUtil; -// import com.mojang.logging.LogUtils; - -// import net.minecraft.core.BlockPos; -// import net.minecraft.nbt.CompoundTag; -// import net.minecraft.nbt.Tag; -// import net.minecraft.resources.ResourceLocation; -// import net.minecraft.sounds.SoundEvent; -// import net.minecraft.world.item.ItemStack; -// import net.minecraft.world.level.Level; -// import net.minecraft.world.level.block.entity.BlockEntity; -// import net.minecraft.world.level.block.state.BlockState; -// import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent; -// import net.minecraftforge.eventbus.api.SubscribeEvent; -// import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -// import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; - -//TODO re-implement -// @EventBusSubscriber(bus = Bus.FORGE, modid = Main.MODID) -// public class LooperBlockEntity extends BlockEntity { -// private static final Logger LOGGER = LogUtils.getLogger(); - -// private static final HashSet RECORDING_LOOPERS = new HashSet<>(); -// private UUID lockedBy; - -// public CompoundTag getChannel() { -// return getChannel(getPersistentData()); -// } -// public CompoundTag getChannel(final CompoundTag data) { -// return CommonUtil.getOrCreateElementTag(data, "channel"); -// } - -// public boolean hasChannel() { -// return getPersistentData().contains("channel"); -// } - - -// public LooperBlockEntity(BlockPos pPos, BlockState pBlockState) { -// super(ModBlockEntities.LOOPER.get(), pPos, pBlockState); - -// final CompoundTag data = getPersistentData(); - -// // Construct all the data stuff -// if (!data.contains("ticks", CompoundTag.TAG_INT)) -// setTicks(0); -// if (!data.contains("repeatTick", CompoundTag.TAG_INT)) -// setRepeatTick(-1); -// } -// @Override -// public void setRemoved() { -// RECORDING_LOOPERS.remove(this); -// } - - -// public void setRecording(final boolean recording) { -// getPersistentData().putBoolean("recording", recording); - -// if (recording) -// RECORDING_LOOPERS.add(this); -// else -// RECORDING_LOOPERS.remove(this); -// } - -// public void setTicks(final int ticks) { -// getPersistentData().putInt("ticks", ticks); -// } -// /** -// * Increment the ticks of this looper by 1. Wrap back to the start -// * if the track finished playing. -// * @return The new tick value -// */ -// public int incrementTick() { -// int ticks = getTicks(); - -// // Wrap back to the start when we finished playing -// final int repTick = getRepeatTick(); -// if ((repTick != -1) && (ticks > repTick)) -// ticks = 0; -// else -// ticks++; - -// setTicks(ticks); -// setChanged(); - -// return ticks; -// } -// public void setRepeatTick(final int tick) { -// getPersistentData().putInt("repeatTick", tick); -// } - -// public void setLockedBy(final UUID player) { -// lockedBy = player; -// } - -// public void lock() { -// getPersistentData().putBoolean("locked", true); -// lockedBy = null; - -// setRepeatTick(getTicks()); -// setRecording(false); - -// setChanged(); -// } -// //TODO implement to Looper GUI -// /** -// * This method resets the looper, assuming it is not recording. -// */ -// public void reset() { -// getPersistentData().remove("locked"); -// getPersistentData().remove("lockedBy"); -// lockedBy = null; - -// setRepeatTick(-1); -// setTicks(0); - -// getPersistentData().remove("channel"); -// } - -// public boolean isLocked() { -// return lockedByAnyone() || getPersistentData().getBoolean("locked"); -// } -// public boolean isRecording() { -// return getPersistentData().getBoolean("recording"); -// } - -// public boolean isAllowedToRecord(final UUID player) { -// return !lockedByAnyone() || isLockedBy(player); -// } -// public boolean lockedByAnyone() { -// return lockedBy != null; -// } -// public boolean isLockedBy(final UUID player) { -// return lockedBy.equals(player); -// } - -// public int getTicks() { -// return getPersistentData().getInt("ticks"); -// } -// public int getRepeatTick() { -// return getPersistentData().getInt("repeatTick"); -// } - - -// public void addNote(NoteSound sound, int pitch, float volume, int timestamp) { -// final CompoundTag channel = getChannel(); -// final CompoundTag noteTag = new CompoundTag(); - - -// noteTag.putInt("pitch", pitch); -// noteTag.putFloat("volume", volume); - -// noteTag.putString("mono", sound.getMono().getLocation().toString()); -// sound.getStereo().ifPresent((stereo) -> -// noteTag.putString("stereo", stereo.getLocation().toString()) -// ); - -// noteTag.putInt("timestamp", timestamp); - - -// CommonUtil.getOrCreateListTag(channel, "notes").add(noteTag); -// setChanged(); -// } - - -// public void tick(Level pLevel, BlockPos pPos, BlockState pState) { -// // idk why but it needs to be here for it to work -// final LooperBlockEntity lbe = getLBE(pLevel, pPos); -// final boolean isPlaying = lbe.getBlockState().getValue(LooperBlock.PLAYING); - -// if (!isPlaying && !lbe.isRecording()) -// return; - -// final int ticks = lbe.incrementTick(); - -// if (!isPlaying) -// return; - - -// final CompoundTag channel = lbe.getChannel(); -// final ResourceLocation instrumentId = new ResourceLocation(channel.getString("instrumentId")); - -// for (final Tag pNote : channel.getList("notes", Tag.TAG_COMPOUND)) { -// if (!(pNote instanceof CompoundTag)) -// continue; - -// final CompoundTag note = (CompoundTag)pNote; -// if (ticks != note.getInt("timestamp")) -// continue; - -// try { - -// final String stereoLoc = note.getString("stereo"); -// final int pitch = note.getInt("pitch"); -// // Volume property did not exist before v2.1 -// final float volume = note.contains("volume", Tag.TAG_FLOAT) ? note.getFloat("volume") : 1; - -// ServerUtil.sendPlayNotePackets(pLevel, pPos, -// new NoteSound( -// new SoundEvent(new ResourceLocation(note.getString("mono"))), -// stereoLoc.equals("") ? Optional.empty() : Optional.of( -// new SoundEvent(new ResourceLocation(stereoLoc)) -// ) -// ), instrumentId, -// pitch, volume -// ); - -// pLevel.blockEvent(pPos, ModBlocks.LOOPER.get(), 42, pitch); - -// } catch (Exception e) { -// LOGGER.error("Attempted to play a looper note, but met with an exception", e); -// } -// } -// } - - - -// public static LooperBlockEntity getLBE(final Level level, final ItemStack instrument) { -// return getLBE(level, LooperUtil.looperTag(instrument), () -> LooperUtil.remLooperTag(instrument)); -// } -// public static LooperBlockEntity getLBE(final Level level, final BlockEntity instrument) { -// return getLBE(level, LooperUtil.looperTag(instrument), () -> { -// LooperUtil.remLooperTag(instrument); - -// final BlockPos pos = instrument.getBlockPos(); -// final BlockState state = level.getBlockState(pos); -// if (state.getBlock() instanceof IDoubleBlock doubleBlock) -// LooperUtil.remLooperTag(level.getBlockEntity(doubleBlock.getOtherBlock(state, pos, level))); -// }); -// } -// /** -// * Attempts to get the looper pointed out by {@code looperData}. Removes its reference if not found. -// * @return The Looper's block entity as pointed in the {@code instrument}'s data. -// * Null if not found -// */ -// private static LooperBlockEntity getLBE(Level level, CompoundTag looperData, Runnable onInvalid) { -// if (looperData.isEmpty()) -// return null; - -// final LooperBlockEntity looperBE = getLBE(level, LooperUtil.getLooperPos(looperData)); - -// if (looperBE == null) -// onInvalid.run(); - -// return looperBE; -// } - -// private static LooperBlockEntity getLBE(final Level level, final BlockPos pos) { -// return (level.getBlockEntity(pos) instanceof LooperBlockEntity lbe) ? lbe : null; -// } - - - -// @SubscribeEvent -// public static void onInstrumentPlayed(final InstrumentPlayedEvent.ByPlayer event) { -// if (event.isClientSide || !LooperUtil.isRecording(LooperUtil.getLooperTagFromEvent(event))) -// return; - -// final Level level = event.player.getLevel(); - -// final LooperBlockEntity looperBE = event.itemInstrument.isPresent() -// ? getLBE(level, event.itemInstrument.get()) -// : getLBE(level, event.level.getBlockEntity(event.blockInstrumentPos.get())); - -// if (looperBE == null) -// return; - -// if (looperBE.isCapped(level)) -// return; - - -// if (looperBE.isLocked()) { -// if (!looperBE.isRecording() || !looperBE.isAllowedToRecord(event.player.getUUID())) -// return; -// } else { -// looperBE.setLockedBy(event.player.getUUID()); -// looperBE.setRecording(true); -// looperBE.getChannel().putString("instrumentId", event.instrumentId.toString()); -// } - -// looperBE.addNote(event.sound, event.pitch, event.volume, looperBE.getTicks()); -// looperBE.setChanged(); -// } - -// /** -// * A capped looper is a looper that cannot have any more notes in it, as defined in {@link ModGameRules#RULE_LOOPER_MAX_NOTES}. -// * Any negative will make the looper uncappable. -// * @return Whether this looper is capped -// */ -// public boolean isCapped(final Level level) { -// final int cap = level.getGameRules().getInt(ModGameRules.RULE_LOOPER_MAX_NOTES); -// return (cap >= 0) && (getChannel().getList("notes", Tag.TAG_COMPOUND).size() >= cap); -// } - - -// // If the player leaves the world, we shouldn't record anymore -// @SubscribeEvent -// public static void onPlayerLeave(final PlayerLoggedOutEvent event) { -// final ArrayList toBeRemoved = new ArrayList<>(); - -// //TODO keep track of where player recording to in (future) record data tag -// // Thus limit the possibilities of player recording at once to 1 -// RECORDING_LOOPERS.forEach((looper) -> { -// if (looper.lockedBy.equals(event.getEntity().getUUID())) { -// looper.reset(); -// looper.getPersistentData().putBoolean("recording", false); -// toBeRemoved.add(looper); -// } -// }); - -// RECORDING_LOOPERS.removeAll(toBeRemoved); -// } - -// } +//package com.cstav.evenmoreinstruments.block.blockentity; +// +//import java.util.ArrayList; +//import java.util.HashSet; +//import java.util.UUID; +// +//import org.slf4j.Logger; +// +//import com.cstav.evenmoreinstruments.Main; +//import com.cstav.evenmoreinstruments.block.IDoubleBlock; +//import com.cstav.evenmoreinstruments.block.LooperBlock; +//import com.cstav.evenmoreinstruments.block.ModBlocks; +//import com.cstav.evenmoreinstruments.gamerule.ModGameRules; +//import com.cstav.evenmoreinstruments.util.CommonUtil; +//import com.cstav.evenmoreinstruments.util.LooperUtil; +//import com.cstav.genshinstrument.event.InstrumentPlayedEvent; +//import com.cstav.genshinstrument.sound.NoteSound; +//import com.cstav.genshinstrument.sound.NoteSoundRegistrar; +//import com.cstav.genshinstrument.util.ServerUtil; +//import com.mojang.logging.LogUtils; +// +//import net.minecraft.core.BlockPos; +//import net.minecraft.nbt.CompoundTag; +//import net.minecraft.nbt.Tag; +//import net.minecraft.resources.ResourceLocation; +//import net.minecraft.world.item.ItemStack; +//import net.minecraft.world.level.Level; +//import net.minecraft.world.level.block.entity.BlockEntity; +//import net.minecraft.world.level.block.state.BlockState; +//import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent; +//import net.minecraftforge.eventbus.api.SubscribeEvent; +//import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +//import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; +// +//@EventBusSubscriber(bus = Bus.FORGE, modid = Main.MODID) +//public class LooperBlockEntity extends BlockEntity { +// private static final Logger LOGGER = LogUtils.getLogger(); +// +// private static final HashSet RECORDING_LOOPERS = new HashSet<>(); +// private UUID lockedBy; +// +// public CompoundTag getChannel() { +// return getChannel(getPersistentData()); +// } +// public CompoundTag getChannel(final CompoundTag data) { +// return CommonUtil.getOrCreateElementTag(data, "channel"); +// } +// +// public boolean hasChannel() { +// return getPersistentData().contains("channel"); +// } +// +// +// public LooperBlockEntity(BlockPos pPos, BlockState pBlockState) { +// super(ModBlockEntities.LOOPER.get(), pPos, pBlockState); +// +// final CompoundTag data = getPersistentData(); +// +// // Construct all the data stuff +// if (!data.contains("ticks", CompoundTag.TAG_INT)) +// setTicks(0); +// if (!data.contains("repeatTick", CompoundTag.TAG_INT)) +// setRepeatTick(-1); +// } +// @Override +// public void setRemoved() { +// RECORDING_LOOPERS.remove(this); +// } +// +// +// public void setRecording(final boolean recording) { +// getPersistentData().putBoolean("recording", recording); +// +// if (recording) +// RECORDING_LOOPERS.add(this); +// else +// RECORDING_LOOPERS.remove(this); +// } +// +// public void setTicks(final int ticks) { +// getPersistentData().putInt("ticks", ticks); +// } +// /** +// * Increment the ticks of this looper by 1. Wrap back to the start +// * if the track finished playing. +// * @return The new tick value +// */ +// public int incrementTick() { +// int ticks = getTicks(); +// +// // Wrap back to the start when we finished playing +// final int repTick = getRepeatTick(); +// if ((repTick != -1) && (ticks > repTick)) +// ticks = 0; +// else +// ticks++; +// +// setTicks(ticks); +// setChanged(); +// +// return ticks; +// } +// public void setRepeatTick(final int tick) { +// getPersistentData().putInt("repeatTick", tick); +// } +// +// public void setLockedBy(final UUID player) { +// lockedBy = player; +// } +// +// public void lock() { +// getPersistentData().putBoolean("locked", true); +// lockedBy = null; +// +// setRepeatTick(getTicks()); +// setRecording(false); +// +// setChanged(); +// } +// //TODO implement to Looper GUI +// /** +// * This method resets the looper, assuming it is not recording. +// */ +// public void reset() { +// getPersistentData().remove("locked"); +// getPersistentData().remove("lockedBy"); +// lockedBy = null; +// +// setRepeatTick(-1); +// setTicks(0); +// +// getPersistentData().remove("channel"); +// } +// +// public boolean isLocked() { +// return lockedByAnyone() || getPersistentData().getBoolean("locked"); +// } +// public boolean isRecording() { +// return getPersistentData().getBoolean("recording"); +// } +// +// public boolean isAllowedToRecord(final UUID player) { +// return !lockedByAnyone() || isLockedBy(player); +// } +// public boolean lockedByAnyone() { +// return lockedBy != null; +// } +// public boolean isLockedBy(final UUID player) { +// return lockedBy.equals(player); +// } +// +// public int getTicks() { +// return getPersistentData().getInt("ticks"); +// } +// public int getRepeatTick() { +// return getPersistentData().getInt("repeatTick"); +// } +// +// +// public void addNote(NoteSound sound, int pitch, int volume, int timestamp) { +// final CompoundTag channel = getChannel(); +// final CompoundTag noteTag = new CompoundTag(); +// +// +// noteTag.putInt("soundIndex", sound.index); +// noteTag.putString("soundType", sound.baseSoundLocation.toString()); +// +// noteTag.putInt("pitch", pitch); +// noteTag.putFloat("volume", volume / 100f); +// +// noteTag.putInt("timestamp", timestamp); +// +// +// CommonUtil.getOrCreateListTag(channel, "notes").add(noteTag); +// setChanged(); +// } +// +// +// public void tick(Level pLevel, BlockPos pPos, BlockState pState) { +// // idk why but it needs to be here for it to work +// final LooperBlockEntity lbe = getLBE(pLevel, pPos); +// final boolean isPlaying = lbe.getBlockState().getValue(LooperBlock.PLAYING); +// +// if (!isPlaying && !lbe.isRecording()) +// return; +// +// final int ticks = lbe.incrementTick(); +// +// if (!isPlaying) +// return; +// +// +// final CompoundTag channel = lbe.getChannel(); +// final ResourceLocation instrumentId = new ResourceLocation(channel.getString("instrumentId")); +// +// for (final Tag pNote : channel.getList("notes", Tag.TAG_COMPOUND)) { +// if (!(pNote instanceof CompoundTag note)) +// continue; +// +// if (ticks != note.getInt("timestamp")) +// continue; +// +// try { +// +// final int pitch = note.getInt("pitch"); +// // Volume property did not exist before v2.1 +// final float volume = note.contains("volume", Tag.TAG_FLOAT) ? note.getFloat("volume") : 1; +// +// final ResourceLocation soundLocation = new ResourceLocation(note.getString("soundType")); +// +// ServerUtil.sendPlayNotePackets(pLevel, pPos, +// NoteSoundRegistrar.getSounds(soundLocation)[note.getInt("soundIndex")], +// instrumentId, pitch, (int)(volume * 100) +// ); +// +// pLevel.blockEvent(pPos, ModBlocks.LOOPER.get(), 42, pitch); +// +// } catch (Exception e) { +// LOGGER.error("Attempted to play a looper note, but met with an exception", e); +// } +// } +// } +// +// +// +// public static LooperBlockEntity getLBE(final Level level, final ItemStack instrument) { +// return getLBE(level, LooperUtil.looperTag(instrument), () -> LooperUtil.remLooperTag(instrument)); +// } +// public static LooperBlockEntity getLBE(final Level level, final BlockEntity instrument) { +// return getLBE(level, LooperUtil.looperTag(instrument), () -> { +// LooperUtil.remLooperTag(instrument); +// +// final BlockPos pos = instrument.getBlockPos(); +// final BlockState state = level.getBlockState(pos); +// if (state.getBlock() instanceof IDoubleBlock doubleBlock) +// LooperUtil.remLooperTag(level.getBlockEntity(doubleBlock.getOtherBlock(state, pos, level))); +// }); +// } +// /** +// * Attempts to get the looper pointed out by {@code looperData}. Removes its reference if not found. +// * @return The Looper's block entity as pointed in the {@code instrument}'s data. +// * Null if not found +// */ +// private static LooperBlockEntity getLBE(Level level, CompoundTag looperData, Runnable onInvalid) { +// if (looperData.isEmpty()) +// return null; +// +// final LooperBlockEntity looperBE = getLBE(level, LooperUtil.getLooperPos(looperData)); +// +// if (looperBE == null) +// onInvalid.run(); +// +// return looperBE; +// } +// +// private static LooperBlockEntity getLBE(final Level level, final BlockPos pos) { +// return (level.getBlockEntity(pos) instanceof LooperBlockEntity lbe) ? lbe : null; +// } +// +// +// +// @SubscribeEvent +// public static void onInstrumentPlayed(final InstrumentPlayedEvent.ByPlayer event) { +// if (event.isClientSide || !LooperUtil.isRecording(LooperUtil.getLooperTagFromEvent(event))) +// return; +// +// final Level level = event.player.level(); +// +// final LooperBlockEntity looperBE = event.itemInstrument.isPresent() +// ? getLBE(level, event.itemInstrument.get()) +// : getLBE(level, event.level.getBlockEntity(event.playPos)); +// +// if (looperBE == null) +// return; +// +// if (looperBE.isCapped(level)) +// return; +// +// +// if (looperBE.isLocked()) { +// if (!looperBE.isRecording() || !looperBE.isAllowedToRecord(event.player.getUUID())) +// return; +// } else { +// looperBE.setLockedBy(event.player.getUUID()); +// looperBE.setRecording(true); +// looperBE.getChannel().putString("instrumentId", event.instrumentId.toString()); +// } +// +// looperBE.addNote(event.sound, event.pitch, event.volume, looperBE.getTicks()); +// looperBE.setChanged(); +// } +// +// /** +// * A capped looper is a looper that cannot have any more notes in it, as defined in {@link ModGameRules#RULE_LOOPER_MAX_NOTES}. +// * Any negative will make the looper uncappable. +// * @return Whether this looper is capped +// */ +// public boolean isCapped(final Level level) { +// final int cap = level.getGameRules().getInt(ModGameRules.RULE_LOOPER_MAX_NOTES); +// return (cap >= 0) && (getChannel().getList("notes", Tag.TAG_COMPOUND).size() >= cap); +// } +// +// +// // If the player leaves the world, we shouldn't record anymore +// @SubscribeEvent +// public static void onPlayerLeave(final PlayerLoggedOutEvent event) { +// final ArrayList toBeRemoved = new ArrayList<>(); +// +// //TODO keep track of where player recording to in (future) record data tag +// // Thus limit the possibilities of player recording at once to 1 +// RECORDING_LOOPERS.forEach((looper) -> { +// if (looper.lockedBy.equals(event.getEntity().getUUID())) { +// looper.reset(); +// looper.getPersistentData().putBoolean("recording", false); +// toBeRemoved.add(looper); +// } +// }); +// +// RECORDING_LOOPERS.removeAll(toBeRemoved); +// } +// +//} diff --git a/src/main/java/com/cstav/evenmoreinstruments/client/gui/instrument/noteblockinstrument/NoteBlockInstrumentScreen.java b/src/main/java/com/cstav/evenmoreinstruments/client/gui/instrument/noteblockinstrument/NoteBlockInstrumentScreen.java index 5629903..d16201e 100644 --- a/src/main/java/com/cstav/evenmoreinstruments/client/gui/instrument/noteblockinstrument/NoteBlockInstrumentScreen.java +++ b/src/main/java/com/cstav/evenmoreinstruments/client/gui/instrument/noteblockinstrument/NoteBlockInstrumentScreen.java @@ -1,15 +1,13 @@ package com.cstav.evenmoreinstruments.client.gui.instrument.noteblockinstrument; -import java.util.Optional; - import com.cstav.evenmoreinstruments.Main; import com.cstav.evenmoreinstruments.item.NoteBlockInstrumentItem; +import com.cstav.evenmoreinstruments.sound.ModSounds; import com.cstav.genshinstrument.client.gui.screen.instrument.floralzither.FloralZitherScreen; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.InstrumentThemeLoader; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.notegrid.AbstractGridInstrumentScreen; import com.cstav.genshinstrument.client.gui.screen.instrument.partial.notegrid.NoteGridButton; import com.cstav.genshinstrument.sound.NoteSound; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.resources.ResourceLocation; @@ -19,9 +17,6 @@ @Environment(EnvType.CLIENT) public class NoteBlockInstrumentScreen extends AbstractGridInstrumentScreen { public static final String[] NOTES_LAYOUT = {"F#", "G", "G#", "A", "A#", "B", "C", "C#", "D", "D#", "E", "F"}; - private static final NoteSound[] DEFAULT_NOTE_SOUNDS = new NoteSound[] { - new NoteSound(NoteBlockInstrument.BASS.getSoundEvent().value(), Optional.empty()) - }; public final NoteBlockInstrument instrumentType; public final ResourceLocation instrumentId; @@ -33,7 +28,7 @@ public NoteBlockInstrumentScreen(InteractionHand hand, final NoteBlockInstrument instrumentId = new ResourceLocation(Main.MODID, NoteBlockInstrumentItem.getId(instrumentType)); // Update the sound to match the note block's - noteGrid.setNoteSounds(new NoteSound[] {new NoteSound(instrumentType.getSoundEvent().value(), Optional.empty())}); + noteGrid.setNoteSounds(ModSounds.getNoteblockSounds(instrumentType)); } @Override @@ -70,7 +65,7 @@ public ResourceLocation getSourcePath() { @Override public NoteSound[] getInitSounds() { - return DEFAULT_NOTE_SOUNDS; + return ModSounds.getNoteblockSounds(NoteBlockInstrument.HARP); } @Override diff --git a/src/main/java/com/cstav/evenmoreinstruments/client/gui/instrument/violin/ViolinScreen.java b/src/main/java/com/cstav/evenmoreinstruments/client/gui/instrument/violin/ViolinScreen.java index 096e1c7..1e0f9ff 100644 --- a/src/main/java/com/cstav/evenmoreinstruments/client/gui/instrument/violin/ViolinScreen.java +++ b/src/main/java/com/cstav/evenmoreinstruments/client/gui/instrument/violin/ViolinScreen.java @@ -35,7 +35,7 @@ public void setSoundType(ViolinSoundType soundType) { } public ViolinSoundType defSoundType() { - return ((ViolinOptionsScreen)optionsScreen).getPerferredSoundType(); + return ((ViolinOptionsScreen)optionsScreen).getPreferredSoundType(); } @Override diff --git a/src/main/java/com/cstav/evenmoreinstruments/sound/ModSounds.java b/src/main/java/com/cstav/evenmoreinstruments/sound/ModSounds.java index 90142b6..8c62d66 100644 --- a/src/main/java/com/cstav/evenmoreinstruments/sound/ModSounds.java +++ b/src/main/java/com/cstav/evenmoreinstruments/sound/ModSounds.java @@ -2,26 +2,55 @@ import com.cstav.evenmoreinstruments.Main; import com.cstav.genshinstrument.sound.NoteSound; -import com.cstav.genshinstrument.sound.NoteSoundRegistrer; - +import com.cstav.genshinstrument.sound.NoteSoundRegistrar; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; + +import java.util.HashMap; public class ModSounds { public static void load() {} + static { + NOTEBLOCK_SOUNDS = new HashMap<>(); + registerNoteBlockSounds(); + } + public static final NoteSound[] - KEYBOARD = NoteSoundRegistrer.createInstrumentNotes(loc("keyboard"), true), + KEYBOARD = nsr(loc("keyboard")).stereo().registerGrid(), - VIOLIN_FULL_NOTE = NoteSoundRegistrer.createInstrumentNotes(loc("violin_full")), - VIOLIN_HALF_NOTE = NoteSoundRegistrer.createInstrumentNotes(loc("violin_half")), + VIOLIN_FULL_NOTE = nsr(loc("violin_full")).registerGrid(), + VIOLIN_HALF_NOTE = nsr(loc("violin_half")).registerGrid(), - TROMBONE = NoteSoundRegistrer.createInstrumentNotes(loc("trombone")), - GUITAR = NoteSoundRegistrer.createInstrumentNotes(loc("guitar")) + TROMBONE = nsr(loc("trombone")).registerGrid(), + GUITAR = nsr(loc("guitar")).registerGrid() ; + private static final HashMap NOTEBLOCK_SOUNDS; + public static NoteSound[] getNoteblockSounds(final NoteBlockInstrument instrumentType) { + return new NoteSound[] {NOTEBLOCK_SOUNDS.get(instrumentType)}; + } + + private static void registerNoteBlockSounds() { + final NoteSoundRegistrar registrar = nsr(loc("note_block_instrument")); + + for (NoteBlockInstrument noteSound : NoteBlockInstrument.values()) { + registrar.chain(noteSound.getSoundEvent().value().getLocation()) + .alreadyRegistered() + .add(); + NOTEBLOCK_SOUNDS.put(noteSound, registrar.peek()); + } + + registrar.registerAll(); + } + + private static ResourceLocation loc(final String id) { return new ResourceLocation(Main.MODID, id); } + private static NoteSoundRegistrar nsr(final ResourceLocation location) { + return new NoteSoundRegistrar(location); + } } diff --git a/src/main/java/com/cstav/evenmoreinstruments/util/LooperUtil.java b/src/main/java/com/cstav/evenmoreinstruments/util/LooperUtil.java index d94d1ed..80da3f6 100644 --- a/src/main/java/com/cstav/evenmoreinstruments/util/LooperUtil.java +++ b/src/main/java/com/cstav/evenmoreinstruments/util/LooperUtil.java @@ -1,124 +1,123 @@ -// package com.cstav.evenmoreinstruments.util; - -// import javax.annotation.Nullable; - -// import com.cstav.evenmoreinstruments.Main; -// import com.cstav.evenmoreinstruments.block.blockentity.LooperBlockEntity; -// import com.cstav.genshinstrument.event.InstrumentPlayedEvent; - -// import net.minecraft.ChatFormatting; -// import net.minecraft.core.BlockPos; -// import net.minecraft.nbt.CompoundTag; -// import net.minecraft.nbt.NbtUtils; -// import net.minecraft.network.chat.Component; -// import net.minecraft.world.entity.player.Player; -// import net.minecraft.world.item.ItemStack; -// import net.minecraft.world.level.block.entity.BlockEntity; - -//TODO re-implement -// public class LooperUtil { -// public static final String LOOPER_TAG = "looper", -// POS_TAG = "pos", RECORDING_TAG = "recording"; - - -// // Handle instrument's looper tag -// public static boolean hasLooperTag(final ItemStack instrument) { -// return hasLooperTag(Main.modTag(instrument)); -// } -// public static boolean hasLooperTag(final BlockEntity instrument) { -// return hasLooperTag(Main.modTag(instrument)); -// } -// private static boolean hasLooperTag(final CompoundTag modTag) { -// return modTag.contains(LOOPER_TAG, CompoundTag.TAG_COMPOUND) && !modTag.getCompound(LOOPER_TAG).isEmpty(); -// } - -// public static void remLooperTag(final ItemStack instrument) { -// Main.modTag(instrument).remove(LOOPER_TAG); -// } -// public static void remLooperTag(final BlockEntity instrument) { -// Main.modTag(instrument).remove(LOOPER_TAG); -// } - -// public static void createLooperTag(final ItemStack instrument, final BlockPos looperPos) { -// Main.modTag(instrument).put(LOOPER_TAG, new CompoundTag()); -// constructLooperTag(looperTag(instrument), looperPos); -// } -// public static void createLooperTag(final BlockEntity instrument, final BlockPos looperPos) { -// Main.modTag(instrument).put(LOOPER_TAG, new CompoundTag()); -// constructLooperTag(looperTag(instrument), looperPos); -// } -// private static void constructLooperTag(final CompoundTag looperTag, final BlockPos looperPos) { -// looperTag.put(POS_TAG, NbtUtils.writeBlockPos(looperPos)); -// setRecording(looperTag, false); -// } - -// public static CompoundTag looperTag(final ItemStack instrument) { -// return looperTag(Main.modTag(instrument)); -// } -// public static CompoundTag looperTag(final BlockEntity instrument) { -// return looperTag(Main.modTag(instrument)); -// } -// public static CompoundTag looperTag(final CompoundTag parentTag) { -// return parentTag.contains(LOOPER_TAG, CompoundTag.TAG_COMPOUND) -// ? parentTag.getCompound(LOOPER_TAG) -// : CommonUtil.TAG_EMPTY; -// } - -// public static CompoundTag getLooperTagFromEvent(final InstrumentPlayedEvent.ByPlayer event) { -// return (event.itemInstrument.isPresent()) -// ? looperTag(event.itemInstrument.get()) -// : looperTag(event.level.getBlockEntity(event.blockInstrumentPos.get())); -// } - - -// public static boolean performPair(LooperBlockEntity lbe, Runnable pairPerformer, Player pairingPlayer) { -// if (!performChannelCheck(lbe, pairingPlayer)) -// return false; - -// pairPerformer.run(); - -// pairingPlayer.displayClientMessage( -// Component.translatable("evenmoreinstruments.looper.success_pair").withStyle(ChatFormatting.GREEN) -// , true); - -// return true; -// } -// public static boolean performChannelCheck(final LooperBlockEntity lbe, final Player pairingPlayer) { -// if (!lbe.hasChannel()) -// return true; - -// pairingPlayer.displayClientMessage( -// Component.translatable("evenmoreinstruments.looper.pair_conflict").withStyle(ChatFormatting.GREEN) -// , true); - -// return false; -// } - - -// /** -// * @param pos The position of the block to check for {@code item} -// * @return Whether {@code item} is pointing to a looper, and if its position is equal to {@code pos}'s -// */ -// public static boolean isSameBlock(final CompoundTag looperTag, final BlockPos pos) { -// try { -// return getLooperPos(looperTag).equals(pos); -// } catch (NullPointerException e) { -// return false; -// } -// } - -// @Nullable -// public static BlockPos getLooperPos(final CompoundTag looperTag) { -// final CompoundTag looperPosTag = looperTag.getCompound(POS_TAG); -// return (looperPosTag == null) ? null : NbtUtils.readBlockPos(looperPosTag); -// } - -// //TODO Move recording data to player -// public static void setRecording(final CompoundTag looperTag, final boolean recording) { -// looperTag.putBoolean(RECORDING_TAG, recording); -// } -// public static boolean isRecording(final CompoundTag looperTag) { -// return looperTag.getBoolean(RECORDING_TAG); -// } - -// } +//package com.cstav.evenmoreinstruments.util; +// +//import javax.annotation.Nullable; +// +//import com.cstav.evenmoreinstruments.Main; +//import com.cstav.evenmoreinstruments.block.blockentity.LooperBlockEntity; +//import com.cstav.genshinstrument.event.InstrumentPlayedEvent; +// +//import net.minecraft.ChatFormatting; +//import net.minecraft.core.BlockPos; +//import net.minecraft.nbt.CompoundTag; +//import net.minecraft.nbt.NbtUtils; +//import net.minecraft.network.chat.Component; +//import net.minecraft.world.entity.player.Player; +//import net.minecraft.world.item.ItemStack; +//import net.minecraft.world.level.block.entity.BlockEntity; +// +//public class LooperUtil { +// public static final String LOOPER_TAG = "looper", +// POS_TAG = "pos", RECORDING_TAG = "recording"; +// +// +// // Handle instrument's looper tag +// public static boolean hasLooperTag(final ItemStack instrument) { +// return hasLooperTag(Main.modTag(instrument)); +// } +// public static boolean hasLooperTag(final BlockEntity instrument) { +// return hasLooperTag(Main.modTag(instrument)); +// } +// private static boolean hasLooperTag(final CompoundTag modTag) { +// return modTag.contains(LOOPER_TAG, CompoundTag.TAG_COMPOUND) && !modTag.getCompound(LOOPER_TAG).isEmpty(); +// } +// +// public static void remLooperTag(final ItemStack instrument) { +// Main.modTag(instrument).remove(LOOPER_TAG); +// } +// public static void remLooperTag(final BlockEntity instrument) { +// Main.modTag(instrument).remove(LOOPER_TAG); +// } +// +// public static void createLooperTag(final ItemStack instrument, final BlockPos looperPos) { +// Main.modTag(instrument).put(LOOPER_TAG, new CompoundTag()); +// constructLooperTag(looperTag(instrument), looperPos); +// } +// public static void createLooperTag(final BlockEntity instrument, final BlockPos looperPos) { +// Main.modTag(instrument).put(LOOPER_TAG, new CompoundTag()); +// constructLooperTag(looperTag(instrument), looperPos); +// } +// private static void constructLooperTag(final CompoundTag looperTag, final BlockPos looperPos) { +// looperTag.put(POS_TAG, NbtUtils.writeBlockPos(looperPos)); +// setRecording(looperTag, false); +// } +// +// public static CompoundTag looperTag(final ItemStack instrument) { +// return looperTag(Main.modTag(instrument)); +// } +// public static CompoundTag looperTag(final BlockEntity instrument) { +// return looperTag(Main.modTag(instrument)); +// } +// public static CompoundTag looperTag(final CompoundTag parentTag) { +// return parentTag.contains(LOOPER_TAG, CompoundTag.TAG_COMPOUND) +// ? parentTag.getCompound(LOOPER_TAG) +// : CommonUtil.TAG_EMPTY; +// } +// +// public static CompoundTag getLooperTagFromEvent(final InstrumentPlayedEvent.ByPlayer event) { +// return (!event.isBlockInstrument()) +// ? looperTag(event.itemInstrument.get()) +// : looperTag(event.level.getBlockEntity(event.playPos)); +// } +// +// +// public static boolean performPair(LooperBlockEntity lbe, Runnable pairPerformer, Player pairingPlayer) { +// if (!performChannelCheck(lbe, pairingPlayer)) +// return false; +// +// pairPerformer.run(); +// +// pairingPlayer.displayClientMessage( +// Component.translatable("evenmoreinstruments.looper.success_pair").withStyle(ChatFormatting.GREEN) +// , true); +// +// return true; +// } +// public static boolean performChannelCheck(final LooperBlockEntity lbe, final Player pairingPlayer) { +// if (!lbe.hasChannel()) +// return true; +// +// pairingPlayer.displayClientMessage( +// Component.translatable("evenmoreinstruments.looper.pair_conflict").withStyle(ChatFormatting.GREEN) +// , true); +// +// return false; +// } +// +// +// /** +// * @param pos The position of the block to check for {@code item} +// * @return Whether {@code item} is pointing to a looper, and if its position is equal to {@code pos}'s +// */ +// public static boolean isSameBlock(final CompoundTag looperTag, final BlockPos pos) { +// try { +// return getLooperPos(looperTag).equals(pos); +// } catch (NullPointerException e) { +// return false; +// } +// } +// +// @Nullable +// public static BlockPos getLooperPos(final CompoundTag looperTag) { +// final CompoundTag looperPosTag = looperTag.getCompound(POS_TAG); +// return (looperPosTag == null) ? null : NbtUtils.readBlockPos(looperPosTag); +// } +// +// //TODO Move recording data to player +// public static void setRecording(final CompoundTag looperTag, final boolean recording) { +// looperTag.putBoolean(RECORDING_TAG, recording); +// } +// public static boolean isRecording(final CompoundTag looperTag) { +// return looperTag.getBoolean(RECORDING_TAG); +// } +// +//} diff --git a/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/guitar/instrument_style.json b/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/guitar/instrument_style.json index 6195bec..bc5e739 100644 --- a/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/guitar/instrument_style.json +++ b/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/guitar/instrument_style.json @@ -1,4 +1,10 @@ { - "note_theme": [244, 165, 55], - "label_theme": [249, 169, 56] + "note": { + "released": [249, 169, 56] + }, + "label": { + "released": [224, 155, 45] + }, + + "note_ring": [244, 165, 55] } \ No newline at end of file diff --git a/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/keyboard/instrument_style.json b/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/keyboard/instrument_style.json index 7571024..1b091ab 100644 --- a/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/keyboard/instrument_style.json +++ b/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/keyboard/instrument_style.json @@ -1,5 +1,10 @@ { - "note_theme": [150, 150, 150], - "label_theme": [20, 20, 20], - "note_ring_theme": [50, 50, 50] + "note": { + "released": [20, 20, 20] + }, + "label": { + "released": [130, 130, 130] + }, + + "note_ring": [50, 50, 50] } \ No newline at end of file diff --git a/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/trombone/instrument_style.json b/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/trombone/instrument_style.json index f1e0acf..70ca3fe 100644 --- a/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/trombone/instrument_style.json +++ b/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/trombone/instrument_style.json @@ -1,4 +1,8 @@ { - "note_theme": [254, 217, 133], - "label_theme": [255, 207, 96] + "note": { + "released": [255, 207, 96] + }, + "label": { + "released": [254, 217, 133] + } } \ No newline at end of file diff --git a/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/violin/instrument_style.json b/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/violin/instrument_style.json index 5250bde..6c1a071 100644 --- a/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/violin/instrument_style.json +++ b/src/main/resources/assets/evenmoreinstruments/textures/gui/genshinstrument/instrument/violin/instrument_style.json @@ -1,4 +1,9 @@ { - "note_theme": [221, 147, 102], - "label_theme": [206, 135, 88] + "note": { + "pressed": [255, 255, 255], + "released": [206, 135, 88] + }, + "label": { + "released": [221, 147, 102] + } } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b0eef02..39bc5a4 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -32,7 +32,7 @@ "mixins.evenmoreinstruments.optional.json" ], "depends": { - "genshinstrument": ">=3.3.1", + "genshinstrument": ">=3.4", "fabricloader": ">=0.14.21", "minecraft": "~1.20.1",