From 994aec97a42eb42a8d978af7e044bb70a16757c5 Mon Sep 17 00:00:00 2001 From: "petrak@" Date: Mon, 1 May 2023 13:13:43 -0500 Subject: [PATCH] syncing code sucks --- .../client/render/HexAdditionalRenderers.java | 56 +++++++++++++++++++ .../render/patternado/PatternadosTracker.java | 2 +- .../common/msgs/MsgNewPatternadoPatS2C.java | 3 +- ...S2C.java => MsgOverridePatternadoS2C.java} | 19 ++++--- .../fabric/cc/HexCardinalComponents.java | 4 +- .../hexcasting/forge/cap/CapSyncers.java | 1 + 6 files changed, 74 insertions(+), 11 deletions(-) rename Common/src/main/java/at/petrak/hexcasting/common/msgs/{MsgLoadPatternadoS2C.java => MsgOverridePatternadoS2C.java} (58%) diff --git a/Common/src/main/java/at/petrak/hexcasting/client/render/HexAdditionalRenderers.java b/Common/src/main/java/at/petrak/hexcasting/client/render/HexAdditionalRenderers.java index bfb13ca8..4c071a63 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/render/HexAdditionalRenderers.java +++ b/Common/src/main/java/at/petrak/hexcasting/client/render/HexAdditionalRenderers.java @@ -27,12 +27,15 @@ import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import java.util.List; import java.util.function.BiConsumer; public class HexAdditionalRenderers { + private static final float PATTERNADO_SPEEN_SPEED = 0.01f; + public static void overlayLevel(PoseStack ps, float partialTick) { var player = Minecraft.getInstance().player; if (player != null) { @@ -58,8 +61,61 @@ public class HexAdditionalRenderers { return; } + var oldShader = RenderSystem.getShader(); + RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.enableDepthTest(); + RenderSystem.disableCull(); ps.pushPose(); + float time = player.level.getGameTime() + partialTicks; + var col = IXplatAbstractions.INSTANCE.getColorizer(player).getColorProvider(); + + for (var spinner : pats) { + // So it stops moving near the end? + float lifetimeOffset = spinner.getLifetime() <= 5 ? (5f - spinner.getLifetime()) / 5f : 0f; + { + ps.mulPose(Vector3f.YP.rotationDegrees(time * spinner.getLifetime() * PATTERNADO_SPEEN_SPEED)); + // X: sideways, don't move it + // Y: up/down, each pattern stays on its own ring + // Z: in/out, it's mostly determined by the idx but also slowly drifts in/out + ps.translate( + 0, + Mth.sin(spinner.getIdx() * 0.75f), + 0.75f + (Mth.cos(spinner.getIdx() / 8f) * 0.25f) + Mth.cos(time) / (7f + (spinner.getIdx() / 4f)) * 0.065f + ); + var scale = 1f / 24f * (1 - lifetimeOffset); + ps.scale(scale, scale, scale); + // Don't know why amo did this in two translate calls + ps.translate( + 0, + Mth.floor(spinner.getIdx() / 8f) + Mth.sin(time) / (7f + (spinner.getIdx() / 8f)), + 0 + ); + } + + var pat = spinner.getPattern(); + var lines = RenderLib.getCenteredPattern(pat, 1, 1, 3.8f).getSecond(); + + float variance = 0.65f; + float speed = 0.1f; + List zappy = RenderLib.makeZappy(lines, RenderLib.findDupIndices(pat.positions()), + 5, variance, speed, 0.2f, 0f, + 1f, spinner.getUuid().hashCode()); + int outer = col.getColor(ClientTickCounter.getTotal() / 2f, Vec3.ZERO); + int rgbOnly = outer & 0x00FFFFFF; + int newAlpha = outer >>> 24; + if (spinner.getLifetime() <= 60) { + newAlpha = (int) Math.floor(spinner.getLifetime() / 60f * 255); + } + int newARGB = (newAlpha << 24) | rgbOnly; + int inner = RenderLib.screen(newARGB); + RenderLib.drawLineSeq(ps.last().pose(), zappy, 0.35f, 0f, newARGB, newARGB); + RenderLib.drawLineSeq(ps.last().pose(), zappy, 0.14f, 0.01f, inner, inner); + } + + ps.popPose(); + RenderSystem.setShader(() -> oldShader); + RenderSystem.enableCull(); } private static void renderSentinel(Sentinel sentinel, LocalPlayer owner, diff --git a/Common/src/main/java/at/petrak/hexcasting/client/render/patternado/PatternadosTracker.java b/Common/src/main/java/at/petrak/hexcasting/client/render/patternado/PatternadosTracker.java index d32053d1..644ed5a2 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/render/patternado/PatternadosTracker.java +++ b/Common/src/main/java/at/petrak/hexcasting/client/render/patternado/PatternadosTracker.java @@ -37,7 +37,7 @@ public class PatternadosTracker { /** * Load a player fresh. */ - public void clobberPatterns(UUID owner, List pats) { + public static void clobberPatterns(UUID owner, List pats) { PATTERNADOS.put(owner, PlayerPats.newFromList(pats)); } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewPatternadoPatS2C.java b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewPatternadoPatS2C.java index 9acaf248..53f26437 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewPatternadoPatS2C.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgNewPatternadoPatS2C.java @@ -21,6 +21,7 @@ public record MsgNewPatternadoPatS2C(UUID owner, PatternadoPatInstance newPat) i public static MsgNewPatternadoPatS2C deserialize(ByteBuf buffer) { var buf = new FriendlyByteBuf(buffer); + var owner = buf.readUUID(); var pat = PatternadoPatInstance.loadFromWire(buf); return new MsgNewPatternadoPatS2C(owner, pat); @@ -28,8 +29,8 @@ public record MsgNewPatternadoPatS2C(UUID owner, PatternadoPatInstance newPat) i @Override public void serialize(FriendlyByteBuf buf) { - this.newPat.saveToWire(buf); buf.writeUUID(this.owner); + this.newPat.saveToWire(buf); } public static void handle(MsgNewPatternadoPatS2C msg) { diff --git a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgLoadPatternadoS2C.java b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgOverridePatternadoS2C.java similarity index 58% rename from Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgLoadPatternadoS2C.java rename to Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgOverridePatternadoS2C.java index c359a7c4..94a248b4 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgLoadPatternadoS2C.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgOverridePatternadoS2C.java @@ -7,11 +7,16 @@ import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import static at.petrak.hexcasting.api.HexAPI.modLoc; -public record MsgLoadPatternadoS2C(UUID owner, PatternadoPatInstance newPat) implements IMessage { +/** + * Set the patternado of a given player to this, overwrite the previous + */ +public record MsgOverridePatternadoS2C(UUID owner, List pats) implements IMessage { public static final ResourceLocation ID = modLoc("nados"); @Override @@ -19,24 +24,24 @@ public record MsgLoadPatternadoS2C(UUID owner, PatternadoPatInstance newPat) imp return ID; } - public static MsgLoadPatternadoS2C deserialize(ByteBuf buffer) { + public static MsgOverridePatternadoS2C deserialize(ByteBuf buffer) { var buf = new FriendlyByteBuf(buffer); var owner = buf.readUUID(); - var pat = PatternadoPatInstance.loadFromWire(buf); - return new MsgLoadPatternadoS2C(owner, pat); + var pats = buf.readCollection(ArrayList::new, PatternadoPatInstance::loadFromWire); + return new MsgOverridePatternadoS2C(owner, pats); } @Override public void serialize(FriendlyByteBuf buf) { - this.newPat.saveToWire(buf); buf.writeUUID(this.owner); + buf.writeCollection(this.pats, (bf, it) -> it.saveToWire(bf)); } - public static void handle(MsgLoadPatternadoS2C msg) { + public static void handle(MsgOverridePatternadoS2C msg) { Minecraft.getInstance().execute(new Runnable() { @Override public void run() { - PatternadosTracker.getNewPat(msg.owner, msg.newPat); + PatternadosTracker.clobberPatterns(msg.owner, msg.pats); } }); } diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/HexCardinalComponents.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/HexCardinalComponents.java index 2777d542..0e291289 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/HexCardinalComponents.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/cc/HexCardinalComponents.java @@ -42,11 +42,11 @@ public class HexCardinalComponents implements EntityComponentInitializer, ItemCo CCSentinel.class); public static final ComponentKey FLIGHT = ComponentRegistry.getOrCreate(modLoc("flight"), CCFlight.class); - public static final ComponentKey ALTIORA = ComponentRegistry.getOrCreate(modLoc("altiora"), CCAltiora.class); + public static final ComponentKey STAFFCAST_IMAGE = ComponentRegistry.getOrCreate(modLoc( - "harness"), + "harness"), CCStaffcastImage.class); public static final ComponentKey PATTERNS = ComponentRegistry.getOrCreate(modLoc("patterns"), CCPatterns.class); diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/CapSyncers.java b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/CapSyncers.java index 8fda7232..b3f2852d 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/CapSyncers.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/CapSyncers.java @@ -29,6 +29,7 @@ public class CapSyncers { x.setAltiora(player, x.getAltiora(proto)); x.setSentinel(player, x.getSentinel(proto)); x.setColorizer(player, x.getColorizer(proto)); + // TODO: do we want staff stuff to remain on death? x.setStaffcastImage(player, x.getStaffcastVM(proto, InteractionHand.MAIN_HAND).getImage()); x.setPatterns(player, x.getPatternsSavedInUi(proto)); }