fix: update advancement packet to 1.20.4

This commit is contained in:
mworzala 2024-01-07 15:25:09 -05:00 committed by Matt Worzala
parent 3bbdb1f0c9
commit 03ef3e2374
4 changed files with 16 additions and 12 deletions

View File

@ -4,6 +4,9 @@ import net.kyori.adventure.resource.ResourcePackInfo;
import net.kyori.adventure.resource.ResourcePackRequest;
import net.kyori.adventure.text.Component;
import net.minestom.server.MinecraftServer;
import net.minestom.server.advancements.FrameType;
import net.minestom.server.advancements.notifications.Notification;
import net.minestom.server.advancements.notifications.NotificationCenter;
import net.minestom.server.adventure.MinestomAdventure;
import net.minestom.server.adventure.audience.Audiences;
import net.minestom.server.coordinate.Pos;
@ -115,6 +118,15 @@ public class PlayerInit {
})
.build();
player.getInventory().addItemStack(bundle);
if (event.isFirstSpawn()) {
Notification notification = new Notification(
Component.text("Welcome!"),
FrameType.TASK,
Material.IRON_SWORD
);
NotificationCenter.send(notification, event.getPlayer());
}
})
.addListener(PlayerPacketOutEvent.class, event -> {
//System.out.println("out " + event.getPacket().getClass().getSimpleName());

View File

@ -308,7 +308,6 @@ public class Advancement {
final Advancement parent = getParent();
final String parentIdentifier = parent != null ? parent.getIdentifier() : null;
AdvancementsPacket.Advancement adv = new AdvancementsPacket.Advancement(parentIdentifier, toDisplayData(),
List.of(criteria.criterionIdentifier()),
List.of(new AdvancementsPacket.Requirement(List.of(criteria.criterionIdentifier()))),
sendTelemetryData);
return new AdvancementsPacket.AdvancementMapping(getIdentifier(), adv);

View File

@ -65,7 +65,6 @@ public final class NotificationCenter {
new AdvancementsPacket.CriterionProgress(System.currentTimeMillis()));
final var advancement = new AdvancementsPacket.Advancement(null, displayData,
List.of(criteria.criterionIdentifier()),
List.of(new AdvancementsPacket.Requirement(List.of(criteria.criterionIdentifier()))),
false);

View File

@ -104,27 +104,21 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
}
public record Advancement(@Nullable String parentIdentifier, @Nullable DisplayData displayData,
@NotNull List<String> criteria,
@NotNull List<Requirement> requirements,
boolean sendTelemetryData) implements NetworkBuffer.Writer, ComponentHolder<Advancement> {
public Advancement {
criteria = List.copyOf(criteria);
requirements = List.copyOf(requirements);
}
public Advancement(@NotNull NetworkBuffer reader) {
this(reader.read(BOOLEAN) ? reader.read(STRING) : null,
reader.read(BOOLEAN) ? new DisplayData(reader) : null,
reader.readCollection(STRING),
reader.readCollection(Requirement::new),
reader.read(BOOLEAN));
this(reader.readOptional(STRING), reader.readOptional(DisplayData::new),
reader.readCollection(Requirement::new), reader.read(BOOLEAN));
}
@Override
public void write(@NotNull NetworkBuffer writer) {
writer.writeOptional(STRING, parentIdentifier);
writer.writeOptional(displayData);
writer.writeCollection(STRING, criteria);
writer.writeCollection(requirements);
writer.write(BOOLEAN, sendTelemetryData);
}
@ -136,7 +130,7 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
@Override
public @NotNull Advancement copyWithOperator(@NotNull UnaryOperator<Component> operator) {
return this.displayData == null ? this : new Advancement(this.parentIdentifier, this.displayData.copyWithOperator(operator), this.criteria, this.requirements, this.sendTelemetryData);
return this.displayData == null ? this : new Advancement(this.parentIdentifier, this.displayData.copyWithOperator(operator), this.requirements, this.sendTelemetryData);
}
}
@ -190,7 +184,7 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
writer.write(COMPONENT, title);
writer.write(COMPONENT, description);
writer.write(ITEM, icon);
writer.write(VAR_INT, frameType.ordinal());
writer.writeEnum(FrameType.class, frameType);
writer.write(INT, flags);
if ((flags & 0x1) != 0) {
assert backgroundTexture != null;