Unicopia/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java

82 lines
3.4 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.mixin;
2020-01-16 12:35:46 +01:00
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.ModifyVariable;
2020-01-27 11:05:22 +01:00
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2020-01-16 12:35:46 +01:00
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
2020-04-15 18:12:00 +02:00
import com.minelittlepony.unicopia.ducks.PonyContainer;
import com.minelittlepony.unicopia.entity.Ponylike;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.entity.player.PlayerImpl;
2020-01-16 12:35:46 +01:00
import com.mojang.datafixers.util.Either;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityPose;
2020-01-16 12:35:46 +01:00
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Unit;
import net.minecraft.util.math.BlockPos;
2020-01-27 11:05:22 +01:00
import net.minecraft.world.GameMode;
2020-01-16 12:35:46 +01:00
@Mixin(PlayerEntity.class)
abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<Pony> {
2020-01-16 12:35:46 +01:00
private MixinPlayerEntity() { super(null, null); }
@Override
2020-04-15 18:12:00 +02:00
public Ponylike create() {
return new PlayerImpl((PlayerEntity)(Object)this);
2020-01-16 12:35:46 +01:00
}
@ModifyVariable(method = "handleFallDamage(FF)Z",
2020-01-16 12:35:46 +01:00
at = @At("HEAD"),
ordinal = 0,
argsOnly = true)
2020-01-16 12:35:46 +01:00
private float onHandleFallDamage(float distance) {
2020-04-15 18:12:00 +02:00
return get().onImpact(distance);
2020-01-16 12:35:46 +01:00
}
@Inject(method = "trySleep(Lnet/minecraft/util/math/BlockPos;)Lcom/mojang/datafixers/util/Either;",
at = @At("HEAD"),
cancellable = true)
private void onTrySleep(BlockPos pos, CallbackInfoReturnable<Either<PlayerEntity.SleepFailureReason, Unit>> info) {
if (!world.isClient) {
2020-04-15 18:12:00 +02:00
Either<PlayerEntity.SleepFailureReason, Unit> result = get().trySleep(pos);
2020-01-16 12:35:46 +01:00
result.ifLeft(reason -> info.setReturnValue(result));
}
}
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;",
at = @At("HEAD"))
private void onDropItem(ItemStack itemStack_1, boolean a, boolean b, CallbackInfoReturnable<ItemEntity> info) {
2020-04-15 18:12:00 +02:00
PonyContainer.of(info.getReturnValue()).ifPresent(o -> {
o.get().setSpecies(get().getSpecies());
2020-01-16 12:35:46 +01:00
});
}
2020-01-27 11:05:22 +01:00
@Inject(method = "setGameMode(Lnet/minecraft/world/GameMode;)V",
at = @At("RETURN"))
private void onSetGameMode(GameMode mode, CallbackInfo info) {
2020-04-15 18:12:00 +02:00
get().setSpecies(get().getSpecies());
2020-01-27 11:05:22 +01:00
}
@Inject(method = "getActiveEyeHeight(Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntityDimensions;)F",
at = @At("RETURN"),
cancellable = true)
private void onGetActiveEyeHeight(EntityPose pose, EntityDimensions dimensions, CallbackInfoReturnable<Float> info) {
info.setReturnValue(get().getGravity().getDimensions().getActiveEyeHeight(info.getReturnValue()));
}
@Inject(method = "getDimensions(Lnet/minecraft/entity/EntityPose;)Lnet/minecraft/entity/EntityDimensions;",
at = @At("RETURN"),
cancellable = true)
public void onGetDimensions(EntityPose pose, CallbackInfoReturnable<EntityDimensions> info) {
info.setReturnValue(get().getGravity().getDimensions().getDimensions(pose, info.getReturnValue()));
}
2020-01-16 12:35:46 +01:00
}