Skip to content

Commit

Permalink
AzureLib兼容修复,版本1.20.1-1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ChloePrime committed May 26, 2024
1 parent d2f23e1 commit 89f2466
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 4 deletions.
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ subprojects {
name = "Fuzs Mod Resources (Forge Config API Port)"
url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/"
}
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
// AzureLib
// maven {url 'https://libs.azuredoom.com:4443/mods'}
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies {
// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury:${rootProject.architectury_version}"
modApi "fuzs.forgeconfigapiport:forgeconfigapiport-common:${rootProject.forge_config_api_version}"
modImplementation "maven.modrinth:azurelib:${rootProject.azurelib_version_fabric}"
}

architectury {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected EntityPieceParticle(Entity entity, ClientLevel level, double x, double
this.lifetime += random.nextInt(40, 100);

var tex = getEntityTexture(entity);
this.valid = tex.isPresent();
this.valid = tex.filter(t -> t.width >= SIZE && t.height >= SIZE).isPresent();
this.texture = valid ? tex.get().texture : MissingTextureAtlasSprite.getLocation();
var w = valid ? tex.get().width : 1;
var h = valid ? tex.get().height : 1;
Expand Down Expand Up @@ -62,7 +62,7 @@ public static Optional<EntityTextureInfo> getEntityTexture(Entity entity) {
}

return texture
.map(tex -> MC.getTextureManager().getTexture(tex))
.map(MC.getTextureManager()::getTexture)
.map(tex -> tex instanceof SizedTexture simple ? simple : null)
.map(tex -> new EntityTextureInfo(texture.get(), tex.hit_feedback$getWidth(), tex.hit_feedback$getHeight(), tex.hit_feedback$getFillRate()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package mod.chloeprime.hitfeedback.mixin.compat.azurelib.client;

import com.mojang.blaze3d.platform.NativeImage;
import mod.azure.azurelib.cache.texture.AnimatableTexture;
import mod.chloeprime.hitfeedback.client.internal.SizedTexture;
import mod.chloeprime.hitfeedback.util.ImageHelper;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.resources.metadata.animation.AnimationMetadataSection;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.io.IOException;

@Mixin(value = AnimatableTexture.class, remap = false)
public class MixinAzureLibTexture extends SimpleTexture implements SizedTexture {
private @Unique int hit_feedback$w;
private @Unique int hit_feedback$h;
private volatile @Unique float hit_feedback$fillRate = 0.6F;

@Override
public int hit_feedback$getWidth() {
return hit_feedback$w;
}

@Override
public int hit_feedback$getHeight() {
return hit_feedback$h;
}

@Override
public float hit_feedback$getFillRate() {
return hit_feedback$fillRate;
}

// 计算每帧的图像大小

@Inject(method = "load", at = @At("RETURN"), remap = true)
private void calculateFrameSize(ResourceManager manager, CallbackInfo ci) throws IOException {
var res = manager.getResource(location);
if (res.isEmpty()) {
return;
}
var resource = res.get();

int w, h;
try (var imageFile = resource.open()) {
try (var image = NativeImage.read(imageFile)) {
w = image.getWidth();
h = image.getHeight();
hit_feedback$fillRate = ImageHelper.getFillRate(image);

var meta = resource.metadata();
meta.getSection(AnimationMetadataSection.SERIALIZER).ifPresentOrElse(section -> {
var size = section.calculateFrameSize(w, h);
hit_feedback$w = size.width();
hit_feedback$h = size.height();
}, () -> {
hit_feedback$w = image.getWidth();
hit_feedback$h = image.getHeight();
});
}
}
}

public MixinAzureLibTexture(ResourceLocation location) {
super(location);
}
}
3 changes: 2 additions & 1 deletion common/src/main/resources/hit_feedback-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"client": [
"MixinSimpleTexture",
"client.ParticleEngineAccessor",
"client.TrackingEmitterAccessor"
"client.TrackingEmitterAccessor",
"compat.azurelib.client.MixinAzureLibTexture"
],
"injectors": {
"defaultRequire": 1
Expand Down
1 change: 1 addition & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}"
modApi "fuzs.forgeconfigapiport:forgeconfigapiport-fabric:${rootProject.forge_config_api_version}"
compileOnly 'com.electronwill.night-config:toml:3.6.4'
modImplementation "maven.modrinth:azurelib:${rootProject.azurelib_version_fabric}"

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
Expand Down
2 changes: 2 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ loom {
"hit_feedback.mixins.json",
"hit_feedback-common.mixins.json"
]
convertAccessWideners = true
}
}

Expand All @@ -27,6 +28,7 @@ dependencies {
forge "net.minecraftforge:forge:${rootProject.forge_version}"
// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}"
modImplementation "maven.modrinth:azurelib:${rootProject.azurelib_version_forge}"

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minecraft_version=1.20.1
parchment_version=2023.09.03

archives_base_name=HitFeedback
mod_version=1.20.1-1.1.1
mod_version=1.20.1-1.1.2
maven_group=mod.chloeprime

architectury_version=9.2.14
Expand All @@ -14,3 +14,6 @@ fabric_api_version=0.92.1+1.20.1

forge_version=1.20.1-47.2.32
forge_config_api_version=8.0.0

azurelib_version_forge=2.0.22
azurelib_version_fabric=ObfJleQ4

0 comments on commit 89f2466

Please sign in to comment.