2020-04-15 14:22:03 +02:00
|
|
|
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;
|
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-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.PonyContainer;
|
|
|
|
import com.minelittlepony.unicopia.entity.Equine;
|
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2020-01-16 12:35:46 +01:00
|
|
|
import com.mojang.datafixers.util.Either;
|
|
|
|
|
2021-01-27 12:16:05 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
2020-04-23 23:44:31 +02:00
|
|
|
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;
|
2020-06-26 11:44:47 +02:00
|
|
|
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2020-09-25 22:59:36 +02:00
|
|
|
import net.minecraft.stat.Stats;
|
2020-01-16 12:35:46 +01:00
|
|
|
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-05-05 18:48:12 +02:00
|
|
|
import net.minecraft.world.World;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
@Mixin(PlayerEntity.class)
|
2020-04-24 17:10:45 +02:00
|
|
|
abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<Pony> {
|
2020-01-16 12:35:46 +01:00
|
|
|
private MixinPlayerEntity() { super(null, null); }
|
|
|
|
|
|
|
|
@Override
|
2020-09-22 15:11:20 +02:00
|
|
|
public Equine<?> create() {
|
2020-05-10 17:18:45 +02:00
|
|
|
return new Pony((PlayerEntity)(Object)this);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
2020-09-25 22:59:36 +02:00
|
|
|
@Inject(method = "handleFallDamage(FF)Z", at = @At("HEAD"), cancellable = true)
|
|
|
|
private void onHandleFallDamage(float distance, float damageMultiplier, CallbackInfoReturnable<Boolean> info) {
|
|
|
|
get().onImpact(fallDistance, damageMultiplier).ifPresent(newDistance -> {
|
|
|
|
PlayerEntity self = (PlayerEntity)(Object)this;
|
|
|
|
|
|
|
|
if (newDistance >= 2) {
|
|
|
|
self.increaseStat(Stats.FALL_ONE_CM, Math.round(newDistance * 100));
|
|
|
|
}
|
|
|
|
|
|
|
|
info.setReturnValue(super.handleFallDamage(newDistance, damageMultiplier));
|
|
|
|
});
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
2020-06-26 11:44:47 +02:00
|
|
|
@Inject(method = "createPlayerAttributes()Lnet/minecraft/entity/attribute/DefaultAttributeContainer$Builder;", at = @At("RETURN"))
|
|
|
|
private static void onCreateAttributes(CallbackInfoReturnable<DefaultAttributeContainer.Builder> info) {
|
|
|
|
Pony.registerAttributes(info.getReturnValue());
|
|
|
|
}
|
|
|
|
|
2020-05-31 23:14:12 +02:00
|
|
|
@Inject(method = "eatFood(Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;",
|
2020-05-05 18:48:12 +02:00
|
|
|
at = @At("HEAD"))
|
2021-01-27 12:16:05 +01:00
|
|
|
private void onEatFood(World world, ItemStack stack, CallbackInfoReturnable<ItemStack> info) {
|
2020-05-05 18:48:12 +02:00
|
|
|
if (stack.isFood()) {
|
|
|
|
get().onEat(stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-09-23 17:41:24 +02:00
|
|
|
get().trySleep(pos).ifPresent(reason -> {
|
|
|
|
((PlayerEntity)(Object)this).sendMessage(reason, true);
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-09-23 17:41:24 +02:00
|
|
|
info.setReturnValue(Either.right(Unit.INSTANCE));
|
|
|
|
});
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;",
|
2020-04-26 16:48:48 +02:00
|
|
|
at = @At("RETURN"))
|
|
|
|
private void onDropItem(ItemStack itemStack_1, boolean scatter, boolean retainOwnership, CallbackInfoReturnable<ItemEntity> info) {
|
|
|
|
PonyContainer.of(info.getReturnValue()).ifPresent(container -> {
|
|
|
|
container.get().setSpecies(get().getSpecies());
|
2021-02-21 22:18:15 +01:00
|
|
|
container.get().getPhysics().setBaseGravityModifier(get().getPhysics().getGravityModifier());
|
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"))
|
2020-04-23 23:44:31 +02:00
|
|
|
private void onSetGameMode(GameMode mode, CallbackInfo info) {
|
2020-04-15 18:12:00 +02:00
|
|
|
get().setSpecies(get().getSpecies());
|
2020-05-10 17:18:45 +02:00
|
|
|
get().setDirty();
|
2020-01-27 11:05:22 +01:00
|
|
|
}
|
2020-04-23 23:44:31 +02: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) {
|
2020-09-29 19:18:25 +02:00
|
|
|
info.setReturnValue(get().getMotion().getDimensions().calculateActiveEyeHeight(dimensions, info.getReturnValue()));
|
2020-04-24 17:10:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Inject(method = "getDimensions(Lnet/minecraft/entity/EntityPose;)Lnet/minecraft/entity/EntityDimensions;",
|
|
|
|
at = @At("RETURN"),
|
|
|
|
cancellable = true)
|
2021-01-27 12:16:05 +01:00
|
|
|
private void onGetDimensions(EntityPose pose, CallbackInfoReturnable<EntityDimensions> info) {
|
2020-09-29 19:18:25 +02:00
|
|
|
info.setReturnValue(get().getMotion().getDimensions().calculateDimensions(info.getReturnValue()));
|
2020-04-23 23:44:31 +02:00
|
|
|
}
|
2021-01-27 12:16:05 +01:00
|
|
|
|
|
|
|
@Inject(method = "getBlockBreakingSpeed(Lnet/minecraft/block/BlockState;)F",
|
|
|
|
at = @At("RETURN"),
|
|
|
|
cancellable = true)
|
|
|
|
private void onGetBlockBreakingSpeed(BlockState state, CallbackInfoReturnable<Float> info) {
|
|
|
|
info.setReturnValue(info.getReturnValue() * get().getBlockBreakingSpeed());
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|