Skip to content

Commit

Permalink
Merge pull request #51 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Jun 4, 2024
2 parents 41c6ced + 6815c70 commit a3a556c
Show file tree
Hide file tree
Showing 51 changed files with 509 additions and 602 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
curse-publish-task: ""
maven-snapshots: true
java-version: 21
secrets:
ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
uses: FTBTeam/mods-meta/.github/workflows/standard-release.yml@main
with:
curse-publish-task: curseforge
java-version: 21
secrets:
ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }}
saps-token: ${{ secrets.SAPS_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
}

architectury {
Expand Down Expand Up @@ -33,7 +33,7 @@ allprojects {
// needs to be done AFTER version is set
apply from: "https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/publishing.gradle"

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = 17
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = 21

compileJava {
options.encoding = "UTF-8"
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
def ENV = System.getenv()

architectury {
common("forge", "fabric", "neoforge")
common(/*"forge",*/ "fabric", "neoforge")
}

publishing {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/dev/ftb/mods/ftbteams/FTBTeams.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public FTBTeams() {

EnvExecutor.runInEnv(Env.CLIENT, () -> FTBTeamsClient::init);

FTBTeamsNet.init();
FTBTeamsNet.register();
}

private void serverAboutToStart(MinecraftServer server) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;

import java.util.Optional;
Expand Down Expand Up @@ -44,7 +45,7 @@ public Optional<Boolean> fromString(String string) {
}

@Override
public void write(FriendlyByteBuf buf) {
public void write(RegistryFriendlyByteBuf buf) {
buf.writeBoolean(getDefaultValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.ftb.mods.ftblibrary.config.ConfigGroup;
import dev.ftb.mods.ftblibrary.icon.Color4I;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;

import java.util.Optional;
Expand Down Expand Up @@ -33,7 +34,7 @@ public Optional<Color4I> fromString(String string) {
}

@Override
public void write(FriendlyByteBuf buf) {
public void write(RegistryFriendlyByteBuf buf) {
buf.writeVarInt(getDefaultValue().rgb());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;

Expand Down Expand Up @@ -49,7 +50,7 @@ public Optional<Double> fromString(String string) {
}

@Override
public void write(FriendlyByteBuf buf) {
public void write(RegistryFriendlyByteBuf buf) {
buf.writeDouble(getDefaultValue());
buf.writeDouble(minValue);
buf.writeDouble(maxValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentSerialization;
import net.minecraft.resources.ResourceLocation;

import java.util.*;
Expand All @@ -31,10 +33,14 @@ private static <T> Map<String,Component> buildMap(NameMap<T> nameMap) {
return res;
}

static EnumProperty fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
static EnumProperty fromNetwork(ResourceLocation id, RegistryFriendlyByteBuf buf) {
String def = buf.readUtf(Short.MAX_VALUE);
List<String> values = buf.readList(b -> b.readUtf(Short.MAX_VALUE));
Map<String,Component> names = buf.readMap(b -> b.readUtf(Short.MAX_VALUE), FriendlyByteBuf::readComponent);
int len = buf.readVarInt();
Map<String,Component> names = new HashMap<>();
for (int i = 0; i < len; i++) {
names.put(buf.readUtf(), ComponentSerialization.STREAM_CODEC.decode(buf));
}
return new EnumProperty(id, () -> def, values, names);
}

Expand All @@ -49,10 +55,15 @@ public Optional<String> fromString(String string) {
}

@Override
public void write(FriendlyByteBuf buf) {
public void write(RegistryFriendlyByteBuf buf) {
buf.writeUtf(getDefaultValue(), Short.MAX_VALUE);
buf.writeCollection(values, FriendlyByteBuf::writeUtf);
buf.writeMap(names, FriendlyByteBuf::writeUtf, FriendlyByteBuf::writeComponent);

buf.writeVarInt(names.size());
names.forEach((k, v) -> {
buf.writeUtf(k);
ComponentSerialization.STREAM_CODEC.encode(buf, v);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;

Expand Down Expand Up @@ -53,7 +54,7 @@ public Optional<Integer> fromString(String string) {
}

@Override
public void write(FriendlyByteBuf buf) {
public void write(RegistryFriendlyByteBuf buf) {
buf.writeVarInt(getDefaultValue());
buf.writeVarInt(minValue);
buf.writeVarInt(maxValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.ftb.mods.ftblibrary.config.ConfigGroup;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;

import java.util.Optional;
Expand Down Expand Up @@ -36,7 +37,7 @@ public String toString(PrivacyMode value) {
}

@Override
public void write(FriendlyByteBuf buf) {
public void write(RegistryFriendlyByteBuf buf) {
buf.writeEnum(getDefaultValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;

import java.util.ArrayList;
Expand Down Expand Up @@ -41,7 +42,7 @@ public Optional<List<String>> fromString(String string) {
}

@Override
public void write(FriendlyByteBuf buf) {
public void write(RegistryFriendlyByteBuf buf) {
buf.writeCollection(getDefaultValue(), FriendlyByteBuf::writeUtf);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.ftb.mods.ftblibrary.config.ConfigGroup;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -53,7 +54,7 @@ public Optional<String> fromString(String string) {
}

@Override
public void write(FriendlyByteBuf buf) {
public void write(RegistryFriendlyByteBuf buf) {
buf.writeUtf(getDefaultValue(), Short.MAX_VALUE);
buf.writeVarInt(pattern == null ? 0 : pattern.flags());
buf.writeUtf(pattern == null ? "" : pattern.pattern(), Short.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dev.ftb.mods.ftblibrary.config.ConfigGroup;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;

import java.util.Optional;
Expand Down Expand Up @@ -39,7 +39,7 @@ public String getTranslationKey(String prefix) {

public abstract Optional<T> fromString(String string);

public abstract void write(FriendlyByteBuf buf);
public abstract void write(RegistryFriendlyByteBuf buf);

public String toString(T value) {
return value.toString();
Expand All @@ -63,11 +63,11 @@ public final boolean equals(Object o) {
return false;
}

public void writeValue(FriendlyByteBuf buf, T value) {
public void writeValue(RegistryFriendlyByteBuf buf, T value) {
buf.writeUtf(toString(value), Short.MAX_VALUE);
}

public T readValue(FriendlyByteBuf buf) {
public T readValue(RegistryFriendlyByteBuf buf) {
return fromString(buf.readUtf(Short.MAX_VALUE)).orElse(getDefaultValue());
}

Expand All @@ -86,7 +86,7 @@ public TeamPropertyValue<T> createDefaultValue() {
return new TeamPropertyValue<>(this, getDefaultValue());
}

public TeamPropertyValue<T> createValueFromNetwork(FriendlyByteBuf buf) {
public TeamPropertyValue<T> createValueFromNetwork(RegistryFriendlyByteBuf buf) {
return new TeamPropertyValue<>(this, readValue(buf));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.ftb.mods.ftbteams.api.property;

import net.minecraft.network.FriendlyByteBuf;

import java.util.function.BiConsumer;

/**
Expand Down Expand Up @@ -53,16 +51,9 @@ public interface TeamPropertyCollection {
<T> void set(TeamProperty<T> key, T value);

/**
* Write this property collection to the network buffer.
*
* @param buffer the network buffer
*/
void write(FriendlyByteBuf buffer);

/**
* Read value from the network buffer into this property collection, replacing any existing property values.
* Get the number of properties in this collection.
*
* @param buffer the network buffer
* @return the number of properties
*/
void read(FriendlyByteBuf buffer);
int size();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.ftb.mods.ftbteams.api.property;

import dev.ftb.mods.ftblibrary.icon.Color4I;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;

import java.util.HashMap;
Expand All @@ -28,11 +28,11 @@ private TeamPropertyType(String id, FromNet<T> deserializer) {
this.deserializer = deserializer;
}

public static TeamProperty<?> read(FriendlyByteBuf buf) {
public static TeamProperty<?> read(RegistryFriendlyByteBuf buf) {
return MAP.get(buf.readUtf(Short.MAX_VALUE)).deserializer.apply(buf.readResourceLocation(), buf);
}

public static void write(FriendlyByteBuf buf, TeamProperty<?> p) {
public static void write(RegistryFriendlyByteBuf buf, TeamProperty<?> p) {
buf.writeUtf(p.getType().id, Short.MAX_VALUE);
buf.writeResourceLocation(p.id);
p.write(buf);
Expand All @@ -45,6 +45,6 @@ private static <Y> TeamPropertyType<Y> register(String id, FromNet<Y> p) {
}

public interface FromNet<Y> {
TeamProperty<Y> apply(ResourceLocation id, FriendlyByteBuf buf);
TeamProperty<Y> apply(ResourceLocation id, RegistryFriendlyByteBuf buf);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void init() {

CustomClickEvent.EVENT.register(event -> {
if (event.id().equals(OPEN_GUI_ID)) {
new OpenGUIMessage().sendToServer();
OpenGUIMessage.sendToServer();
return EventResult.interruptTrue();
}
return EventResult.pass();
Expand All @@ -47,7 +47,7 @@ private static void registerKeys() {

private static EventResult keyPressed(Minecraft client, int keyCode, int scanCode, int action, int modifiers) {
if (openTeamsKey.isDown()) {
new OpenGUIMessage().sendToServer();
OpenGUIMessage.sendToServer();
return EventResult.interruptTrue();
}
return EventResult.pass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@

import com.mojang.authlib.GameProfile;
import dev.ftb.mods.ftbteams.api.client.KnownClientPlayer;
import net.minecraft.core.UUIDUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;

import java.util.UUID;

public class KnownClientPlayerNet {
public static StreamCodec<FriendlyByteBuf, KnownClientPlayer> STREAM_CODEC = StreamCodec.composite(
UUIDUtil.STREAM_CODEC, KnownClientPlayer::id,
ByteBufCodecs.STRING_UTF8, KnownClientPlayer::name,
ByteBufCodecs.BOOL, KnownClientPlayer::online,
UUIDUtil.STREAM_CODEC, KnownClientPlayer::teamId,
ByteBufCodecs.GAME_PROFILE, KnownClientPlayer::profile,
ByteBufCodecs.COMPOUND_TAG, KnownClientPlayer::extraData,
KnownClientPlayer::new
);

public static KnownClientPlayer fromNetwork(FriendlyByteBuf buf) {
UUID id = buf.readUUID();
String name = buf.readUtf(Short.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.Sets;
import com.mojang.authlib.GameProfile;
import dev.architectury.networking.NetworkManager;
import dev.ftb.mods.ftblibrary.icon.Icons;
import dev.ftb.mods.ftbteams.api.client.KnownClientPlayer;
import dev.ftb.mods.ftbteams.data.ClientTeamManagerImpl;
Expand Down Expand Up @@ -45,10 +46,10 @@ public void setInvited(GameProfile profile, boolean invited) {
protected ExecuteButton makeExecuteButton() {
return new ExecuteButton(Component.translatable("gui.accept"), Icons.ADD, () -> {
if (!toAdd.isEmpty()) {
new PlayerGUIOperationMessage(PlayerGUIOperationMessage.Operation.ADD_ALLY, toAdd).sendToServer();
NetworkManager.sendToServer(PlayerGUIOperationMessage.forGameProfiles(PlayerGUIOperationMessage.Operation.ADD_ALLY, toAdd));
}
if (!toRemove.isEmpty()) {
new PlayerGUIOperationMessage(PlayerGUIOperationMessage.Operation.REMOVE_ALLY, toRemove).sendToServer();
NetworkManager.sendToServer(PlayerGUIOperationMessage.forGameProfiles(PlayerGUIOperationMessage.Operation.REMOVE_ALLY, toRemove));
}
closeGui();
}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ftb.mods.ftbteams.client.gui;

import com.mojang.authlib.GameProfile;
import dev.architectury.networking.NetworkManager;
import dev.ftb.mods.ftblibrary.icon.Color4I;
import dev.ftb.mods.ftblibrary.icon.FaceIcon;
import dev.ftb.mods.ftblibrary.icon.Icons;
Expand Down Expand Up @@ -76,7 +77,7 @@ public boolean renderTitleInCenter() {
@Override
public void onClicked(MouseButton mouseButton) {
closeGui(false);
new CreatePartyMessage(nameTextBox.getText(), descriptionTextBox.getText(), teamColor.rgb(), invitedMembers).sendToServer();
NetworkManager.sendToServer(new CreatePartyMessage(nameTextBox.getText(), descriptionTextBox.getText(), teamColor.rgb(), invitedMembers));
}
});

Expand Down
Loading

0 comments on commit a3a556c

Please sign in to comment.