Skip to content

Commit

Permalink
Merge branch 'refs/heads/1.20' into 1.20.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	common/src/main/java/org/figuramc/figura/mixin/render/renderers/PlayerRendererMixin.java
  • Loading branch information
UnlikePaladin committed Aug 4, 2024
2 parents 496fe1f + 10a386b commit 0fc146a
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ else if (inverted && time < offset - loopDelay)
}
case HOLD -> {
time = inverted ? Math.max(time, offset) : Math.min(time, length);
if (time == length)
playState = PlayState.HOLDING;
if (!inverted && time >= length)
playState = PlayState.HOLDING;
else if (inverted && time <= 0)
playState = PlayState.HOLDING;
}
}

Expand Down Expand Up @@ -576,6 +578,10 @@ public Animation setSpeed(Float speed) {
if (speed == null) speed = 1f;
this.speed = speed;
this.inverted = speed < 0;
if (inverted && this.time >= this.length && this.playState == PlayState.HOLDING)
this.playState = PlayState.PLAYING;
else if (!inverted && this.time <= 0 && this.playState == PlayState.HOLDING)
this.playState = PlayState.PLAYING;
return this;
}

Expand Down
12 changes: 11 additions & 1 deletion common/src/main/java/org/figuramc/figura/backend2/HttpAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,18 @@ protected static URI getUri(String url) {
}

protected static String getBackendAddress() {
return "https://" + getBackendAddressWithPort() + "/api";
}

private static String getBackendAddressWithPort() {
ServerAddress backendIP = ServerAddress.parseString(Configs.SERVER_IP.value);
return "https://" + backendIP.getHost() + "/api";
boolean hasPort = Configs.SERVER_IP.value.matches("[^:]+:\\d+");
if (hasPort) {
try {
return backendIP.getHost() + ":" + backendIP.getPort();
} catch (IllegalStateException ignored) { }
}
return backendIP.getHost();
}

protected HttpRequest.Builder header(String url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@ public void onConnected(WebSocket websocket, Map<String, List<String>> headers)
}

public static String getBackendAddress() {
return "wss://" + getBackendAddressWithPort() + "/ws";
}

private static String getBackendAddressWithPort() {
ServerAddress backendIP = ServerAddress.parseString(Configs.SERVER_IP.value);
return "wss://" + backendIP.getHost() + "/ws";
boolean hasPort = Configs.SERVER_IP.value.matches("[^:]+:\\d+");
if (hasPort) {
try {
return backendIP.getHost() + ":" + backendIP.getPort();
} catch (IllegalStateException ignored) { }
}
return backendIP.getHost();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.figuramc.figura.ducks;

public interface EntityRendererAccessor {
default boolean figura$isRenderingName() {
return false;
}

default boolean figura$hasScore() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,20 @@ public boolean isCrouching() {
}

@LuaWhitelist
@LuaMethodDoc("entity.is_moving")
public boolean isMoving() {
@LuaMethodDoc(
overloads = {
@LuaMethodOverload,
@LuaMethodOverload(
argumentTypes = Boolean.class,
argumentNames = "ignoreY"
)
},
value = "entity.is_moving"
)
public boolean isMoving(boolean ignoreY) {
checkEntity();
return entity.getX() != entity.xOld
|| entity.getY() != entity.yOld
|| (ignoreY ? false : (entity.getY() != entity.yOld))
|| entity.getZ() != entity.zOld;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,193 @@
package org.figuramc.figura.mixin.render.renderers;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import org.figuramc.figura.FiguraMod;
import org.figuramc.figura.avatar.Avatar;
import org.figuramc.figura.avatar.AvatarManager;
import org.figuramc.figura.config.Configs;
import org.figuramc.figura.ducks.EntityRendererAccessor;
import org.figuramc.figura.lua.api.nameplate.EntityNameplateCustomization;
import org.figuramc.figura.math.vector.FiguraVec3;
import org.figuramc.figura.permissions.Permissions;
import org.figuramc.figura.utils.TextUtils;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

@Mixin(EntityRenderer.class)
public abstract class EntityRendererMixin<T extends Entity> {
public abstract class EntityRendererMixin<T extends Entity> implements EntityRendererAccessor {

@Inject(at = @At("HEAD"), method = "shouldRender", cancellable = true)
private void shouldRender(T entity, Frustum frustum, double d, double e, double f, CallbackInfoReturnable<Boolean> cir) {
Avatar avatar = AvatarManager.getAvatar(entity);
if (avatar != null && avatar.permissions.get(Permissions.OFFSCREEN_RENDERING) == 1)
cir.setReturnValue(true);
}

@Unique
Avatar figura$avatar;
@Unique
boolean figura$hasCustomNameplate;
@Unique
boolean figura$enabled;

@Unique
EntityNameplateCustomization figura$custom;

@Unique
List<Component> figura$textList;

@Inject(at = @At(value = "HEAD"), method = "renderNameTag")
private void setupAvatar(T entity, Component text, PoseStack matrices, MultiBufferSource vertexConsumers, int light, CallbackInfo ci) {
figura$avatar = AvatarManager.getAvatar(entity);
figura$custom = figura$avatar == null || figura$avatar.luaRuntime == null ? null : figura$avatar.luaRuntime.nameplate.ENTITY;
figura$hasCustomNameplate = figura$custom != null && figura$avatar.permissions.get(Permissions.NAMEPLATE_EDIT) == 1;
figura$enabled = Configs.ENTITY_NAMEPLATE.value > 0 && !AvatarManager.panic;


figura$textList = TextUtils.splitText(text, "\n");
}

@WrapOperation(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;translate(FFF)V"), method = "renderNameTag")
private void modifyPivot(PoseStack instance, float x, float y, float z, Operation<Void> original) {
FiguraVec3 pivot = FiguraVec3.of(x, y, z);
if (figura$enabled && figura$avatar != null) {
// pivot
FiguraMod.pushProfiler("pivot");
if (figura$hasCustomNameplate && figura$custom.getPivot() != null)
pivot = figura$custom.getPivot();
}
original.call(instance, (float)pivot.x, (float)pivot.y, (float)pivot.z);
}

@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;mulPose(Lorg/joml/Quaternionf;)V", shift = At.Shift.AFTER), method = "renderNameTag")
private void modifyPos(T entity, Component text, PoseStack matrices, MultiBufferSource vertexConsumers, int light, CallbackInfo ci) {
if (figura$enabled && figura$avatar != null) {
// pos
FiguraMod.popPushProfiler("position");
if (figura$hasCustomNameplate && figura$custom.getPos() != null) {
FiguraVec3 pos = figura$custom.getPos();
matrices.translate(pos.x, pos.y, pos.z);
}
}
}

@WrapOperation(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;scale(FFF)V"), method = "renderNameTag")
private void modifyScale(PoseStack instance, float x, float y, float z, Operation<Void> original) {
FiguraVec3 scaleVec = FiguraVec3.of(x, y, z);
if (figura$enabled && figura$avatar != null) {
// scale
FiguraMod.popPushProfiler("scale");
if (figura$hasCustomNameplate && figura$custom.getScale() != null)
scaleVec.multiply(figura$custom.getScale());
}
original.call(instance, (float) scaleVec.x, (float) scaleVec.y, (float) scaleVec.z);
}



@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack$Pose;pose()Lorg/joml/Matrix4f;"), method = "renderNameTag")
private void setShadowMatrix(T entity, Component text, PoseStack matrices, MultiBufferSource vertexConsumers, int light, CallbackInfo ci, @Share("textMatrix") LocalRef<Matrix4f> textMatrix) {
textMatrix.set(matrices.last().pose());
if (figura$enabled && figura$avatar != null && figura$hasCustomNameplate && figura$custom.shadow) {
matrices.pushPose();
matrices.scale(1, 1, -1);
textMatrix.set(matrices.last().pose());
matrices.popPose();
}
}

@WrapOperation(method = "renderNameTag", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Font;drawInBatch(Lnet/minecraft/network/chat/Component;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/client/gui/Font$DisplayMode;II)I", ordinal = 0))
private int drawWithColor(Font font, Component component, float x, float y, int color, boolean shadow, Matrix4f matrix4f, MultiBufferSource multiBufferSource, Font.DisplayMode displayMode, int backgroundColor, int light, Operation<Integer> original) {
if (figura$enabled && figura$avatar != null && figura$hasCustomNameplate) {
light = figura$custom.light != null ? figura$custom.light : light;
backgroundColor = figura$custom.background != null ? figura$custom.background : backgroundColor;
boolean deadmau = component.getString().equals("deadmau5");

if (figura$isRenderingName()) {
int ret = 0;
// If the player's name is being rendered, render by lines otherwise just render whatever component is being passed. Applies for the rest of the loops below
for (int i = 0; i < figura$textList.size(); i++) {
Component text1 = figura$textList.get(i);

if (text1.getString().isEmpty())
continue;

int line = i - figura$textList.size() + (figura$hasScore() ? 0 : 1);
x = -font.width(text1) / 2f;
y = (deadmau ? -10f : 0f) + (font.lineHeight + 1) * line;
ret = original.call(font, text1, x, y, color, shadow, matrix4f, multiBufferSource, displayMode, backgroundColor, light);
}
return ret;
} else {
return original.call(font, component, x, y, color, shadow, matrix4f, multiBufferSource, displayMode, backgroundColor, light);
}
} else {
return original.call(font, component, x, y, color, shadow, matrix4f, multiBufferSource, displayMode, backgroundColor, light);
}
}

@WrapOperation(method = "renderNameTag", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Font;drawInBatch(Lnet/minecraft/network/chat/Component;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/client/gui/Font$DisplayMode;II)I", ordinal = 1))
private int drawWithOutline(Font font, Component component, float x, float y, int color, boolean shadow, Matrix4f matrix4f, MultiBufferSource multiBufferSource, Font.DisplayMode displayMode, int backgroundColor, int light, Operation<Integer> original, @Share("textMatrix") LocalRef<Matrix4f> textMatrix) {
light = figura$enabled && figura$avatar != null && figura$hasCustomNameplate && figura$custom.light != null ? figura$custom.light : light;
shadow = figura$enabled && figura$avatar != null && figura$hasCustomNameplate ? figura$custom.shadow : shadow;
boolean deadmau = component.getString().equals("deadmau5");

if (figura$enabled && figura$avatar != null && figura$hasCustomNameplate && figura$custom.outline) {
int outlineColor = figura$custom.outlineColor != null ? figura$custom.outlineColor : 0x202020;
if (figura$isRenderingName()) {
for (int i = 0; i < figura$textList.size(); i++) {
Component text1 = figura$textList.get(i);

if (text1.getString().isEmpty())
continue;

int line = i - figura$textList.size() + (figura$hasScore() ? 0 : 1);
x = -font.width(text1) / 2f;
y = (deadmau ? -10f : 0f) + (font.lineHeight + 1) * line;
font.drawInBatch8xOutline(text1.getVisualOrderText(), x, y, color, outlineColor, matrix4f, multiBufferSource, light);
}
} else {
font.drawInBatch8xOutline(component.getVisualOrderText(), x, y, color, outlineColor, matrix4f, multiBufferSource, light);
}
return original.call(font, Component.empty(), x, y, color, shadow, textMatrix.get(), multiBufferSource, displayMode, backgroundColor, light);
} else {
if (figura$enabled && figura$isRenderingName()) {
int ret = 0;

for (int i = 0; i < figura$textList.size(); i++) {
Component text1 = figura$textList.get(i);

if (text1.getString().isEmpty())
continue;

int line = i - figura$textList.size() + (figura$hasScore() ? 0 : 1);
x = -font.width(text1) / 2f;
y = (deadmau ? -10f : 0f) + (font.lineHeight + 1) * line;
ret = original.call(font, text1, x, y, color, shadow, textMatrix.get(), multiBufferSource, displayMode, backgroundColor, light);
}

return ret;
} else {
return original.call(font, component, x, y, color, shadow, textMatrix.get(), multiBufferSource, displayMode, backgroundColor, light);
}
}
}
}
Loading

0 comments on commit 0fc146a

Please sign in to comment.