Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to 1.21.4 #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'fabric-loom' version '1.9-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.mod_version
Expand Down Expand Up @@ -42,8 +42,8 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
// Minecraft 1.20.5 upwards uses Java 21.
it.options.release = 21
}

java {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.2
loader_version=0.14.21
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.8
loader_version=0.16.9

# Mod Properties
mod_version=1.1.1
maven_group=xyz.nat1an
archives_base_name=notebot
# Dependencies
fabric_version=0.83.1+1.20.1
fabric_version=0.115.1+1.21.4
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
72 changes: 38 additions & 34 deletions src/main/java/xyz/nat1an/notebot/NotebotPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import net.minecraft.block.Block;
import net.minecraft.block.NoteBlock;
import net.minecraft.block.enums.Instrument;
import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.client.MinecraftClient;
import net.minecraft.registry.Registries;
import net.minecraft.sound.BlockSoundGroup;
Expand Down Expand Up @@ -65,8 +65,8 @@ public static Instrument getInstrument(BlockPos pos) {
return mc.world.getBlockState(pos).get(NoteBlock.INSTRUMENT);
}
*/
public static Instrument getInstrumentUnderneath(BlockPos pos) {
if (!isNoteblock(pos)) return Instrument.HARP;
public static NoteBlockInstrument getInstrumentUnderneath(BlockPos pos) {
if (!isNoteblock(pos)) return NoteBlockInstrument.HARP;

// Retrieve the block underneath
BlockPos posUnderneath = pos.down();
Expand All @@ -76,61 +76,61 @@ public static Instrument getInstrumentUnderneath(BlockPos pos) {
return blockToInstrument(blockUnderneath);
}

public static Instrument blockToInstrument(Block block) {
public static NoteBlockInstrument blockToInstrument(Block block) {

// Specific block checks
Identifier blockId = Registries.BLOCK.getId(block);
String blockIdString = blockId.toString();
Instrument instrument = Instrument.HARP; // Default to Harp for any other block
NoteBlockInstrument instrument = NoteBlockInstrument.HARP; // Default to Harp for any other block


if (blockIdString.equals("minecraft:dirt" ) || blockIdString.equals("minecraft:air")) {
return Instrument.HARP;
return NoteBlockInstrument.HARP;
} else if (blockIdString.equals("minecraft:clay")) {
return Instrument.FLUTE;
return NoteBlockInstrument.FLUTE;
} else if (blockIdString.equals("minecraft:gold_block")) {
return Instrument.BELL;
return NoteBlockInstrument.BELL;
} else if (blockIdString.equals("minecraft:packed_ice")) {
return Instrument.CHIME;
return NoteBlockInstrument.CHIME;
} else if (blockIdString.equals("minecraft:bone_block")) {
return Instrument.XYLOPHONE;
return NoteBlockInstrument.XYLOPHONE;
} else if (blockIdString.equals("minecraft:iron_block")) {
return Instrument.IRON_XYLOPHONE;
return NoteBlockInstrument.IRON_XYLOPHONE;
} else if (blockIdString.equals("minecraft:soul_sand")) {
return Instrument.COW_BELL;
return NoteBlockInstrument.COW_BELL;
} else if (blockIdString.equals("minecraft:pumpkin")) {
return Instrument.DIDGERIDOO;
return NoteBlockInstrument.DIDGERIDOO;
} else if (blockIdString.equals("minecraft:emerald_block")) {
return Instrument.BIT;
return NoteBlockInstrument.BIT;
} else if (blockIdString.equals("minecraft:hay_block")) {
return Instrument.BANJO;
return NoteBlockInstrument.BANJO;
} else if (blockIdString.equals("minecraft:glowstone")) {
return Instrument.PLING;
return NoteBlockInstrument.PLING;
} else if (blockIdString.equals("minecraft:sand") || blockIdString.equals("minecraft:gravel") || blockIdString.equals("minecraft:concrete_powder")) {
return Instrument.SNARE;
return NoteBlockInstrument.SNARE;
} else if (Arrays.asList("minecraft:stone", "minecraft:cobblestone", "minecraft:blackstone", "minecraft:netherrack", "minecraft:nylium", "minecraft:obsidian",
"minecraft:quartz", "minecraft:sandstone", "minecraft:ores", "minecraft:bricks", "minecraft:corals",
"minecraft:respawn_anchor", "minecraft:bedrock", "minecraft:concrete").contains(blockIdString)) {
return Instrument.BASEDRUM;
return NoteBlockInstrument.BASEDRUM;
} else if (blockIdString.equals("minecraft:glass")) {
return Instrument.HAT;
return NoteBlockInstrument.HAT;
}


BlockSoundGroup material = block.getDefaultState().getSoundGroup();

// Check for blocks with specific materials
if (material.equals(BlockSoundGroup.WOOD)) {
return Instrument.BASS;
return NoteBlockInstrument.BASS;
}
if (material.equals(BlockSoundGroup.WOOL)) {
return Instrument.GUITAR;
return NoteBlockInstrument.GUITAR;
}
if (material.equals(BlockSoundGroup.GLASS)) {
return Instrument.HAT;
return NoteBlockInstrument.HAT;
}
if (material.equals(BlockSoundGroup.STONE)) {
return Instrument.BASEDRUM;
return NoteBlockInstrument.BASEDRUM;
}


Expand All @@ -156,11 +156,11 @@ public static boolean loadSong() {

try {
if (!mc.interactionManager.getCurrentGameMode().isSurvivalLike()) {
mc.player.sendMessage(Text.literal("§cNot in Survival mode!"));
mc.player.sendMessage(Text.literal("§cNot in Survival mode!"), false);

return false;
} else if (song == null) {
mc.player.sendMessage(Text.literal("§6No song in queue!, Use §c/notebot queue add §6to add a song."));
mc.player.sendMessage(Text.literal("§6No song in queue!, Use §c/notebot queue add §6to add a song."), false);

return false;
}
Expand All @@ -178,16 +178,16 @@ public static boolean loadSong() {
NotebotPlayer::isNoteblock).map(BlockPos::toImmutable
).toList();

HashMap<Instrument, Integer> requiredInstruments = new HashMap<>();
HashMap<Instrument, Integer> foundInstruments = new HashMap<>();
HashMap<NoteBlockInstrument, Integer> requiredInstruments = new HashMap<>();
HashMap<NoteBlockInstrument, Integer> foundInstruments = new HashMap<>();

for (Note note : song.requirements) {
Instrument instrument = Instrument.values()[note.instrument];
NoteBlockInstrument instrument = NoteBlockInstrument.values()[note.instrument];
requiredInstruments.put(instrument, requiredInstruments.getOrDefault(instrument, 0) + 1);
for (BlockPos pos : noteblocks) {
if (blockPitches.containsKey(pos)) continue;

Instrument blockInstrument = getInstrumentUnderneath(pos);
NoteBlockInstrument blockInstrument = getInstrumentUnderneath(pos);
if (note.instrument == blockInstrument.ordinal() && blockPitches.entrySet().stream().filter(e -> e.getValue() == note.pitch).noneMatch(e -> getInstrumentUnderneath(e.getKey()).ordinal() == blockInstrument.ordinal())) {
blockPitches.put(pos, note.pitch);
foundInstruments.put(blockInstrument, foundInstruments.getOrDefault(blockInstrument, 0) + 1);
Expand All @@ -196,13 +196,13 @@ public static boolean loadSong() {
}
}

for (Instrument instrument : requiredInstruments.keySet()) {
for (NoteBlockInstrument instrument : requiredInstruments.keySet()) {
int requiredCount = requiredInstruments.get(instrument);
int foundCount = foundInstruments.getOrDefault(instrument, 0);
int missingCount = requiredCount - foundCount;

if (missingCount > 0) {
mc.player.sendMessage(Text.literal("§6Warning: Missing §c" + missingCount + " §6" + instrument + " Noteblocks"));
mc.player.sendMessage(Text.literal("§6Warning: Missing §c" + missingCount + " §6" + instrument + " Noteblocks"), false);
}
}

Expand All @@ -211,10 +211,14 @@ public static boolean loadSong() {

public static void onTick(MinecraftClient client) {
if (!playing) return;
if (mc.world == null || mc.player == null) {
playing = false;
return;
}

if (song == null) {
if (queue.isEmpty()) {
mc.player.sendMessage(Text.literal("§cYou have no songs in your queue!"));
mc.player.sendMessage(Text.literal("§cYou have no songs in your queue!"), false);
stop();
return;
}
Expand Down Expand Up @@ -260,14 +264,14 @@ public static void onTick(MinecraftClient client) {
song = null;
return;
} else {
mc.player.sendMessage(Text.literal("§6The queue is empty, stopping..."));
mc.player.sendMessage(Text.literal("§6The queue is empty, stopping..."), false);
stop();
return;
}
}

if (timer == -10) {
mc.player.sendMessage(Text.literal("§6Now Playing: §a" + song.filename));
mc.player.sendMessage(Text.literal("§6Now Playing: §a" + song.filename), false);
}

timer++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.block.enums.Instrument;
import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -43,7 +43,7 @@ public static String listRequirements(Song song) {

result.append("§6Song: §e").append(song.name);

for (Map.Entry<Instrument, ItemStack> e : NotebotUtils.INSTRUMENT_TO_ITEM.entrySet()) {
for (Map.Entry<NoteBlockInstrument, ItemStack> e : NotebotUtils.INSTRUMENT_TO_ITEM.entrySet()) {
int count = (int) song.requirements.stream().filter(n -> n.instrument == e.getKey().ordinal()).count();

if (count != 0) {
Expand All @@ -61,7 +61,7 @@ private static int run(CommandContext<FabricClientCommandSource> context) {
)
);

mc.player.sendMessage(Text.literal(listRequirements(song)));
mc.player.sendMessage(Text.literal(listRequirements(song)), false);

return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ private static int run(CommandContext<FabricClientCommandSource> context) {
NotebotPlayer.queue.add(context.getArgument("song", String.class));

mc.player.sendMessage(
Text.literal("§6Added §a" + context.getArgument("song", String.class) + "§6 to the queue.")
Text.literal("§6Added §a" + context.getArgument("song", String.class) + "§6 to the queue."),
false
);

return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ private static int run(CommandContext<FabricClientCommandSource> context) {
NotebotPlayer.queue.clear();

mc.player.sendMessage(
Text.literal("§6Cleared §a" + amount + "§6 songs from the queue.")
Text.literal("§6Cleared §a" + amount + "§6 songs from the queue."),
false
);

return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static String listQueue() {
}

private static int run(CommandContext<FabricClientCommandSource> context) {
mc.player.sendMessage(Text.literal(listQueue()));
mc.player.sendMessage(Text.literal(listQueue()), false);

return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ private static int run(CommandContext<FabricClientCommandSource> context) {
try {
name = NotebotPlayer.queue.remove(index);
} catch (IndexOutOfBoundsException e) {
mc.player.sendMessage(Text.literal("§cIndex out of bounds."));
mc.player.sendMessage(Text.literal("§cIndex out of bounds."), false);
return 0;
}

mc.player.sendMessage(Text.literal("§6Removed §a" + name + "§6 at §e" + index + " §6from the queue."));
mc.player.sendMessage(Text.literal("§6Removed §a" + name + "§6 at §e" + index + " §6from the queue."), false);

return 1;
}
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/xyz/nat1an/notebot/utils/NotebotUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import net.minecraft.block.enums.Instrument;
import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
Expand All @@ -32,23 +32,23 @@

public class NotebotUtils {
public static final String[] NOTE_NAMES = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
public static final EnumMap<Instrument, ItemStack> INSTRUMENT_TO_ITEM = Util.make(new EnumMap<>(Instrument.class), it -> {
it.put(Instrument.HARP, new ItemStack(Items.DIRT));
it.put(Instrument.BASEDRUM, new ItemStack(Items.STONE));
it.put(Instrument.SNARE, new ItemStack(Items.SAND));
it.put(Instrument.HAT, new ItemStack(Items.GLASS));
it.put(Instrument.BASS, new ItemStack(Items.OAK_WOOD));
it.put(Instrument.FLUTE, new ItemStack(Items.CLAY));
it.put(Instrument.BELL, new ItemStack(Items.GOLD_BLOCK));
it.put(Instrument.GUITAR, new ItemStack(Items.WHITE_WOOL));
it.put(Instrument.CHIME, new ItemStack(Items.PACKED_ICE));
it.put(Instrument.XYLOPHONE, new ItemStack(Items.BONE_BLOCK));
it.put(Instrument.IRON_XYLOPHONE, new ItemStack(Items.IRON_BLOCK));
it.put(Instrument.COW_BELL, new ItemStack(Items.SOUL_SAND));
it.put(Instrument.DIDGERIDOO, new ItemStack(Items.PUMPKIN));
it.put(Instrument.BIT, new ItemStack(Items.EMERALD_BLOCK));
it.put(Instrument.BANJO, new ItemStack(Items.HAY_BLOCK));
it.put(Instrument.PLING, new ItemStack(Items.GLOWSTONE));
public static final EnumMap<NoteBlockInstrument, ItemStack> INSTRUMENT_TO_ITEM = Util.make(new EnumMap<>(NoteBlockInstrument.class), it -> {
it.put(NoteBlockInstrument.HARP, new ItemStack(Items.DIRT));
it.put(NoteBlockInstrument.BASEDRUM, new ItemStack(Items.STONE));
it.put(NoteBlockInstrument.SNARE, new ItemStack(Items.SAND));
it.put(NoteBlockInstrument.HAT, new ItemStack(Items.GLASS));
it.put(NoteBlockInstrument.BASS, new ItemStack(Items.OAK_WOOD));
it.put(NoteBlockInstrument.FLUTE, new ItemStack(Items.CLAY));
it.put(NoteBlockInstrument.BELL, new ItemStack(Items.GOLD_BLOCK));
it.put(NoteBlockInstrument.GUITAR, new ItemStack(Items.WHITE_WOOL));
it.put(NoteBlockInstrument.CHIME, new ItemStack(Items.PACKED_ICE));
it.put(NoteBlockInstrument.XYLOPHONE, new ItemStack(Items.BONE_BLOCK));
it.put(NoteBlockInstrument.IRON_XYLOPHONE, new ItemStack(Items.IRON_BLOCK));
it.put(NoteBlockInstrument.COW_BELL, new ItemStack(Items.SOUL_SAND));
it.put(NoteBlockInstrument.DIDGERIDOO, new ItemStack(Items.PUMPKIN));
it.put(NoteBlockInstrument.BIT, new ItemStack(Items.EMERALD_BLOCK));
it.put(NoteBlockInstrument.BANJO, new ItemStack(Items.HAY_BLOCK));
it.put(NoteBlockInstrument.PLING, new ItemStack(Items.GLOWSTONE));
});
private static final int[] NOTE_POSES = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
private static Logger logger = Notebot.LOGGER;
Expand Down Expand Up @@ -252,10 +252,10 @@ public static Song parseNbs(Path path) {

int key = input.read() - 33;
if (key < 0) {
mc.player.sendMessage(Text.literal("Note @" + tick + " Key: " + key + " is below the 2-octave range!"));
mc.player.sendMessage(Text.literal("Note @" + tick + " Key: " + key + " is below the 2-octave range!"), false);
key = Math.floorMod(key, 12);
} else if (key > 25) {
mc.player.sendMessage(Text.literal("Note @" + tick + " Key: " + key + " is above the 2-octave range!"));
mc.player.sendMessage(Text.literal("Note @" + tick + " Key: " + key + " is above the 2-octave range!"), false);
key = Math.floorMod(key, 12) + 12;
}

Expand Down