Skip to content

Commit 789ec9f

Browse files
feat: port to 21.11
1 parent f380706 commit 789ec9f

33 files changed

+215
-217
lines changed

common/src/main/java/dev/ftb/mods/ftbteams/FTBTeams.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import net.minecraft.commands.CommandBuildContext;
2323
import net.minecraft.commands.CommandSourceStack;
2424
import net.minecraft.commands.Commands;
25+
import net.minecraft.core.UUIDUtil;
2526
import net.minecraft.network.chat.Component;
2627
import net.minecraft.server.MinecraftServer;
2728
import net.minecraft.server.level.ServerLevel;
@@ -55,12 +56,12 @@ public FTBTeams() {
5556

5657
private void serverStarted(MinecraftServer server) {
5758
NBTEditResponseHandlers.INSTANCE.registerHandler("ftbteams:team", (serverPlayer, info, data) -> {
58-
TeamManagerImpl.INSTANCE.getTeamByID(info.getUUID("id")).ifPresent(team -> {
59-
if (team instanceof AbstractTeam abstractTeam) {
60-
abstractTeam.deserializeNBT(data, server.registryAccess());
61-
abstractTeam.markDirty();
62-
}
63-
});
59+
info.read("id", UUIDUtil.CODEC).flatMap(e -> TeamManagerImpl.INSTANCE.getTeamByID(e)).ifPresent(team -> {
60+
if (team instanceof AbstractTeam abstractTeam) {
61+
abstractTeam.deserializeNBT(data, server.registryAccess());
62+
abstractTeam.markDirty();
63+
}
64+
});
6465
});
6566
}
6667

common/src/main/java/dev/ftb/mods/ftbteams/api/FTBTeamsAPI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import dev.ftb.mods.ftbteams.api.client.ClientTeamManager;
44
import dev.ftb.mods.ftbteams.api.event.TeamManagerEvent;
55
import net.minecraft.network.chat.Component;
6-
import net.minecraft.resources.ResourceLocation;
6+
import net.minecraft.resources.Identifier;
77
import org.jetbrains.annotations.ApiStatus;
88
import org.jetbrains.annotations.Nullable;
99

@@ -30,8 +30,8 @@ public static FTBTeamsAPI.API api() {
3030
* @param path the resource location path component
3131
* @return a new resource location
3232
*/
33-
public static ResourceLocation rl(String path) {
34-
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
33+
public static Identifier rl(String path) {
34+
return Identifier.fromNamespaceAndPath(MOD_ID, path);
3535
}
3636

3737
/**

common/src/main/java/dev/ftb/mods/ftbteams/api/event/PlayerTransferredTeamOwnershipEvent.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import dev.ftb.mods.ftbteams.api.Team;
55
import dev.ftb.mods.ftbteams.data.PartyTeam;
66
import net.minecraft.server.level.ServerPlayer;
7+
import net.minecraft.server.players.NameAndId;
78
import org.jetbrains.annotations.Nullable;
89

910
public class PlayerTransferredTeamOwnershipEvent extends TeamEvent {
1011
private final ServerPlayer from, to;
11-
private final GameProfile toProfile;
12+
private final NameAndId toProfile;
1213

1314
public PlayerTransferredTeamOwnershipEvent(Team team, ServerPlayer prevOwner, ServerPlayer newOwner) {
1415
super(team);
@@ -17,7 +18,7 @@ public PlayerTransferredTeamOwnershipEvent(Team team, ServerPlayer prevOwner, Se
1718
toProfile = null;
1819
}
1920

20-
public PlayerTransferredTeamOwnershipEvent(PartyTeam t, ServerPlayer from, GameProfile toProfile) {
21+
public PlayerTransferredTeamOwnershipEvent(PartyTeam t, ServerPlayer from, NameAndId toProfile) {
2122
super(t);
2223
this.from = from;
2324
this.to = null;
@@ -35,6 +36,6 @@ public ServerPlayer getTo() {
3536
}
3637

3738
public GameProfile getToProfile() {
38-
return to == null ? toProfile : to.getGameProfile();
39+
return to == null ? new GameProfile(toProfile.id(), toProfile.name()) : to.getGameProfile();
3940
}
40-
}
41+
}

common/src/main/java/dev/ftb/mods/ftbteams/api/property/BigIntegerProperty.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import dev.ftb.mods.ftblibrary.config.ConfigGroup;
55
import dev.ftb.mods.ftblibrary.config.ConfigValue;
66
import net.minecraft.network.RegistryFriendlyByteBuf;
7-
import net.minecraft.resources.ResourceLocation;
7+
import net.minecraft.resources.Identifier;
88
import org.jetbrains.annotations.Nullable;
99

1010
import java.math.BigInteger;
@@ -13,11 +13,11 @@
1313
import java.util.function.Supplier;
1414

1515
public class BigIntegerProperty extends TeamProperty<BigInteger> {
16-
public BigIntegerProperty(ResourceLocation id, Supplier<BigInteger> def) {
16+
public BigIntegerProperty(Identifier id, Supplier<BigInteger> def) {
1717
super(id, def);
1818
}
1919

20-
public BigIntegerProperty(ResourceLocation id, BigInteger def) {
20+
public BigIntegerProperty(Identifier id, BigInteger def) {
2121
this(id, () -> def);
2222
}
2323

@@ -40,7 +40,7 @@ public void write(RegistryFriendlyByteBuf buf) {
4040
buf.writeByteArray(getDefaultValue().toByteArray());
4141
}
4242

43-
public static TeamProperty<BigInteger> fromNetwork(ResourceLocation id, RegistryFriendlyByteBuf buf) {
43+
public static TeamProperty<BigInteger> fromNetwork(Identifier id, RegistryFriendlyByteBuf buf) {
4444
return new BigIntegerProperty(id, new BigInteger(buf.readByteArray()));
4545
}
4646

common/src/main/java/dev/ftb/mods/ftbteams/api/property/BooleanProperty.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import net.minecraft.nbt.Tag;
88
import net.minecraft.network.FriendlyByteBuf;
99
import net.minecraft.network.RegistryFriendlyByteBuf;
10-
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.resources.Identifier;
1111

1212
import java.util.Optional;
1313
import java.util.function.Supplier;
@@ -16,15 +16,15 @@ public class BooleanProperty extends TeamProperty<Boolean> {
1616
private static final Optional<Boolean> TRUE = Optional.of(Boolean.TRUE);
1717
private static final Optional<Boolean> FALSE = Optional.of(Boolean.FALSE);
1818

19-
public BooleanProperty(ResourceLocation id, Supplier<Boolean> def) {
19+
public BooleanProperty(Identifier id, Supplier<Boolean> def) {
2020
super(id, def);
2121
}
2222

23-
public BooleanProperty(ResourceLocation id, Boolean def) {
23+
public BooleanProperty(Identifier id, Boolean def) {
2424
this(id, () -> def);
2525
}
2626

27-
static BooleanProperty fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
27+
static BooleanProperty fromNetwork(Identifier id, FriendlyByteBuf buf) {
2828
return new BooleanProperty(id, buf.readBoolean());
2929
}
3030

@@ -61,10 +61,14 @@ public Tag toNBT(Boolean value) {
6161

6262
@Override
6363
public Optional<Boolean> fromNBT(Tag tag) {
64-
if (tag instanceof NumericTag) {
65-
if (tag.asByte().orElse((byte) 0) == 1) {
66-
return TRUE;
67-
}
64+
if (tag instanceof NumericTag) {
65+
if (tag.asByte().orElse((byte) 0) == 1) {
66+
return TRUE;
67+
}
68+
}
69+
70+
return FALSE;
71+
}
6872

6973
@Override
7074
public void writeValue(RegistryFriendlyByteBuf buf, Boolean value) {

common/src/main/java/dev/ftb/mods/ftbteams/api/property/ColorProperty.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
import dev.ftb.mods.ftblibrary.icon.Color4I;
66
import net.minecraft.network.FriendlyByteBuf;
77
import net.minecraft.network.RegistryFriendlyByteBuf;
8-
import net.minecraft.resources.ResourceLocation;
8+
import net.minecraft.resources.Identifier;
99

1010
import java.util.Optional;
1111
import java.util.function.Supplier;
1212

1313
public class ColorProperty extends TeamProperty<Color4I> {
14-
public ColorProperty(ResourceLocation id, Supplier<Color4I> def) {
14+
public ColorProperty(Identifier id, Supplier<Color4I> def) {
1515
super(id, def);
1616
}
1717

18-
public ColorProperty(ResourceLocation id, Color4I def) {
18+
public ColorProperty(Identifier id, Color4I def) {
1919
this(id, () -> def);
2020
}
2121

22-
static ColorProperty fromNetwork(ResourceLocation id, FriendlyByteBuf def) {
22+
static ColorProperty fromNetwork(Identifier id, FriendlyByteBuf def) {
2323
return new ColorProperty(id, Color4I.rgb(def.readVarInt()));
2424
}
2525

@@ -48,4 +48,4 @@ public String toString(Color4I value) {
4848
public ConfigValue<?> config(ConfigGroup config, TeamPropertyValue<Color4I> value) {
4949
return config.addColor(id.getPath(), value.getValue(), value::setValue, getDefaultValue());
5050
}
51-
}
51+
}

common/src/main/java/dev/ftb/mods/ftbteams/api/property/DoubleProperty.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import net.minecraft.nbt.Tag;
88
import net.minecraft.network.FriendlyByteBuf;
99
import net.minecraft.network.RegistryFriendlyByteBuf;
10-
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.resources.Identifier;
1111
import net.minecraft.util.Mth;
1212

1313
import java.util.Optional;
@@ -17,21 +17,21 @@ public class DoubleProperty extends TeamProperty<Double> {
1717
public final double minValue;
1818
public final double maxValue;
1919

20-
public DoubleProperty(ResourceLocation id, Supplier<Double> def, double min, double max) {
20+
public DoubleProperty(Identifier id, Supplier<Double> def, double min, double max) {
2121
super(id, def);
2222
minValue = min;
2323
maxValue = max;
2424
}
2525

26-
public DoubleProperty(ResourceLocation id, double def, double min, double max) {
26+
public DoubleProperty(Identifier id, double def, double min, double max) {
2727
this(id, () -> def, min, max);
2828
}
2929

30-
public DoubleProperty(ResourceLocation id, Supplier<Double> def) {
30+
public DoubleProperty(Identifier id, Supplier<Double> def) {
3131
this(id, def, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
3232
}
3333

34-
static DoubleProperty fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
34+
static DoubleProperty fromNetwork(Identifier id, FriendlyByteBuf buf) {
3535
return new DoubleProperty(id, buf.readDouble(), buf.readDouble(), buf.readDouble());
3636
}
3737

@@ -69,9 +69,12 @@ public Tag toNBT(Double value) {
6969

7070
@Override
7171
public Optional<Double> fromNBT(Tag tag) {
72-
if (tag instanceof NumericTag) {
73-
return Optional.of(Mth.clamp(tag.asDouble().orElse(minValue), minValue, maxValue));
74-
}
72+
if (tag instanceof NumericTag) {
73+
return Optional.of(Mth.clamp(tag.asDouble().orElse(minValue), minValue, maxValue));
74+
}
75+
76+
return Optional.empty();
77+
}
7578

7679
@Override
7780
public Double readValue(RegistryFriendlyByteBuf buf) {

common/src/main/java/dev/ftb/mods/ftbteams/api/property/EnumProperty.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import net.minecraft.network.RegistryFriendlyByteBuf;
1010
import net.minecraft.network.chat.Component;
1111
import net.minecraft.network.chat.ComponentSerialization;
12-
import net.minecraft.resources.ResourceLocation;
12+
import net.minecraft.resources.Identifier;
1313

1414
import java.util.HashMap;
1515
import java.util.List;
@@ -21,13 +21,13 @@ public class EnumProperty extends TeamProperty<String> {
2121
private final List<String> values;
2222
private final Map<String, Component> names;
2323

24-
public EnumProperty(ResourceLocation id, Supplier<String> def, List<String> values, Map<String,Component> names) {
24+
public EnumProperty(Identifier id, Supplier<String> def, List<String> values, Map<String,Component> names) {
2525
super(id, def);
2626
this.values = values;
2727
this.names = names;
2828
}
2929

30-
public <T> EnumProperty(ResourceLocation id, NameMap<T> nameMap) {
30+
public <T> EnumProperty(Identifier id, NameMap<T> nameMap) {
3131
this(id, () -> nameMap.getName(nameMap.defaultValue), nameMap.keys, buildMap(nameMap));
3232
}
3333

@@ -37,7 +37,7 @@ private static <T> Map<String,Component> buildMap(NameMap<T> nameMap) {
3737
return res;
3838
}
3939

40-
static EnumProperty fromNetwork(ResourceLocation id, RegistryFriendlyByteBuf buf) {
40+
static EnumProperty fromNetwork(Identifier id, RegistryFriendlyByteBuf buf) {
4141
String def = buf.readUtf(Short.MAX_VALUE);
4242
List<String> values = buf.readList(b -> b.readUtf(Short.MAX_VALUE));
4343
int len = buf.readVarInt();

common/src/main/java/dev/ftb/mods/ftbteams/api/property/IntProperty.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import net.minecraft.nbt.Tag;
88
import net.minecraft.network.FriendlyByteBuf;
99
import net.minecraft.network.RegistryFriendlyByteBuf;
10-
import net.minecraft.resources.ResourceLocation;
10+
import net.minecraft.resources.Identifier;
1111
import net.minecraft.util.Mth;
1212

1313
import java.util.Optional;
@@ -17,25 +17,25 @@ public class IntProperty extends TeamProperty<Integer> {
1717
public final int minValue;
1818
public final int maxValue;
1919

20-
public IntProperty(ResourceLocation id, Supplier<Integer> def, int min, int max) {
20+
public IntProperty(Identifier id, Supplier<Integer> def, int min, int max) {
2121
super(id, def);
2222
minValue = min;
2323
maxValue = max;
2424
}
2525

26-
public IntProperty(ResourceLocation id, Supplier<Integer> def) {
26+
public IntProperty(Identifier id, Supplier<Integer> def) {
2727
this(id, def, Integer.MIN_VALUE, Integer.MAX_VALUE);
2828
}
2929

30-
public IntProperty(ResourceLocation id, int def, int min, int max) {
30+
public IntProperty(Identifier id, int def, int min, int max) {
3131
this(id, () -> def, min, max);
3232
}
3333

34-
public IntProperty(ResourceLocation id, int def) {
34+
public IntProperty(Identifier id, int def) {
3535
this(id, () -> def);
3636
}
3737

38-
static IntProperty fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
38+
static IntProperty fromNetwork(Identifier id, FriendlyByteBuf buf) {
3939
return new IntProperty(id, buf.readVarInt(), buf.readVarInt(), buf.readVarInt());
4040
}
4141

common/src/main/java/dev/ftb/mods/ftbteams/api/property/PrivacyProperty.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
import dev.ftb.mods.ftblibrary.config.ConfigValue;
55
import net.minecraft.network.FriendlyByteBuf;
66
import net.minecraft.network.RegistryFriendlyByteBuf;
7-
import net.minecraft.resources.ResourceLocation;
7+
import net.minecraft.resources.Identifier;
88

99
import java.util.Optional;
1010
import java.util.function.Supplier;
1111

1212
// TODO this should be moved to FTB Chunks
1313
public class PrivacyProperty extends TeamProperty<PrivacyMode> {
14-
public PrivacyProperty(ResourceLocation id, Supplier<PrivacyMode> def) {
14+
public PrivacyProperty(Identifier id, Supplier<PrivacyMode> def) {
1515
super(id, def);
1616
}
1717

18-
public PrivacyProperty(ResourceLocation id, PrivacyMode def) {
18+
public PrivacyProperty(Identifier id, PrivacyMode def) {
1919
this(id, () -> def);
2020
}
2121

22-
static PrivacyProperty fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
22+
static PrivacyProperty fromNetwork(Identifier id, FriendlyByteBuf buf) {
2323
return new PrivacyProperty(id, buf.readEnum(PrivacyMode.class));
2424
}
2525

@@ -47,4 +47,4 @@ public void write(RegistryFriendlyByteBuf buf) {
4747
public ConfigValue<?> config(ConfigGroup config, TeamPropertyValue<PrivacyMode> value) {
4848
return config.addEnum(id.getPath(), value.getValue(), value::setValue, PrivacyMode.NAME_MAP);
4949
}
50-
}
50+
}

0 commit comments

Comments
 (0)