Skip to content

Commit

Permalink
Add pose power type and change impl. of crawling power type
Browse files Browse the repository at this point in the history
* The `crawling` power type now uses the `pose` power type as its base
  • Loading branch information
eggohito committed Feb 6, 2024
1 parent 0dcd748 commit 57a646a
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.command.EntitySelector;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.argument.ScoreHolderArgumentType;
import net.minecraft.entity.EntityPose;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.entry.RegistryEntry;
Expand Down Expand Up @@ -334,4 +335,6 @@ public class EggolibDataTypes {

public static final SerializableDataType<List<NbtOperation>> NBT_OPERATIONS = SerializableDataType.list(NBT_OPERATION);

public static final SerializableDataType<EntityPose> ENTITY_POSE = SerializableDataType.enumValue(EntityPose.class);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.github.eggohito.eggolib.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import io.github.apace100.apoli.component.PowerHolderComponent;
import io.github.eggohito.eggolib.power.ModelFlipPower;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.LivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -19,4 +21,9 @@ public abstract class LivingEntityRendererMixin {
}
}

@ModifyExpressionValue(method = "setupTransforms", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isUsingRiptide()Z"))
private boolean eggolib$inRiptidePose(boolean original, LivingEntity entity) {
return original || entity.isInPose(EntityPose.SPIN_ATTACK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import io.github.apace100.apoli.component.PowerHolderComponent;
import io.github.apace100.apoli.power.Prioritized;
import io.github.eggohito.eggolib.power.ActionOnCriticalHitPower;
import io.github.eggohito.eggolib.power.CrawlingPower;
import io.github.eggohito.eggolib.power.PreventCriticalHitPower;
import io.github.eggohito.eggolib.power.PrioritizedPower;
import io.github.eggohito.eggolib.power.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
Expand All @@ -22,6 +19,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Comparator;
import java.util.List;

@Mixin(PlayerEntity.class)
Expand Down Expand Up @@ -100,10 +98,16 @@ protected PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World
}

@Inject(method = "updatePose", at = @At("HEAD"), cancellable = true)
private void eggolib$forceCrawlPose(CallbackInfo ci) {
if (PowerHolderComponent.hasPower(this, CrawlingPower.class)) {
ci.cancel();
}
private void eggolib$forcePose(CallbackInfo ci) {

PowerHolderComponent.getPowers(this, PosePower.class)
.stream()
.max(Comparator.comparing(PosePower::getPriority))
.ifPresent(p -> {
this.setPose(p.getPose());
ci.cancel();
});

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.github.eggohito.eggolib.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.PlayerEntityRenderer;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.entity.EntityPose;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(PlayerEntityRenderer.class)
public abstract class PlayerEntityRendererMixin extends LivingEntityRenderer<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> {

private PlayerEntityRendererMixin(EntityRendererFactory.Context ctx, PlayerEntityModel<AbstractClientPlayerEntity> model, float shadowRadius) {
super(ctx, model, shadowRadius);
}

@Unique
private int eggolib$pseudoRoll = 0;

@ModifyExpressionValue(method = "setupTransforms(Lnet/minecraft/client/network/AbstractClientPlayerEntity;Lnet/minecraft/client/util/math/MatrixStack;FFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;isFallFlying()Z"))
private boolean eggolib$inFallFlyingPose(boolean original, AbstractClientPlayerEntity player, @Share("applyPseudoRoll") LocalBooleanRef applyPseudoRollRef) {

if (original || player.isInPose(EntityPose.FALL_FLYING)) {

if (player.isInPose(EntityPose.FALL_FLYING)) {
applyPseudoRollRef.set(true);
++eggolib$pseudoRoll;
}

return true;

}

this.eggolib$pseudoRoll = 0;
return false;

}

@ModifyExpressionValue(method = "setupTransforms(Lnet/minecraft/client/network/AbstractClientPlayerEntity;Lnet/minecraft/client/util/math/MatrixStack;FFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;getRoll()I"))
private int eggolib$applyPseudoRoll(int original, AbstractClientPlayerEntity player, @Share("applyPseudoRoll") LocalBooleanRef applyPseudoRollRef) {
return applyPseudoRollRef.get()
? eggolib$pseudoRoll
: original;
}

}
22 changes: 8 additions & 14 deletions src/main/java/io/github/eggohito/eggolib/power/CrawlingPower.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
package io.github.eggohito.eggolib.power;

import io.github.apace100.apoli.power.Power;
import io.github.apace100.apoli.power.PowerType;
import io.github.apace100.apoli.power.factory.PowerFactory;
import io.github.apace100.calio.data.SerializableData;
import io.github.apace100.calio.data.SerializableDataTypes;
import io.github.eggohito.eggolib.Eggolib;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.LivingEntity;

public class CrawlingPower extends Power {
public class CrawlingPower extends PosePower {

public CrawlingPower(PowerType<?> powerType, LivingEntity livingEntity) {
super(powerType, livingEntity);
this.setTicking();
}

@Override
public void tick() {
if (!entity.isCrawling()) {
entity.setPose(EntityPose.SWIMMING);
}
public CrawlingPower(PowerType<?> powerType, LivingEntity livingEntity, int priority) {
super(powerType, livingEntity, EntityPose.SWIMMING, priority);
}

public static PowerFactory<?> getFactory() {
return new PowerFactory<>(
Eggolib.identifier("crawling"),
new SerializableData(),
new SerializableData()
.add("priority", SerializableDataTypes.INT, 0),
data -> (powerType, livingEntity) -> new CrawlingPower(
powerType,
livingEntity
livingEntity,
data.get("priority")
)
).allowCondition();
}
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/io/github/eggohito/eggolib/power/PosePower.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.eggohito.eggolib.power;

import io.github.apace100.apoli.power.Power;
import io.github.apace100.apoli.power.PowerType;
import io.github.apace100.apoli.power.Prioritized;
import io.github.apace100.apoli.power.factory.PowerFactory;
import io.github.apace100.calio.data.SerializableData;
import io.github.apace100.calio.data.SerializableDataTypes;
import io.github.eggohito.eggolib.Eggolib;
import io.github.eggohito.eggolib.data.EggolibDataTypes;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.LivingEntity;

public class PosePower extends Power implements Prioritized<PosePower> {

private final EntityPose pose;
private final int priority;

public PosePower(PowerType<?> type, LivingEntity entity, EntityPose pose, int priority) {
super(type, entity);
this.pose = pose;
this.priority = priority;
}

@Override
public int getPriority() {
return priority;
}

public EntityPose getPose() {
return pose;
}

public static PowerFactory<?> getFactory() {
return new PowerFactory<>(
Eggolib.identifier("pose"),
new SerializableData()
.add("pose", EggolibDataTypes.ENTITY_POSE)
.add("priority", SerializableDataTypes.INT, 0),
data -> (powerType, entity) -> new PosePower(
powerType,
entity,
data.get("pose"),
data.get("priority")
)
).allowCondition();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static void register() {
register(ModifyMouseSensitivityPower.getFactory());
register(PreventCriticalHitPower.getFactory());
register(PreventKeyUsePower.getFactory());
register(PosePower.getFactory());
}

public static PowerFactory<?> register(PowerFactory<?> powerFactory) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/eggolib.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"LivingEntityRendererMixin",
"MinecraftClientMixin",
"MouseMixin",
"PlayerEntityRendererMixin",
"apace100.apoli.ApoliClientMixin"
],
"server": [],
Expand Down

0 comments on commit 57a646a

Please sign in to comment.