Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
plugins {
id 'fabric-loom' version "${loom_version}"
id "net.fabricmc.fabric-loom" version "${loom_version}"
}

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
}

repositories {
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

implementation "net.fabricmc:fabric-loader:${project.loader_version}"
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
}

processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
expand "version": inputs.properties.version
}
}

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 21
it.options.release = 25
}

java {
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
rename { "${it}_${inputs.properties.archivesName}"}
}
}
11 changes: 5 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.21.5
yarn_mappings=1.21.5+build.1
loader_version=0.16.14
loom_version=1.10-SNAPSHOT
minecraft_version=26.1-snapshot-2
loader_version=0.18.4
loom_version=1.14-SNAPSHOT

# Fabric API
fabric_version=0.127.1+1.21.5
fabric_api_version=0.141.2+26.1

mod_version = 0.6.1+1.21.5
mod_version = 0.6.2+26.1
maven_group = io.github.foundationgames
archives_base_name = animatica

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import io.github.foundationgames.animatica.config.AnimaticaConfig;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.PackType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -17,10 +17,10 @@ public class Animatica implements ClientModInitializer {

@Override
public void onInitializeClient() {
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(AnimationLoader.INSTANCE);
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(AnimationLoader.INSTANCE);
}

public static Identifier id(String path) {
return Identifier.of(NAMESPACE, path);
return Identifier.fromNamespaceAndPath(NAMESPACE, path);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.foundationgames.animatica.accessor;

public interface NativeImageAccessor {
long animatica$getPixels();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package io.github.foundationgames.animatica.animation;

import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.platform.NativeImage;
import io.github.foundationgames.animatica.Animatica;
import io.github.foundationgames.animatica.util.TextureUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.client.texture.TextureTickListener;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
Expand All @@ -21,8 +15,14 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Supplier;

public class AnimatedTexture extends NativeImageBackedTexture implements TextureTickListener {
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TickableTexture;
import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.Mth;

public class AnimatedTexture extends DynamicTexture implements TickableTexture {
public static final ExecutorService EXECUTORS = Executors.newFixedThreadPool(4);

public final Animation[] anims;
Expand All @@ -32,7 +32,7 @@ public class AnimatedTexture extends NativeImageBackedTexture implements Texture
private CompletableFuture<Void> frameWaitingOn = null;

public static Optional<AnimatedTexture> tryCreate(ResourceManager resources, Identifier targetTexId, List<AnimationMeta> anims) {
try (var targetTexResource = resources.getResourceOrThrow(targetTexId).getInputStream()) {
try (var targetTexResource = resources.getResourceOrThrow(targetTexId).open()) {
return Optional.of(new AnimatedTexture(targetTexId::toString, resources, anims, NativeImage.read(targetTexResource)));
} catch (IOException e) { Animatica.LOG.error(e); }

Expand All @@ -48,7 +48,7 @@ public AnimatedTexture(Supplier<String> name, ResourceManager resources, List<An
}
this.original = image;

updateAndDraw(this.getImage(), true, MinecraftClient.getInstance());
updateAndDraw(this.getPixels(), true, Minecraft.getInstance());
this.upload();
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public void updateAndDraw(NativeImage image, boolean force, Executor exec) {
TextureUtil.copy(anim.sourceTexture, 0, phase.v, anim.width, anim.height, image, anim.targetX, anim.targetY);
}
}
}, exec).thenAccept(v -> MinecraftClient.getInstance().execute(this::upload));
}, exec).thenAccept(v -> Minecraft.getInstance().execute(this::upload));
}
}

Expand All @@ -115,7 +115,7 @@ public void updateAndDraw(NativeImage image, boolean force, Executor exec) {

@Override
public void tick() {
this.updateAndDraw(this.getImage(), false, EXECUTORS);
this.updateAndDraw(this.getPixels(), false, EXECUTORS);
}

@Override
Expand Down Expand Up @@ -150,7 +150,7 @@ public Animation(AnimationMeta meta, ResourceManager resources) throws IOExcepti
this.width = meta.width();
this.height = meta.height();

try (var source = resources.getResourceOrThrow(meta.source()).getInputStream()) {
try (var source = resources.getResourceOrThrow(meta.source()).open()) {
this.sourceTexture = NativeImage.read(source);
}

Expand Down Expand Up @@ -256,7 +256,7 @@ public void close() {
}

private int getVForFrame(int frame, int textureFrameCount) {
return MathHelper.clamp(frame * this.height, 0, (textureFrameCount - 1) * this.height);
return Mth.clamp(frame * this.height, 0, (textureFrameCount - 1) * this.height);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import io.github.foundationgames.animatica.util.Flags;
import io.github.foundationgames.animatica.util.exception.PropertyParseException;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.client.MinecraftClient;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
Expand Down Expand Up @@ -35,7 +35,7 @@ private AnimationLoader() {

private static void findAllMCPAnimations(ResourceManager manager, BiConsumer<Identifier, Resource> action) {
for (var path : ANIM_PATHS) {
manager.findResources(path, p -> p.getPath().endsWith(".properties")).forEach(action);
manager.listResources(path, p -> p.getPath().endsWith(".properties")).forEach(action);
}
}

Expand All @@ -49,7 +49,7 @@ public Identifier getFabricId() {
}

@Override
public void reload(ResourceManager manager) {
public void onResourceManagerReload(ResourceManager manager) {
this.animationIds.clear();

if (!Animatica.CONFIG.animatedTextures) {
Expand All @@ -62,7 +62,7 @@ public void reload(ResourceManager manager) {

findAllMCPAnimations(manager, (id, resource) -> {
try {
try (var resourceInputStream = resource.getInputStream()) {
try (var resourceInputStream = resource.open()) {
var ppt = new Properties();
ppt.load(resourceInputStream);

Expand All @@ -80,9 +80,9 @@ public void reload(ResourceManager manager) {
for (var targetId : animations.keySet()) {
AnimatedTexture.tryCreate(manager, targetId, animations.get(targetId))
.ifPresent(tex -> {
var animId = Identifier.of(targetId.getNamespace(), targetId.getPath() + "-anim");
var animId = Identifier.fromNamespaceAndPath(targetId.getNamespace(), targetId.getPath() + "-anim");
this.animationIds.put(targetId, animId);
MinecraftClient.getInstance().getTextureManager().registerTexture(animId, tex);
Minecraft.getInstance().getTextureManager().register(animId, tex);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import io.github.foundationgames.animatica.util.Utilities;
import io.github.foundationgames.animatica.util.exception.InvalidPropertyException;
import io.github.foundationgames.animatica.util.exception.PropertyParseException;
import net.minecraft.util.Identifier;
import net.minecraft.util.InvalidIdentifierException;

import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import net.minecraft.IdentifierException;
import net.minecraft.resources.Identifier;

public record AnimationMeta(
Identifier source, Identifier target, int targetX,
Expand All @@ -22,11 +21,11 @@ public static AnimationMeta of(Identifier file, Properties properties) throws Pr
Identifier source;
Identifier target;
try {
source = Utilities.processPath(file, Identifier.of(PropertyUtil.get(file, properties, "from")));
} catch (InvalidIdentifierException ex) { throw new InvalidPropertyException(file, "from", "resource location"); }
source = Utilities.processPath(file, Identifier.parse(PropertyUtil.get(file, properties, "from")));
} catch (IdentifierException ex) { throw new InvalidPropertyException(file, "from", "resource location"); }
try {
target = Utilities.processPath(file, Identifier.of(PropertyUtil.get(file, properties, "to")));
} catch (InvalidIdentifierException ex) { throw new InvalidPropertyException(file, "to", "resource location"); }
target = Utilities.processPath(file, Identifier.parse(PropertyUtil.get(file, properties, "to")));
} catch (IdentifierException ex) { throw new InvalidPropertyException(file, "to", "resource location"); }
return new AnimationMeta(
source,
target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import io.github.foundationgames.animatica.Animatica;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.SimpleOption;
import net.minecraft.client.Minecraft;
import net.minecraft.client.OptionInstance;
import net.minecraft.network.chat.Component;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -12,10 +13,11 @@

public class AnimaticaConfig {
public static String ANIMATED_TEXTURES_KEY = "animated_textures";
private static final Component GRAPHICS_TOOLTIP_ANIMATIONS = Component.translatable("options.animatica.animations.tooltip");

public static final String FILE_NAME = "animatica.properties";

private final SimpleOption<Boolean> animatedTexturesOption;
private final OptionInstance<Boolean> animatedTexturesOption;
public boolean animatedTextures;

public AnimaticaConfig() {
Expand All @@ -25,15 +27,16 @@ public AnimaticaConfig() {
Animatica.LOG.error("Error loading config during initialization!", e);
}

this.animatedTexturesOption = SimpleOption.ofBoolean(
this.animatedTexturesOption = OptionInstance.createBoolean(
"option.animatica.animated_textures",
OptionInstance.cachedConstantTooltip(GRAPHICS_TOOLTIP_ANIMATIONS),
this.animatedTextures,
value -> {
this.animatedTextures = value;
try {
this.save();
} catch (IOException e) { Animatica.LOG.error("Error saving config while changing in game!", e); }
MinecraftClient.getInstance().reloadResources();
Minecraft.getInstance().reloadResourcePacks();
}
);
}
Expand All @@ -55,7 +58,7 @@ public Path getFile() throws IOException {
return file;
}

public SimpleOption<Boolean> getAnimatedTexturesOption() {
public OptionInstance<Boolean> getAnimatedTexturesOption() {
return animatedTexturesOption;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

import io.github.foundationgames.animatica.Animatica;
import io.github.foundationgames.animatica.util.Flags;
import net.minecraft.util.Identifier;
import net.minecraft.resources.Identifier;
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;

// Allows invalid characters in paths to support packs with extremely outdated formatting (because OptiFine does too)
@Mixin(Identifier.class)
public class IdentifierMixin {
@Inject(method = "of(Ljava/lang/String;)Lnet/minecraft/util/Identifier;", at = @At("TAIL"))
@Inject(method = "parse", at = @At("TAIL"))
private static void animatica$reportInvalidIdentifierCharacters(String id, CallbackInfoReturnable<Identifier> ci) {
if (Flags.ALLOW_INVALID_ID_CHARS && !animatica$isPathAllowed(Identifier.splitOn(id, ':').getPath()) && !Identifier.splitOn(id, ':').getPath().startsWith("~/")) {
if (Flags.ALLOW_INVALID_ID_CHARS && !animatica$isPathAllowed(Identifier.bySeparator(id, ':').getPath()) && !Identifier.bySeparator(id, ':').getPath().startsWith("~/")) {
Animatica.LOG.warn("Legacy resource pack is using an invalid namespaced identifier '{}'! DO NOT use non [a-z0-9_.-] characters for resource pack files and file names!", id);
}
}

@Inject(method = "isPathCharacterValid", at = @At("RETURN"), cancellable = true)
@Inject(method = "isAllowedInIdentifier", at = @At("RETURN"), cancellable = true)
private static void animatica$allowInvalidCharacters(char character, CallbackInfoReturnable<Boolean> cir) {
if (Flags.ALLOW_INVALID_ID_CHARS) {
cir.setReturnValue(true);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.foundationgames.animatica.mixin;

import com.mojang.blaze3d.platform.NativeImage;
import io.github.foundationgames.animatica.accessor.NativeImageAccessor;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(NativeImage.class)
public class NativeImageMixin implements NativeImageAccessor {

@Override
public long animatica$getPixels() {
NativeImage $this = (NativeImage) (Object) this;
return $this.getPointer();
}
}
Loading