Allow sleeping without bed

This commit is contained in:
Bartek Bok committed 2016-01-17 00:43:29 +01:00
1 parent accf6cf218
commit fae5ff67ed
4 files changed
+188 -17

No files matched your search

@@ -65,6 +65,7 @@ import net.minecraftforge.event.entity.player.PlayerSetSpawnEvent;
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
import net.minecraftforge.event.entity.player.PlayerWakeUpEvent;
import net.minecraftforge.event.entity.player.SleepingLocationCheckEvent;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent;
@@ -500,4 +501,17 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(event);
return event.getCapabilities().size() > 0 ? new CapabilityDispatcher(event.getCapabilities(), parent) : null;
}
public static boolean fireSleepingLocationCheck(EntityPlayer player, BlockPos sleepingLocation)
{
SleepingLocationCheckEvent evt = new SleepingLocationCheckEvent(player, sleepingLocation);
MinecraftForge.EVENT_BUS.post(evt);
Result canContinueSleep = evt.getResult();
if (canContinueSleep == Result.DEFAULT)
return player.worldObj.getBlockState(player.playerLocation).getBlock().isBed(player.worldObj, player.playerLocation, player);
else
return canContinueSleep == Result.ALLOW;
}
}
@@ -0,0 +1,28 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockPos;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
/**
* This event is fired when game checks, if sleeping player should be still considered "in bed".<br>
* Failing this check will cause player to wake up.<br>
*
* This event has a result. {@link HasResult}<br>
*
* setResult(ALLOW) informs game that player is still "in bed"<br>
* setResult(DEFAULT) causes game to check {@link net.minecraft.block.Block#isBed(net.minecraft.world.IBlockAccess, BlockPos, net.minecraft.entity.Entity)} instead
*/
@HasResult
public class SleepingLocationCheckEvent extends PlayerEvent
{
public final BlockPos sleepingLocation;
public SleepingLocationCheckEvent(EntityPlayer player, BlockPos sleepingLocation)
{
super(player);
this.sleepingLocation = sleepingLocation;
}
}