Skip to content

Commit

Permalink
Merge branch 'refs/heads/1.20' into 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Nov 20, 2024
2 parents cc7b66a + cae56ef commit 1037413
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 20 deletions.
7 changes: 7 additions & 0 deletions common/src/main/java/org/figuramc/figura/avatar/Avatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public class Avatar {
public int animationComplexity;
public final Instructions complexity;
public final Instructions init, render, worldRender, tick, worldTick, animation;
public final Map<String, Instructions> customInstructions = new HashMap<>();
public final RefilledNumber particlesRemaining, soundsRemaining;
private Avatar(UUID owner, EntityType<?> type, String name) {
this.owner = owner;
Expand All @@ -145,6 +146,12 @@ private Avatar(UUID owner, EntityType<?> type, String name) {
this.particlesRemaining = new RefilledNumber(permissions.get(Permissions.PARTICLES));
this.soundsRemaining = new RefilledNumber(permissions.get(Permissions.SOUNDS));
this.entityName = name == null ? "" : name;

for (Collection<Permissions> pluginPermissions : PermissionManager.CUSTOM_PERMISSIONS.values()) {
for (Permissions customPermission : pluginPermissions) {
customInstructions.putIfAbsent(customPermission.name, new Instructions(permissions.get(customPermission)));
}
}
}

public Avatar(UUID owner) {
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/org/figuramc/figura/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.figuramc.figura.avatar.local.CacheAvatarLoader;
import org.figuramc.figura.avatar.local.LocalAvatarFetcher;
import org.figuramc.figura.backend2.NetworkStuff;
import org.figuramc.figura.entries.EntryPointManager;
import org.figuramc.figura.gui.FiguraToast;
import org.figuramc.figura.gui.screens.ConfigScreen;
import org.figuramc.figura.lua.FiguraLuaPrinter;
Expand Down Expand Up @@ -270,6 +271,7 @@ public void onChange() {
super.onChange();
PermissionManager.reinit();
LocalAvatarFetcher.reinit();
EntryPointManager.reinit();
}
};
public static final ConfigType.IPConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static void init() {
EventsAPI.initEntryPoints(load("figura_event", FiguraEvent.class));
}

public static void reinit() {
PermissionManager.initEntryPoints(load("figura_permissions", FiguraPermissions.class));
}

@ExpectPlatform
private static <T> Set<T> load(String name, Class<T> clazz) {
throw new AssertionError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.ModelPart;
import org.figuramc.figura.model.ParentType;

import java.util.Collection;
import java.util.function.Function;
Expand All @@ -22,4 +23,13 @@ public interface FiguraVanillaPart {
* the string is the parts name, case-insensitive, where the mod ID will be added into the final part name, as "ID_NAME"
*/
Collection<Pair<String, Function<EntityModel<?>, ModelPart>>> getParts();

/**
* @return returns a collection of a pair of the part name and a function to get its model part
* the function consists about giving the current Entity Model and getting a Model Part for that Entity
* the string is the parts name, case-insensitive, where the mod ID will be added into the final part name, as "ID_NAME",
* this version supports Parent Types, you can use either.
*/

Collection<Pair<String, Pair<Function<EntityModel<?>, ModelPart>, ParentType>>> getPartsWithParent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ public VanillaModelAPI(Avatar owner) {
allParts.put(name, model);
parts.add(model);
}
for (Pair<String, Pair<Function<EntityModel<?>, ModelPart>, ParentType>> part : entrypoint.getPartsWithParent()) {
String name = ID + "_" + part.getFirst().toUpperCase(Locale.US);
VanillaModelPart model = new VanillaModelPart(owner, name, part.getSecond().getSecond(), part.getSecond().getFirst());
allParts.put(name, model);
parts.add(model);
}

// add to group list
VanillaGroupPart group = new VanillaGroupPart(owner, ID, parts.toArray(new VanillaModelPart[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,16 @@ default void actuallyRender(PoseStack poseStack, T animatable, BakedGeoModel mod
if (geoBone == null)
return true;

int armorEditPermission = avatar.permissions.get(Permissions.VANILLA_MODEL_EDIT);
// Returns successfully but skips rendering if the part is hidden
VanillaPart part = RenderUtils.pivotToPart(avatar, parentType);
if (avatar.permissions.get(Permissions.VANILLA_MODEL_EDIT) == 1 && part != null && !part.checkVisible())
if (armorEditPermission == 1 && part != null && !part.checkVisible())
return false;

// If the user has no permission disable pivots
if (armorEditPermission != 1)
return true;

return !avatar.pivotPartRender(parentType, stack -> {
geoBone.setRotX(0);
geoBone.setRotY(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,31 @@ public void postRenderArmorPiece(PoseStack poseStack, MultiBufferSource multiBuf

boolean allFailed = true;
VanillaPart mainPart = RenderUtils.partFromSlot(figura$avatar, slot);
if (figura$avatar.permissions.get(Permissions.VANILLA_MODEL_EDIT) == 1 && mainPart != null && !mainPart.checkVisible()) return;
int armorEditPermission = figura$avatar.permissions.get(Permissions.VANILLA_MODEL_EDIT);
if (armorEditPermission == 1 && mainPart != null && !mainPart.checkVisible()) return;

// Don't render armor if GeckoLib is already doing the rendering
if (!GeckoLibCompat.armorHasCustomModel(itemStack)) {
// Go through each parent type needed to render the current piece of armor
for (ParentType parentType : parentTypes) {
// Skip the part if it's hidden
VanillaPart part = RenderUtils.pivotToPart(figura$avatar, parentType);
if (figura$avatar.permissions.get(Permissions.VANILLA_MODEL_EDIT) == 1 && part != null && !part.checkVisible()) continue;

if (armorEditPermission == 1 && part != null && !part.checkVisible()) continue;
boolean renderedPivot = false;
// If the user has no permission disable pivot
if (armorEditPermission == 1) {
// Try to render the pivot part
boolean renderedPivot = figura$avatar.pivotPartRender(parentType, stack -> {
renderedPivot = figura$avatar.pivotPartRender(parentType, stack -> {
stack.pushPose();
figura$prepareArmorRender(stack);
renderer.renderArmorPart(stack, vertexConsumers, light, armorModel, entity, itemStack, slot, armorItem, parentType);
stack.popPose();
});

if (renderedPivot) {
allFailed = false;
}
}
if (renderedPivot) {
allFailed = false;
}
}
}
// As a fallback, render armor the vanilla way
if (allFailed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ private void setupAvatar(T entity, Component text, PoseStack matrices, MultiBuff
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$enabled = Configs.ENTITY_NAMEPLATE.value > 0 && !AvatarManager.panic && figura$hasCustomNameplate;


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

// Push pivot transformations when the nametag is being pivoted (set to entity height in vanilla)
@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);
Expand All @@ -77,6 +78,7 @@ private void modifyPivot(PoseStack instance, float x, float y, float z, Operatio
original.call(instance, (float)pivot.x, (float)pivot.y, (float)pivot.z);
}

// Push position transformations after the nametag has been rotated to face the camera
@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) {
Expand All @@ -89,6 +91,7 @@ private void modifyPos(T entity, Component text, PoseStack matrices, MultiBuffer
}
}

// push the scale when vanilla does so
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private Component modifyPlayerNameText(Component text, @Local(argsOnly = true) A
// customization boolean, which also is the permission check
boolean hasCustom = custom != null && avatar.permissions.get(Permissions.NAMEPLATE_EDIT) == 1;

Component name = Component.literal(text.getString());
Component name = Component.literal(player.getName().getString());
FiguraMod.popPushProfiler("text");

Component replacement = hasCustom && custom.getJson() != null ? custom.getJson().copy() : name;
Expand All @@ -114,12 +114,14 @@ private Component modifyPlayerNameText(Component text, @Local(argsOnly = true) A
return text;
}

// Push for scoreboard rendering
@Inject(method = "renderNameTag(Lnet/minecraft/client/player/AbstractClientPlayer;Lnet/minecraft/network/chat/Component;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V"))
private void pushProfilerForRender(AbstractClientPlayer player, Component text, PoseStack stack, MultiBufferSource multiBufferSource, int light, CallbackInfo ci) {
FiguraMod.popPushProfiler("render");
FiguraMod.pushProfiler("scoreboard");
}

// Pop the profiler after everything's done
@Inject(method = "renderNameTag(Lnet/minecraft/client/player/AbstractClientPlayer;Lnet/minecraft/network/chat/Component;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "TAIL"))
private void popProfiler(AbstractClientPlayer player, Component text, PoseStack stack, MultiBufferSource multiBufferSource, int light, CallbackInfo ci) {
FiguraMod.popProfiler(5);
Expand Down Expand Up @@ -150,9 +152,12 @@ private void renderNameTag(AbstractClientPlayer player, Component text, PoseStac
return;
}

FiguraMod.pushProfiler(FiguraMod.MOD_ID);
FiguraMod.pushProfiler(player.getName().getString());
FiguraMod.pushProfiler("nameplate");
// If the user has an avatar equipped, figura nameplate rendering will be enabled so the profiler is pushed
if (hasCustom) {
FiguraMod.pushProfiler(FiguraMod.MOD_ID);
FiguraMod.pushProfiler(player.getName().getString());
FiguraMod.pushProfiler("nameplate");
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,9 @@ public Map<String, List<Vertex>> getAllVertices() {
value = "model_part.move_to"
)
public FiguraModelPart moveTo(@LuaNotNil FiguraModelPart part) {
if (part == this)
throw new LuaError("Fractal, cannot parent part to itself");

if (parent != null) {
parent.children.remove(this);
parent.childCache.remove(this.name);
Expand All @@ -1428,12 +1431,13 @@ public FiguraModelPart moveTo(@LuaNotNil FiguraModelPart part) {
value = "model_part.add_child"
)
public FiguraModelPart addChild(@LuaNotNil FiguraModelPart part) {
if (part == this)
throw new LuaError("Fractal, cannot parent part to itself");

FiguraModelPart parent = this.parent;
while (parent != null) {
if (part == parent)
throw new LuaError("Cannot add child that's already parent of this part");
if (part == this)
throw new LuaError("Fractal, cannot parent part to itself");
parent = parent.parent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,22 @@ protected boolean renderPart(FiguraModelPart part, int[] remainingComplexity, bo
// recalculate light
FiguraMod.popPushProfiler("calculateLight");
Level l;
if (custom.light != null)
if (custom.light != null) {
updateLight = false;
pivotOffsetter.light = custom.light;
}
else if (updateLight && (l = Minecraft.getInstance().level) != null) {
FiguraVec3 pos = part.savedPartToWorldMat.apply(0d, 0d, 0d);
int block = l.getBrightness(LightLayer.BLOCK, pos.asBlockPos());
int sky = l.getBrightness(LightLayer.SKY, pos.asBlockPos());
customizationStack.peek().light = LightTexture.pack(block, sky);
pivotOffsetter.light = customizationStack.peek().light;
}

if (custom.alpha != null)
pivotOffsetter.alpha = custom.alpha;
if (custom.overlay != null)
pivotOffsetter.overlay = custom.overlay;
}

// mid render function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ else if (hasCapeOrElytra)
if (hasArmor) {
model.addGroup(HelmetPivot, FiguraVec3.of(0, 24, 0), head);
model.addGroup(ChestplatePivot, FiguraVec3.of(0, 24, 0), body);
model.addGroup(LeftElytra, FiguraVec3.of(0, 24, 0), body);
model.addGroup(RightElytra, FiguraVec3.of(0, 24, 0), body);
model.addGroup(LeftElytraPivot, FiguraVec3.of(0, 24, 0), body);
model.addGroup(RightElytraPivot, FiguraVec3.of(0, 24, 0), body);
model.addGroup(LeftShoulderPivot, FiguraVec3.of(-6, 24, 0), leftArm);
model.addGroup(RightShoulderPivot, FiguraVec3.of(6, 24, 0), rightArm);
model.addGroup(LeggingsPivot, FiguraVec3.of(0, 12, 0), body);
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/assets/figura/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@
"figura.docs.events.char_typed": "The CHAR_TYPED event runs every time a character is inputted\nTakes three parameters, the resulting \"string\" after converting the code point, the \"modifier\", which is a bitmask number detecting if you have any modifier keys being pressed (like shift or alt, for example), and the \"codepoint\" of the inputted char",
"figura.docs.events.use_item": "The USE_ITEM event is run every time the entity uses an item\nThe item, action and amount of particles this item would produce is given as argument\nIf returned true, the event cancels its vanilla function",
"figura.docs.events.arrow_render": "The ARROW_RENDER event is run for every arrow entity shot by the Avatar owner\nIt takes two arguments, the tick delta, and the arrow entity\nReturning \"true\" stops this arrow from rendering, including the Arrow parent parts\nRequires the \"Vanilla Model Change\" permission",
"figura.docs.events.trident_render": "The TRIDENT_RENDER event is run for every trident thrown by the Avatar owner\nIt takes two arguments, the tick delta, and the trident entity\nReturning \"true\" stops this trident from rendering, including the Trident parent parts\nRequires the \"Vanilla Model Change\" permission",
"figura.docs.events.item_render": "Called on every one of your items that is being rendered\nIt takes six arguments: the item being rendered, the rendering mode, the position, rotation, and scale that would be applied to the item, and if it's being rendered in the left hand\nReturning a ModelPart parented to Item stops the rendering of this item and will render the returned part instead",
"figura.docs.events.on_play_sound": "Called every time a new sound is played\nTakes the following as arguments: the sound's ID, its world position, volume, pitch, if the sound should loop, the sound's category, and the sound's file path\nReturn true to prevent this sound from playing",
"figura.docs.events.resource_reload": "Called every time that the client resources are reloaded, allowing you to re-create or update resource texture references",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mappings = 1
enabled_platforms = fabric,forge

# Mod Properties
mod_version = 0.1.5-rc.3
mod_version = 0.1.5-rc.4
maven_group = org.figuramc
archives_base_name = figura
assets_version = v2
Expand Down

0 comments on commit 1037413

Please sign in to comment.