Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGlitch76 committed Jun 1, 2024
1 parent 8b18ad5 commit cdf34b5
Show file tree
Hide file tree
Showing 29 changed files with 85 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class BlockContentRegistryTest implements ModInitializer, QuiltGameTest {
@Override
public void onInitialize(ModContainer mod) {
RegistryExtensions.register(Registries.BLOCK, new Identifier(MOD_ID, "oxidizable_iron_block"),
new OxidizableBlock(Oxidizable.OxidizationLevel.UNAFFECTED, AbstractBlock.Settings.method_9630(Blocks.IRON_BLOCK)),
new OxidizableBlock(Oxidizable.OxidizationLevel.UNAFFECTED, AbstractBlock.Settings.copy(Blocks.IRON_BLOCK)),
BlockContentRegistries.OXIDIZABLE, new ReversibleBlockEntry(Blocks.IRON_BLOCK, false));

BlockContentRegistries.ENCHANTING_BOOSTERS.put(Blocks.IRON_BLOCK, new ConstantBooster(3f));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class AngyBlock extends BlockWithEntity {
public AngyBlock(MapColor mapColor) {
super(AbstractBlock.Settings.method_9630(Blocks.STONE).mapColor(mapColor));
super(AbstractBlock.Settings.copy(Blocks.STONE).mapColor(mapColor));
}

@Override
Expand Down
Empty file removed library/core/data_callback/DISABLE
Empty file.
Empty file removed library/core/networking/DISABLE
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.quiltmc.qsl.networking.test;

import net.minecraft.network.packet.payload.CustomPayload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -25,8 +26,8 @@ public final class NetworkingTestMods {
public static final String ID = "quilt_networking_testmod";
public static final Logger LOGGER = LoggerFactory.getLogger(ID);

public static Identifier id(String name) {
return new Identifier(ID, name);
public static <T extends CustomPayload> CustomPayload.Id<T> id(String name) {
return new CustomPayload.Id<>(new Identifier(ID, name));
}

private NetworkingTestMods() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.button.ButtonWidget;
import net.minecraft.network.packet.payload.CustomPayload;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -53,7 +54,7 @@ protected void init() {

@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
this.renderBackgroundTexture(graphics);
this.renderBackground(graphics, mouseX, mouseY, delta);
this.channelList.render(graphics, mouseX, mouseY, delta);
super.render(graphics, mouseX, mouseY, delta);

Expand Down Expand Up @@ -84,8 +85,8 @@ private void toC2S(ButtonWidget button) {
button.active = false;
this.channelList.clear();

for (Identifier receiver : ClientPlayNetworking.getSendable()) {
this.channelList.addEntry(this.channelList.new Entry(receiver));
for (CustomPayload.Id<?> receiver : ClientPlayNetworking.getSendable()) {
this.channelList.addEntry(this.channelList.new Entry(receiver.id()));
}
}

Expand All @@ -94,8 +95,8 @@ private void toS2C(ButtonWidget button) {
button.active = false;
this.channelList.clear();

for (Identifier receiver : ClientPlayNetworking.getReceived()) {
this.channelList.addEntry(this.channelList.new Entry(receiver));
for (CustomPayload.Id<?> receiver : ClientPlayNetworking.getReceived()) {
this.channelList.addEntry(this.channelList.new Entry(receiver.id()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@
import net.minecraft.command.CommandBuildContext;
import net.minecraft.command.CommandSource;
import net.minecraft.command.EntitySelector;
import net.minecraft.network.packet.payload.CustomPayload;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import org.quiltmc.qsl.command.api.CommandRegistrationCallback;
import org.quiltmc.qsl.networking.api.PacketSender;
import org.quiltmc.qsl.networking.api.ServerPlayNetworking;
import org.quiltmc.qsl.networking.impl.payload.PacketByteBufPayload;

public final class NetworkingChannelTest implements CommandRegistrationCallback {
@Override
Expand Down Expand Up @@ -92,27 +97,29 @@ public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher,
private static CompletableFuture<Suggestions> suggestReceivableChannels(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException {
final ServerPlayerEntity player = context.getSource().getPlayer();

return CommandSource.suggestIdentifiers(ServerPlayNetworking.getReceived(player), builder);
return CommandSource.suggestIdentifiers(ServerPlayNetworking.getReceived(player).stream().map(CustomPayload.Id::id), builder);
}

private static int registerChannel(CommandContext<ServerCommandSource> context, ServerPlayerEntity executor) throws CommandSyntaxException {
final Identifier channel = getIdentifier(context, "channel");
final CustomPayload.Id<?> channel = new CustomPayload.Id<>(getIdentifier(context, "channel"));

if (ServerPlayNetworking.getReceived(executor).contains(channel)) {
throw new SimpleCommandExceptionType(Text.of(String.format("Cannot register channel %s twice for server player", channel))).create();
}

ServerPlayNetworking.registerReceiver(executor.networkHandler, channel, (server, player, handler, buf, sender) -> {
System.out.printf("Received packet on channel %s%n", channel);
});
// TODO
if (true) throw new UnsupportedOperationException();
// ServerPlayNetworking.registerReceiver(executor.networkHandler, channel, (server, player, handler, buf, sender) -> {
// System.out.printf("Received packet on channel %s%n", channel);
// });

context.getSource().sendSystemMessage(Text.of(String.format("Registered channel %s for %s", channel, executor.getDisplayName())));

return 1;
}

private static int unregisterChannel(CommandContext<ServerCommandSource> context, ServerPlayerEntity player) throws CommandSyntaxException {
final Identifier channel = getIdentifier(context, "channel");
final CustomPayload.Id<?> channel = new CustomPayload.Id<>(getIdentifier(context, "channel"));

if (!ServerPlayNetworking.getReceived(player).contains(channel)) {
throw new SimpleCommandExceptionType(Text.of("Cannot unregister channel the server player entity cannot receive packets on")).create();
Expand All @@ -126,12 +133,12 @@ private static int unregisterChannel(CommandContext<ServerCommandSource> context

private static int infoCommand(CommandContext<ServerCommandSource> context, ServerPlayerEntity player) {
ServerCommandSource source = context.getSource();
Set<Identifier> channels = ServerPlayNetworking.getSendable(player);
Set<CustomPayload.Id<?>> channels = ServerPlayNetworking.getSendable(player);

source.sendSystemMessage(Text.of(String.format("Available channels for player %s", player.getDisplayName())));

for (Identifier channel : channels) {
source.sendSystemMessage(Text.of(channel.toString()));
for (CustomPayload.Id<?> channel : channels) {
source.sendSystemMessage(Text.of(channel.id().toString()));
}

return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// Listens for a packet from the client which is sent to the server when a keybinding is pressed.
// In response the server will send a message containing the keybind text letting the client know it pressed that key.
public final class NetworkingKeyBindPacketTest implements ModInitializer {
public static final Identifier KEYBINDING_PACKET_ID = NetworkingTestMods.id("keybind_press_test");
public static final CustomPayload.Id<CustomPayload> KEYBINDING_PACKET_ID = NetworkingTestMods.id("keybind_press_test");

private static void receive(MinecraftServer server, ServerPlayerEntity player, ServerPlayNetworkHandler handler, PacketByteBuf buf, PacketSender<CustomPayload> responseSender) {
// TODO: Can we send chat off the server thread?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.FutureTask;

import net.minecraft.network.packet.payload.CustomPayload;
import net.minecraft.network.packet.s2c.login.payload.CustomQueryPayload;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerLoginNetworkHandler;
Expand All @@ -34,8 +35,8 @@
import org.quiltmc.qsl.networking.test.NetworkingTestMods;

public final class NetworkingLoginQueryTest implements ModInitializer {
public static final Identifier TEST_CHANNEL_GLOBAL = NetworkingTestMods.id("test_channel_global");
public static final Identifier TEST_CHANNEL = NetworkingTestMods.id("test_channel");
public static final CustomPayload.Id<?> TEST_CHANNEL_GLOBAL = NetworkingTestMods.id("test_channel_global");
public static final CustomPayload.Id<?> TEST_CHANNEL = NetworkingTestMods.id("test_channel");
private static final boolean useLoginDelayTest = System.getProperty("quilt_networking.login_delay_test") != null;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.payload.CustomPayload;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand All @@ -40,7 +41,7 @@ public class C2SPayloadTest implements ClientModInitializer {
private static boolean received = false;
@Override
public void onInitializeClient(ModContainer mod) {
CustomPayloads.registerC2SPayload(TestC2SPayload.ID, TestC2SPayload::new);
CustomPayloads.registerC2SPayload(TestC2SPayload.ID, TestC2SPayload.CODEC);
ServerPlayNetworking.registerGlobalReceiver(TestC2SPayload.ID, this::handleTestPayload);

ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
Expand Down Expand Up @@ -74,21 +75,21 @@ public void handleTestPayload(MinecraftServer server, ServerPlayerEntity player,
}

public record TestC2SPayload(List<String> strings, int a, double b) implements CustomPayload {
public static final Identifier ID = new Identifier("quilt_networking_testmod", "test_c2s_payload");
public static final Id<TestC2SPayload> ID = new Id<>(new Identifier("quilt_networking_testmod", "test_c2s_payload"));
public static final PacketCodec<PacketByteBuf, TestC2SPayload> CODEC = CustomPayload.create(TestC2SPayload::write, TestC2SPayload::new);

TestC2SPayload(PacketByteBuf buf) {
this(buf.readList(PacketByteBuf::readString), buf.readInt(), buf.readDouble());
}

@Override
public void write(PacketByteBuf buf) {
private void write(PacketByteBuf buf) {
buf.writeCollection(this.strings, PacketByteBuf::writeString);
buf.writeInt(this.a);
buf.writeDouble(this.b);
}

@Override
public Identifier id() {
public Id<? extends CustomPayload> getId() {
return ID;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.payload.CustomPayload;
import net.minecraft.util.Identifier;

Expand All @@ -32,6 +33,7 @@
import org.quiltmc.qsl.networking.api.ServerPlayConnectionEvents;
import org.quiltmc.qsl.networking.api.client.ClientPlayNetworking;
import org.quiltmc.qsl.networking.impl.NetworkingImpl;
import org.quiltmc.qsl.networking.impl.common.CommonRegisterPayload;
import org.quiltmc.qsl.networking.test.NetworkingTestMods;

// Test cannot run on a server, so only run with a client
Expand All @@ -40,7 +42,7 @@ public class S2CPayloadTest implements ClientModInitializer {

@Override
public void onInitializeClient(ModContainer mod) {
CustomPayloads.registerS2CPayload(TestS2CPayload.ID, TestS2CPayload::new);
CustomPayloads.registerS2CPayload(TestS2CPayload.ID, TestS2CPayload.CODEC);
ClientPlayNetworking.registerGlobalReceiver(TestS2CPayload.ID, this::handleTestPayload);

ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
Expand Down Expand Up @@ -74,22 +76,24 @@ public void handleTestPayload(MinecraftClient client, ClientPlayNetworkHandler h
}

public record TestS2CPayload(List<String> strings, int a, double b) implements CustomPayload {
public static final Identifier ID = new Identifier("quilt_networking_testmod", "test_s2c_payload");
public static final Id<TestS2CPayload> ID = new Id<>(new Identifier("quilt_networking_testmod", "test_s2c_payload"));
public static final PacketCodec<PacketByteBuf, TestS2CPayload> CODEC = CustomPayload.create(TestS2CPayload::write, TestS2CPayload::new);

TestS2CPayload(PacketByteBuf buf) {
this(buf.readList(PacketByteBuf::readString), buf.readInt(), buf.readDouble());
}

@Override
public void write(PacketByteBuf buf) {

private void write(PacketByteBuf buf) {
buf.writeCollection(this.strings, PacketByteBuf::writeString);
buf.writeInt(this.a);
buf.writeDouble(this.b);
}


@Override
public Identifier id() {
return ID;
public Id<? extends CustomPayload> getId() {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public void onInitializeClient(ModContainer mod) {
}

private void receive(ClientPlayNetworkHandler handler, PacketSender<CustomPayload> sender, MinecraftClient client, PacketByteBuf buf) {
Text text = buf.readText();
String text = buf.readString();
client.execute(() -> {
LOGGER.info("Received text from {} which says {}.", NetworkingPlayPacketTest.TEST_CHANNEL, text);
client.inGameHud.setOverlayMessage(text, true);
client.inGameHud.setOverlayMessage(Text.literal(text), true);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.payload.CustomPayload;
import net.minecraft.network.packet.s2c.PacketBundleS2CPacket;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -43,11 +44,11 @@
import org.quiltmc.qsl.networking.test.NetworkingTestMods;

public final class NetworkingPlayPacketTest implements ModInitializer {
public static final Identifier TEST_CHANNEL = NetworkingTestMods.id("test_channel");
public static final CustomPayload.Id<?> TEST_CHANNEL = NetworkingTestMods.id("test_channel");

public static void sendToTestChannel(ServerPlayerEntity player, String stuff) {
PacketByteBuf buf = PacketByteBufs.create();
buf.writeText(Text.of(stuff));
buf.writeString(stuff);
ServerPlayNetworking.send(player, TEST_CHANNEL, buf);
NetworkingTestMods.LOGGER.info("Sent custom payload packet in {}", TEST_CHANNEL);
}
Expand All @@ -63,9 +64,9 @@ public static void registerCommand(CommandDispatcher<ServerCommandSource> dispat
}))
.then(literal("bundled").executes(ctx -> {
PacketByteBuf bufA = PacketByteBufs.create();
bufA.writeText(Text.literal("Bundled #1"));
bufA.writeString("Bundled #1");
PacketByteBuf bufB = PacketByteBufs.create();
bufB.writeText(Text.literal("Bundled #2"));
bufB.writeString("Bundled #2");

var packet = new PacketBundleS2CPacket(List.of(
(Packet<ClientPlayPacketListener>) (Object) ServerPlayNetworking.createS2CPacket(TEST_CHANNEL, bufA),
Expand Down
Empty file removed library/core/registry/DISABLE
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package org.quiltmc.qsl.registry.impl.dynamic;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.mojang.serialization.Codec;
import net.minecraft.registry.DynamicRegistrySync;
import org.jetbrains.annotations.ApiStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -32,7 +34,6 @@
import net.minecraft.util.Identifier;

import org.quiltmc.qsl.registry.api.dynamic.DynamicRegistryFlag;
import org.quiltmc.qsl.registry.mixin.DynamicRegistrySyncAccessor;

@ApiStatus.Internal
public class DynamicMetaRegistryImpl {
Expand Down Expand Up @@ -62,12 +63,17 @@ public static <E> void register(RegistryKey<? extends Registry<E>> ref, Codec<E>
public static <E> void registerSynced(RegistryKey<? extends Registry<E>> ref, Codec<E> entryCodec, Codec<E> syncCodec, DynamicRegistryFlag... flags) {
register(ref, entryCodec, flags);

RegistryLoader.SYNCED_REGISTRIES.add(new RegistryLoader.DecodingData<>(ref, entryCodec));
DynamicRegistrySyncAccessor.quilt$getSyncedCodecs().add(ref);
// TODO figure out whether the above works at all and whether the syncCodec arg is still needed
/*var builder = ImmutableSet.<RegistryKey<? extends Registry<?>>>builder().addAll(DynamicRegistrySyncAccessor.quilt$getSyncedCodecs());
DynamicRegistrySyncAccessor.quilt$invokeAddSyncedRegistry(builder, ref, syncCodec);
DynamicRegistrySyncAccessor.quilt$setSyncedCodecs(builder.build());*/
if (!(RegistryLoader.SYNCED_REGISTRIES instanceof ArrayList<RegistryLoader.DecodingData<?>>)) {
RegistryLoader.SYNCED_REGISTRIES = new ArrayList<>(RegistryLoader.SYNCED_REGISTRIES);
}

RegistryLoader.SYNCED_REGISTRIES.add(new RegistryLoader.DecodingData<>(ref, syncCodec));

if (!(DynamicRegistrySync.SYNCED_CODECS instanceof HashSet<RegistryKey<? extends Registry<?>>>)) {
DynamicRegistrySync.SYNCED_CODECS = new HashSet<>(DynamicRegistrySync.SYNCED_CODECS);
}

DynamicRegistrySync.SYNCED_CODECS.add(ref);
}

public static void freeze() {
Expand Down
Loading

0 comments on commit cdf34b5

Please sign in to comment.