Skip to content

Commit

Permalink
EMF Compatibility (#958)
Browse files Browse the repository at this point in the history
* emf compat

* fix server
  • Loading branch information
alex-s168 authored Sep 23, 2024
1 parent 17a8173 commit 0834473
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ dependencies {
modCompileOnly("curse.maven:ftb-teams-404468:4229138")
modCompileOnly("curse.maven:ftb-chunks-314906:4229120")

// EMF compat
modCompileOnly("curse.maven:entity-model-features-844662:5696901")
modCompileOnly("curse.maven:entity-texture-features-fabric-568563:5697084")

//Common create compat,
//We just use a version from a platform and hope the classes exist on both versions and mixins apply correctly
modCompileOnly("com.simibubi.create:create-fabric-${minecraft_version}:${create_fabric_version}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.valkyrienskies.mod.mixin.mod_compat.emf;

import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
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.CallbackInfoReturnable;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import traben.entity_model_features.models.animation.EMFAnimationEntityContext;
import traben.entity_model_features.utils.EMFEntity;

@Mixin(EMFAnimationEntityContext.class)
public class MixinEMFAnimationEntityContext {
@Shadow
private static EMFEntity IEMFEntity;

@Inject(
at = @At("HEAD"),
method = "distanceOfEntityFrom",
cancellable = true
)
private static void distanceOfEntityFrom(final BlockPos pos, final CallbackInfoReturnable<Integer> cir) {
if (IEMFEntity != null) {
final var level = Minecraft.getInstance().level;
final var posW = VSGameUtilsKt.toWorldCoordinates(level, Vec3.atCenterOf(pos));
final var entityW = VSGameUtilsKt.toWorldCoordinates(level, Vec3.atCenterOf(IEMFEntity.etf$getBlockPos()));
final var dist = posW.distanceTo(entityW);
cir.setReturnValue((int) dist);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.valkyrienskies.mod.mixin.mod_compat.etf;

import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import traben.entity_texture_features.utils.ETFEntity;

@Mixin(value = BlockEntity.class, priority = 1200)
public abstract class MixinBlockEntity implements ETFEntity {
@Override
public float etf$distanceTo(final Entity entity) {
final var level = Minecraft.getInstance().level;
final var aW = VSGameUtilsKt.toWorldCoordinates(level, Vec3.atCenterOf(etf$getBlockPos()));
final var bW = VSGameUtilsKt.toWorldCoordinates(level, entity.position());
final var dist = aW.distanceTo(bW);
return (float) dist;
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/valkyrienskies-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
"mod_compat.vanilla_renderer.MixinLevelRendererVanilla",
"mod_compat.vanilla_renderer.MixinViewAreaVanilla",
"mod_compat.vanilla_renderer.RenderChunkInfoAccessor",
"mod_compat.emf.MixinEMFAnimationEntityContext",
"mod_compat.etf.MixinBlockEntity",
"realms.MixinRealmsConnect"
],
"injectors": {
Expand Down

0 comments on commit 0834473

Please sign in to comment.