mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Players of the opposite faction will keep you from sleeping nearby
This commit is contained in:
parent
efc50c5cbd
commit
77f0915d82
3 changed files with 16 additions and 20 deletions
|
@ -1,5 +1,7 @@
|
|||
package com.minelittlepony.unicopia.entity.player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.minelittlepony.unicopia.Affinity;
|
||||
|
@ -24,8 +26,6 @@ import com.minelittlepony.unicopia.util.Copieable;
|
|||
import com.minelittlepony.common.util.animation.LinearInterpolator;
|
||||
import com.minelittlepony.common.util.animation.Interpolator;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
|
@ -33,13 +33,13 @@ import net.minecraft.entity.data.DataTracker;
|
|||
import net.minecraft.entity.data.TrackedData;
|
||||
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity.SleepFailureReason;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Unit;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
|
@ -269,8 +269,13 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
|||
return false;
|
||||
}
|
||||
|
||||
public Either<SleepFailureReason, Unit> trySleep(BlockPos pos) {
|
||||
return Either.right(Unit.INSTANCE);
|
||||
public Optional<Text> trySleep(BlockPos pos) {
|
||||
|
||||
if (findAllSpellsInRange(10).filter(p -> p instanceof Pony).map(Pony.class::cast).map(Pony::getSpecies).anyMatch(r -> r.isEnemy(getSpecies()))) {
|
||||
return Optional.of(new TranslatableText("block.unicopia.bed.not_safe"));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void onEat(ItemStack stack) {
|
||||
|
|
|
@ -59,9 +59,11 @@ abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<P
|
|||
cancellable = true)
|
||||
private void onTrySleep(BlockPos pos, CallbackInfoReturnable<Either<PlayerEntity.SleepFailureReason, Unit>> info) {
|
||||
if (!world.isClient) {
|
||||
Either<PlayerEntity.SleepFailureReason, Unit> result = get().trySleep(pos);
|
||||
get().trySleep(pos).ifPresent(reason -> {
|
||||
((PlayerEntity)(Object)this).sendMessage(reason, true);
|
||||
|
||||
result.ifLeft(reason -> info.setReturnValue(result));
|
||||
info.setReturnValue(Either.right(Unit.INSTANCE));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
|
||||
"block.unicopia.bed.youAreAMonster": "You may not rest here, you are the monster",
|
||||
"block.unicopia.bed.not_safe": "You may not rest here, there are enemies nearby",
|
||||
|
||||
"item.unicopia.green_apple": "Granny Smith Apple",
|
||||
"item.unicopia.sweet_apple": "Sweet Apple Acres Apple",
|
||||
|
@ -79,15 +79,6 @@
|
|||
"curse.siphon": "Siphoning",
|
||||
"curse.siphon.tagline": "Energy III",
|
||||
|
||||
"entity.unicopia.racing_cloud": "Bucking Bronco",
|
||||
"entity.unicopia.construction_cloud": "Construction Cloud",
|
||||
"entity.unicopia.cloud": "Cloud",
|
||||
"entity.unicopia.spell": "Magic",
|
||||
"entity.unicopia.spellbook": "Spellbook",
|
||||
"entity.unicopia.butterfly": "Butterfly",
|
||||
"entity.unicopia.spear": "Spear",
|
||||
"entity.unicopia.cucoon": "Cucoon",
|
||||
|
||||
"toxicity.safe.name": "Safe",
|
||||
"toxicity.mild.name": "Mildly Toxic",
|
||||
"toxicity.fair.name": "Fairly Toxic",
|
||||
|
@ -190,8 +181,6 @@
|
|||
"unicopia.power.feed": "Primary Changeling ability",
|
||||
"unicopia.power.disguise": "Secondary Changeling ability",
|
||||
|
||||
"unicopia.gui.title.bagofholding": "Bag of Holding",
|
||||
|
||||
"death.attack.alicorn_amulet": "%1$s was driven insane",
|
||||
"death.attack.darkness": "%1$s went missing",
|
||||
"death.attack.feed": "%1$s was drained of all life",
|
||||
|
|
Loading…
Reference in a new issue