From 5b82f5f42e9a3dce0235b8dce3374e0be1bb17a0 Mon Sep 17 00:00:00 2001 From: KitCat962 Date: Mon, 4 Mar 2024 20:35:51 -0500 Subject: [PATCH 01/43] fix sound functions breaking when stopped naturally --- .../figura/lua/api/sound/LuaSound.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/sound/LuaSound.java b/common/src/main/java/org/figuramc/figura/lua/api/sound/LuaSound.java index 745ed9f6c..c9e92e76b 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/sound/LuaSound.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/sound/LuaSound.java @@ -8,6 +8,7 @@ import net.minecraft.client.sounds.SoundBufferLibrary; import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundSource; + import org.figuramc.figura.avatar.Avatar; import org.figuramc.figura.avatar.AvatarManager; import org.figuramc.figura.lua.LuaWhitelist; @@ -79,7 +80,8 @@ private float calculateVolume() { @LuaWhitelist @LuaMethodDoc("sound.play") public LuaSound play() { - if (this.playing) + // Only skip logic when we truely know the sound is currently playing + if (this.playing && this.handle != null && !this.handle.isStopped()) return this; if (!owner.soundsRemaining.use()) { @@ -89,6 +91,12 @@ public LuaSound play() { owner.noPermissions.remove(Permissions.SOUNDS); + // if we still have a handle reference but the handle has been released, remove the reference + // This occurs when sounds naturally stops + if (this.handle != null && this.handle.isStopped()) { + this.handle = null; + } + // if handle exists, the sound was previously played. Unpause it if (handle != null) { handle.execute(Channel::unpause); @@ -185,8 +193,18 @@ public LuaSound play() { @LuaWhitelist @LuaMethodDoc("sound.is_playing") public boolean isPlaying() { - if (handle != null) - handle.execute(channel -> this.playing = channel.playing()); + if (handle != null) { + // If the handle was released via the sound stopping naturlly, force set to false. + // When a handle is stopped, it has no channel, so playing will not update. + if (handle.isStopped()) + this.playing = false; + // set playing based on whether the sound is paused or not. + else + handle.execute(channel -> this.playing = channel.playing()); + } + // If there is no handle, forcefully set it to false just incase + else + this.playing = false; return this.playing; } From 603bd2f08f654f5f4a8544abd3fbeef523a35ac9 Mon Sep 17 00:00:00 2001 From: KitCat962 Date: Wed, 6 Mar 2024 12:07:47 -0500 Subject: [PATCH 02/43] fixed Chat Customizations config disabling all --- .../org/figuramc/figura/mixin/gui/ChatComponentMixin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/mixin/gui/ChatComponentMixin.java b/common/src/main/java/org/figuramc/figura/mixin/gui/ChatComponentMixin.java index 8c7271097..7896dc9de 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/gui/ChatComponentMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/gui/ChatComponentMixin.java @@ -127,9 +127,9 @@ private Component addMessage(Component message, Component msg, MessageSignature message = TextUtils.replaceInText(message, quotedName, emptyReplacement, (s, style) -> true, isOwner ? 1 : 0, Integer.MAX_VALUE); // sender badges - if (config > 1 && isOwner) { + if (isOwner) { // badges - Component temp = Badges.appendBadges(replacement, uuid, true); + Component temp = Badges.appendBadges(replacement, uuid, config > 1); // trim temp = TextUtils.trim(temp); // modify message, only first From 0bb2d42d8bda9d69ea8c21af78846d039af60599 Mon Sep 17 00:00:00 2001 From: Super <38338700+superpowers04@users.noreply.github.com> Date: Thu, 7 Mar 2024 22:34:43 -0500 Subject: [PATCH 03/43] Don't parse metadata into json 3 seperate times --- .../avatar/local/LocalAvatarLoader.java | 10 +++--- .../figura/parsers/AvatarMetadataParser.java | 33 +++++++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java b/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java index b768e52fe..c7eead51b 100644 --- a/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java +++ b/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java @@ -131,10 +131,12 @@ public static void loadAvatar(Path path, UserData target) { // metadata loadState = LoadState.METADATA; - String metadata = IOUtils.readFile(finalPath.resolve("avatar.json")); - nbt.put("metadata", AvatarMetadataParser.parse(metadata, IOUtils.getFileNameOrEmpty(finalPath))); - AvatarMetadataParser.injectToModels(metadata, models); - AvatarMetadataParser.injectToTextures(metadata, textures); + CompoundTag metaNBT = AvatarMetadataParser.parse(_meta, IOUtils.getFileNameOrEmpty(finalPath)); + nbt.put("metadata", metaNBT); + metaNBT.putString("uuid",target.id.toString()); + + AvatarMetadataParser.injectToModels(metadata, models); + AvatarMetadataParser.injectToTextures(metadata, textures); // return :3 if (!models.isEmpty()) diff --git a/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java b/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java index b4180e745..cc4475b61 100644 --- a/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java +++ b/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java @@ -101,11 +101,9 @@ public static CompoundTag parse(String json, String filename) { return nbt; } - - public static void injectToModels(String json, CompoundTag models) throws IOException { + public static void injectToModels(Metadata metadata, CompoundTag models) throws IOException { PARTS_TO_MOVE.clear(); - Metadata metadata = GSON.fromJson(json, Metadata.class); if (metadata != null && metadata.customizations != null) { for (Map.Entry entry : metadata.customizations.entrySet()) injectCustomization(entry.getKey(), entry.getValue(), models); @@ -120,7 +118,21 @@ public static void injectToModels(String json, CompoundTag models) throws IOExce targetPart.put("chld", list); } } + public static void injectToTextures(Metadata metadata, CompoundTag textures) { + if (metadata == null || metadata.ignoredTextures == null) + return; + CompoundTag src = textures.getCompound("src"); + + for (String texture : metadata.ignoredTextures) { + byte[] bytes = src.getByteArray(texture); + int[] size = BlockbenchModelParser.getTextureSize(bytes); + ListTag list = new ListTag(); + list.add(IntTag.valueOf(size[0])); + list.add(IntTag.valueOf(size[1])); + src.put(texture, list); + } + } private static void injectCustomization(String path, Customization customization, CompoundTag models) throws IOException { boolean remove = customization.remove != null && customization.remove; CompoundTag modelPart = getTag(models, path, remove); @@ -198,22 +210,7 @@ private static CompoundTag getTag(CompoundTag models, String path, boolean remov return current; } - public static void injectToTextures(String json, CompoundTag textures) { - Metadata metadata = GSON.fromJson(json, Metadata.class); - if (metadata == null || metadata.ignoredTextures == null) - return; - CompoundTag src = textures.getCompound("src"); - - for (String texture : metadata.ignoredTextures) { - byte[] bytes = src.getByteArray(texture); - int[] size = BlockbenchModelParser.getTextureSize(bytes); - ListTag list = new ListTag(); - list.add(IntTag.valueOf(size[0])); - list.add(IntTag.valueOf(size[1])); - src.put(texture, list); - } - } // json object class public static class Metadata { From 3d403f91bd3d34d7ad8dcdabed7df606be9e2d4a Mon Sep 17 00:00:00 2001 From: Super <38338700+superpowers04@users.noreply.github.com> Date: Fri, 8 Mar 2024 21:13:52 -0500 Subject: [PATCH 04/43] ooop forgor something --- .../org/figuramc/figura/avatar/local/LocalAvatarLoader.java | 5 ++++- .../org/figuramc/figura/parsers/AvatarMetadataParser.java | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java b/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java index c7eead51b..0c49683d0 100644 --- a/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java +++ b/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java @@ -131,7 +131,10 @@ public static void loadAvatar(Path path, UserData target) { // metadata loadState = LoadState.METADATA; - CompoundTag metaNBT = AvatarMetadataParser.parse(_meta, IOUtils.getFileNameOrEmpty(finalPath)); + String _meta = IOUtils.readFile(finalPath.resolve("avatar.json")); + var metadata = AvatarMetadataParser.read(_meta); + + CompoundTag metaNBT = AvatarMetadataParser.parse(metadata,_meta, IOUtils.getFileNameOrEmpty(finalPath)); nbt.put("metadata", metaNBT); metaNBT.putString("uuid",target.id.toString()); diff --git a/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java b/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java index cc4475b61..fe7f4b2a1 100644 --- a/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java +++ b/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java @@ -33,6 +33,9 @@ public static Metadata read(String json) { public static CompoundTag parse(String json, String filename) { // parse json -> object Metadata metadata = read(json); + parse(metadata,json,filename); + } + public static CompoundTag parse(Metadata metadata, String json, String filename) { // nbt CompoundTag nbt = new CompoundTag(); From b1c0196f8fde71265d4e1ddbd8b3a8b8ae73db75 Mon Sep 17 00:00:00 2001 From: Super <38338700+superpowers04@users.noreply.github.com> Date: Fri, 8 Mar 2024 21:23:10 -0500 Subject: [PATCH 05/43] chat i might be dumb --- .../java/org/figuramc/figura/parsers/AvatarMetadataParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java b/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java index fe7f4b2a1..dacb81477 100644 --- a/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java +++ b/common/src/main/java/org/figuramc/figura/parsers/AvatarMetadataParser.java @@ -33,7 +33,7 @@ public static Metadata read(String json) { public static CompoundTag parse(String json, String filename) { // parse json -> object Metadata metadata = read(json); - parse(metadata,json,filename); + return parse(metadata,json,filename); } public static CompoundTag parse(Metadata metadata, String json, String filename) { From 0e19ea660adc93b03d6a503014d09ffe332a06da Mon Sep 17 00:00:00 2001 From: 4P5 <4P5@stormheart.net> Date: Tue, 12 Mar 2024 20:01:10 +1300 Subject: [PATCH 06/43] world.getMapData() - Added `world.getMapData()` for getting data related to maps. It takes a string argument, e.g. "map_4", and returns a table of data related to the map --- .../figura/lua/api/world/WorldAPI.java | 42 +++++++++++++++++++ .../resources/assets/figura/lang/en_us.json | 1 + 2 files changed, 43 insertions(+) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java index acc24005b..81c046c28 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java @@ -14,6 +14,9 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.saveddata.maps.MapDecoration; +import net.minecraft.world.level.saveddata.maps.MapItemSavedData; +import org.apache.commons.lang3.ArrayUtils; import org.figuramc.figura.avatar.Avatar; import org.figuramc.figura.avatar.AvatarManager; import org.figuramc.figura.lua.LuaNotNil; @@ -156,6 +159,45 @@ public static List getBlocks(Object x, Object y, Double z, Double return list; } + @LuaWhitelist + @LuaMethodDoc( + overloads = { + @LuaMethodOverload( + argumentTypes = String.class, + argumentNames = "id" + ), + }, + value = "world.get_map_data" + ) + public static HashMap getMapData(String id) { + MapItemSavedData data = getCurrentWorld().getMapData(id); + + if (data == null) + return null; + + HashMap map = new HashMap<>(); + + map.put("center_x", data.centerX); + map.put("center_z", data.centerZ); + map.put("locked", data.locked); + map.put("scale", data.scale); + + ArrayList> decorations = new ArrayList<>(); + for (MapDecoration decoration : data.getDecorations()) { + HashMap decorationMap = new HashMap<>(); + decorationMap.put("type", decoration.getType().toString()); + decorationMap.put("name", decoration.getName() == null ? "" : decoration.getName().getString()); + decorationMap.put("x", decoration.getX()); + decorationMap.put("y", decoration.getY()); + decorationMap.put("rot", decoration.getRot()); + decorationMap.put("image", decoration.getImage()); + decorations.add(decorationMap); + } + map.put("decorations", decorations); + + return map; + } + @LuaWhitelist @LuaMethodDoc( overloads = { diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index aed85254e..71c287104 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -1679,6 +1679,7 @@ "figura.docs.world.get_spawn_point": "Returns a vector with the coordinates of the world spawn", "figura.docs.world.raycast_entity": "Raycasts an Entity in the world, returns a map containing the entity and it's position.", "figura.docs.world.raycast_block": "Raycasts a Block in the world, returns a map containing the block and it's position.", + "figura.docs.world.get_map_data": "Takes a string, e.g., `map_3`, and returns a table of data if the map exists.\nMap data may be unsynced, and will only update when holding the map", "figura.docs.data": "A global API that provides functions to work with data related features", "figura.docs.data.create_buffer": "Creates an empty buffer", "figura.docs.buffer": "A byte buffer object", From c3834204740dee3a729051a76e6cfe7b24722508 Mon Sep 17 00:00:00 2001 From: 4P5 <4P5@stormheart.net> Date: Thu, 14 Mar 2024 18:42:20 +1300 Subject: [PATCH 07/43] world.getEntities() - Added world.getEntities(). It accepts two positions which form a bounding box, then returns a list of all entities inside of the box. --- .../figura/lua/api/world/WorldAPI.java | 29 +++++++++++++++++++ .../resources/assets/figura/lang/en_us.json | 1 + 2 files changed, 30 insertions(+) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java index 81c046c28..d8ff7da0f 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java @@ -7,6 +7,7 @@ import net.minecraft.commands.arguments.blocks.BlockStateArgument; import net.minecraft.commands.arguments.item.ItemArgument; import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -16,6 +17,7 @@ import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.saveddata.maps.MapDecoration; import net.minecraft.world.level.saveddata.maps.MapItemSavedData; +import net.minecraft.world.phys.AABB; import org.apache.commons.lang3.ArrayUtils; import org.figuramc.figura.avatar.Avatar; import org.figuramc.figura.avatar.AvatarManager; @@ -35,6 +37,7 @@ import org.luaj.vm2.LuaTable; import java.util.*; +import java.util.stream.Collectors; @LuaWhitelist @LuaTypeDoc( @@ -474,6 +477,32 @@ public static Map> getPlayers() { return playerList; } + @LuaWhitelist + @LuaMethodDoc( + overloads = { + @LuaMethodOverload( + argumentTypes = {FiguraVec3.class, FiguraVec3.class}, + argumentNames = {"pos1", "pos2"} + ), + @LuaMethodOverload( + argumentTypes = {Double.class, Double.class, Double.class, Double.class, Double.class, Double.class}, + argumentNames = {"x1", "y1", "z1", "x2", "y2", "z2"} + ) + }, + value = "world.get_entities" + ) + public static List> getEntities(Object x1, Object y1, Double z1, Double x2, Double y2, Double z2) { + Pair pair = LuaUtils.parse2Vec3("getEntities", x1, y1, z1, x2, y2, z2, 1); + FiguraVec3 pos1 = pair.getFirst(); + FiguraVec3 pos2 = pair.getSecond(); + + AABB aabb = new AABB(pos1.asVec3(), pos2.asVec3()); + return getCurrentWorld().getEntitiesOfClass(Entity.class, aabb) + .stream() + .map(EntityAPI::wrap) + .collect(Collectors.toList()); + } + @LuaWhitelist @LuaMethodDoc( overloads = @LuaMethodOverload( diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index 71c287104..e3f179f78 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -1670,6 +1670,7 @@ "figura.docs.world.get_height": "Returns the highest point at the given position according to the provided heightmap\nDefaults to MOTION_BLOCKING if no heightmap is provided", "figura.docs.world.get_dimension": "Gets the dimension name of this world", "figura.docs.world.get_entity": "Returns an EntityAPI object from this UUID's entity, or nil if no entity was found", + "figura.docs.world.get_entities": "Returns a list of entities within the bounding box formed by the two given positions", "figura.docs.world.get_players": "Returns a table containing instances of Player for all players in the world\nThe players are indexed by their names", "figura.docs.world.avatar_vars": "Returns a table containing variables stored from all loaded Avatars \"avatar:store()\" function\nThe table will be indexed by the avatar's owner UUID", "figura.docs.world.new_block": "Parses and creates a new BlockState from the given string\nA world position can be optionally given for the blockstate functions that rely on its position", From d3e634c73cc5542ada6ce34efd558ed1455546c1 Mon Sep 17 00:00:00 2001 From: 4P5 <4P5@stormheart.net> Date: Fri, 15 Mar 2024 16:51:42 +1300 Subject: [PATCH 08/43] :getNearestEntity() - Added :getNearestEntity(), which returns the closest entity to the given entity. It takes an optional type to filter by, and a radius which defaults to 20 blocks --- .../figura/lua/api/entity/EntityAPI.java | 50 +++++++++++++++++-- .../resources/assets/figura/lang/en_us.json | 1 + 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java index e221fc289..5dc8753ae 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java @@ -4,11 +4,9 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityDimensions; -import net.minecraft.world.entity.HasCustomInventoryScreen; -import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.*; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.entity.vehicle.ContainerEntity; @@ -35,10 +33,12 @@ import org.figuramc.figura.utils.EntityUtils; import org.figuramc.figura.utils.LuaUtils; import org.jetbrains.annotations.NotNull; +import org.luaj.vm2.LuaError; import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.UUID; @@ -459,6 +459,48 @@ public Object[] getTargetedEntity(Double distance) { return null; } + @LuaWhitelist + @LuaMethodDoc( + overloads = { + @LuaMethodOverload( + argumentTypes = { String.class, Double.class }, + argumentNames = { "type", "radius" } + ), + @LuaMethodOverload( + argumentTypes = { String.class }, + argumentNames = { "type" } + ), + @LuaMethodOverload() + }, + value = "entity.get_nearest_entity" + ) + public EntityAPI getNearestEntity(String type, Double radius) { + checkEntity(); + radius = radius != null ? radius : 20; + + EntityType entityType; + if (type != null) { + ResourceLocation id = ResourceLocation.tryParse(type); + if (id == null) { + throw new LuaError("Invalid entity type: " + type); + } + entityType = BuiltInRegistries.ENTITY_TYPE.get(id); + } else { + entityType = null; + } + + FiguraVec3 pos = getPos(1f); + + AABB aabb = new AABB(pos.offseted(-radius).asVec3(), pos.offseted(radius).asVec3()); + + return getLevel().getEntities(entity, aabb) + .stream() + .filter(e -> entityType == null || e.getType() == entityType) + .min(Comparator.comparingDouble(e -> e.distanceToSqr(pos.x(), pos.y(), pos.z()))) + .map(EntityAPI::wrap) + .orElse(null); + } + @LuaWhitelist @LuaMethodDoc( overloads = { diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index e3f179f78..8b455451f 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -988,6 +988,7 @@ "figura.docs.entity.has_inventory": "Checks if the entity has an inventory (Horses, Camels, LLamas, …)", "figura.docs.entity.get_targeted_block": "Returns a proxy for your currently targeted BlockState\nThis BlockState appears on the F3 screen\nThe maximum (and default) distance is 20, minimum is -20\nReturns the block, the hit position, and the targeted block face as three separate values", "figura.docs.entity.get_targeted_entity": "Returns a proxy for your currently targeted Entity\nThis Entity appears on the F3 screen\nMaximum and Default distance is 20, Minimum is 0", + "figura.docs.entity.get_nearest_entity": "Returns the closest entity to this entity\nIf `type` is an entity id, (e.g. `minecraft:bee`), only entities of that type will be considered\nRadius defaults to 20, and controls the size of the area for checking entities as a box expanding in every direction from the player", "figura.docs.entity.get_variable": "Gets the value of a variable this entity stored in themselves using the Avatar API's store() function", "figura.docs.entity.is_living": "Gets if this entity is a Living Entity", "figura.docs.entity.is_player": "Gets if this entity is a Player Entity", From 69f493869dad1c197faa7a10412dbefdd9623a91 Mon Sep 17 00:00:00 2001 From: 4P5 <4P5@stormheart.net> Date: Wed, 20 Mar 2024 17:39:55 +1300 Subject: [PATCH 09/43] Faster file reading - Heavily optimized `file:readString()` --- .../src/main/java/org/figuramc/figura/lua/api/FileAPI.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/FileAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/FileAPI.java index 3dd64ab34..e7bd23456 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/FileAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/FileAPI.java @@ -173,8 +173,7 @@ public FiguraOutputStream openWriteStream(@LuaNotNil String path) { ) ) public String readString(@LuaNotNil String path, String encoding) { - try (FiguraInputStream fis = openReadStream(path)) { - byte[] data = fis.readAllBytes(); + try { Charset charset = encoding == null ? StandardCharsets.UTF_8 : switch (encoding.toLowerCase(Locale.US)) { case "utf_16", "utf16" -> StandardCharsets.UTF_16; case "utf_16be", "utf16be" -> StandardCharsets.UTF_16BE; @@ -183,6 +182,9 @@ public String readString(@LuaNotNil String path, String encoding) { case "iso_8859_1", "iso88591" -> StandardCharsets.ISO_8859_1; default -> StandardCharsets.UTF_8; }; + Path filePath = securityCheck(path); + File file = filePath.toFile(); + byte[] data = com.google.common.io.Files.toByteArray(file); return new String(data, charset); } catch (IOException e) { throw new LuaError(e); From b8b05c66d8e95c211c532c912ac1944d3c7280db Mon Sep 17 00:00:00 2001 From: Avatcher Date: Mon, 1 Apr 2024 01:41:08 +0200 Subject: [PATCH 10/43] Add `entity:isMoving()` and `entity:isFalling()`` to EntityAPI --- .../figura/lua/api/entity/EntityAPI.java | 18 ++++++++++++++++++ .../resources/assets/figura/lang/en_us.json | 2 ++ 2 files changed, 20 insertions(+) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java index e221fc289..465701a56 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java @@ -14,6 +14,7 @@ import net.minecraft.world.entity.vehicle.ContainerEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.LadderBlock; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; @@ -314,6 +315,23 @@ public boolean isCrouching() { return entity.isCrouching(); } + @LuaWhitelist + @LuaMethodDoc("entity.is_moving") + public boolean isMoving() { + checkEntity(); + return entity.getX() - entity.xOld != 0 + || entity.getY() - entity.yOld != 0 + || entity.getZ() - entity.zOld != 0; + } + + @LuaWhitelist + @LuaMethodDoc("entity.is_falling") + public boolean isFalling() { + checkEntity(); + return !entity.onGround() + && entity.getY() - entity.yOld < 0; + } + @LuaWhitelist @LuaMethodDoc( overloads = @LuaMethodOverload( diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index 6d4300bc6..5bb9bd443 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -976,6 +976,8 @@ "figura.docs.entity.is_silent": "Returns true if this entity is silent", "figura.docs.entity.is_sneaking": "Returns true if this entity is logically sneaking (can't fall from blocks edges, can't see nameplate behind walls, etc)", "figura.docs.entity.is_crouching": "Returns true if this entity is visually sneaking", + "figura.docs.entity.is_moving": "Returns true if this entity has some velocity", + "figura.docs.entity.is_falling": "Returns true if this entity has negative Y-velocity and is not on the ground", "figura.docs.entity.get_item": "Gets an ItemStack for the item in the given slot\nFor the player, slots are indexed with 1 as the main hand, 2 as the off hand, and 3,4,5,6 as the 4 armor slots from the boots to the helmet\nIf an invalid slot number is given, this will return nil", "figura.docs.entity.get_nbt": "Gets a table containing the NBT of this entity\nPlease note that not all values in the entity's NBT may be synced, as some are handled only on the server side", "figura.docs.entity.is_on_fire": "Returns true if this entity is currently on fire", From a2e55fc59cb3593e95080079a86b5531c8aa8a09 Mon Sep 17 00:00:00 2001 From: Avatcher Date: Mon, 1 Apr 2024 01:56:13 +0200 Subject: [PATCH 11/43] Remove unused `LadderBlock` import --- .../main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java index 465701a56..d93e0728b 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java @@ -14,7 +14,6 @@ import net.minecraft.world.entity.vehicle.ContainerEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.LadderBlock; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; From 05bdd5b1f0dd9ae91dfb59c1e31954e5de6115b0 Mon Sep 17 00:00:00 2001 From: Avatcher Date: Mon, 1 Apr 2024 05:47:19 +0200 Subject: [PATCH 12/43] Ignore file changes in hidden folders --- .../avatar/local/LocalAvatarLoader.java | 7 ++-- .../org/figuramc/figura/utils/IOUtils.java | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java b/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java index b768e52fe..2026efe4c 100644 --- a/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java +++ b/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java @@ -15,7 +15,10 @@ import org.figuramc.figura.utils.FiguraText; import org.figuramc.figura.utils.IOUtils; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.nio.file.*; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -310,7 +313,7 @@ public static void tick() { Path path = entry.getKey().resolve((Path) event.context()); String name = IOUtils.getFileNameOrEmpty(path); - if (IOUtils.isHidden(path) || !(Files.isDirectory(path) || name.matches("(.*(\\.lua|\\.bbmodel|\\.ogg|\\.png)$|avatar\\.json)"))) + if (IOUtils.isHiddenAvatarResource(path) || !(Files.isDirectory(path) || name.matches("(.*(\\.lua|\\.bbmodel|\\.ogg|\\.png)$|avatar\\.json)"))) continue; if (kind == StandardWatchEventKinds.ENTRY_CREATE && !IS_WINDOWS) diff --git a/common/src/main/java/org/figuramc/figura/utils/IOUtils.java b/common/src/main/java/org/figuramc/figura/utils/IOUtils.java index b3fce4dbf..c3c7d4a98 100644 --- a/common/src/main/java/org/figuramc/figura/utils/IOUtils.java +++ b/common/src/main/java/org/figuramc/figura/utils/IOUtils.java @@ -3,6 +3,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtIo; import org.figuramc.figura.FiguraMod; +import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.io.InputStream; @@ -166,6 +167,39 @@ public static boolean isHidden(Path path) { return hidden || getFileNameOrEmpty(path).startsWith("."); } + /** + * Checks, if given file is a hidden avatar resource. + * Avatar resource is hidden, if it is contained within + * a hidden folder. Folder is considered "hidden" if either + * it is marked as "hidden" by the OS or folder's name starts + * with a `{@code .}` (dot), or if it is contained within + * another hidden folder. + * + * @param path Path of the file to check + * @return {@code true} if given file is hidden + */ + public static boolean isHiddenAvatarResource(@NotNull Path path) { + final Path avatarsDirectory = FiguraMod.getFiguraDirectory().resolve("avatars/"); + if (!path.toAbsolutePath().startsWith(avatarsDirectory.toAbsolutePath())) { + throw new IllegalArgumentException("A path to a file within avatars folder was expected"); + } + try { + // Iterate through all parent folders of the avatars + // resource to find a hidden one (if any) + for (Path parent = path; + !Files.isSameFile(parent, avatarsDirectory); + parent = parent.resolve("..").normalize()) { + if (Files.isHidden(parent) || parent.getFileName().toString().startsWith(".")) { + return true; + } + } + return false; + } catch (IOException e) { + FiguraMod.LOGGER.error("Failed to get if \"" + path + "\" is hidden", e); + return false; + } + } + public static class DirWrapper { private final Path path; From 47cc3e1ad2b127ad970d28e48da53261918930df Mon Sep 17 00:00:00 2001 From: Super <38338700+superpowers04@users.noreply.github.com> Date: Mon, 15 Apr 2024 19:34:46 -0400 Subject: [PATCH 13/43] client.isIntegratedServer() --- .../src/main/java/org/figuramc/figura/lua/api/ClientAPI.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java index f1618af08..f87dfbc12 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java @@ -482,6 +482,11 @@ public static EntityAPI getCameraEntity() { return EntityAPI.wrap(Minecraft.getInstance().getCameraEntity()); } + @LuaWhitelist + @LuaMethodDoc("client.is_integrated_server") + public static Boolean isIntegratedServer() { + return Minecraft.getInstance().getSingleplayerServer() != null; + } @LuaWhitelist @LuaMethodDoc("client.get_server_data") public static Map getServerData() { From 9414eb179c6204873cdc1e6d05612a0de463eee6 Mon Sep 17 00:00:00 2001 From: Super <38338700+superpowers04@users.noreply.github.com> Date: Tue, 23 Apr 2024 02:21:56 -0400 Subject: [PATCH 14/43] Remove stupid easter egg --- .../main/java/org/figuramc/figura/lua/FiguraLuaPrinter.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/FiguraLuaPrinter.java b/common/src/main/java/org/figuramc/figura/lua/FiguraLuaPrinter.java index cf5092db6..703471c02 100644 --- a/common/src/main/java/org/figuramc/figura/lua/FiguraLuaPrinter.java +++ b/common/src/main/java/org/figuramc/figura/lua/FiguraLuaPrinter.java @@ -73,11 +73,6 @@ public static void sendLuaError(LuaError error, Avatar owner) { .replace("\n\t[Java]: in ?", "") .replace("'' expected", "Expected end of script"); - if (Configs.EASTER_EGGS.value && Math.random() < 0.0001) { - message = message - .replaceFirst("attempt to index ? (a nil value) with key", "attempt to key (a ? value) with index nil") - .replaceFirst("attempt to call a nil value", "attempt to nil a call value"); - } // get script line line: { From b17adace14c40b21d584b6a732aadfa66bdf00a8 Mon Sep 17 00:00:00 2001 From: sky <116099351+skyrina@users.noreply.github.com> Date: Fri, 26 Apr 2024 18:05:50 +0300 Subject: [PATCH 15/43] change avatar file extension --- .../org/figuramc/figura/avatar/local/CacheAvatarLoader.java | 6 +++--- .../org/figuramc/figura/avatar/local/LocalAvatarLoader.java | 2 +- .../java/org/figuramc/figura/commands/ExportCommand.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/avatar/local/CacheAvatarLoader.java b/common/src/main/java/org/figuramc/figura/avatar/local/CacheAvatarLoader.java index ab41ffe0a..7c8de1eb3 100644 --- a/common/src/main/java/org/figuramc/figura/avatar/local/CacheAvatarLoader.java +++ b/common/src/main/java/org/figuramc/figura/avatar/local/CacheAvatarLoader.java @@ -45,7 +45,7 @@ public static void init() { public static boolean checkAndLoad(String hash, UserData target) { Path p = getAvatarCacheDirectory(); - p = p.resolve(hash + ".moon"); + p = p.resolve(hash + ".nbt"); if (Files.exists(p)) { load(hash, target); @@ -57,7 +57,7 @@ public static boolean checkAndLoad(String hash, UserData target) { public static void load(String hash, UserData target) { LocalAvatarLoader.async(() -> { - Path path = getAvatarCacheDirectory().resolve(hash + ".moon"); + Path path = getAvatarCacheDirectory().resolve(hash + ".nbt"); try { target.loadAvatar(NbtIo.readCompressed(Files.newInputStream(path))); FiguraMod.debug("Loaded avatar \"{}\" from cache to \"{}\"", hash, target.id); @@ -69,7 +69,7 @@ public static void load(String hash, UserData target) { public static void save(String hash, CompoundTag nbt) { LocalAvatarLoader.async(() -> { - Path file = getAvatarCacheDirectory().resolve(hash + ".moon"); + Path file = getAvatarCacheDirectory().resolve(hash + ".nbt"); try { NbtIo.writeCompressed(nbt, Files.newOutputStream(file)); FiguraMod.debug("Saved avatar \"{}\" on cache", hash); diff --git a/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java b/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java index b768e52fe..cbbb1bd9b 100644 --- a/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java +++ b/common/src/main/java/org/figuramc/figura/avatar/local/LocalAvatarLoader.java @@ -44,7 +44,7 @@ public class LocalAvatarLoader { CEM_AVATARS.clear(); AvatarManager.clearCEMAvatars(); - for (Map.Entry cem : manager.listResources("cem", location -> location.getNamespace().equals(FiguraMod.MOD_ID) && location.getPath().endsWith(".moon")).entrySet()) { + for (Map.Entry cem : manager.listResources("cem", location -> location.getNamespace().equals(FiguraMod.MOD_ID) && location.getPath().endsWith(".nbt")).entrySet()) { // id ResourceLocation key = cem.getKey(); String[] split = key.getPath().split("/"); diff --git a/common/src/main/java/org/figuramc/figura/commands/ExportCommand.java b/common/src/main/java/org/figuramc/figura/commands/ExportCommand.java index 532ff1209..6deba08af 100644 --- a/common/src/main/java/org/figuramc/figura/commands/ExportCommand.java +++ b/common/src/main/java/org/figuramc/figura/commands/ExportCommand.java @@ -86,7 +86,7 @@ private static int runAvatarExport(CommandContext con if (avatar.nbt == null) throw new Exception(); - NbtIo.writeCompressed(avatar.nbt, FiguraMod.getFiguraDirectory().resolve(filename + ".moon").toFile()); + NbtIo.writeCompressed(avatar.nbt, FiguraMod.getFiguraDirectory().resolve(filename + ".nbt").toFile()); context.getSource().figura$sendFeedback(FiguraText.of("command.export_avatar.success")); return 1; From 86515acecbdcc5d611e0f41a050bd5e9aa7a5fb6 Mon Sep 17 00:00:00 2001 From: TheBunnyMan123 Date: Tue, 30 Apr 2024 21:00:45 -0500 Subject: [PATCH 16/43] writeToLog and warnToLog --- .../figuramc/figura/lua/api/ClientAPI.java | 22 +++++++++++++++++++ .../resources/assets/figura/lang/en_us.json | 2 ++ 2 files changed, 24 insertions(+) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java index f1618af08..78f27a58b 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java @@ -735,6 +735,28 @@ public static List getEnum(@LuaNotNil String enumName) { } } + @LuaWhitelist + @LuaMethodDoc( + overloads = { + @LuaMethodOverload(argumentTypes = String.class, argumentNames = "string"), + }, + value = "client.write_to_log" + ) + public static void writeToLog(@LuaNotNil String string) { + FiguraMod.LOGGER.info("[FIGURA] -- " + string); + } + + @LuaWhitelist + @LuaMethodDoc( + overloads = { + @LuaMethodOverload(argumentTypes = String.class, argumentNames = "string"), + }, + value = "client.warn_to_log" + ) + public static void warnToLog(@LuaNotNil String string) { + FiguraMod.LOGGER.warn("[FIGURA] -- " + string); + } + @Override public String toString() { return "ClientAPI"; diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index 6d4300bc6..5604fcc04 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -939,6 +939,8 @@ "figura.docs.client.list_atlases": "Returns a list of all registered atlases paths", "figura.docs.client.get_atlas": "Returns a TextureAtlasAPI object with information about the given atlas\nReturns nil if the atlas was not found", "figura.docs.client.get_enum": "Return an array containing the entries in the given enum\nEnums can be found in /figura docs enums", + "figura.docs.client.write_to_log": "Write directly to the minecraft log, allowing for\nlogging debug data without filling chat", + "figura.docs.client.warn_to_log": "Write a warning directly to the minecraft log,\nallowing forlogging debug data without filling chat", "figura.docs.client.get_tab_list": "Returns a table with the text shown in the tablist", "figura.docs.client.get_translated_string": "Returns the translated string of the given key\nTranslation is done using the current client language\nOptionally takes a single argument, or a list with all arguments, that will populate the translation", "figura.docs.config": "A global API used to save and load avatar data between game sessions", From d7d67edab75b97826f97cc79344d3b24e23a92b3 Mon Sep 17 00:00:00 2001 From: TheBunnyMan123 Date: Tue, 30 Apr 2024 21:08:27 -0500 Subject: [PATCH 17/43] move to host to prevent log filling --- .../figuramc/figura/lua/api/ClientAPI.java | 22 ------------------- .../org/figuramc/figura/lua/api/HostAPI.java | 22 +++++++++++++++++++ .../resources/assets/figura/lang/en_us.json | 4 ++-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java index 78f27a58b..f1618af08 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java @@ -735,28 +735,6 @@ public static List getEnum(@LuaNotNil String enumName) { } } - @LuaWhitelist - @LuaMethodDoc( - overloads = { - @LuaMethodOverload(argumentTypes = String.class, argumentNames = "string"), - }, - value = "client.write_to_log" - ) - public static void writeToLog(@LuaNotNil String string) { - FiguraMod.LOGGER.info("[FIGURA] -- " + string); - } - - @LuaWhitelist - @LuaMethodDoc( - overloads = { - @LuaMethodOverload(argumentTypes = String.class, argumentNames = "string"), - }, - value = "client.warn_to_log" - ) - public static void warnToLog(@LuaNotNil String string) { - FiguraMod.LOGGER.warn("[FIGURA] -- " + string); - } - @Override public String toString() { return "ClientAPI"; diff --git a/common/src/main/java/org/figuramc/figura/lua/api/HostAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/HostAPI.java index 05bffe506..fc4ff894d 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/HostAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/HostAPI.java @@ -620,6 +620,28 @@ public boolean isChatVerified() { return playerInfo != null && playerInfo.hasVerifiableChat(); } + @LuaWhitelist + @LuaMethodDoc( + overloads = { + @LuaMethodOverload(argumentTypes = String.class, argumentNames = "string"), + }, + value = "host.write_to_log" + ) + public static void writeToLog(@LuaNotNil String string) { + FiguraMod.LOGGER.info("[FIGURA/LUA] -- " + string); + } + + @LuaWhitelist + @LuaMethodDoc( + overloads = { + @LuaMethodOverload(argumentTypes = String.class, argumentNames = "string"), + }, + value = "host.warn_to_log" + ) + public static void warnToLog(@LuaNotNil String string) { + FiguraMod.LOGGER.warn("[FIGURA/LUA] -- " + string); + } + public Object __index(String arg) { if ("unlockCursor".equals(arg)) return unlockCursor; diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index 5604fcc04..8bec6cbc7 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -939,8 +939,6 @@ "figura.docs.client.list_atlases": "Returns a list of all registered atlases paths", "figura.docs.client.get_atlas": "Returns a TextureAtlasAPI object with information about the given atlas\nReturns nil if the atlas was not found", "figura.docs.client.get_enum": "Return an array containing the entries in the given enum\nEnums can be found in /figura docs enums", - "figura.docs.client.write_to_log": "Write directly to the minecraft log, allowing for\nlogging debug data without filling chat", - "figura.docs.client.warn_to_log": "Write a warning directly to the minecraft log,\nallowing forlogging debug data without filling chat", "figura.docs.client.get_tab_list": "Returns a table with the text shown in the tablist", "figura.docs.client.get_translated_string": "Returns the translated string of the given key\nTranslation is done using the current client language\nOptionally takes a single argument, or a list with all arguments, that will populate the translation", "figura.docs.config": "A global API used to save and load avatar data between game sessions", @@ -1065,6 +1063,8 @@ "figura.docs.event.remove": "Removes either a function from this event or when given a string, remove all functions registered under that name\nReturns the number of functions that were removed", "figura.docs.event.get_registered_count": "Returns the number of functions that are registered with the given name", "figura.docs.host": "A global API dedicated to specifically the host of the avatar\nFor other viewers, these do nothing", + "figura.docs.host.write_to_log": "Write directly to the minecraft log, allowing for\nlogging debug data without filling chat", + "figura.docs.host.warn_to_log": "Write a warning directly to the minecraft log,\nallowing forlogging debug data without filling chat", "figura.docs.host.unlock_cursor": "Setting this value to true will unlock your cursor, letting you move it freely on the screen instead of it controlling your player's rotation", "figura.docs.host.is_host": "Returns true if this instance of the script is running on host", "figura.docs.host.is_cursor_unlocked": "Checks if the cursor is currently unlocked\nOnly responds to your own changes in your script, not anything done by Minecraft itself", From f115019c0b4675e8ddf693db1a956f4e18b39655 Mon Sep 17 00:00:00 2001 From: TheBunnyMan123 Date: Tue, 30 Apr 2024 21:10:12 -0500 Subject: [PATCH 18/43] add host check because I forgor :skull: --- .../src/main/java/org/figuramc/figura/lua/api/HostAPI.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/HostAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/HostAPI.java index fc4ff894d..39ebf16af 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/HostAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/HostAPI.java @@ -627,7 +627,8 @@ public boolean isChatVerified() { }, value = "host.write_to_log" ) - public static void writeToLog(@LuaNotNil String string) { + public void writeToLog(@LuaNotNil String string) { + if (!isHost()) return; FiguraMod.LOGGER.info("[FIGURA/LUA] -- " + string); } @@ -638,7 +639,8 @@ public static void writeToLog(@LuaNotNil String string) { }, value = "host.warn_to_log" ) - public static void warnToLog(@LuaNotNil String string) { + public void warnToLog(@LuaNotNil String string) { + if (!isHost()) return; FiguraMod.LOGGER.warn("[FIGURA/LUA] -- " + string); } From 8a0e08969284a1a900284e0894f370f5ecc48ce3 Mon Sep 17 00:00:00 2001 From: Super <38338700+superpowers04@users.noreply.github.com> Date: Sat, 11 May 2024 21:02:02 -0400 Subject: [PATCH 19/43] Update BlockbenchModelParser.java --- .../figura/parsers/BlockbenchModelParser.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/parsers/BlockbenchModelParser.java b/common/src/main/java/org/figuramc/figura/parsers/BlockbenchModelParser.java index 93917451c..e97c5c7f1 100644 --- a/common/src/main/java/org/figuramc/figura/parsers/BlockbenchModelParser.java +++ b/common/src/main/java/org/figuramc/figura/parsers/BlockbenchModelParser.java @@ -272,11 +272,17 @@ private CompoundTag parseCubeFaces(JsonObject faces) { continue; //convert face json to java object - BlockbenchModel.CubeFace face = GSON.fromJson(faces.getAsJsonObject(cubeFace), BlockbenchModel.CubeFace.class); - + JsonObject faceObj = faces.getAsJsonObject(cubeFace); //dont add null faces - if (face.texture == null) + if (!faceObj.has("texture")) continue; + try{ + faceObj.get("texture").getAsNumber(); + }catch(Exception e){ + continue; + } + BlockbenchModel.CubeFace face = GSON.fromJson(faceObj, BlockbenchModel.CubeFace.class); + //parse texture TextureData texture = textureMap.get(textureIdMap.get(face.texture)); From 607e4f33a425313fc59b80d1bc5820b79dd27b49 Mon Sep 17 00:00:00 2001 From: JimmyHelp <103872776+JimmyHelp@users.noreply.github.com> Date: Tue, 14 May 2024 18:37:06 -0500 Subject: [PATCH 20/43] animations --- .../org/figuramc/figura/animation/Animation.java | 15 +++++++++++++-- .../figuramc/figura/lua/api/AnimationAPI.java | 16 +++++++++++++--- .../main/resources/assets/figura/lang/en_us.json | 9 +++++---- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/animation/Animation.java b/common/src/main/java/org/figuramc/figura/animation/Animation.java index 4de083a70..895571eee 100644 --- a/common/src/main/java/org/figuramc/figura/animation/Animation.java +++ b/common/src/main/java/org/figuramc/figura/animation/Animation.java @@ -101,7 +101,11 @@ public void tick() { else if (inverted && time < offset - loopDelay) time += length + loopDelay - offset; } - case HOLD -> time = inverted ? Math.max(time, offset) : Math.min(time, length); + case HOLD -> { + time = inverted ? Math.max(time, offset) : Math.min(time, length); + if (time == length) + playState = PlayState.HOLDING; + } } this.lastTime = this.frameTime; @@ -158,6 +162,12 @@ public boolean isStopped() { return this.playState == PlayState.STOPPED; } + @LuaWhitelist + @LuaMethodDoc("animation.is_holding") + public boolean isHolding() { + return this.playState == PlayState.HOLDING; + } + @LuaWhitelist @LuaMethodDoc("animation.play") public Animation play() { @@ -598,7 +608,8 @@ public String toString() { public enum PlayState { STOPPED, PAUSED, - PLAYING + PLAYING, + HOLDING } public enum LoopMode { diff --git a/common/src/main/java/org/figuramc/figura/lua/api/AnimationAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/AnimationAPI.java index 9955aa83a..a900b0b82 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/AnimationAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/AnimationAPI.java @@ -4,6 +4,7 @@ import org.figuramc.figura.avatar.Avatar; import org.figuramc.figura.lua.LuaWhitelist; import org.figuramc.figura.lua.docs.LuaMethodDoc; +import org.figuramc.figura.lua.docs.LuaMethodOverload; import org.figuramc.figura.lua.docs.LuaTypeDoc; import java.util.ArrayList; @@ -51,11 +52,20 @@ public List getAnimations() { } @LuaWhitelist - @LuaMethodDoc("animations.get_playing") - public List getPlaying() { + @LuaMethodDoc( + overloads = { + @LuaMethodOverload, + @LuaMethodOverload( + argumentTypes = Boolean.class, + argumentNames = "hold" + ) + }, + value = "animations.get_playing" + ) + public List getPlaying(boolean hold) { List list = new ArrayList<>(); for (Animation animation : avatar.animations.values()) - if (animation.playState == Animation.PlayState.PLAYING) + if (hold ? (animation.playState == Animation.PlayState.PLAYING || animation.playState == Animation.PlayState.HOLDING) : (animation.playState == Animation.PlayState.PLAYING)) list.add(animation); return list; } diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index 6d4300bc6..dbc0b58cc 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -741,13 +741,14 @@ "figura.docs.wheel_action.set_toggled": "Sets the toggle state of the Action", "figura.docs.animations": "A global API used for control of Blockbench Animations", "figura.docs.animations.get_animations": "Returns a table with all animations", - "figura.docs.animations.get_playing": "Return a table with all playing animations", + "figura.docs.animations.get_playing": "Return a table with all playing animations\nIf true is passed in for hold animations in the HOLDING play state will be included", "figura.docs.animations.stop_all": "Stops all playing (and paused) animations", "figura.docs.animation": "A Blockbench animation", "figura.docs.animation.name": "This animation's name", - "figura.docs.animation.animation.is_playing": "Checks if this animation is being played", - "figura.docs.animation.animation.is_paused": "Checks if this animation is paused", - "figura.docs.animation.animation.is_stopped": "Checks if this animation is stopped", + "figura.docs.animation.is_playing": "Checks if this animation is being played", + "figura.docs.animation.is_paused": "Checks if this animation is paused", + "figura.docs.animation.is_stopped": "Checks if this animation is stopped", + "figura.docs.animation.is_holding": "Checks if this animation is holding on its last frame", "figura.docs.animation.play": "Initializes the animation\nResume the animation if it was paused", "figura.docs.animation.pause": "Pause the animation's playback", "figura.docs.animation.stop": "Stop the animation", From aa70f0931a41e48a9ccd7cf0a66a45704ffb4b28 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Mon, 20 May 2024 16:46:35 -0600 Subject: [PATCH 21/43] Added issue templates --- .github/ISSUE_TEMPLATE/bug_report.yml | 58 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 7 +++ .github/ISSUE_TEMPLATE/feature_request.yml | 26 ++++++++++ 3 files changed, 91 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 000000000..18bbd9a8e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,58 @@ +name: Bug Report +description: "For reporting bugs and other defects" +labels: + - bug +body: + - type: markdown + attributes: + value: >- + **Note: This issue tracker is not intended for support requests!** If you need help with crashes or other issues, then + you should [ask on our Discord server](https://discord.figuramc.org/) instead. +

+ Additionally, please make sure you have done the following: + + - **Have you ensured that all of your mods are up-to-date?** The latest version of Figura + can always be found [on Modrinth](https://modrinth.com/mod/figura) or [on CurseForge](https://curseforge.com/minecraft/mc-mods/figura). + + - **Have you used the [search tool](https://github.com/FiguraMC/Figura/issues) to check whether your issue + has already been reported?** If it has been, then consider adding more information to the existing issue instead. + + - **Have you determined the minimum set of instructions to reproduce the issue?** If your problem only occurs + with other mods installed, then you should narrow down exactly which mods are causing the issue. Please do not + provide your entire list of mods to us and expect that we will be able to figure out the problem. +
+ + This issue template was based [off of Sodium's](https://github.com/CaffeineMC/sodium-fabric/blob/dev/.github/ISSUE_TEMPLATE/bug_report.yml) + - type: textarea + id: description + attributes: + label: Bug Description + description: >- + Use this section to describe the issue you are experiencing in as much depth as possible. The description should + explain what behavior you were expecting, and why you believe the issue to be a bug. If the issue you are reporting + only occurs with specific mods installed, then provide the name and version of each mod. + + **Hint:** If you have any screenshots, videos, or other information that you feel is necessary to + explain the issue, you can attach them here. + - type: textarea + id: description-reproduction-steps + attributes: + label: Reproduction Steps + description: >- + Provide as much information as possible on how to reproduce this bug. Make sure your instructions are as clear and + concise as possible, because other people will need to be able to follow your guide in order to re-create the issue. + + **Hint:** A common way to fill this section out is to write a step-by-step guide. + validations: + required: true + - type: textarea + id: log-file + attributes: + label: Log File + description: >- + **Hint:** You can usually find the log files within the folder `.minecraft/logs`. Most often, you will want the `latest.log` + file, since that file belongs to the last played session of the game. + placeholder: >- + Drag-and-drop the log file here. + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000..621a3c047 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,7 @@ +blank_issues_enabled: true +contact_links: + - name: For help with other issues, join the Discord community + url: https://discord.figuramc.org/ + about: This is the best option for getting help with mod installation, performance issues, and any other support inquiries + # Copied from https://github.com/CaffeineMC/sodium-fabric#community + # Copied from https://github.com/CaffeineMC/sodium-fabric/blob/dev/.github/ISSUE_TEMPLATE/config.yml \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 000000000..8728fd571 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,26 @@ +name: Feature Request +description: "For requesting new features or improvements" +labels: + - enhancement +body: + - type: markdown + attributes: + value: >- + This form is for requesting new features or improvements, and should not be used for bug reports or other issues. + - type: markdown + attributes: + value: >- + Make sure you have used the [search tool](https://github.com/FiguraMC/Figura/issues) to see if a similar + request already exists. If we have previously closed a feature request, then please do not create another request. + - type: markdown + attributes: + value: >- + This template was based [off of Sodium's](https://github.com/CaffeineMC/sodium-fabric/blob/dev/.github/ISSUE_TEMPLATE/feature_request.yml) + - type: textarea + id: description + attributes: + label: Request Description + description: >- + Use this section to describe the feature or improvement that you are looking for. The description should explain + what you would like to see added, and a clear and concise description + of what you would like changed. \ No newline at end of file From 82e99290f3b96ba1f34417e3f2e07cbd9d427a39 Mon Sep 17 00:00:00 2001 From: TheBunnyMan123 Date: Tue, 21 May 2024 12:17:59 -0500 Subject: [PATCH 22/43] Fix typo --- common/src/main/resources/assets/figura/lang/en_us.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index f438df9db..d7bbefb60 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -1068,7 +1068,7 @@ "figura.docs.event.get_registered_count": "Returns the number of functions that are registered with the given name", "figura.docs.host": "A global API dedicated to specifically the host of the avatar\nFor other viewers, these do nothing", "figura.docs.host.write_to_log": "Write directly to the minecraft log, allowing for\nlogging debug data without filling chat", - "figura.docs.host.warn_to_log": "Write a warning directly to the minecraft log,\nallowing forlogging debug data without filling chat", + "figura.docs.host.warn_to_log": "Write a warning directly to the minecraft log,\nallowing for logging debug data without filling chat", "figura.docs.host.unlock_cursor": "Setting this value to true will unlock your cursor, letting you move it freely on the screen instead of it controlling your player's rotation", "figura.docs.host.is_host": "Returns true if this instance of the script is running on host", "figura.docs.host.is_cursor_unlocked": "Checks if the cursor is currently unlocked\nOnly responds to your own changes in your script, not anything done by Minecraft itself", From 620ecea7b2e90257c94529686bb6044ecd777137 Mon Sep 17 00:00:00 2001 From: ItsToastCraft Date: Thu, 23 May 2024 15:27:45 -0400 Subject: [PATCH 23/43] Removed random green pixels ARE THEY HERE WHO LET THIS HAPPEN WHO APPROVED THIS HOW DO YOU GET GREEN???? THIS WASN'T PART OF THE CERTIFIED FIGURAMC PALETTE? ARE THESE HERE ON PURPOSE??? DO THEY SERVE A PURPOSE? I am in pain :sob: --- .../assets/figura/textures/gui/help_icons.png | Bin 3836 -> 3717 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/common/src/main/resources/assets/figura/textures/gui/help_icons.png b/common/src/main/resources/assets/figura/textures/gui/help_icons.png index 73dd3cdcba0ba18e37ecce7a2f0cd36171bab57d..2f91032c308c4aa780f3ae8991234f202967cdd0 100644 GIT binary patch delta 1074 zcmV-21kL;W9fci`Be63>3V#F%Nkl zj6Ci_P6kgF05X{jX7^8N7}9gQi^4M___C`@Eq^p4JjYnag)9J2S^%Yms?IyYjXO_z zb+jL=qy4VxM$GLl;(zYjNoV~QdB8@N?-K&*N>uhPLliH6-uhnakG^>9ECZ^9<#28W z7}=GPzS`KzNFSy)51?8I6I4W8WI#2f8CjEetMWkKW&>P#m-Us$grw6<#8iWP=*l3Z zC=h2T7VX5BhkH?}RD`xX+#6=T0ItH8wJG%t?mm3z+Dll*J zzl0QxQJ})oP*1?StSt@ognCy!5JH;IxN=68^a3`jkRIDQs(IJWti8GmV+tPB=PlR zRfJr?Er>RxT~7i+2vV^G&MTLol#=R%X;iWdY>{hOIx1Ng+c3u-rBv9@QBn13?U^l@ z_E;Ls?|)!0zvDc9ow%5sz{TW*_L+ygeUya9r;pLzkwbe&P9Qg!-%*Y?1G;0(L{uiN z%JSC2qrD?%?cXFQ3G;i>rQZzb_Hpaly4FUPsg5%3IjkcTg($iDV(+XAm@Bi^we>*w z>J~!I?$=gJ>k1B8ClyN=$ujT+Rb)$LUm(l=Uw`XiTT=S+>4{dBiX~7g`$E-pUb!@S z+GRmxn8I82?o!z&HNu1W9f1Vv%axQWq*?ZsA(xA$uvS%I^*~Y0iKQif)R?@-gXyct z^4@gazb4Y@c+$DF>P6E&@igi>_aAlQ51is9rq=)F-T(jq07*qoM6N<$f+t}SOaK4? delta 1193 zcmV;a1XlZn9sC`TBMtxrXF*Lt006O%3;baPu^~kYe*hq3NK#Dz0D2|>0Dy!50Qvv` z0D$NK0Cg|`0P0`>06Lfe02gqax=}m;000SaNLh0L01m$Z01m$aI0aKA0000RbVXQn zQ*UN;cVTj607GSLb9r+hQ*?D?X>TA@Z*OeDr{R1600ZtxL_t(&f#sP^NK{c2$NyJx zNYKWGe=Y=FDVR7>RMaAZNF>8P1Vspfl8G{C)xvf|xXVSWAPdEUAP@!n7%IdNq=ivY zq?Dj51sA$-R4_*Lw&&6asc}UVyue;0O#g?IwqDm0Q8(H$@z=Ze`Yw-zyczPU~WF0IwqERG#Ui}q*5tg z(A}|^BiPQ#N#>_b23XFl3?qy41oI0l!jk+zcgJG9^Yc@??euK`z@_qX06^{F1BYJ; zEXoa*^8~fQJ)XiN7A3oJc3(7~003Mc{u&w>0EUy}sOcXC5CGT&R%mOycE#+9z<_y{ ze+hUvIi9gKH=VHoPq)|Gd`e((I%f;`{-6JE_W70LHv5g&-v9s)4>4n4S%EX`wQd3X zloo8pYq$UMF`KXb&36E1SQ{ZP8e-7)K003^i|CM`Sf)>}QxKU|7Yp#LF%+1Yt0?P`O zVZa>P3%0bh6oB(6(ut0!rKKe$^o{}txmwb*ZaNb%sj#pRkx0a5OQ+LVUthP`f82m| z@zB-s?ZSe?=b2$qK?(%Y$tRxz7299#obz2p{cdRBwId^*{X&(8yRkNQ&G26Q5x{dw z?=|gT;I{Z;DDr{6GTRhqjM>I3$}7L&M9?ye{p^!RE#v119+gX%+a_lzUb+*{GPyo6PjSHz7Al5 z72Ej{ec$S4n%RI=KqeAih!L=x2zYI41Dx{=a8OthL1%!2!jjtJi&|j6Cjqm5?Fj=c zWYuQV0ynmd0RTP>oi(!O68P`6s{nulFJCD?6C8>9YJtUdxw1T!fop6Tf5X9&I)^SmgWeT{&D?X|75lW*4oi*SDIxt`Lp0#E56as#%4HyVdv zbr~kf&?2nW2Y`=F%S-c^M+GV}pS^%B0M{`U=d Date: Fri, 24 May 2024 13:47:59 -0600 Subject: [PATCH 24/43] Fix Legacy 4J compatibility --- .../figuramc/figura/mixin/gui/books/BookViewScreenMixin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/org/figuramc/figura/mixin/gui/books/BookViewScreenMixin.java b/common/src/main/java/org/figuramc/figura/mixin/gui/books/BookViewScreenMixin.java index 01e5b44e4..c5eaa9edf 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/gui/books/BookViewScreenMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/gui/books/BookViewScreenMixin.java @@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(BookViewScreen.class) +@Mixin(value = BookViewScreen.class, priority = 1100) public class BookViewScreenMixin { @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;drawString(Lnet/minecraft/client/gui/Font;Lnet/minecraft/util/FormattedCharSequence;IIIZ)I")) public int render(GuiGraphics graphics, Font font, FormattedCharSequence formattedCharSequence, int x, int y, int color, boolean shadowed) { From 1399de171d69cfee333c36cd00babfb09893bb16 Mon Sep 17 00:00:00 2001 From: Super <38338700+superpowers04@users.noreply.github.com> Date: Fri, 24 May 2024 23:48:25 -0400 Subject: [PATCH 25/43] Remove useless subtraction from isMoving and isFalling --- .../org/figuramc/figura/lua/api/entity/EntityAPI.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java index 2987a2c0e..a2a820c8a 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/entity/EntityAPI.java @@ -318,17 +318,16 @@ public boolean isCrouching() { @LuaMethodDoc("entity.is_moving") public boolean isMoving() { checkEntity(); - return entity.getX() - entity.xOld != 0 - || entity.getY() - entity.yOld != 0 - || entity.getZ() - entity.zOld != 0; + return entity.getX() != entity.xOld + || entity.getY() != entity.yOld + || entity.getZ() != entity.zOld; } @LuaWhitelist @LuaMethodDoc("entity.is_falling") public boolean isFalling() { checkEntity(); - return !entity.onGround() - && entity.getY() - entity.yOld < 0; + return !entity.onGround() && entity.getY() < entity.yOld; } @LuaWhitelist From 71410715859e11ce19f24caebca4388e9c922b28 Mon Sep 17 00:00:00 2001 From: Lexize Date: Tue, 18 Jun 2024 06:39:40 +0500 Subject: [PATCH 26/43] Quick fix of FileAPI so it always uses actual path --- .../org/figuramc/figura/lua/api/FileAPI.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/FileAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/FileAPI.java index e7bd23456..08dfd2a46 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/FileAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/FileAPI.java @@ -25,8 +25,6 @@ @LuaTypeDoc(name = "FileAPI", value = "file") public class FileAPI { private final Avatar parent; - private static final Path rootFolderPath = FiguraMod.getFiguraDirectory().resolve("data").toAbsolutePath() - .normalize(); private static final String WRITE_NOT_ALLOWED = "You are only allowed to write in the data folder! Anything else is read only!"; public FileAPI(Avatar parent) { @@ -41,10 +39,15 @@ private Path securityCheck(String path) { return p; } + private static Path dataPath() { + return FiguraMod.getFiguraDirectory().resolve("data").toAbsolutePath() + .normalize(); + } + private Path relativizePath(String path) { Path p = Path.of(path); if (p.isAbsolute()) return p.normalize(); - return rootFolderPath.resolve(path).toAbsolutePath().normalize(); + return dataPath().resolve(path).toAbsolutePath().normalize(); } @LuaWhitelist @@ -61,7 +64,7 @@ public boolean isPathAllowed(@LuaNotNil String path) { } public boolean isPathAllowed(Path path) { - return !Files.isSymbolicLink(path) && path.toAbsolutePath().startsWith(rootFolderPath); + return !Files.isSymbolicLink(path) && path.toAbsolutePath().startsWith(dataPath()); } @LuaWhitelist @@ -152,7 +155,7 @@ public FiguraInputStream openReadStream(@LuaNotNil String path) { public FiguraOutputStream openWriteStream(@LuaNotNil String path) { try { Path p = securityCheck(path); - if (!p.startsWith(rootFolderPath)) { + if (!p.startsWith(dataPath())) { throw new LuaError(WRITE_NOT_ALLOWED); } File f = p.toFile(); @@ -226,7 +229,7 @@ public void writeString(@LuaNotNil String path, @LuaNotNil String data, String e ) public boolean mkdir(@LuaNotNil String path) { Path p = securityCheck(path); - if (!p.startsWith(rootFolderPath)) { + if (!p.startsWith(dataPath())) { throw new LuaError(WRITE_NOT_ALLOWED); } File f = p.toFile(); @@ -244,7 +247,7 @@ public boolean mkdir(@LuaNotNil String path) { ) public boolean mkdirs(@LuaNotNil String path) { Path p = securityCheck(path); - if (!p.startsWith(rootFolderPath)) { + if (!p.startsWith(dataPath())) { throw new LuaError(WRITE_NOT_ALLOWED); } File f = p.toFile(); @@ -262,7 +265,7 @@ public boolean mkdirs(@LuaNotNil String path) { ) public boolean delete(@LuaNotNil String path) { Path p = securityCheck(path); - if (!p.startsWith(rootFolderPath)) { + if (!p.startsWith(dataPath())) { throw new LuaError(WRITE_NOT_ALLOWED); } File f = p.toFile(); From 4207e873aa1fa6ad2a7475f81a1ad0068f1f6a4b Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Fri, 21 Jun 2024 19:58:22 -0600 Subject: [PATCH 27/43] Fixed getShaderPack to work with Iris 1.7+ --- build.gradle | 4 +--- .../java/org/figuramc/figura/lua/api/ClientAPI.java | 13 +++++++++++-- gradle.properties | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 98c5ef503..71c1ce27d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.2-SNAPSHOT" apply false - id "io.github.juuxel.loom-vineflower" version "1.+" apply false + id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false } architectury { @@ -10,7 +9,6 @@ architectury { subprojects { apply plugin: "dev.architectury.loom" - apply plugin: "io.github.juuxel.loom-vineflower" loom { silentMojangMappingsLicense() diff --git a/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java index f87dfbc12..5a716cd69 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java @@ -42,6 +42,8 @@ import org.luaj.vm2.LuaValue; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.*; import java.util.function.Supplier; @@ -367,14 +369,21 @@ public static boolean hasShaderPack() { public static String getShaderPackName() { try { if (HAS_IRIS) { - return net.coderbot.iris.Iris.getCurrentPackName(); + Method shaderNameField = Class.forName("net.coderbot.iris.Iris").getMethod("getCurrentPackName"); + shaderNameField.setAccessible(true); + return shaderNameField.invoke(null).toString(); } else if (OPTIFINE_LOADED.get()) { Field shaderNameField = Class.forName("net.optifine.shaders.Shaders").getField("currentShaderName"); Class shaderClass = shaderNameField.getType(); if (shaderClass == String.class) return (String) shaderNameField.get(null); } - }catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) { + } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | + InvocationTargetException | NoSuchMethodException ignored) { + try { + return net.irisshaders.iris.Iris.getCurrentPackName(); + }catch (Exception ignored1) { + } } return ""; } diff --git a/gradle.properties b/gradle.properties index 6b1ab79ae..a0d8fc0b5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,7 +33,7 @@ fabric_loader_version = 0.14.22 # https://modrinth.com/mod/geckolib # https://github.com/bernie-g/geckolib/blob/1.20.1/gradle.properties modmenu = 7.2.1 -iris = 1.6.4+1.20 +iris = 1.7.1+1.20.1 immediately_fast = 1.2.0+1.20.1 geckolib_version = 1.20.1:4.4 mclib_version=20 From d410ca6a949639f668937b2c6a8d513cd0b94707 Mon Sep 17 00:00:00 2001 From: soup587 Date: Fri, 28 Jun 2024 19:39:11 +0100 Subject: [PATCH 28/43] damage event!! --- .../java/org/figuramc/figura/avatar/Avatar.java | 4 ++++ .../figuramc/figura/lua/api/event/EventsAPI.java | 4 ++++ .../figuramc/figura/mixin/LivingEntityMixin.java | 16 ++++++++++++++++ .../main/resources/assets/figura/lang/en_us.json | 1 + 4 files changed, 25 insertions(+) diff --git a/common/src/main/java/org/figuramc/figura/avatar/Avatar.java b/common/src/main/java/org/figuramc/figura/avatar/Avatar.java index 6a2855545..30d520cb6 100644 --- a/common/src/main/java/org/figuramc/figura/avatar/Avatar.java +++ b/common/src/main/java/org/figuramc/figura/avatar/Avatar.java @@ -430,6 +430,10 @@ public void resourceReloadEvent() { if (loaded) run("RESOURCE_RELOAD", tick); } + public void damageEvent(String sourceType, EntityAPI sourceCause, EntityAPI sourceDirect, FiguraVec3 sourcePosition) { + if (loaded) run("DAMAGE", tick, sourceType, sourceCause, sourceDirect, sourcePosition); + } + // -- host only events -- // public String chatSendMessageEvent(String message) { // piped event diff --git a/common/src/main/java/org/figuramc/figura/lua/api/event/EventsAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/event/EventsAPI.java index f5594cb3f..175d15af4 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/event/EventsAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/event/EventsAPI.java @@ -87,6 +87,9 @@ public class EventsAPI { @LuaWhitelist @LuaFieldDoc("events.resource_reload") public final LuaEvent RESOURCE_RELOAD = new LuaEvent(); + @LuaWhitelist + @LuaFieldDoc("events.damage") + public final LuaEvent DAMAGE = new LuaEvent(); private final Map events = new HashMap<>(); @@ -112,6 +115,7 @@ public EventsAPI() { events.put("ITEM_RENDER", ITEM_RENDER); events.put("ON_PLAY_SOUND", ON_PLAY_SOUND); events.put("RESOURCE_RELOAD", RESOURCE_RELOAD); + events.put("DAMAGE", DAMAGE); for (FiguraEvent entrypoint : ENTRYPOINTS) { String ID = entrypoint.getID().toUpperCase(Locale.US); diff --git a/common/src/main/java/org/figuramc/figura/mixin/LivingEntityMixin.java b/common/src/main/java/org/figuramc/figura/mixin/LivingEntityMixin.java index 3b0a14090..2f296b68d 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/LivingEntityMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/LivingEntityMixin.java @@ -1,5 +1,6 @@ package org.figuramc.figura.mixin; +import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -7,7 +8,9 @@ import net.minecraft.world.level.Level; import org.figuramc.figura.avatar.Avatar; import org.figuramc.figura.avatar.AvatarManager; +import org.figuramc.figura.lua.api.entity.EntityAPI; import org.figuramc.figura.lua.api.world.ItemStackAPI; +import org.figuramc.figura.math.vector.FiguraVec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -26,4 +29,17 @@ private void triggerItemUseEffects(ItemStack stack, int particleCount, CallbackI if (avatar != null && avatar.useItemEvent(ItemStackAPI.verify(stack), stack.getUseAnimation().name(), particleCount)) ci.cancel(); } + + @Inject(at = @At("TAIL"), method = "handleDamageEvent") + private void handleDamageEvent(DamageSource source, CallbackInfo ci) { + //Avatar avatar = AvatarManager.getAvatarForPlayer(FiguraMod.getLocalPlayerUUID()); + Avatar avatar = AvatarManager.getAvatar(this); + if (avatar == null) return; + avatar.damageEvent( + source.typeHolder().unwrapKey().get().location().toString(), + EntityAPI.wrap(source.getEntity()), + EntityAPI.wrap(source.getDirectEntity()), + source.getSourcePosition() != null ? FiguraVec3.fromVec3(source.getSourcePosition()) : null + ); + } } diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index d7bbefb60..3f963913f 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -1060,6 +1060,7 @@ "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", + "figura.docs.events.damage": "Called every time you take damage\nTakes four arguments, the damage type as a string, the entity that dealt the damage, the attacking entity, and the damage position\nThe last three arguments may return nil if there is no direct damage source", "figura.docs.events.get_events": "Returns a table with all events types", "figura.docs.event": "A hook for a certain event in Minecraft\nYou may register functions to one, and those functions will be called when the event occurs", "figura.docs.event.register": "Register a function on this event\nFunctions are run in registration order\nAn optional string argument can be given, grouping functions under that name, for an easier management later on", From fd20341e32978b7318d409ce6d4f4768fc0469d6 Mon Sep 17 00:00:00 2001 From: soup587 Date: Fri, 28 Jun 2024 21:13:27 +0100 Subject: [PATCH 29/43] Update en_us (Replace comma with colon, thanks Riftlight) --- common/src/main/resources/assets/figura/lang/en_us.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index 3f963913f..9569dc36a 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -1060,7 +1060,7 @@ "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", - "figura.docs.events.damage": "Called every time you take damage\nTakes four arguments, the damage type as a string, the entity that dealt the damage, the attacking entity, and the damage position\nThe last three arguments may return nil if there is no direct damage source", + "figura.docs.events.damage": "Called every time you take damage\nTakes four arguments: the damage type as a string, the entity that dealt the damage, the attacking entity, and the damage position\\nThe last three arguments may return nil if there is no direct damage source", "figura.docs.events.get_events": "Returns a table with all events types", "figura.docs.event": "A hook for a certain event in Minecraft\nYou may register functions to one, and those functions will be called when the event occurs", "figura.docs.event.register": "Register a function on this event\nFunctions are run in registration order\nAn optional string argument can be given, grouping functions under that name, for an easier management later on", From cedabfddbebe224c8f1f08d1da0efa7dd78f336c Mon Sep 17 00:00:00 2001 From: soup587 Date: Fri, 28 Jun 2024 22:12:51 +0100 Subject: [PATCH 30/43] Remove commented out code --- .../main/java/org/figuramc/figura/mixin/LivingEntityMixin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/main/java/org/figuramc/figura/mixin/LivingEntityMixin.java b/common/src/main/java/org/figuramc/figura/mixin/LivingEntityMixin.java index 2f296b68d..98f58ef09 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/LivingEntityMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/LivingEntityMixin.java @@ -32,7 +32,6 @@ private void triggerItemUseEffects(ItemStack stack, int particleCount, CallbackI @Inject(at = @At("TAIL"), method = "handleDamageEvent") private void handleDamageEvent(DamageSource source, CallbackInfo ci) { - //Avatar avatar = AvatarManager.getAvatarForPlayer(FiguraMod.getLocalPlayerUUID()); Avatar avatar = AvatarManager.getAvatar(this); if (avatar == null) return; avatar.damageEvent( From 45e5a2280b9f697b4e43219cb2ae9c3068ca9cab Mon Sep 17 00:00:00 2001 From: soup587 Date: Sat, 29 Jun 2024 17:46:13 +0100 Subject: [PATCH 31/43] Implement a TOTEM event (fires whenever a player uses a totem) (returning the event cancels the animation) --- .../org/figuramc/figura/avatar/Avatar.java | 4 ++++ .../figura/lua/api/event/EventsAPI.java | 4 ++++ .../mixin/ClientPacketListenerMixin.java | 19 ++++++++++++++++++- .../resources/assets/figura/lang/en_us.json | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/figuramc/figura/avatar/Avatar.java b/common/src/main/java/org/figuramc/figura/avatar/Avatar.java index 6a2855545..794c9c6eb 100644 --- a/common/src/main/java/org/figuramc/figura/avatar/Avatar.java +++ b/common/src/main/java/org/figuramc/figura/avatar/Avatar.java @@ -477,6 +477,10 @@ public void charTypedEvent(String chars, int modifiers, int codePoint) { if (loaded) run("CHAR_TYPED", tick, chars, modifiers, codePoint); } + public boolean totemEvent() { + return isCancelled(loaded ? run("TOTEM",tick) : null); + } + // -- rendering events -- // private void render() { diff --git a/common/src/main/java/org/figuramc/figura/lua/api/event/EventsAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/event/EventsAPI.java index f5594cb3f..675d2ba45 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/event/EventsAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/event/EventsAPI.java @@ -87,6 +87,9 @@ public class EventsAPI { @LuaWhitelist @LuaFieldDoc("events.resource_reload") public final LuaEvent RESOURCE_RELOAD = new LuaEvent(); + @LuaWhitelist + @LuaFieldDoc("events.totem") + public final LuaEvent TOTEM = new LuaEvent(); private final Map events = new HashMap<>(); @@ -112,6 +115,7 @@ public EventsAPI() { events.put("ITEM_RENDER", ITEM_RENDER); events.put("ON_PLAY_SOUND", ON_PLAY_SOUND); events.put("RESOURCE_RELOAD", RESOURCE_RELOAD); + events.put("TOTEM", TOTEM); for (FiguraEvent entrypoint : ENTRYPOINTS) { String ID = entrypoint.getID().toUpperCase(Locale.US); diff --git a/common/src/main/java/org/figuramc/figura/mixin/ClientPacketListenerMixin.java b/common/src/main/java/org/figuramc/figura/mixin/ClientPacketListenerMixin.java index bdbba0722..c9960ce20 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/ClientPacketListenerMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/ClientPacketListenerMixin.java @@ -1,18 +1,35 @@ package org.figuramc.figura.mixin; +import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; +import net.minecraft.world.level.Level; import org.figuramc.figura.FiguraMod; +import org.figuramc.figura.avatar.Avatar; +import org.figuramc.figura.avatar.AvatarManager; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; 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; @Mixin(value = ClientPacketListener.class, priority = 999) -public class ClientPacketListenerMixin { +public abstract class ClientPacketListenerMixin { + + @Shadow public abstract ClientLevel getLevel(); @Inject(at = @At("HEAD"), method = "sendUnsignedCommand", cancellable = true) private void sendUnsignedCommand(String command, CallbackInfoReturnable cir) { if (command.startsWith(FiguraMod.MOD_ID)) cir.setReturnValue(false); } + + @Inject(method = "handleEntityEvent", at = @At(value = "FIELD", target = "Lnet/minecraft/core/particles/ParticleTypes;TOTEM_OF_UNDYING:Lnet/minecraft/core/particles/SimpleParticleType;"), cancellable = true) + private void handleTotem(ClientboundEntityEventPacket packet, CallbackInfo ci) { + Level level = getLevel(); + Avatar avatar = AvatarManager.getAvatar(packet.getEntity(level)); + if (avatar != null && avatar.totemEvent()) + ci.cancel(); + } } diff --git a/common/src/main/resources/assets/figura/lang/en_us.json b/common/src/main/resources/assets/figura/lang/en_us.json index d7bbefb60..32a67fb8a 100644 --- a/common/src/main/resources/assets/figura/lang/en_us.json +++ b/common/src/main/resources/assets/figura/lang/en_us.json @@ -1060,6 +1060,7 @@ "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", + "figura.docs.events.totem": "Called whenever you use a Totem of Undying to cheat death\nIf returned true the animation is cancelled", "figura.docs.events.get_events": "Returns a table with all events types", "figura.docs.event": "A hook for a certain event in Minecraft\nYou may register functions to one, and those functions will be called when the event occurs", "figura.docs.event.register": "Register a function on this event\nFunctions are run in registration order\nAn optional string argument can be given, grouping functions under that name, for an easier management later on", From 54fc82d5f8cccf810302574b4bb86128e2d52b48 Mon Sep 17 00:00:00 2001 From: GrandpaScout <35317603+GrandpaScout@users.noreply.github.com> Date: Wed, 3 Jul 2024 07:48:17 -0400 Subject: [PATCH 32/43] Fix texture issue with 4.10+ models. Blockbench pushed a fix in update 4.10.0 that fixed relative paths for textures. It originally treated the bbmodel file itself as a directory, which caused the relative path to contain an extra "../". Since this has been fixed, Figura tries to read textures as if the bbmodel is a directory (which it is not.) This commit should fix this issue while still keeping compatibility with 4.9- models by doing the old method of if a file at the relative path doesn't exist and the path starts with "../". --- .../figura/parsers/BlockbenchModelParser.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/parsers/BlockbenchModelParser.java b/common/src/main/java/org/figuramc/figura/parsers/BlockbenchModelParser.java index e97c5c7f1..291189621 100644 --- a/common/src/main/java/org/figuramc/figura/parsers/BlockbenchModelParser.java +++ b/common/src/main/java/org/figuramc/figura/parsers/BlockbenchModelParser.java @@ -131,11 +131,27 @@ private void parseTextures(Path avatar, Path sourceFile, String folders, String byte[] source; try { //check the file to load - Path p = sourceFile.resolve(texture.relative_path); + Path p = sourceFile.getParent().resolve(texture.relative_path); if (p.getFileSystem() == FileSystems.getDefault()) { File f = p.toFile().getCanonicalFile(); p = f.toPath(); - if (!f.exists()) throw new IllegalStateException("File do not exists!"); + if (!f.exists()) { + // Compatibility with old Blockbench models. (BB 4.9-) + if (texture.relative_path.startsWith("../")) { + p = sourceFile.resolve(texture.relative_path); + if (p.getFileSystem() == FileSystems.getDefault()) { + f = p.toFile().getCanonicalFile(); + p = f.toPath(); + if (!f.exists()) throw new IllegalStateException("File do not exists!"); + } else { + p = p.normalize(); + if (p.getFileSystem() != avatar.getFileSystem()) + throw new IllegalStateException("File from outside the avatar folder!"); + } + } else { + throw new IllegalStateException("File do not exists!"); + } + } } else { p = p.normalize(); if (p.getFileSystem() != avatar.getFileSystem()) From 5ee3897fd618a351207b7c92b3c1084bbbc16c55 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Fri, 21 Jun 2024 19:05:43 -0600 Subject: [PATCH 33/43] Fixed Animated Emojis being offset --- .../java/org/figuramc/figura/mixin/font/BakedGlyphMixin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/mixin/font/BakedGlyphMixin.java b/common/src/main/java/org/figuramc/figura/mixin/font/BakedGlyphMixin.java index a70022f62..dcaeffaf0 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/font/BakedGlyphMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/font/BakedGlyphMixin.java @@ -51,8 +51,8 @@ public abstract class BakedGlyphMixin implements BakedGlyphAccessor { public void render(boolean italic, float x, float y, Matrix4f matrix, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, int light, CallbackInfo ci) { if (figura$metadata == null) return; - float h = this.up - 3.0f; - float j = this.down - 3.0f; + float h = this.up; + float j = this.down; float k = y + h; float l = y + j; float m = italic ? 1.0f - 0.25f * h : 0f; From 99882a92f007e4e1000c980bed7c8c26b6b2eae7 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:39:33 -0600 Subject: [PATCH 34/43] Fix VM Error on empty table Fix a Crash on no-sound systems --- .../java/org/figuramc/figura/avatar/Avatar.java | 16 +++++++++++----- .../figura/ducks/SoundEngineAccessor.java | 1 + .../org/figuramc/figura/lua/FiguraLuaJson.java | 1 + .../figura/mixin/sound/SoundEngineMixin.java | 5 +++++ .../java/org/figuramc/figura/utils/LuaUtils.java | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/avatar/Avatar.java b/common/src/main/java/org/figuramc/figura/avatar/Avatar.java index 105fb763c..66b5f3a9f 100644 --- a/common/src/main/java/org/figuramc/figura/avatar/Avatar.java +++ b/common/src/main/java/org/figuramc/figura/avatar/Avatar.java @@ -949,8 +949,10 @@ public void clean() { public void clearSounds() { SoundAPI.getSoundEngine().figura$stopSound(owner, null); - for (SoundBuffer value : customSounds.values()) - value.releaseAlBuffer(); + if (SoundAPI.getSoundEngine().figura$isEngineActive()) { + for (SoundBuffer value : customSounds.values()) + value.releaseAlBuffer(); + } } public void closeBuffers() { @@ -1087,9 +1089,13 @@ private void loadCustomSounds() { } public void loadSound(String name, byte[] data) throws Exception { - try (ByteArrayInputStream inputStream = new ByteArrayInputStream(data); OggAudioStream oggAudioStream = new OggAudioStream(inputStream)) { - SoundBuffer sound = new SoundBuffer(oggAudioStream.readAll(), oggAudioStream.getFormat()); - this.customSounds.put(name, sound); + if (SoundAPI.getSoundEngine().figura$isEngineActive()) { + try (ByteArrayInputStream inputStream = new ByteArrayInputStream(data); OggAudioStream oggAudioStream = new OggAudioStream(inputStream)) { + SoundBuffer sound = new SoundBuffer(oggAudioStream.readAll(), oggAudioStream.getFormat()); + this.customSounds.put(name, sound); + } + } else { + FiguraMod.LOGGER.error("Sound is not supported or enabled on this system but a custom sound tried to load anyway, scripts may break."); } } diff --git a/common/src/main/java/org/figuramc/figura/ducks/SoundEngineAccessor.java b/common/src/main/java/org/figuramc/figura/ducks/SoundEngineAccessor.java index d76531a8d..7600b6eba 100644 --- a/common/src/main/java/org/figuramc/figura/ducks/SoundEngineAccessor.java +++ b/common/src/main/java/org/figuramc/figura/ducks/SoundEngineAccessor.java @@ -17,4 +17,5 @@ public interface SoundEngineAccessor { float figura$getVolume(SoundSource category); SoundBufferLibrary figura$getSoundBuffers(); boolean figura$isPlaying(UUID owner); + boolean figura$isEngineActive(); } diff --git a/common/src/main/java/org/figuramc/figura/lua/FiguraLuaJson.java b/common/src/main/java/org/figuramc/figura/lua/FiguraLuaJson.java index f44983dfb..661b6c5a6 100644 --- a/common/src/main/java/org/figuramc/figura/lua/FiguraLuaJson.java +++ b/common/src/main/java/org/figuramc/figura/lua/FiguraLuaJson.java @@ -32,6 +32,7 @@ public String tojstring() { private static final Function TO_JSON_FUNCTION = runtime -> new VarArgFunction() { @Override public Varargs invoke(Varargs args) { + if (args.narg() == 0) return LuaValue.NIL; return LuaValue.valueOf(tableToJsonString(args.arg(1))); } diff --git a/common/src/main/java/org/figuramc/figura/mixin/sound/SoundEngineMixin.java b/common/src/main/java/org/figuramc/figura/mixin/sound/SoundEngineMixin.java index 5314c465f..a85f764f0 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/sound/SoundEngineMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/sound/SoundEngineMixin.java @@ -202,4 +202,9 @@ public void play(SoundInstance sound, CallbackInfo c) { } return false; } + + @Override + public boolean figura$isEngineActive() { + return loaded; + } } diff --git a/common/src/main/java/org/figuramc/figura/utils/LuaUtils.java b/common/src/main/java/org/figuramc/figura/utils/LuaUtils.java index 346278e52..c5894552a 100644 --- a/common/src/main/java/org/figuramc/figura/utils/LuaUtils.java +++ b/common/src/main/java/org/figuramc/figura/utils/LuaUtils.java @@ -292,7 +292,7 @@ public static JsonElement asJsonValue(LuaValue value) { LuaTable table = value.checktable(); // If it's an "array" (uses numbers as keys) - if (checkTableArray(table)) { + if (checkTableArray(table) && table.length() > 0) { JsonArray arr = new JsonArray(); LuaValue[] keys = table.keys(); int arrayLength = keys[keys.length-1].checkint(); From 0f4d65fc063309ecc73d870df76f5707e753498c Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:02:45 -0600 Subject: [PATCH 35/43] Don't tick avatars if the player doesn't exist Add a message if the texture couldn't be read Fix Incorrect UV on Avatar Wizard Cape --- common/src/main/java/org/figuramc/figura/FiguraMod.java | 6 ++++-- .../main/java/org/figuramc/figura/lua/api/TextureAPI.java | 2 +- .../main/java/org/figuramc/figura/wizards/AvatarWizard.java | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/FiguraMod.java b/common/src/main/java/org/figuramc/figura/FiguraMod.java index dcdac5692..1495ec5ca 100644 --- a/common/src/main/java/org/figuramc/figura/FiguraMod.java +++ b/common/src/main/java/org/figuramc/figura/FiguraMod.java @@ -86,8 +86,10 @@ public static void tick() { popPushProfiler("files"); LocalAvatarLoader.tick(); LocalAvatarFetcher.tick(); - popPushProfiler("avatars"); - AvatarManager.tickLoadedAvatars(); + if (Minecraft.getInstance().player != null) { + popPushProfiler("avatars"); + AvatarManager.tickLoadedAvatars(); + } popPushProfiler("chatPrint"); FiguraLuaPrinter.printChatFromQueue(); popPushProfiler("emojiAnim"); diff --git a/common/src/main/java/org/figuramc/figura/lua/api/TextureAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/TextureAPI.java index 83ac46f3c..183217015 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/TextureAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/TextureAPI.java @@ -101,7 +101,7 @@ public FiguraTexture read(@LuaNotNil String name, @LuaNotNil Object object) { image = NativeImage.read(null, bais); bais.close(); } catch (Exception e) { - throw new LuaError(e.getMessage()); + throw new LuaError("Could not read image: " + e.getMessage()); } return register(name, image, false); diff --git a/common/src/main/java/org/figuramc/figura/wizards/AvatarWizard.java b/common/src/main/java/org/figuramc/figura/wizards/AvatarWizard.java index 920c6d422..04fd1da40 100644 --- a/common/src/main/java/org/figuramc/figura/wizards/AvatarWizard.java +++ b/common/src/main/java/org/figuramc/figura/wizards/AvatarWizard.java @@ -271,7 +271,7 @@ else if (hasCapeOrElytra) if (hasCape) { Group cape = model.addGroup(Cape, FiguraVec3.of(0, 24, 2), root); Cube cube = model.addCube("Cape", FiguraVec3.of(-5, 8, 2), FiguraVec3.of(10, 16, 1), cape); - cube.generateBoxFaces(0, 0, capeTex, 1, hasPlayer ? 2 : 1); + cube.generateBoxFaces(0, 0, capeTex, 1, 1); } //elytra From 2f243235536bb0b79000cc2e69b6e0e0d2daeb3f Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:30:11 -0600 Subject: [PATCH 36/43] Add MixinExtras as a dependency Fix compatibility issues with mods that modify the name of an itemstack --- common/build.gradle | 2 ++ .../org/figuramc/figura/mixin/ItemStackMixin.java | 12 ++++++------ fabric/build.gradle | 1 + forge/build.gradle | 3 +++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/common/build.gradle b/common/build.gradle index 6fa14855f..647e39475 100755 --- a/common/build.gradle +++ b/common/build.gradle @@ -28,6 +28,8 @@ dependencies { exclude group: "net.fabricmc" } + implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.6")) + // We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies // Do NOT use other classes from fabric loader modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" diff --git a/common/src/main/java/org/figuramc/figura/mixin/ItemStackMixin.java b/common/src/main/java/org/figuramc/figura/mixin/ItemStackMixin.java index f6b83c3a5..1f9748ded 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/ItemStackMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/ItemStackMixin.java @@ -1,20 +1,20 @@ package org.figuramc.figura.mixin; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import org.figuramc.figura.config.Configs; import org.figuramc.figura.font.Emojis; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(ItemStack.class) +@Mixin(value = ItemStack.class, priority = 999) public class ItemStackMixin { - @Inject(method = "getHoverName", at = @At("RETURN"), cancellable = true) - private void getHoverName(CallbackInfoReturnable cir) { + @ModifyReturnValue(method = "getHoverName", at = @At("RETURN")) + private Component getHoverName(Component original) { if (Configs.EMOJIS.value > 0) - cir.setReturnValue(Emojis.applyEmojis(cir.getReturnValue())); + return Emojis.applyEmojis(original); + return original; } } diff --git a/fabric/build.gradle b/fabric/build.gradle index bb8d5e1da..1395b7d5d 100755 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -29,6 +29,7 @@ dependencies { include(implementation("com.github.FiguraMC.luaj:luaj-core:$luaj-figura")) include(implementation("com.github.FiguraMC.luaj:luaj-jse:$luaj-figura")) include(implementation("com.neovisionaries:nv-websocket-client:$nv_websocket")) + include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:0.3.6"))) if(rootProject.run_on_quilt == "false") { modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" diff --git a/forge/build.gradle b/forge/build.gradle index 133e68fd2..82c60cab6 100755 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -33,6 +33,9 @@ dependencies { officialMojangMappings() } + compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.6")) + implementation(include("io.github.llamalad7:mixinextras-forge:0.3.6")) + // Libraries include(forgeRuntimeLibrary("com.github.FiguraMC.luaj:luaj-core:$luaj-figura")) include(forgeRuntimeLibrary("com.github.FiguraMC.luaj:luaj-jse:$luaj-figura")) From dfcf707eba2254bef5d14d12e0b679bced8c046a Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:43:12 -0600 Subject: [PATCH 37/43] Fix possible compatibility issues when modifying eye pos --- .../figuramc/figura/mixin/EntityMixin.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/mixin/EntityMixin.java b/common/src/main/java/org/figuramc/figura/mixin/EntityMixin.java index ca478642a..c3af3978c 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/EntityMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/EntityMixin.java @@ -1,5 +1,6 @@ package org.figuramc.figura.mixin; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.minecraft.world.entity.Entity; import net.minecraft.world.phys.Vec3; import org.figuramc.figura.avatar.Avatar; @@ -8,23 +9,25 @@ import org.spongepowered.asm.mixin.Intrinsic; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(Entity.class) +@Mixin(value = Entity.class, priority = 999) public class EntityMixin { - @Inject(method = "getEyePosition(F)Lnet/minecraft/world/phys/Vec3;", at = @At("RETURN"), cancellable = true) - private void getEyePosition(float tickDelta, CallbackInfoReturnable cir) { - figura$offsetEyePos(cir); + @ModifyReturnValue(method = "getEyePosition(F)Lnet/minecraft/world/phys/Vec3;", at = @At("RETURN")) + private Vec3 getEyePosition(Vec3 original) { + return figura$offsetEyePos(original); } @Intrinsic - private void figura$offsetEyePos(CallbackInfoReturnable cir) { + private Vec3 figura$offsetEyePos(Vec3 original) { Avatar avatar = AvatarManager.getAvatar((Entity) (Object) this); if (avatar == null || avatar.luaRuntime == null) - return; + return original; + FiguraVec3 vec = avatar.luaRuntime.renderer.eyeOffset; - if (vec != null) cir.setReturnValue(cir.getReturnValue().add(vec.asVec3())); + if (vec != null) return original.add(vec.asVec3()); + + return original; } } From 6671952ad587e06ad3d9becb111a1275030cc362 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Fri, 5 Jul 2024 19:38:42 -0600 Subject: [PATCH 38/43] Fix compatibility issues with Chat Patches --- .../java/org/figuramc/figura/mixin/gui/ChatComponentMixin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/figuramc/figura/mixin/gui/ChatComponentMixin.java b/common/src/main/java/org/figuramc/figura/mixin/gui/ChatComponentMixin.java index 7896dc9de..63bc9d589 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/gui/ChatComponentMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/gui/ChatComponentMixin.java @@ -30,7 +30,8 @@ import java.util.UUID; import java.util.regex.Pattern; -@Mixin(ChatComponent.class) +// 400 Priority is used as messages must be modified before ChatPatches tries to. +@Mixin(value = ChatComponent.class, priority = 400) public class ChatComponentMixin { @Unique private Integer color; From 039d08f383a2a049f4a5405707b4f83092551d7c Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Fri, 5 Jul 2024 21:12:29 -0600 Subject: [PATCH 39/43] Bump to Fabric Loader 0.14.25 as required by MixinExtras --- fabric/src/main/resources/fabric.mod.json | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index ad3e544a0..046731229 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -35,7 +35,7 @@ "depends": { "java": ">=${java_version}", "minecraft": "${minecraft_version}", - "fabricloader": ">=0.14.21" + "fabricloader": ">=0.14.25" }, "conflicts": { "immersive_portals": "*", diff --git a/gradle.properties b/gradle.properties index a0d8fc0b5..6c546fafe 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,7 +24,7 @@ nv_websocket = 2.14 # https://fabricmc.net/develop # https://modrinth.com/mod/fabric-api fabric_api = 0.86.1+1.20.1 -fabric_loader_version = 0.14.22 +fabric_loader_version = 0.14.25 # Mod Dependencies # https://modrinth.com/mod/modmenu From 10c3ed364eaf4d3f0103f0b23d03ddf155b6501b Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Fri, 5 Jul 2024 21:23:55 -0600 Subject: [PATCH 40/43] Change bezier calculations to use newton raphson and catmull rom ordering to match the definition --- .../org/figuramc/figura/utils/MathUtils.java | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/utils/MathUtils.java b/common/src/main/java/org/figuramc/figura/utils/MathUtils.java index 059051500..288ad91a4 100644 --- a/common/src/main/java/org/figuramc/figura/utils/MathUtils.java +++ b/common/src/main/java/org/figuramc/figura/utils/MathUtils.java @@ -170,7 +170,7 @@ public static FiguraVec3 catmullrom(double delta, FiguraVec3 prevA, FiguraVec3 p // no idea how it works // it is the same function from minecraft, but using doubles instead public static double catmullrom(double delta, double prevA, double prevB, double nextA, double nextB) { - return 0.5 * (2 * prevB + (nextA - prevA) * delta + (2 * prevA - 5 * prevB + 4 * nextA - nextB) * delta * delta + (3 * prevB - prevA - 3 * nextA + nextB) * delta * delta * delta); + return 0.5 * (2 * prevB + (-prevA + nextA) * delta + (2 * prevA - 5 * prevB + 4 * nextA - nextB) * delta * delta + (-prevA + 3 * prevB - 3 * nextA + nextB) * delta * delta * delta); } // bezier function generated by ChatGPT @@ -179,23 +179,36 @@ public static double bezier(double t, double p0, double p1, double p2, double p3 return p0 * d * d * d + 3 * p1 * d * d * t + 3 * p2 * d * t * t + p3 * t * t * t; } - // secant method for finding bezier t based on x, also provided by ChatGPT + // newton raphson method for finding bezier t based on x, also provided by ChatGPT + // this approximation method is more accurate and often requires less iterations than secant based public static double bezierFindT(double x, double p0, double p1, double p2, double p3) { - double x0 = 0.4; - double x1 = 0.6; - double tolerance = 0.001; + double tolerance = 0.0001; + double t = 0.5; int iterations = 100; for (int i = 0; i < iterations; i++) { - double fx1 = bezier(x1, p0, p1, p2, p3) - x; - double fx0 = bezier(x0, p0, p1, p2, p3) - x; - double xNext = x1 - fx1 * (x1 - x0) / (fx1 - fx0); - if (Math.abs(xNext - x1) < tolerance) - return xNext; - x0 = x1; - x1 = xNext; + double xBezier = bezier(t, p0, p1, p2, p3); + double dxBezier = bezierDerivative(t, p0, p1, p2, p3); + + if (dxBezier == 0) { + break; // Avoid division by zero + } + + double tNext = t - (xBezier - x) / dxBezier; + + if (Math.abs(tNext - t) < tolerance) { + return tNext; + } + + t = tNext; } - return x1; + return t; } + + private static double bezierDerivative(double t, double p0, double p1, double p2, double p3) { + double d = 1 - t; + return 3 * (p1 - p0) * d * d + 6 * (p2 - p1) * d * t + 3 * (p3 - p2) * t * t; + } + } From 8ff2a3afa6c2b1187cf7e122c6ded7ee14676388 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:01:10 -0600 Subject: [PATCH 41/43] Bump to 0.1.5 RC 1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6c546fafe..2c23c0d09 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ mappings = 1 enabled_platforms = fabric,forge # Mod Properties -mod_version = 0.1.4 +mod_version = 0.1.5-rc.1 maven_group = org.figuramc archives_base_name = figura assets_version = v2 From 14450ac5f2439f50e0716f6a674ab2fec8a3ae69 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Fri, 21 Jun 2024 19:58:22 -0600 Subject: [PATCH 42/43] Fixed getShaderPack to work with Iris 1.7+ --- .../java/org/figuramc/figura/lua/api/ClientAPI.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java index 20e652d7c..b7c6d85fa 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/ClientAPI.java @@ -366,14 +366,21 @@ public static boolean hasShaderPack() { public static String getShaderPackName() { try { if (HAS_IRIS) { - return net.coderbot.iris.Iris.getCurrentPackName(); + Method shaderNameField = Class.forName("net.coderbot.iris.Iris").getMethod("getCurrentPackName"); + shaderNameField.setAccessible(true); + return shaderNameField.invoke(null).toString(); } else if (OPTIFINE_LOADED.get()) { Field shaderNameField = Class.forName("net.optifine.shaders.Shaders").getField("currentShaderName"); Class shaderClass = shaderNameField.getType(); if (shaderClass == String.class) return (String) shaderNameField.get(null); } - } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) { + } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | + InvocationTargetException | NoSuchMethodException ignored) { + try { + return net.irisshaders.iris.Iris.getCurrentPackName(); + }catch (Exception ignored1) { + } } return ""; } From 360e7b0833302c16137392f7741ca1d75520cb3d Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sat, 6 Jul 2024 00:48:35 -0600 Subject: [PATCH 43/43] Fixes oops --- .../java/org/figuramc/figura/lua/api/world/WorldAPI.java | 2 +- .../java/org/figuramc/figura/mixin/font/FontSetMixin.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java b/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java index abd526ee0..1acf063e0 100644 --- a/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java +++ b/common/src/main/java/org/figuramc/figura/lua/api/world/WorldAPI.java @@ -205,7 +205,7 @@ public static HashMap getMapData(String id) { decorationMap.put("x", decoration.x()); decorationMap.put("y", decoration.y()); decorationMap.put("rot", decoration.rot()); - decorationMap.put("image", decoration.type().getIcon()); + decorationMap.put("image", decoration.getSpriteLocation()); decorations.add(decorationMap); } map.put("decorations", decorations); diff --git a/common/src/main/java/org/figuramc/figura/mixin/font/FontSetMixin.java b/common/src/main/java/org/figuramc/figura/mixin/font/FontSetMixin.java index b0a233cbe..6b29bb5dd 100644 --- a/common/src/main/java/org/figuramc/figura/mixin/font/FontSetMixin.java +++ b/common/src/main/java/org/figuramc/figura/mixin/font/FontSetMixin.java @@ -35,10 +35,8 @@ public abstract class FontSetMixin { @Unique int figura$codePoint = -1; - //method_27545 for fabric intermediary, m_232558_ for SRG, lambda$setGlyphProviders$5 unmapped for OF, lambda$reload$5 for NeoForge, i had dig at the bytecode for this one - //@Inject(method = {"method_27545", "m_232558_", "lambda$setGlyphProviders$5", "lambda$reload$5"}, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/font/GlyphInfo;getAdvance(Z)F", shift = At.Shift.BEFORE, remap = true), locals = LocalCapture.CAPTURE_FAILEXCEPTION, remap = false) - //method_57035 for fabric intermediary - @Inject(method = {"method_57035"}, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/font/GlyphInfo;getAdvance(Z)F", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILEXCEPTION) + //method_57035 for fabric intermediary, lambda$selectProviders$5 for everything else + @Inject(method = {"method_57035", "lambda$selectProviders$5"}, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/font/GlyphInfo;getAdvance(Z)F", shift = At.Shift.BEFORE, remap = true), locals = LocalCapture.CAPTURE_FAILEXCEPTION, remap = false) public void thing(List list, Set set, int i, CallbackInfo ci, Iterator var4, GlyphProvider glyphProvider, GlyphInfo glyphInfo) { if (figura$isEmojiFont() && glyphInfo instanceof BitmapProvider.Glyph) { ((BitmapProviderGlyphAccessor) glyphInfo).figura$setAdvance(8);