public void onSleepSuccess(World world, EnumHand hand, ItemStack stack, EntityPlayerMP player, final IPlayerExtendedProperties sleep) { sleep.setSleeping(true); if (doPotions) { player.addPotionEffect(new PotionEffect(MobEffects.MINING_FATIGUE, seconds * Const.TICKS_PER_SEC, Const.Potions.I)); player.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, seconds * Const.TICKS_PER_SEC, Const.Potions.I)); } this.onUse(stack, player, world, hand); //hack because vanilla/forge has that java.lang.IllegalArgumentException: Cannot get property PropertyDirection error with assuming its a bed when its blocks.air ObfuscationReflectionHelper.setPrivateValue(EntityPlayer.class, player, true, "sleeping", "field_71083_bS"); ObfuscationReflectionHelper.setPrivateValue(EntityPlayer.class, player, 0, "sleepTimer", "field_71076_b"); UtilChat.addChatMessage(player, this.getUnlocalizedName() + ".trying"); //first set bed location player.bedLocation = player.getPosition(); ModCyclic.network.sendTo(new PacketSleepClient(player.bedLocation), player); //then stop player in place player.motionX = player.motionZ = player.motionY = 0; world.updateAllPlayersSleepingFlag(); //then trigger vanilla sleep event(s) // world.setBlockState(player.getPosition(), Blocks.BED.getDefaultState()); SPacketUseBed sleepPacket = new SPacketUseBed(player, player.getPosition()); player.getServerWorld().getEntityTracker().sendToTracking(player, sleepPacket); player.connection.sendPacket(sleepPacket); if (this.isOn(stack)) { player.setSpawnPoint(player.getPosition(), true);//true means it wont check for bed block } }
public EntityPlayer.SleepResult trySleep(BlockPos bedLocation) { EntityPlayer.SleepResult entityplayer$sleepresult = super.trySleep(bedLocation); if (entityplayer$sleepresult == EntityPlayer.SleepResult.OK) { this.addStat(StatList.SLEEP_IN_BED); Packet<?> packet = new SPacketUseBed(this, bedLocation); this.getServerWorld().getEntityTracker().sendToAllTrackingEntity(this, packet); this.connection.setPlayerLocation(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); this.connection.sendPacket(packet); } return entityplayer$sleepresult; }
/** * Retrieves the player identified by the packet, puts him to sleep if possible (and flags whether all players are * asleep) */ public void handleUseBed(SPacketUseBed packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); packetIn.getPlayer(this.clientWorldController).trySleep(packetIn.getBedPosition()); }
/** * Retrieves the player identified by the packet, puts him to sleep if possible (and flags whether all players are * asleep) */ void handleUseBed(SPacketUseBed packetIn);