Skip to content

Commit

Permalink
Update to 1.20.6 (Merge #13)
Browse files Browse the repository at this point in the history
* Update to Java 21 & Minecraft 1.20.6
* Small code refactor

---------

Co-authored-by: shurik204 <iwmdiif@gmail.com>
  • Loading branch information
MaGyul and shurik204 authored May 17, 2024
1 parent 25bf91b commit 93dceef
Show file tree
Hide file tree
Showing 30 changed files with 257 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Setup JDK 17
- name: Setup JDK 21
uses: actions/setup-java@v3
with:
java-version: 17
java-version: 21
distribution: 'microsoft'

- name: build
Expand Down
14 changes: 6 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.6-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 + "-" + project.minecraft_version
version = project.mod_version
Expand Down Expand Up @@ -38,10 +38,8 @@ dependencies {
exclude(group: "net.fabricmc.fabric-api")
}

// 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}"
modRuntimeOnly("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
modRuntimeOnly("com.terraformersmc:modmenu:${project.modmenu_version}")
}

loom {
Expand All @@ -57,7 +55,7 @@ processResources {
}

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

java {
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.0
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
loader_version=0.15.11

# Mod Properties
mod_version=1.2.5
maven_group=me.shurik.better-suggestions
archives_base_name=better-suggestions

# Dependencies
fabric_version=0.91.2+1.20.4
cloth_config_version=13.0.114
modmenu_version=9.0.0-pre.1
fabric_version=0.98.0+1.20.6
cloth_config_version=14.0.126
modmenu_version=10.0.0-beta.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-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.shurik.bettersuggestions.suggestion.FunctionArgumentTypeSuggestions;
import me.shurik.bettersuggestions.suggestion.ScoreHolderArgumentTypeSuggestions;
import net.fabricmc.api.ModInitializer;
import net.minecraft.util.Identifier;

public class BetterSuggestionsMod implements ModInitializer {
static {
Expand All @@ -20,4 +21,8 @@ public void onInitialize() {

ModConstants.LOGGER.info("Suggestions!");
}

public static Identifier id(String path) {
return new Identifier(ModConstants.MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
package me.shurik.bettersuggestions.client.data;

import me.shurik.bettersuggestions.utils.Scoreboards;

// Client doesn't have access to `ScoreboardObjective`s so we store the name instead
public record ClientScoreboardValue(String objective, int score) {}
public record ClientScoreboardValue(String objective, int score) implements Scoreboards.ScoreboardValue {
@Override
public String getObjective() {
return objective;
}

@Override
public int getScore() {
return score;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import me.shurik.bettersuggestions.client.Client;
import me.shurik.bettersuggestions.client.access.ClientEntityDataAccessor;
import me.shurik.bettersuggestions.client.render.SpecialRendererQueue;
import me.shurik.bettersuggestions.network.ModPackets;
import me.shurik.bettersuggestions.network.packet.ModPresenceBeaconPacket;
import net.fabricmc.fabric.api.client.networking.v1.C2SPlayChannelEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;


public class ClientEvents {
public static void init() {
// Special cases for rendering highlighted entities
Expand All @@ -28,7 +27,7 @@ public static void init() {
C2SPlayChannelEvents.REGISTER.register((handler, sender, client, channels) -> {
if (Client.SERVER_SIDE_PRESENT) return;

Client.SERVER_SIDE_PRESENT = channels.contains(ModPackets.ModPresenceBeacon);
Client.SERVER_SIDE_PRESENT = channels.contains(ModPresenceBeaconPacket.ID.id());
if (Client.SERVER_SIDE_PRESENT) {
Client.LOGGER.info("Detected mod installed on server");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class ClientPlayNetworkHandlerMixin {
void captureSuggestions(CommandSuggestionsS2CPacket packet, CallbackInfo info) {
// Abusing completion packet to store entity id
// Hopefully no one else uses this or spawns more than a billion entities lol
if (packet.getCompletionId() < -1_000_000_000 && packet.getCompletionId() > -2_000_000_000) {
if (packet.id() < -1_000_000_000 && packet.id() > -2_000_000_000) {
// Convert back
int entityId = -packet.getCompletionId() - 1_000_000_000;
int entityId = -packet.id() - 1_000_000_000;
// Remove from pending requests
ClientDataGetter.pendingTagRequests.remove(entityId);
// Get entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;

public class ClientNetworking {
public static void send(Identifier packetId, PacketByteBuf buf) {
ClientPlayNetworking.send(packetId, buf);
public static void send(CustomPayload packet) {
ClientPlayNetworking.send(packet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,46 @@
import me.shurik.bettersuggestions.client.Client;
import me.shurik.bettersuggestions.client.access.ClientEntityDataAccessor;
import me.shurik.bettersuggestions.client.data.ClientDataGetter;
import me.shurik.bettersuggestions.network.ModPackets;
import me.shurik.bettersuggestions.utils.ByteBufUtils;
import me.shurik.bettersuggestions.network.packet.EntityCommandTagsResponseS2CPacket;
import me.shurik.bettersuggestions.network.packet.EntityScoresResponseS2CPacket;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketByteBuf;

public class ClientPacketHandler {
public static void init() {
ClientPlayNetworking.registerGlobalReceiver(ModPackets.EntityCommandTagsS2CPacketResponseID, ClientPacketHandler::receiveEntityCommandTagsUpdate);
ClientPlayNetworking.registerGlobalReceiver(ModPackets.EntityScoresS2CPacketResponseID, ClientPacketHandler::receiveEntityScoresUpdate);
ClientPlayNetworking.registerGlobalReceiver(EntityCommandTagsResponseS2CPacket.ID, ClientPacketHandler::receiveEntityCommandTagsUpdate);
ClientPlayNetworking.registerGlobalReceiver(EntityScoresResponseS2CPacket.ID, ClientPacketHandler::receiveEntityScoresUpdate);
}

private static void receiveEntityCommandTagsUpdate(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
int entityId = buf.readInt();
private static void receiveEntityCommandTagsUpdate(EntityCommandTagsResponseS2CPacket packet, ClientPlayNetworking.Context context) {
int entityId = packet.entityId();
// Remove from pending requests
ClientDataGetter.pendingTagRequests.remove(entityId);
// Get entity
Entity entity = client.world.getEntityById(entityId);
Entity entity = context.client().world.getEntityById(entityId);
if (entity == null) {
if (ModConstants.DEBUG) {
Client.LOGGER.warn("Received tag list for an unknown entity with ID " + entityId);
}
return;
}

((ClientEntityDataAccessor) entity).setClientCommandTags(ByteBufUtils.readSet(buf, PacketByteBuf::readString));
((ClientEntityDataAccessor) entity).setClientCommandTags(packet.commandTags());
}

private static void receiveEntityScoresUpdate(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
int entityId = buf.readInt();
private static void receiveEntityScoresUpdate(EntityScoresResponseS2CPacket packet, ClientPlayNetworking.Context context) {
int entityId = packet.entityId();
// Remove from pending requests
ClientDataGetter.pendingScoreRequests.remove(entityId);
// Get entity
Entity entity = client.world.getEntityById(entityId);
Entity entity = context.client().world.getEntityById(entityId);
if (entity == null) {
if (ModConstants.DEBUG) {
Client.LOGGER.warn("Received score list for an unknown entity with ID " + entityId);
}
return;
}

((ClientEntityDataAccessor) entity).setClientScoreboardValues(ByteBufUtils.readSet(buf, ByteBufUtils::readScoreboardValue));
((ClientEntityDataAccessor) entity).setClientScoreboardValues(packet.convertClientScoreboardValue());
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package me.shurik.bettersuggestions.client.network;

import me.shurik.bettersuggestions.network.ModPackets;
import me.shurik.bettersuggestions.utils.ByteBufUtils;
import me.shurik.bettersuggestions.network.packet.EntityCommandTagsRequestC2SPacket;
import me.shurik.bettersuggestions.network.packet.EntityScoresRequestC2SPacket;
import net.minecraft.entity.Entity;

public class ClientPacketSender {
public static void sendEntityCommandTagsRequest(Entity entity) { sendEntityCommandTagsRequest(entity.getId()); }
public static void sendEntityCommandTagsRequest(int entityId) { ClientNetworking.send(ModPackets.EntityCommandTagsRequestC2SPacketID, ByteBufUtils.withInt(entityId)); }
public static void sendEntityCommandTagsRequest(int entityId) { ClientNetworking.send(new EntityCommandTagsRequestC2SPacket(entityId)); }
public static void sendEntityScoresRequest(Entity entity) { sendEntityScoresRequest(entity.getId()); }
public static void sendEntityScoresRequest(int entityId) { ClientNetworking.send(ModPackets.EntityScoresRequestC2SPacketID, ByteBufUtils.withInt(entityId)); }
public static void sendEntityScoresRequest(int entityId) { ClientNetworking.send(new EntityScoresRequestC2SPacket(entityId)); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<
return builder.buildFuture();
}

CompletionsContainer<TextCompletion> completions = TextParser.getCompletions(input, builder);
CompletionsContainer<TextCompletion> completions = TextParser.getCompletions(input, context, builder);
if (completions != null) {
builder = builder.createOffset(builder.getStart() + builder.getRemaining().length() - completions.getOffset());
for (TextCompletion completion : completions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package me.shurik.bettersuggestions.client.utils.text;

import com.google.gson.*;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import me.shurik.bettersuggestions.client.utils.CompletionsContainer;
import me.shurik.bettersuggestions.client.utils.text.TextCompletions.TextCompletion;
import me.shurik.bettersuggestions.utils.CustomJsonReader;
import net.minecraft.command.CommandSource;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;

Expand All @@ -13,10 +15,13 @@

public class TextParser {
@Nullable
public static CompletionsContainer<TextCompletion> getCompletions(String json, SuggestionsBuilder builder) {
public static <S> CompletionsContainer<TextCompletion> getCompletions(String json, CommandContext<S> context, SuggestionsBuilder builder) {
try {
// Try parsing the input as a Text object
Text.Serialization.fromJson(builder.getInput().substring(builder.getStart()));
S source = context.getSource();
if (source instanceof CommandSource cs) {
Text.Serialization.fromJson(builder.getInput().substring(builder.getStart()), cs.getRegistryManager());
}
// if successful, don't suggest anything
return null;
} catch (Exception ignored) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class EntityTypeBuilderMixin<T extends Entity> {

@Inject(at = @At("TAIL"), method = "maxTrackingRange")
public void maxTrackingRange(int maxTrackRange, CallbackInfoReturnable<EntityType.Builder<?>> info) {
if (maxTrackRange == 0 && dimensions.width == 0.0F && dimensions.height == 0.0F) {
if (maxTrackRange == 0 && dimensions.width() == 0.0F && dimensions.height() == 0.0F) {
maxTrackingRange = 6;
dimensions = EntityDimensions.fixed(0.0F, 0.0F);
}
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/me/shurik/bettersuggestions/network/ModPackets.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
package me.shurik.bettersuggestions.network;

import me.shurik.bettersuggestions.utils.ByteBufUtils;
import me.shurik.bettersuggestions.utils.Scoreboards.ScoreboardScoreContainer;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

import java.util.Collection;
import java.util.Set;

public class ServerNetworking {
public static PacketByteBuf createEntityCommandTagsBuffer(int entityId, Set<String> commandTags) {
return ByteBufUtils.writeCollection(ByteBufUtils.withInt(entityId), commandTags, PacketByteBuf::writeString);
}

public static PacketByteBuf createEntityScoresBuffer(int entityId, Collection<ScoreboardScoreContainer> scores) {
return ByteBufUtils.writeCollection(ByteBufUtils.withInt(entityId), scores, ByteBufUtils::writeScoreboardValue);
}

// Copy of Fabric PlayerLookup.tracking
public static Collection<ServerPlayerEntity> tracking(Entity entity) {
return PlayerLookup.tracking(entity);
}

public static void broadcastFromEntity(Entity entity, Identifier packetId, PacketByteBuf buf) {
public static void broadcastFromEntity(Entity entity, CustomPayload packet) {
for (ServerPlayerEntity player : tracking(entity)) {
send(player, packetId, buf);
send(player, packet);
}
}

public static void send(ServerPlayerEntity player, Identifier packetId, PacketByteBuf buf) {
ServerPlayNetworking.send(player, packetId, buf);
public static void send(ServerPlayerEntity player, CustomPayload packet) {
ServerPlayNetworking.send(player, packet);
}
}
Loading

0 comments on commit 93dceef

Please sign in to comment.