Search in sources :

Example 1 with IPlayerData

use of cavern.api.IPlayerData in project Cavern2 by kegare.

the class CaveEventHooks method onPlayerSleepInBed.

@SubscribeEvent
public void onPlayerSleepInBed(PlayerSleepInBedEvent event) {
    EntityPlayer player = event.getEntityPlayer();
    if (!CavernAPI.dimension.isInCaveDimensions(player)) {
        return;
    }
    SleepResult result = null;
    World world = player.world;
    if (!world.isRemote) {
        IPlayerData data = PlayerData.get(player);
        long worldTime = world.getTotalWorldTime();
        long sleepTime = data.getLastSleepTime();
        if (sleepTime <= 0L) {
            sleepTime = worldTime;
            data.setLastSleepTime(sleepTime);
        }
        long requireTime = GeneralConfig.sleepWaitTime * 20;
        if (sleepTime + requireTime > worldTime) {
            result = SleepResult.OTHER_PROBLEM;
            long remainTime = requireTime - (worldTime - sleepTime);
            int min = MathHelper.ceil(remainTime / 20 / 60 + 1);
            player.sendStatusMessage(new TextComponentTranslation("cavern.message.sleep.still", min), true);
        }
    }
    if (result == null) {
        result = PlayerHelper.trySleep(player, event.getPos());
    }
    if (!world.isRemote && result == SleepResult.OK) {
        PlayerData.get(player).setLastSleepTime(world.getTotalWorldTime());
    }
    event.setResult(result);
}
Also used : SleepResult(net.minecraft.entity.player.EntityPlayer.SleepResult) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IPlayerData(cavern.api.IPlayerData) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IPlayerData

use of cavern.api.IPlayerData in project Cavern2 by kegare.

the class CaveCapabilities method onPlayerClone.

@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone event) {
    EntityPlayer player = event.getEntityPlayer();
    if (player.world.isRemote) {
        return;
    }
    EntityPlayer original = event.getOriginal();
    IPortalCache originalPortalCache = getCapability(original, PORTAL_CACHE);
    IPortalCache portalCache = getCapability(player, PORTAL_CACHE);
    if (originalPortalCache != null && portalCache != null) {
        NBTTagCompound nbt = new NBTTagCompound();
        originalPortalCache.writeToNBT(nbt);
        portalCache.readFromNBT(nbt);
    }
    IPlayerData originalPlayerData = getCapability(original, PLAYER_DATA);
    IPlayerData playerData = getCapability(player, PLAYER_DATA);
    if (originalPlayerData != null && playerData != null) {
        NBTTagCompound nbt = new NBTTagCompound();
        originalPlayerData.writeToNBT(nbt);
        playerData.readFromNBT(nbt);
    }
    IMinerStats originalMinerStats = getCapability(original, MINER_STATS);
    IMinerStats minerStats = getCapability(player, MINER_STATS);
    if (originalMinerStats != null && minerStats != null) {
        NBTTagCompound nbt = new NBTTagCompound();
        originalMinerStats.writeToNBT(nbt);
        minerStats.readFromNBT(nbt);
    }
}
Also used : IPortalCache(cavern.api.IPortalCache) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IPlayerData(cavern.api.IPlayerData) IMinerStats(cavern.api.IMinerStats) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IPlayerData (cavern.api.IPlayerData)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IMinerStats (cavern.api.IMinerStats)1 IPortalCache (cavern.api.IPortalCache)1 SleepResult (net.minecraft.entity.player.EntityPlayer.SleepResult)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 World (net.minecraft.world.World)1