Skip to content

Commit

Permalink
port
Browse files Browse the repository at this point in the history
  • Loading branch information
BasiqueEvangelist committed Feb 19, 2024
1 parent 623e125 commit 13c4f5f
Show file tree
Hide file tree
Showing 31 changed files with 383 additions and 289 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//file:noinspection GradlePackageVersionRange
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -119,7 +119,7 @@ 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}")

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
org.gradle.jvmargs=-Xmx2G
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_base_version=1.20.3
minecraft_version=1.20.3
yarn_mappings=1.20.3+build.1
loader_version=0.15.0
minecraft_base_version=1.20.5
minecraft_version=24w07a
yarn_mappings=24w07a+build.4
loader_version=0.15.7
# Mod Properties
mod_version=0.12.5
maven_group=io.wispforest
archives_base_name=owo-lib
# Dependencies
fabric_version=0.91.1+1.20.3
fabric_version=0.96.3+1.20.5

# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=14.0.688
Expand Down
96 changes: 58 additions & 38 deletions src/main/java/io/wispforest/owo/client/screens/ScreenInternals.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,70 @@
package io.wispforest.owo.client.screens;

import io.wispforest.owo.Owo;
import io.wispforest.owo.serialization.Endec;
import io.wispforest.owo.serialization.endec.BuiltInEndecs;
import io.wispforest.owo.serialization.endec.StructEndecBuilder;
import io.wispforest.owo.util.pond.OwoScreenHandlerExtension;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public class ScreenInternals {
public static final Identifier LOCAL_PACKET = new Identifier("owo", "local_packet");
public static final Identifier SYNC_PROPERTIES = new Identifier("owo", "sync_screen_handler_properties");

public static void init() {
ServerPlayNetworking.registerGlobalReceiver(LOCAL_PACKET, (server, player, handler, buf, responseSender) -> {
buf.retain();
server.execute(() -> {
var screenHandler = player.currentScreenHandler;
PayloadTypeRegistry.playS2C().register(LocalPacket.ID, LocalPacket.ENDEC.packetCodec());
PayloadTypeRegistry.playC2S().register(LocalPacket.ID, LocalPacket.ENDEC.packetCodec());
PayloadTypeRegistry.playS2C().register(SyncPropertiesPacket.ID, SyncPropertiesPacket.ENDEC.packetCodec());

if (screenHandler == null) {
Owo.LOGGER.error("Received local packet for null ScreenHandler");
return;
}
ServerPlayNetworking.registerGlobalReceiver(LocalPacket.ID, (payload, context) -> {
var screenHandler = context.player().currentScreenHandler;

((OwoScreenHandlerExtension) screenHandler).owo$handlePacket(buf, false);
buf.release();
});
if (screenHandler == null) {
Owo.LOGGER.error("Received local packet for null ScreenHandler");
return;
}

((OwoScreenHandlerExtension) screenHandler).owo$handlePacket(payload, false);
});
}

public record LocalPacket(int packetId, PacketByteBuf payload) implements CustomPayload {
public static final Id<LocalPacket> ID = new Id<>(new Identifier("owo", "local_packet"));
public static final Endec<LocalPacket> ENDEC = StructEndecBuilder.of(
Endec.VAR_INT.fieldOf("packetId", LocalPacket::packetId),
BuiltInEndecs.PACKET_BYTE_BUF.fieldOf("payload", LocalPacket::payload),
LocalPacket::new
);

@Override
public Id<? extends CustomPayload> getId() {
return ID;
}
}

public record SyncPropertiesPacket(PacketByteBuf payload) implements CustomPayload {
public static final Id<SyncPropertiesPacket> ID = new Id<>(SYNC_PROPERTIES);
public static final Endec<SyncPropertiesPacket> ENDEC = StructEndecBuilder.of(
BuiltInEndecs.PACKET_BYTE_BUF.fieldOf("payload", SyncPropertiesPacket::payload),
SyncPropertiesPacket::new
);

@Override
public Id<? extends CustomPayload> getId() {
return ID;
}
}

@Environment(EnvType.CLIENT)
public static class Client {
public static void init() {
Expand All @@ -41,38 +73,26 @@ public static void init() {
((OwoScreenHandlerExtension) handled.getScreenHandler()).owo$attachToPlayer(client.player);
});

ClientPlayNetworking.registerGlobalReceiver(LOCAL_PACKET, (client, handler, buf, responseSender) -> {
if (client.player == null) return;

buf.retain();
client.execute(() -> {
var screenHandler = client.player.currentScreenHandler;
ClientPlayNetworking.registerGlobalReceiver(LocalPacket.ID, (payload, context) -> {
var screenHandler = context.player().currentScreenHandler;

if (screenHandler == null) {
Owo.LOGGER.error("Received local packet for null ScreenHandler");
return;
}
if (screenHandler == null) {
Owo.LOGGER.error("Received local packet for null ScreenHandler");
return;
}

((OwoScreenHandlerExtension) screenHandler).owo$handlePacket(buf, true);
buf.release();
});
((OwoScreenHandlerExtension) screenHandler).owo$handlePacket(payload, true);
});

ClientPlayNetworking.registerGlobalReceiver(SYNC_PROPERTIES, (client, handler, buf, responseSender) -> {
buf.retain();

client.execute(() -> {
if (client.player == null) return;

if (client.player.currentScreenHandler == null) {
Owo.LOGGER.error("Received sync properties packet for null ScreenHandler");
return;
}
ClientPlayNetworking.registerGlobalReceiver(SyncPropertiesPacket.ID, (payload, context) -> {
var screenHandler = context.player().currentScreenHandler;

((OwoScreenHandlerExtension) client.player.currentScreenHandler).owo$readPropertySync(buf);
if (screenHandler == null) {
Owo.LOGGER.error("Received sync properties packet for null ScreenHandler");
return;
}

buf.release();
});
((OwoScreenHandlerExtension) screenHandler).owo$readPropertySync(payload);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static int executeBlock(CommandContext<ServerCommandSource> context, Nbt
final var blockEntity = player.getWorld().getBlockEntity(pos);
if (blockEntity != null) {
feedback(source, TextOps.withFormatting("Block Entity NBT" + formatPath(path) + ": ", Formatting.GRAY)
.append(NbtHelper.toPrettyPrintedText(getPath(blockEntity.createNbt(), path))));
.append(NbtHelper.toPrettyPrintedText(getPath(blockEntity.createNbt(player.getRegistryManager()), path))));
} else {
feedback(source, TextOps.withFormatting("No block entity", Formatting.GRAY));
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/io/wispforest/owo/compat/rei/OwoReiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,30 +140,30 @@ private static void renderOverlay(Screen screen, Runnable renderFunction) {

final var time = System.currentTimeMillis();
float scale = .75f + (float) (Math.sin(time / 500d) * .5f);
modelView.push();
modelView.pushMatrix();
modelView.translate(screen.width / 2f - scale / 2f * screen.width, screen.height / 2f - scale / 2f * screen.height, 0);
modelView.scale(scale, scale, 1f);
modelView.translate((float) (Math.sin(time / 1000d) * .75f) * screen.width, (float) (Math.sin(time / 500d) * .75f) * screen.height, 0);

modelView.translate(screen.width / 2f, screen.height / 2f, 0);
modelView.multiply(RotationAxis.POSITIVE_Z.rotationDegrees((float) (time / 25d % 360d)));
modelView.rotate(RotationAxis.POSITIVE_Z.rotationDegrees((float) (time / 25d % 360d)));
modelView.translate(screen.width / -2f, screen.height / -2f, 0);

for (int i = 0; i < 20; i++) {
modelView.push();
modelView.pushMatrix();
modelView.translate(screen.width / 2f, screen.height / 2f, 0);
modelView.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(i * 18));
modelView.rotate(RotationAxis.POSITIVE_Z.rotationDegrees(i * 18));
modelView.translate(screen.width / -2f, screen.height / -2f, 0);

RenderSystem.applyModelViewMatrix();
ScissorStack.pushDirect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
renderFunction.run();
GlStateManager._enableScissorTest();
ScissorStack.pop();
modelView.pop();
modelView.popMatrix();
}

modelView.pop();
modelView.popMatrix();
RenderSystem.applyModelViewMatrix();
} else {
ScissorStack.pushDirect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
Expand Down
Loading

0 comments on commit 13c4f5f

Please sign in to comment.