Update to 1.21 and small cleanups

This commit is contained in:
EnderKill98 2024-07-07 20:15:54 +02:00
parent 1ee9f114c9
commit bb3eb426e5
7 changed files with 66 additions and 63 deletions

View File

@ -2,8 +2,8 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
minecraft_version=1.21
yarn_mappings=1.21+build.2
loader_version=0.15.11
# Mod Properties
mod_version=1.5.0
@ -11,4 +11,4 @@ maven_group=semmiedev
archives_base_name=disc_jockey
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.98.0+1.20.6
fabric_version=0.100.1+1.21

View File

@ -5,11 +5,10 @@ import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.block.enums.Instrument;
import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.CommandSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.Nullable;
import semmiedev.disc_jockey.gui.screen.DiscJockeyScreen;
@ -26,7 +25,7 @@ public class DiscjockeyCommand {
public static void register(CommandDispatcher<FabricClientCommandSource> commandDispatcher) {
final ArrayList<String> instrumentNames = new ArrayList<>();
for (Instrument instrument : Instrument.values()) {
for (NoteBlockInstrument instrument : NoteBlockInstrument.values()) {
instrumentNames.add(instrument.toString().toLowerCase());
}
final ArrayList<String> instrumentNamesAndAll = new ArrayList<>(instrumentNames);
@ -127,8 +126,8 @@ public class DiscjockeyCommand {
.executes(context -> {
String originalInstrumentStr = StringArgumentType.getString(context, "originalInstrument");
String newInstrumentStr = StringArgumentType.getString(context, "newInstrument");
@Nullable Instrument originalInstrument = null, newInstrument = null;
for(Instrument maybeInstrument : Instrument.values()) {
@Nullable NoteBlockInstrument originalInstrument = null, newInstrument = null;
for(NoteBlockInstrument maybeInstrument : NoteBlockInstrument.values()) {
if(maybeInstrument.toString().equalsIgnoreCase(originalInstrumentStr)) {
originalInstrument = maybeInstrument;
}
@ -152,7 +151,7 @@ public class DiscjockeyCommand {
if(originalInstrument == null) {
// All instruments
for(Instrument instrument : Instrument.values()) {
for(NoteBlockInstrument instrument : NoteBlockInstrument.values()) {
Main.SONG_PLAYER.instrumentMap.put(instrument, newInstrument);
}
context.getSource().sendFeedback(Text.translatable(Main.MOD_ID + ".instrument_mapped_all", newInstrumentStr.toLowerCase()));
@ -171,8 +170,8 @@ public class DiscjockeyCommand {
.executes(context -> {
String instrumentStr = StringArgumentType.getString(context, "instrument");
Instrument instrument = null;
for(Instrument maybeInstrument : Instrument.values()) {
NoteBlockInstrument instrument = null;
for(NoteBlockInstrument maybeInstrument : NoteBlockInstrument.values()) {
if(maybeInstrument.toString().equalsIgnoreCase(instrumentStr)) {
instrument = maybeInstrument;
break;
@ -198,7 +197,7 @@ public class DiscjockeyCommand {
}
StringBuilder maps = new StringBuilder();
for(Map.Entry<Instrument, Instrument> entry : Main.SONG_PLAYER.instrumentMap.entrySet()) {
for(Map.Entry<NoteBlockInstrument, NoteBlockInstrument> entry : Main.SONG_PLAYER.instrumentMap.entrySet()) {
if(maps.length() > 0) {
maps.append(", ");
}

View File

@ -2,52 +2,53 @@ package semmiedev.disc_jockey;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.enums.Instrument;
import net.minecraft.block.enums.NoteBlockInstrument;
import java.util.HashMap;
public record Note(Instrument instrument, byte note) {
public static final HashMap<Instrument, Block> INSTRUMENT_BLOCKS = new HashMap<>();
public record Note(NoteBlockInstrument instrument, byte note) {
public static final HashMap<NoteBlockInstrument, Block> INSTRUMENT_BLOCKS = new HashMap<>();
public static final byte LAYER_SHIFT = Short.SIZE;
public static final byte INSTRUMENT_SHIFT = Short.SIZE * 2;
public static final byte NOTE_SHIFT = Short.SIZE * 2 + Byte.SIZE;
public static final Instrument[] INSTRUMENTS = new Instrument[]{
Instrument.HARP,
Instrument.BASS,
Instrument.BASEDRUM,
Instrument.SNARE,
Instrument.HAT,
Instrument.GUITAR,
Instrument.FLUTE,
Instrument.BELL,
Instrument.CHIME,
Instrument.XYLOPHONE,
Instrument.IRON_XYLOPHONE,
Instrument.COW_BELL,
Instrument.DIDGERIDOO,
Instrument.BIT,
Instrument.BANJO,
Instrument.PLING
public static final NoteBlockInstrument[] INSTRUMENTS = new NoteBlockInstrument[]{
NoteBlockInstrument.HARP,
NoteBlockInstrument.BASS,
NoteBlockInstrument.BASEDRUM,
NoteBlockInstrument.SNARE,
NoteBlockInstrument.HAT,
NoteBlockInstrument.GUITAR,
NoteBlockInstrument.FLUTE,
NoteBlockInstrument.BELL,
NoteBlockInstrument.CHIME,
NoteBlockInstrument.XYLOPHONE,
NoteBlockInstrument.IRON_XYLOPHONE,
NoteBlockInstrument.COW_BELL,
NoteBlockInstrument.DIDGERIDOO,
NoteBlockInstrument.BIT,
NoteBlockInstrument.BANJO,
NoteBlockInstrument.PLING
};
static {
INSTRUMENT_BLOCKS.put(Instrument.HARP, Blocks.AIR);
INSTRUMENT_BLOCKS.put(Instrument.BASEDRUM, Blocks.STONE);
INSTRUMENT_BLOCKS.put(Instrument.SNARE, Blocks.SAND);
INSTRUMENT_BLOCKS.put(Instrument.HAT, Blocks.GLASS);
INSTRUMENT_BLOCKS.put(Instrument.BASS, Blocks.OAK_PLANKS);
INSTRUMENT_BLOCKS.put(Instrument.FLUTE, Blocks.CLAY);
INSTRUMENT_BLOCKS.put(Instrument.BELL, Blocks.GOLD_BLOCK);
INSTRUMENT_BLOCKS.put(Instrument.GUITAR, Blocks.WHITE_WOOL);
INSTRUMENT_BLOCKS.put(Instrument.CHIME, Blocks.PACKED_ICE);
INSTRUMENT_BLOCKS.put(Instrument.XYLOPHONE, Blocks.BONE_BLOCK);
INSTRUMENT_BLOCKS.put(Instrument.IRON_XYLOPHONE, Blocks.IRON_BLOCK);
INSTRUMENT_BLOCKS.put(Instrument.COW_BELL, Blocks.SOUL_SAND);
INSTRUMENT_BLOCKS.put(Instrument.DIDGERIDOO, Blocks.PUMPKIN);
INSTRUMENT_BLOCKS.put(Instrument.BIT, Blocks.EMERALD_BLOCK);
INSTRUMENT_BLOCKS.put(Instrument.BANJO, Blocks.HAY_BLOCK);
INSTRUMENT_BLOCKS.put(Instrument.PLING, Blocks.GLOWSTONE);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.HARP, Blocks.AIR);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.BASEDRUM, Blocks.STONE);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.SNARE, Blocks.SAND);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.HAT, Blocks.GLASS);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.BASS, Blocks.OAK_PLANKS);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.FLUTE, Blocks.CLAY);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.BELL, Blocks.GOLD_BLOCK);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.GUITAR, Blocks.WHITE_WOOL);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.CHIME, Blocks.PACKED_ICE);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.XYLOPHONE, Blocks.BONE_BLOCK);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.IRON_XYLOPHONE, Blocks.IRON_BLOCK);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.COW_BELL, Blocks.SOUL_SAND);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.DIDGERIDOO, Blocks.PUMPKIN);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.BIT, Blocks.EMERALD_BLOCK);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.BANJO, Blocks.HAY_BLOCK);
INSTRUMENT_BLOCKS.put(NoteBlockInstrument.PLING, Blocks.GLOWSTONE);
}
}

View File

@ -4,7 +4,7 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.enums.Instrument;
import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.ChatHud;
import net.minecraft.client.network.ClientPlayerEntity;
@ -35,7 +35,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick {
private int index;
private double tick; // Aka song position
private HashMap<Instrument, HashMap<Byte, BlockPos>> noteBlocks = null;
private HashMap<NoteBlockInstrument, HashMap<Byte, BlockPos>> noteBlocks = null;
public boolean tuned;
private long lastPlaybackTickAt = -1L;
@ -69,7 +69,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick {
Main.TICK_LISTENERS.add(this);
}
public @NotNull HashMap<Instrument, @Nullable Instrument> instrumentMap = new HashMap<>(); // Toy
public @NotNull HashMap<NoteBlockInstrument, @Nullable NoteBlockInstrument> instrumentMap = new HashMap<>(); // Toy
public synchronized void startPlaybackThread() {
if(Main.config.disableAsyncPlayback) {
playbackThread = null;
@ -254,8 +254,8 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick {
ClientPlayerEntity player = client.player;
// Create list of available noteblock positions per used instrument
HashMap<Instrument, ArrayList<BlockPos>> noteblocksForInstrument = new HashMap<>();
for(Instrument instrument : Instrument.values())
HashMap<NoteBlockInstrument, ArrayList<BlockPos>> noteblocksForInstrument = new HashMap<>();
for(NoteBlockInstrument instrument : NoteBlockInstrument.values())
noteblocksForInstrument.put(instrument, new ArrayList<>());
final Vec3d playerEyePos = player.getEyePos();
@ -275,7 +275,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick {
if(offset != 0) orderedOffsets.add(offset * -1);
}
for(Instrument instrument : noteblocksForInstrument.keySet().toArray(new Instrument[0])) {
for(NoteBlockInstrument instrument : noteblocksForInstrument.keySet().toArray(new NoteBlockInstrument[0])) {
for (int y : orderedOffsets) {
for (int x : orderedOffsets) {
for (int z : orderedOffsets) {
@ -296,9 +296,9 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick {
// Remap instruments for funzies
if(!instrumentMap.isEmpty()) {
HashMap<Instrument, ArrayList<BlockPos>> newNoteblocksForInstrument = new HashMap<>();
for(Instrument orig : noteblocksForInstrument.keySet()) {
Instrument mappedInstrument = instrumentMap.getOrDefault(orig, orig);
HashMap<NoteBlockInstrument, ArrayList<BlockPos>> newNoteblocksForInstrument = new HashMap<>();
for(NoteBlockInstrument orig : noteblocksForInstrument.keySet()) {
NoteBlockInstrument mappedInstrument = instrumentMap.getOrDefault(orig, orig);
if(mappedInstrument == null) {
// Instrument got likely mapped to "nothing"
newNoteblocksForInstrument.put(orig, null);
@ -348,7 +348,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick {
HashMap<Block, Integer> missing = new HashMap<>();
for (Note note : missingNotes) {
Instrument mappedInstrument = instrumentMap.getOrDefault(note.instrument(), note.instrument());
NoteBlockInstrument mappedInstrument = instrumentMap.getOrDefault(note.instrument(), note.instrument());
if(mappedInstrument == null) continue; // Ignore if mapped to nothing
Block block = Note.INSTRUMENT_BLOCKS.get(mappedInstrument);
Integer got = missing.get(block);
@ -485,11 +485,13 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick {
}
}
private HashMap<Byte, BlockPos> getNotes(Instrument instrument) {
private HashMap<Byte, BlockPos> getNotes(NoteBlockInstrument instrument) {
return noteBlocks.computeIfAbsent(instrument, k -> new HashMap<>());
}
// The server limits interacts to 6 Blocks from Player Eye to Block Center
// Before 1.20.5, the server limits interacts to 6 Blocks from Player Eye to Block Center
// With 1.20.5 and later, the server does a more complex check, to the closest point of a full block hitbox
// (max distance is BlockInteractRange + 1.0).
private boolean canInteractWith(ClientPlayerEntity player, BlockPos blockPos) {
final Vec3d eyePos = player.getEyePos();
if(Main.config.expectedServerVersion == Config.ExpectedServerVersion.v1_20_4_Or_Earlier) {

View File

@ -41,7 +41,7 @@ public class SongListWidget extends EntryListWidget<SongListWidget.SongEntry> {
// TODO: 6/2/2022 Add a delete icon
public static class SongEntry extends Entry<SongEntry> {
private static final Identifier ICONS = new Identifier(Main.MOD_ID, "textures/gui/icons.png");
private static final Identifier ICONS = Identifier.of(Main.MOD_ID, "textures/gui/icons.png");
public final int index;
public final Song song;

View File

@ -4,6 +4,7 @@ import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.ColorHelper;
@ -15,7 +16,7 @@ public class BlocksOverlay {
private static final ItemStack NOTE_BLOCK = Blocks.NOTE_BLOCK.asItem().getDefaultStack();
public static void render(DrawContext context, float tickDelta) {
public static void render(DrawContext context, RenderTickCounter tickCounter) {
if (itemStacks != null) {
context.fill(2, 2, 62, (itemStacks.length + 1) * 20 + 7, ColorHelper.Argb.getArgb(255, 22, 22, 27));
context.fill(4, 4, 60, (itemStacks.length + 1) * 20 + 5, ColorHelper.Argb.getArgb(255, 42, 42, 47));

View File

@ -27,7 +27,7 @@
],
"depends": {
"fabric": "*",
"minecraft": ">=1.20.5 <=1.20.6",
"minecraft": "~1.21",
"cloth-config": "*"
}
}