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

Expand All @@ -21,11 +21,10 @@ repositories {
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}"
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

}

Expand All @@ -38,7 +37,7 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
it.options.release = 25
}

java {
Expand All @@ -47,8 +46,8 @@ java {
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
}

jar {
Expand All @@ -73,4 +72,4 @@ publishing {
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
}
9 changes: 4 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ org.gradle.parallel=true
org.gradle.configuration-cache=false

# Fabric Properties
minecraft_version=1.21.9
yarn_mappings=1.21.9+build.1
loader_version=0.18.4
loom_version=1.14-SNAPSHOT
minecraft_version=26.1
loader_version=0.18.5
loom_version=1.15-SNAPSHOT

# Mod Properties
mod_version = 3.3.5
maven_group = com.github.hhhzzzsss
archives_base_name = song-player

# Dependencies
fabric_version=0.134.1+1.21.9
fabric_version=0.143.12+26.1
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-9.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
67 changes: 35 additions & 32 deletions src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import com.github.hhhzzzsss.songplayer.song.Song;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.command.CommandSource;
import net.minecraft.item.ItemStack;
import net.minecraft.text.*;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.world.GameMode;

import net.minecraft.ChatFormatting;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -169,7 +172,7 @@ else if (c.getSyntax().length == 1) {
return true;
}
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
return CommandSource.suggestMatching(commandCompletions, suggestionsBuilder);
return SharedSuggestionProvider.suggest(commandCompletions, suggestionsBuilder);
}
}

Expand Down Expand Up @@ -219,7 +222,7 @@ public String getDescription() {
}
public boolean processCommand(String args) {
if (args.length() > 0) {
if (Config.getConfig().survivalOnly && SongPlayer.MC.interactionManager.getCurrentGameMode() != GameMode.SURVIVAL) {
if (Config.getConfig().survivalOnly && SongPlayer.MC.gameMode.getPlayerMode() != GameType.SURVIVAL) {
Util.showChatMessage("§cTo play in survival only mode, you must be in survival mode to start with.");
return true;
}
Expand Down Expand Up @@ -646,7 +649,7 @@ public boolean processCommand(String args) {
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
String[] split = args.split(" ", -1);
if (split.length <= 1) {
return CommandSource.suggestMatching(new String[]{
return SharedSuggestionProvider.suggest(new String[]{
"play",
"create",
"delete",
Expand Down Expand Up @@ -691,7 +694,7 @@ public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBui
if (playlistFiles == null) {
return null;
}
return CommandSource.suggestMatching(
return SharedSuggestionProvider.suggest(
playlistFiles.map(Path::getFileName)
.map(Path::toString),
suggestionsBuilder);
Expand All @@ -709,7 +712,7 @@ public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBui
}
int max = playlistFiles.collect(Collectors.toList()).size();
Stream<String> suggestions = IntStream.range(1, max+1).mapToObj(Integer::toString);
return CommandSource.suggestMatching(suggestions, suggestionsBuilder);
return SharedSuggestionProvider.suggest(suggestions, suggestionsBuilder);
}
return null;
}
Expand Down Expand Up @@ -894,7 +897,7 @@ public boolean processCommand(String args) {
}
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
if (!args.contains(" ")) {
return CommandSource.suggestMatching(Arrays.stream(Stage.StageType.values()).map(Stage.StageType::name), suggestionsBuilder);
return SharedSuggestionProvider.suggest(Arrays.stream(Stage.StageType.values()).map(Stage.StageType::name), suggestionsBuilder);
}
else {
return null;
Expand Down Expand Up @@ -952,7 +955,7 @@ public boolean processCommand(String args) {
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
String[] split = args.split(" ", -1);
if (split.length <= 1) {
return CommandSource.suggestMatching(new String[]{
return SharedSuggestionProvider.suggest(new String[]{
"set",
"reset",
}, suggestionsBuilder);
Expand Down Expand Up @@ -1012,7 +1015,7 @@ public boolean processCommand(String args) {
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
String[] split = args.split(" ", -1);
if (split.length <= 1) {
return CommandSource.suggestMatching(new String[]{
return SharedSuggestionProvider.suggest(new String[]{
"set",
"reset",
}, suggestionsBuilder);
Expand Down Expand Up @@ -1063,7 +1066,7 @@ public boolean processCommand(String args) {
}
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
if (!args.contains(" ")) {
return CommandSource.suggestMatching(new String[]{"swing", "rotate"}, suggestionsBuilder);
return SharedSuggestionProvider.suggest(new String[]{"swing", "rotate"}, suggestionsBuilder);
}
else {
return null;
Expand Down Expand Up @@ -1160,23 +1163,23 @@ public boolean processCommand(String args) {
Util.showChatMessage("§6There is nothing to clean up");
return true;
}
if (MC.player.getEntityPos().squaredDistanceTo(lastStage.getOriginBottomCenter()) > 3*3 || !lastStage.worldName.equals(Util.getWorldName())) {
if (MC.player.position().distanceToSqr(lastStage.getOriginBottomCenter()) > 3*3 || !lastStage.worldName.equals(Util.getWorldName())) {
String coordStr = String.format(
"%d %d %d",
lastStage.position.getX(), lastStage.position.getY(), lastStage.position.getZ()
);
Util.showChatMessage("§6You must be within §33 §6blocks of the center of your stage to start cleanup.");
MutableText coordText = Util.joinTexts(null,
Text.literal("This is at ").setStyle(Style.EMPTY.withColor(Formatting.GOLD)),
Text.literal(coordStr).setStyle(
MutableComponent coordText = Util.joinTexts(null,
Component.literal("This is at ").setStyle(Style.EMPTY.withColor(ChatFormatting.GOLD)),
Component.literal(coordStr).setStyle(
Style.EMPTY
.withColor(Formatting.DARK_AQUA)
.withUnderline(true)
.withColor(ChatFormatting.DARK_AQUA)
.withUnderlined(true)
.withClickEvent(new ClickEvent.CopyToClipboard(coordStr))
.withHoverEvent(new HoverEvent.ShowText(Text.literal("Copy \"" + coordStr + "\"")))
.withHoverEvent(new HoverEvent.ShowText(Component.literal("Copy \"" + coordStr + "\"")))
),
Text.literal(" in world ").setStyle(Style.EMPTY.withColor(Formatting.GOLD)),
Text.literal(lastStage.worldName).setStyle(Style.EMPTY.withColor(Formatting.DARK_AQUA))
Component.literal(" in world ").setStyle(Style.EMPTY.withColor(ChatFormatting.GOLD)),
Component.literal(lastStage.worldName).setStyle(Style.EMPTY.withColor(ChatFormatting.DARK_AQUA))
);
Util.showChatMessage(coordText);
return true;
Expand Down Expand Up @@ -1237,7 +1240,7 @@ public boolean processCommand(String args) {
}
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
if (!args.contains(" ")) {
return CommandSource.suggestMatching(new String[]{"enable", "disable", "getMessage", "setMessage"}, suggestionsBuilder);
return SharedSuggestionProvider.suggest(new String[]{"enable", "disable", "getMessage", "setMessage"}, suggestionsBuilder);
}
else {
return null;
Expand Down Expand Up @@ -1333,12 +1336,12 @@ public boolean processCommand(String args) {
return false;
}

if (MC.interactionManager.getCurrentGameMode() != GameMode.CREATIVE) {
if (MC.gameMode.getPlayerMode() != GameType.CREATIVE) {
Util.showChatMessage("§cYou must be in creative mode to use this command");
return true;
}

ItemStack stack = MC.player.getMainHandStack();
ItemStack stack = MC.player.getMainHandItem();

String[] split = args.split(" ");
switch (split[0].toLowerCase(Locale.ROOT)) {
Expand All @@ -1358,8 +1361,8 @@ public boolean processCommand(String args) {
String name = String.join(" ", Arrays.copyOfRange(split, 1, split.length));
SongItemUtils.updateSongItemTag(stack, (songItemTag) -> songItemTag.putString(SongItemUtils.DISPLAY_NAME_KEY, name));
SongItemUtils.addSongItemDisplay(stack);
MC.player.setStackInHand(Hand.MAIN_HAND, stack);
MC.interactionManager.clickCreativeStack(MC.player.getStackInHand(Hand.MAIN_HAND), 36 + MC.player.getInventory().getSelectedSlot());
MC.player.setItemInHand(InteractionHand.MAIN_HAND, stack);
MC.gameMode.handleCreativeModeItemAdd(MC.player.getItemInHand(InteractionHand.MAIN_HAND), 36 + MC.player.getInventory().getSelectedSlot());
Util.showChatMessage("§6Set song display name to §3" + name);
return true;
} else {
Expand All @@ -1373,7 +1376,7 @@ public boolean processCommand(String args) {
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
String[] split = args.split(" ", -1);
if (split.length <= 1) {
return CommandSource.suggestMatching(new String[]{
return SharedSuggestionProvider.suggest(new String[]{
"create",
"setSongName",
}, suggestionsBuilder);
Expand Down Expand Up @@ -1423,7 +1426,7 @@ public static CompletableFuture<Suggestions> handleSuggestions(String text, Sugg
.stream()
.map((commandName) -> Config.getConfig().prefix+commandName)
.collect(Collectors.toList());
return CommandSource.suggestMatching(names, suggestionsBuilder);
return SharedSuggestionProvider.suggest(names, suggestionsBuilder);
} else {
String[] split = text.split(" ", 2);
if (split[0].startsWith(Config.getConfig().prefix)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/hhhzzzsss/songplayer/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void saveConfigWithErrorHandling() {
Config.saveConfig();
}
catch (IOException e) {
if (SongPlayer.MC.world != null) {
if (SongPlayer.MC.level != null) {
Util.showChatMessage("§cFailed to save config file");
}
e.printStackTrace();
Expand Down
67 changes: 33 additions & 34 deletions src/main/java/com/github/hhhzzzsss/songplayer/FakePlayerEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,36 @@
import com.github.hhhzzzsss.songplayer.playing.Stage;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.PropertyMap;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.OtherClientPlayerEntity;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.player.PlayerEntity;

import java.util.UUID;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.player.RemotePlayer;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player;

public class FakePlayerEntity extends OtherClientPlayerEntity {
public class FakePlayerEntity extends RemotePlayer {
public static final UUID FAKE_PLAYER_UUID = UUID.randomUUID();

ClientPlayerEntity player = SongPlayer.MC.player;
ClientWorld world = SongPlayer.MC.world;
LocalPlayer player = SongPlayer.MC.player;
ClientLevel world = SongPlayer.MC.level;

public FakePlayerEntity() {
super(SongPlayer.MC.world, getProfile());
super(SongPlayer.MC.level, createProfile());

copyStagePosAndPlayerLook();

getInventory().clone(player.getInventory());
getInventory().replaceWith(player.getInventory());

Byte playerModel = player.getDataTracker().get(PlayerEntity.PLAYER_MODE_CUSTOMIZATION_ID);
getDataTracker().set(PlayerEntity.PLAYER_MODE_CUSTOMIZATION_ID, playerModel);
Byte playerModel = player.getEntityData().get(Player.DATA_PLAYER_MODE_CUSTOMISATION);
getEntityData().set(Player.DATA_PLAYER_MODE_CUSTOMISATION, playerModel);

headYaw = player.headYaw;
bodyYaw = player.bodyYaw;
yHeadRot = player.yHeadRot;
yBodyRot = player.yBodyRot;

if (player.isSneaking()) {
setSneaking(true);
setPose(EntityPose.CROUCHING);
if (player.isShiftKeyDown()) {
setShiftKeyDown(true);
setPose(Pose.CROUCHING);
}

// capeX = getX();
Expand All @@ -46,28 +45,28 @@ public FakePlayerEntity() {
}

public void resetPlayerPosition() {
player.refreshPositionAndAngles(getX(), getY(), getZ(), getYaw(), getPitch());
player.snapTo(getX(), getY(), getZ(), getYRot(), getXRot());
}

public void copyStagePosAndPlayerLook() {
Stage lastStage = SongHandler.getInstance().lastStage;
if (lastStage != null) {
refreshPositionAndAngles(lastStage.position.getX()+0.5, lastStage.position.getY(), lastStage.position.getZ()+0.5, player.getYaw(), player.getPitch());
headYaw = player.headYaw;
snapTo(lastStage.position.getX()+0.5, lastStage.position.getY(), lastStage.position.getZ()+0.5, player.getYRot(), player.getXRot());
yHeadRot = player.yHeadRot;
}
else {
copyPositionAndRotation(player);
copyPosition(player);
}
}

private static GameProfile getProfile() {
GameProfile profile = new GameProfile(
FAKE_PLAYER_UUID,
SongPlayer.MC.player.getGameProfile().name(),
SongPlayer.MC.getGameProfile().properties()
);
PlayerListEntry playerListEntry = new PlayerListEntry(SongPlayer.MC.player.getGameProfile(), false);
((ClientPlayNetworkHandlerAccessor)SongPlayer.MC.getNetworkHandler()).getPlayerListEntries().put(FAKE_PLAYER_UUID, playerListEntry);
return profile;
}
}
private static GameProfile createProfile() {
GameProfile profile = new GameProfile(
FAKE_PLAYER_UUID,
SongPlayer.MC.player.getGameProfile().name(),
SongPlayer.MC.getGameProfile().properties()
);
PlayerInfo playerListEntry = new PlayerInfo(SongPlayer.MC.player.getGameProfile(), false);
((ClientPlayNetworkHandlerAccessor)SongPlayer.MC.getConnection()).getSeenPlayersMap().put(FAKE_PLAYER_UUID, playerListEntry);
return profile;
}
}
11 changes: 5 additions & 6 deletions src/main/java/com/github/hhhzzzsss/songplayer/SongPlayer.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.github.hhhzzzsss.songplayer;

import net.fabricmc.api.ModInitializer;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;

import net.minecraft.client.Minecraft;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import java.nio.file.Files;
import java.nio.file.Path;

public class SongPlayer implements ModInitializer {
public static final MinecraftClient MC = MinecraftClient.getInstance();
public static final int NOTEBLOCK_BASE_ID = Block.getRawIdFromState(Blocks.NOTE_BLOCK.getDefaultState())-1;
public static final Minecraft MC = Minecraft.getInstance();
public static final int NOTEBLOCK_BASE_ID = Block.getId(Blocks.NOTE_BLOCK.defaultBlockState())-1;

public static final Path SONG_DIR = Path.of("songs");
public static final Path SONGPLAYER_DIR = Path.of("SongPlayer");
Expand Down
Loading