Skip to content

Commit

Permalink
update REI, bump version to 0.12.0, fix OwoNetChannel documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gliscowo committed Dec 28, 2023
1 parent 8c87eb3 commit 378cc88
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 36 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ loom {
}

dependencies {
// modLocalRuntime("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}")
modLocalRuntime("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-default-plugin:${project.rei_version}")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}")

modCompileOnly("dev.emi:emi-fabric:${project.emi_version}")
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ minecraft_version=1.20.3
yarn_mappings=1.20.3+build.1
loader_version=0.15.0
# Mod Properties
mod_version=0.12.0-pre.5
mod_version=0.12.0
maven_group=io.wispforest
archives_base_name=owo-lib
# Dependencies
fabric_version=0.91.1+1.20.3

# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=13.0.661
rei_version=14.0.688

# https://maven.terraformersmc.com/releases/dev/emi/emi-fabric/
emi_version=1.0.19+1.20.1
emi_version=1.0.29+1.20.4

# https://search.maven.org/artifact/blue.endless/jankson
jankson_version=1.2.2

# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu
modmenu_version=9.0.0-pre.1
modmenu_version=9.0.0

# https://maven.nucleoid.xyz/xyz/nucleoid/server-translations-api/
stapi_version=2.2.0+1.20.3-rc1
2 changes: 0 additions & 2 deletions src/main/java/io/wispforest/owo/compat/rei/OwoReiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
import me.shedaniel.rei.api.client.registry.screen.OverlayRendererProvider;
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.RotationAxis;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/wispforest/owo/network/OwoHandshake.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.Set;
import java.util.function.ToIntFunction;

@SuppressWarnings("UnstableApiUsage")
@ApiStatus.Internal
public final class OwoHandshake {

Expand Down
45 changes: 17 additions & 28 deletions src/main/java/io/wispforest/owo/network/OwoNetChannel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.wispforest.owo.network;

import io.wispforest.owo.mixin.ServerCommonNetworkHandlerAccessor;
import io.wispforest.owo.serialization.Endec;
import io.wispforest.owo.serialization.endec.RecordEndec;
import io.wispforest.owo.serialization.StructEndec;
import io.wispforest.owo.serialization.format.bytebuf.ByteBufDeserializer;
Expand Down Expand Up @@ -37,9 +38,10 @@
/**
* An efficient networking abstraction that uses {@code record}s to store
* and define packet data. Serialization for most types is fully automatic
* and no custom handling needs to be done, should one of your record
* components be of an unsupported type use {@link PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)}
* to register a custom serializer.
* and no custom handling needs to be done.
*
* <p> Should one of your record components be of an unsupported type, either use {@link io.wispforest.owo.serialization.endec.ReflectiveEndecBuilder#register(Endec, Class)}
* to register an appropriate endec, or supply it directly using {@link #registerClientbound(Class, StructEndec, ChannelHandler)} and {@link #registerServerbound(Class, StructEndec, ChannelHandler)}
*
* <p> To define a packet class suited for use with this wrapper, simply create a
* standard Java {@code record} class and put the desired data into the record header.
Expand All @@ -56,9 +58,6 @@
*
* <p> The registered packet handlers are executed synchronously on the target environment's
* game thread instead of Netty's event loops - there is no need to call {@code .execute(...)}
*
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
* @see PacketBufSerializer#registerCollectionProvider(Class, Supplier)
*/
public class OwoNetChannel {

Expand Down Expand Up @@ -129,14 +128,14 @@ private OwoNetChannel(Identifier id, String ownerClassName, boolean required) {

ServerPlayNetworking.registerGlobalReceiver(packetId, (server, player, handler, buf, responseSender) -> {
int handlerIndex = buf.readVarInt();
final Record message = serializersByIndex.get(handlerIndex).serializer.decodeFully(ByteBufDeserializer::new, buf);
final Record message = serializersByIndex.get(handlerIndex).endec.decodeFully(ByteBufDeserializer::new, buf);
server.execute(() -> serverHandlers.get(handlerIndex).handle(message, new ServerAccess(player)));
});

if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
ClientPlayNetworking.registerGlobalReceiver(packetId, (client, handler, buf, responseSender) -> {
int handlerIndex = buf.readVarInt();
final Record message = serializersByIndex.get(-handlerIndex).serializer.decodeFully(ByteBufDeserializer::new, buf);
final Record message = serializersByIndex.get(-handlerIndex).endec.decodeFully(ByteBufDeserializer::new, buf);
client.execute(() -> clientHandlers.get(handlerIndex).handle(message, new ClientAccess(handler)));
});
}
Expand All @@ -162,9 +161,7 @@ private OwoNetChannel(Identifier id, String ownerClassName, boolean required) {
* @see #serverHandle(PlayerEntity)
* @see #serverHandle(MinecraftServer)
* @see #serverHandle(ServerWorld, BlockPos)
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
*/
@SuppressWarnings("unchecked")
public <R extends Record> void registerClientbound(Class<R> messageClass, ChannelHandler<R, ClientAccess> handler) {
registerClientbound(messageClass, handler, () -> RecordEndec.create(messageClass));
}
Expand All @@ -178,7 +175,6 @@ public <R extends Record> void registerClientbound(Class<R> messageClass, Channe
* @see #serverHandle(PlayerEntity)
* @see #serverHandle(MinecraftServer)
* @see #serverHandle(ServerWorld, BlockPos)
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
*/
public <R extends Record> void registerClientboundDeferred(Class<R> messageClass) {
registerClientboundDeferred(messageClass, () -> RecordEndec.create(messageClass));
Expand All @@ -192,9 +188,7 @@ public <R extends Record> void registerClientboundDeferred(Class<R> messageClass
* @param messageClass The type of packet data to send and serialize
* @param handler The handler that will receive the deserialized
* @see #clientHandle()
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
*/
@SuppressWarnings("unchecked")
public <R extends Record> void registerServerbound(Class<R> messageClass, ChannelHandler<R, ServerAccess> handler) {
registerServerbound(messageClass, handler, () -> RecordEndec.create(messageClass));
}
Expand All @@ -212,9 +206,7 @@ public <R extends Record> void registerServerbound(Class<R> messageClass, Channe
* @see #serverHandle(PlayerEntity)
* @see #serverHandle(MinecraftServer)
* @see #serverHandle(ServerWorld, BlockPos)
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
*/
@SuppressWarnings("unchecked")
public <R extends Record> void registerClientbound(Class<R> messageClass, StructEndec<R> endec, ChannelHandler<R, ClientAccess> handler) {
registerClientbound(messageClass, handler, () -> endec);
}
Expand All @@ -229,7 +221,6 @@ public <R extends Record> void registerClientbound(Class<R> messageClass, Struct
* @see #serverHandle(PlayerEntity)
* @see #serverHandle(MinecraftServer)
* @see #serverHandle(ServerWorld, BlockPos)
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
*/
public <R extends Record> void registerClientboundDeferred(Class<R> messageClass, StructEndec<R> endec) {
registerClientboundDeferred(messageClass, () -> endec);
Expand All @@ -244,9 +235,7 @@ public <R extends Record> void registerClientboundDeferred(Class<R> messageClass
* @param endec The alternative Endec to Serialize the given Record
* @param handler The handler that will receive the deserialized
* @see #clientHandle()
* @see PacketBufSerializer#register(Class, PacketByteBuf.PacketWriter, PacketByteBuf.PacketReader)
*/
@SuppressWarnings("unchecked")
public <R extends Record> void registerServerbound(Class<R> messageClass, StructEndec<R> endec, ChannelHandler<R, ServerAccess> handler) {
registerServerbound(messageClass, handler, () -> endec);
}
Expand Down Expand Up @@ -443,7 +432,7 @@ private <R extends Record> PacketByteBuf encode(R message, EnvType target) {
}

buffer.writeVarInt(serializer.handlerIndex(target));
return serializer.serializer.encodeFully(() -> new ByteBufSerializer<>(buffer), message);
return serializer.endec.encodeFully(() -> new ByteBufSerializer<>(buffer), message);
}

public class ClientHandle {
Expand Down Expand Up @@ -548,7 +537,7 @@ public interface EnvironmentAccess<P extends PlayerEntity, R, N> {

private void verify() {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
if (deferredClientSerializers.size() > 0) {
if (!this.deferredClientSerializers.isEmpty()) {
throw new NetworkException("Some deferred client handlers for channel " + packetId + " haven't been registered: " + deferredClientSerializers.keySet().stream().map(Class::getName).collect(Collectors.joining(", ")));
}
}
Expand All @@ -566,16 +555,16 @@ static final class IndexedSerializer<R extends Record> {
private int clientHandlerIndex = -1;
private int serverHandlerIndex = -1;

final Class<R> rClass;
final StructEndec<R> serializer;
private final Class<R> recordClass;
private final StructEndec<R> endec;

private IndexedSerializer(Class<R> rClass, StructEndec<R> serializer) {
this.serializer = serializer;
this.rClass = rClass;
private IndexedSerializer(Class<R> recordClass, StructEndec<R> endec) {
this.endec = endec;
this.recordClass = recordClass;
}

public static <R extends Record> IndexedSerializer<R> create(Class<R> rClass, StructEndec<R> serializer, int index, EnvType target) {
return new IndexedSerializer<>(rClass, serializer).setHandlerIndex(index, target);
public static <R extends Record> IndexedSerializer<R> create(Class<R> rClass, StructEndec<R> endec, int index, EnvType target) {
return new IndexedSerializer<>(rClass, endec).setHandlerIndex(index, target);
}

public IndexedSerializer<R> setHandlerIndex(int index, EnvType target) {
Expand All @@ -594,7 +583,7 @@ public int handlerIndex(EnvType target) {
}

public Class<R> getRecordClass(){
return this.rClass;
return this.recordClass;
}
}
}
Expand Down

0 comments on commit 378cc88

Please sign in to comment.