syncing code sucks

This commit is contained in:
petrak@ 2023-05-01 13:13:43 -05:00
parent 6a4c254ed0
commit 994aec97a4
6 changed files with 74 additions and 11 deletions

View file

@ -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<Vec2> 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,

View file

@ -37,7 +37,7 @@ public class PatternadosTracker {
/**
* Load a player fresh.
*/
public void clobberPatterns(UUID owner, List<PatternadoPatInstance> pats) {
public static void clobberPatterns(UUID owner, List<PatternadoPatInstance> pats) {
PATTERNADOS.put(owner, PlayerPats.newFromList(pats));
}

View file

@ -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) {

View file

@ -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<PatternadoPatInstance> 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);
}
});
}

View file

@ -42,11 +42,11 @@ public class HexCardinalComponents implements EntityComponentInitializer, ItemCo
CCSentinel.class);
public static final ComponentKey<CCFlight> FLIGHT = ComponentRegistry.getOrCreate(modLoc("flight"),
CCFlight.class);
public static final ComponentKey<CCAltiora> ALTIORA = ComponentRegistry.getOrCreate(modLoc("altiora"),
CCAltiora.class);
public static final ComponentKey<CCStaffcastImage> STAFFCAST_IMAGE = ComponentRegistry.getOrCreate(modLoc(
"harness"),
"harness"),
CCStaffcastImage.class);
public static final ComponentKey<CCPatterns> PATTERNS = ComponentRegistry.getOrCreate(modLoc("patterns"),
CCPatterns.class);

View file

@ -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));
}