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) { IBlockState state = player.worldObj.getBlockState(player.bedLocation); return state.getBlock().isBed(state, player.worldObj, player.bedLocation, player); } else return canContinueSleep == Result.ALLOW; }
@SubscribeEvent public void onBedCheck(SleepingLocationCheckEvent event) { EntityPlayer p = event.getEntityPlayer(); final IPlayerExtendedProperties sleep = p.getCapability(ModCyclic.CAPABILITYSTORAGE, null); if (sleep != null && sleep.isSleeping()) { if (p.isSneaking()) { //you want to cancel, ok sleep.setSleeping(false); } else { p.bedLocation = p.getPosition(); event.setResult(Result.ALLOW); } } }
@SubscribeEvent public void onBedCheck(SleepingLocationCheckEvent evt) { if (isWearingSleepingBag(evt.getEntityPlayer())) evt.setResult(Result.ALLOW); }