2020-05-29 20:13:10 +02:00
|
|
|
package com.minelittlepony.unicopia.mixin;
|
|
|
|
|
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
2021-08-26 18:51:58 +02:00
|
|
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
2020-05-29 20:13:10 +02:00
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
2023-04-30 13:34:20 +02:00
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
2020-05-29 20:13:10 +02:00
|
|
|
|
2022-12-25 16:01:12 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.Equine;
|
2022-09-11 16:58:42 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.duck.ServerPlayerEntityDuck;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2023-04-30 13:34:20 +02:00
|
|
|
import com.minelittlepony.unicopia.server.world.UGameRules;
|
|
|
|
import com.mojang.datafixers.util.Either;
|
|
|
|
|
2020-05-29 20:13:10 +02:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2020-06-26 11:44:47 +02:00
|
|
|
import net.minecraft.screen.ScreenHandlerListener;
|
2020-05-29 20:13:10 +02:00
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
2023-04-30 13:34:20 +02:00
|
|
|
import net.minecraft.text.Text;
|
|
|
|
import net.minecraft.util.Unit;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-05-29 20:13:10 +02:00
|
|
|
|
|
|
|
@Mixin(ServerPlayerEntity.class)
|
2022-12-25 16:01:12 +01:00
|
|
|
abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHandlerListener, Equine.Container<Pony>, ServerPlayerEntityDuck {
|
2022-12-18 22:07:24 +01:00
|
|
|
MixinServerPlayerEntity() {super(null, null, 0, null);}
|
2020-05-29 20:13:10 +02:00
|
|
|
|
2021-08-26 18:51:58 +02:00
|
|
|
@Override
|
|
|
|
@Accessor("inTeleportationState")
|
|
|
|
public abstract void setPreventMotionChecks(boolean enabled);
|
|
|
|
|
2020-05-29 20:13:10 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Inject(method = "copyFrom(Lnet/minecraft/server/network/ServerPlayerEntity;Z)V", at = @At("HEAD"))
|
|
|
|
private void onCopyFrom(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
|
2023-01-27 19:06:06 +01:00
|
|
|
get().copyFrom(((Equine.Container<Pony>)oldPlayer).get(), alive);
|
2020-05-29 20:13:10 +02:00
|
|
|
}
|
2021-08-26 18:51:58 +02:00
|
|
|
|
2023-04-30 13:34:20 +02:00
|
|
|
@Inject(method = "trySleep(Lnet/minecraft/util/math/BlockPos;)Lcom/mojang/datafixers/util/Either;",
|
|
|
|
at = @At(value = "FIELD", target = "net/minecraft/entity/player/PlayerEntity$SleepFailureReason.NOT_POSSIBLE_NOW"),
|
|
|
|
cancellable = true)
|
|
|
|
private void onTrySleep(BlockPos pos, CallbackInfoReturnable<Either<PlayerEntity.SleepFailureReason, Unit>> info) {
|
|
|
|
if (get().getActualSpecies().isNocturnal() && get().asWorld().getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES)) {
|
|
|
|
((PlayerEntity)this).sendMessage(Text.translatable("block.minecraft.bed.no_sleep.nocturnal"), true);
|
|
|
|
|
|
|
|
info.setReturnValue(Either.left(PlayerEntity.SleepFailureReason.OTHER_PROBLEM));
|
|
|
|
}
|
2023-04-30 02:41:21 +02:00
|
|
|
}
|
2020-05-29 20:13:10 +02:00
|
|
|
}
|