Monsers can't sleep in beds

This commit is contained in:
Sollace 2019-02-18 21:13:39 +02:00
parent de202d131b
commit 37ef2c0199
4 changed files with 43 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import net.minecraftforge.event.entity.item.ItemTossEvent;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
@ -44,6 +45,13 @@ class Hooks {
.forEach(item -> item.setPlayerSpecies(race));
}
@SubscribeEvent
public static void onPlayerTrySleep(PlayerSleepInBedEvent event) {
if (event.getResultStatus() == null) {
event.setResult(PlayerSpeciesList.instance().getPlayer(event.getEntityPlayer()).trySleep(event.getPos()));
}
}
@SubscribeEvent
public static void onPlayerFall(PlayerFlyableFallEvent event) {
PlayerSpeciesList.instance().getPlayer(event.getEntityPlayer()).onFall(event.getDistance(), event.getMultiplier());

View file

@ -13,9 +13,11 @@ import com.mojang.authlib.GameProfile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayer.SleepResult;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.FMLCommonHandler;
/**
@ -127,6 +129,15 @@ public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPla
*/
boolean onProjectileImpact(Entity projectile);
/**
* Attempts to sleep in a bed.
*
* @param pos The position of the bed
*
* @return The sleep result.
*/
SleepResult trySleep(BlockPos pos);
/**
* Returns true if this player is the use.
*/

View file

@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.enchanting.PageState;
import com.minelittlepony.unicopia.init.UEffects;
import com.minelittlepony.unicopia.init.UItems;
import com.minelittlepony.unicopia.network.EffectSync;
import com.minelittlepony.unicopia.network.MsgPlayerCapabilities;
import com.minelittlepony.unicopia.spell.IMagicEffect;
@ -21,6 +22,7 @@ import com.minelittlepony.unicopia.spell.SpellRegistry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.EntityPlayer.SleepResult;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
@ -32,6 +34,8 @@ import net.minecraft.network.play.server.SPacketSetPassengers;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.EnumDifficulty;
class PlayerCapabilities implements IPlayer {
@ -268,6 +272,24 @@ class PlayerCapabilities implements IPlayer {
return false;
}
@Override
public SleepResult trySleep(BlockPos pos) {
if (getInventory().isWearing(UItems.alicorn_amulet)) {
if (!getWorld().isRemote) {
entity.sendStatusMessage(new TextComponentTranslation("tile.bed.youAreAMonster"), true);
}
return SleepResult.OTHER_PROBLEM;
}
if (findAllSpellsInRange(10).anyMatch(c -> c instanceof IPlayer && ((IPlayer)c).getInventory().isWearing(UItems.alicorn_amulet))) {
return SleepResult.NOT_SAFE;
}
return null;
}
@Override
public IFood getFood() {
return food;

View file

@ -32,6 +32,8 @@ item.staff_meadow_brook.tagline=It's a big stick
item.alicorn_amulet.name=The Alicorn Amulet
item.alicorn_amulet.tagline=Time Worn: %s
tile.bed.youAreAMonster=You may not rest here, you are the monster
item.gem.name=Gem
item.gem.enchanted.name=Gem of %s
item.corrupted_gem.name=Fractured Gem