Skip to content

Commit

Permalink
Update to 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sciwhiz12 committed May 13, 2024
1 parent f925a4a commit 201800a
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 129 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugins {
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.96'
id 'net.neoforged.gradle.userdev' version '7.0.120'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'org.cadixdev.licenser' version '0.6.1'
id 'tk.sciwhiz12.gradle.simplversion' version '0.1.0'
id 'dev.sciwhiz12.gradle.simplversion' version '0.2.0'
}

versions {
Expand Down Expand Up @@ -111,7 +111,7 @@ tasks.withType(Jar).configureEach {
reproducibleFileOrder = true

// Normalize line endings from CRLF to LF
filesMatching('META-INF/mods.toml') {
filesMatching('META-INF/neoforge.mods.toml') {
//noinspection UnnecessaryQualifiedReference
filter(org.apache.tools.ant.filters.FixCrLfFilter.class,
eol: org.apache.tools.ant.filters.FixCrLfFilter.CrLf.newInstance('lf'))
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ neogradle.subsystems.decompiler.maxMemory=4g
org.gradle.caching=true

# Minecraft, Forge, and mappings versions
mc_version=1.20.4
neoforge_version=20.4.182
mc_version=1.20.6
neoforge_version=20.6.62-beta
mappings_channel=parchment
mappings_version=2023.08.06-1.20.1
java_version=17
mappings_version=2024.05.01
java_version=21

# Logging markers and console logging level
logging_markers=REGISTRIES
logging_console=debug

# Versions of dependencies
jda_version=5.0.0-beta.20
jda_version=5.0.0-beta.24
webhook_version=0.8.4
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
import net.minecraft.util.InclusiveRange;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.data.event.GatherDataEvent;

import java.util.Optional;

@Mod.EventBusSubscriber(modid = Concord.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
@EventBusSubscriber(modid = Concord.MODID, bus = EventBusSubscriber.Bus.MOD)
public class DataGeneration {
@SubscribeEvent
static void onGatherData(GatherDataEvent event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.4 2024-02-29T05:09:37.7276443 Pack Metadata
6640faea5dcd2503e4ce56c9abce87dce67ea86d pack.mcmeta
// 1.20.6 2024-05-13T21:50:15.7912936 Pack Metadata
e6104518bcfaf9d156fa44714a7934fce53b4660 pack.mcmeta
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.4 2024-03-01T06:11:22.5691513 Languages: en_us for mod: concord
// 1.20.6 2024-05-13T21:50:15.788291 Languages: en_us for mod: concord
9aada5c1a216ea46fcf82e4f1c65fe748c2bd007 assets/concord/lang/en_us.json
6 changes: 3 additions & 3 deletions src/data/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"pack": {
"description": "concord resources",
"pack_format": 26,
"pack_format": 41,
"supported_formats": [
22,
26
32,
41
]
}
}
1 change: 0 additions & 1 deletion src/main/java/dev/sciwhiz12/concord/Concord.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public Concord(ModContainer container, IEventBus modBus) {
// ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class,
// () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (ver, remote) -> true));
ConcordNetwork.register(modBus);
ConcordFeatures.register(modBus);
ConcordConfig.register(container);

NeoForge.EVENT_BUS.addListener(EventPriority.LOWEST, this::onServerStarting);
Expand Down
44 changes: 13 additions & 31 deletions src/main/java/dev/sciwhiz12/concord/features/ConcordFeatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,19 @@
package dev.sciwhiz12.concord.features;

import dev.sciwhiz12.concord.Concord;
import net.minecraft.nbt.Tag;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.attachment.AttachmentType;
import net.neoforged.neoforge.attachment.IAttachmentHolder;
import net.neoforged.neoforge.attachment.IAttachmentSerializer;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import io.netty.util.AttributeKey;
import net.minecraft.server.level.ServerPlayer;
import org.apache.maven.artifact.versioning.ArtifactVersion;

import javax.annotation.Nullable;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Supplier;
import java.util.Optional;

public class ConcordFeatures {
private static final DeferredRegister<AttachmentType<?>> ATTACHMENT_TYPES =
DeferredRegister.create(NeoForgeRegistries.ATTACHMENT_TYPES, Concord.MODID);

public static final Supplier<AttachmentType<ConcordFeatures>> ATTACHMENT = ATTACHMENT_TYPES.register(
"features", () -> AttachmentType.builder(holder -> new ConcordFeatures(Map.of()))
.serialize(new IAttachmentSerializer<>() {
@Override
public @Nullable Tag write(ConcordFeatures attachment) {
return null;
}

@Override
public ConcordFeatures read(IAttachmentHolder holder, Tag tag) {
throw new UnsupportedOperationException("Attempted to deserialize attachment that can never be serialized");
}
})
.copyHandler((holder, attachment) -> new ConcordFeatures(attachment.features))
.copyOnDeath()
.build()
);
public static final AttributeKey<ConcordFeatures> CHANNEL_ATTRIBUTE_KEY = AttributeKey.newInstance(Concord.MODID +":features");
public static final ConcordFeatures EMPTY =new ConcordFeatures(Map.of());

private final Map<String, ArtifactVersion> features;

Expand Down Expand Up @@ -104,8 +81,13 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(features);
}

public static void register(IEventBus modBus) {
ATTACHMENT_TYPES.register(modBus);

@Nullable
public static ConcordFeatures getOrNull(ServerPlayer player) {
return player.connection.getConnection().channel().attr(CHANNEL_ATTRIBUTE_KEY).get();
}

public static ConcordFeatures getOrEmpty(ServerPlayer player) {
return Optional.ofNullable(getOrNull(player)).orElse(EMPTY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static MutableComponent processCustomFormatting(String input) {
// Make sure that formatting at the end of messages, or lone formatting, is dealt with.
final String formatString = firstSpacePosition == -1 ? part.substring(1) : part.substring(1, firstSpacePosition);
// Use TextColor's built-in parsing to do the heavy lifting.
final TextColor color = TextColor.parseColor(formatString).get().left().orElse(TextColor.fromLegacyFormat(WHITE));
final TextColor color = TextColor.parseColor(formatString).result().orElse(TextColor.fromLegacyFormat(WHITE));
// Assign the TextColor into a Style instance so that we can use it with a TextComponent.
final Style formatting = Style.EMPTY.withColor(color);

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/dev/sciwhiz12/concord/msg/MessageListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.ServerChatEvent;
import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.neoforge.event.tick.ServerTickEvent;

import java.util.Objects;

Expand Down Expand Up @@ -69,8 +69,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
}

@SubscribeEvent
void onServerTick(TickEvent.ServerTickEvent event) {
if (event.phase != TickEvent.Phase.END) return;
void onServerTickPost(ServerTickEvent.Post event) {
bot.messaging().processMessages();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/sciwhiz12/concord/msg/Messaging.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static record DiscordBound(String message, CompletableFuture<Message> future) im
private static final DefaultArtifactVersion ZERO_VERSION = new DefaultArtifactVersion("0.0.0");

static ArtifactVersion getFeatureVersionWithDefault(ServerPlayer player, FeatureVersion feature) {
final @Nullable ArtifactVersion version = player.getData(ConcordFeatures.ATTACHMENT).getFeature(feature);
final @Nullable ArtifactVersion version = ConcordFeatures.getOrEmpty(player).getFeature(feature);
if (version == null) return ZERO_VERSION;
return version;
}
Expand Down
29 changes: 16 additions & 13 deletions src/main/java/dev/sciwhiz12/concord/network/ConcordNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import dev.sciwhiz12.concord.features.FeatureVersion;
import net.minecraft.Util;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.network.event.OnGameConfigurationEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
import net.neoforged.neoforge.network.event.RegisterConfigurationTasksEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
import org.apache.maven.artifact.versioning.ArtifactVersion;

import java.util.Arrays;
Expand All @@ -42,27 +42,31 @@ public static void register(IEventBus modBus) {
modBus.addListener(ConcordNetwork::onGatherPayloads);
}

static void onRegisterPayloadHandlers(RegisterPayloadHandlerEvent event) {
final IPayloadRegistrar registrar = event.registrar(Concord.MODID)
static void onRegisterPayloadHandlers(RegisterPayloadHandlersEvent event) {
final PayloadRegistrar registrar = event.registrar(Concord.MODID)
.optional();

registrar.configuration(FeaturesPayload.ID, FeaturesPayload::read,
handlers -> handlers
.client(ConcordNetwork::handleClient)
.server(ConcordNetwork::handleServer));
registrar.configurationBidirectional(FeaturesPayload.TYPE, FeaturesPayload.STREAM_CODEC, ConcordNetwork::handle);
}

static void onGatherPayloads(OnGameConfigurationEvent event) {
static void onGatherPayloads(RegisterConfigurationTasksEvent event) {
event.register(new FeaturesTask(event.getListener()));
}

static void handle(FeaturesPayload payload, IPayloadContext context) {
switch (context.flow()) {
case CLIENTBOUND -> handleClient(payload, context);
case SERVERBOUND -> handleServer(payload, context);
}
}

static void handleClient(FeaturesPayload payload, IPayloadContext context) {
// Received the payload from the server, so we know the server has Concord enabled
// Send back our own payload, to inform the server that we, the client, have Concord enabled too
final Map<String, ArtifactVersion> features = Arrays.stream(FeatureVersion.values())
.map(f -> Map.entry(f.featureName(), f.currentVersion()))
.collect(Util.toMap());
context.replyHandler().send(new FeaturesPayload(features));
context.reply(new FeaturesPayload(features));

// In the future, we can use the info from the payload to decide on what we are going to do
// For now, the features payload is a 'ping' for server->client
Expand All @@ -71,7 +75,6 @@ static void handleClient(FeaturesPayload payload, IPayloadContext context) {
static void handleServer(FeaturesPayload payload, IPayloadContext context) {
// The client sent back the features payload, so it has Concord enabled
// Store the features info it sent
context.player().ifPresent(player ->
player.setData(ConcordFeatures.ATTACHMENT, new ConcordFeatures(payload.features())));
context.connection().channel().attr(ConcordFeatures.CHANNEL_ATTRIBUTE_KEY).set(new ConcordFeatures(payload.features()));
}
}
39 changes: 21 additions & 18 deletions src/main/java/dev/sciwhiz12/concord/network/FeaturesPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@

package dev.sciwhiz12.concord.network;

import com.google.common.collect.Maps;
import dev.sciwhiz12.concord.Concord;
import dev.sciwhiz12.concord.features.ConcordFeatures;
import io.netty.buffer.ByteBuf;
import io.netty.util.AttributeKey;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import org.apache.maven.artifact.versioning.ArtifactVersion;
Expand All @@ -32,29 +38,26 @@
import java.util.Map;

public record FeaturesPayload(Map<String, ArtifactVersion> features) implements CustomPacketPayload {
public static final ResourceLocation ID = new ResourceLocation(Concord.MODID, "features");
public static final Type<FeaturesPayload> TYPE = new Type<>(new ResourceLocation(Concord.MODID, "features"));
private static final StreamCodec<ByteBuf, ArtifactVersion> ARTIFACT_VERSION_CODEC = ByteBufCodecs.STRING_UTF8.map(
DefaultArtifactVersion::new,
ArtifactVersion::toString
);
public static final StreamCodec<FriendlyByteBuf, FeaturesPayload> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.map(
Maps::newHashMapWithExpectedSize,
ByteBufCodecs.STRING_UTF8,
ARTIFACT_VERSION_CODEC
),
FeaturesPayload::features,
FeaturesPayload::new);

public FeaturesPayload {
features = Map.copyOf(features);
}

@Override
public void write(FriendlyByteBuf buffer) {
buffer.writeMap(features,
FriendlyByteBuf::writeUtf,
(buf, ver) -> buf.writeUtf(ver.toString())
);
}

public static FeaturesPayload read(FriendlyByteBuf buffer) {
return new FeaturesPayload(buffer.readMap(
FriendlyByteBuf::readUtf,
buf -> new DefaultArtifactVersion(buf.readUtf())
));
}

@Override
public ResourceLocation id() {
return ID;
public Type<? extends CustomPacketPayload> type() {
return TYPE;
}
}
4 changes: 2 additions & 2 deletions src/main/java/dev/sciwhiz12/concord/util/Translation.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ default MutableComponent eagerComponent(Object... formatArgs) {

private boolean translateEagerly(CommandSourceStack source) {
return !ConcordConfig.LAZY_TRANSLATIONS.get()
|| (source.getEntity() instanceof ServerPlayer player && !player.getData(ConcordFeatures.ATTACHMENT).isEmpty());
|| (source.getEntity() instanceof ServerPlayer player && ConcordFeatures.getOrNull(player) != null);
}

private boolean translateEagerly(@Nullable Entity sourceEntity) {
return !ConcordConfig.LAZY_TRANSLATIONS.get()
|| (sourceEntity instanceof ServerPlayer player && !player.getData(ConcordFeatures.ATTACHMENT).isEmpty());
|| (sourceEntity instanceof ServerPlayer player && ConcordFeatures.getOrNull(player) != null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static MutableComponent createTranslation(boolean lazyTranslate, final St
}

public static MutableComponent createTranslation(@Nullable ServerPlayer entity, String translationKey, Object... args) {
return createTranslation(!ConcordConfig.LAZY_TRANSLATIONS.get() || (entity != null && !entity.getData(ConcordFeatures.ATTACHMENT).isEmpty()),
return createTranslation(!ConcordConfig.LAZY_TRANSLATIONS.get() || (entity != null && ConcordFeatures.getOrNull(entity) != null),
translationKey, args);
}

Expand Down
Loading

0 comments on commit 201800a

Please sign in to comment.