Posted May 4, 201510 yr I'm trying to cause the Nausea effect on the player when their Sanity (custom variable) has run out. The console spams "Sanity = 0" when it runs out, but the effect is never added. Why not? @SubscribeEvent public void onLivingUpdate(LivingUpdateEvent event) { if (event.entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.entity; ExtendedPlayer props = ExtendedPlayer.get(player); if (player.isPlayerFullyAsleep()) { props.replenishSanity(); //This works fine } //Problem starts here if(props.getCurrentSanity() == 0) { Tools.printcon("Sanity = " + props.getCurrentSanity()); //This DOES happen. player.addPotionEffect(new PotionEffect(Potion.confusion.getId(), 1, 5)); //This does NOT happen. } } }
May 4, 201510 yr 1st of all - you need to addPotion effect on !world.isRemote (server side). Second problem - in adding potion method you are feeding it time parameter == 1. There is this "bad design" thing there which causes potion to be automatically removed just after adding it if the time was == 1. To make effect actually happen you need to set time to 2 or more ticks. Setting it to 2+ should remove problems (also visual ones), but still - I personally don't like potion updating code. It should be feeded in for-next-tick-queue, not just randomly put there (effect might be added in different places in tick "lifespan" therefore it can be treated differently in different situations). 1.7.10 is no longer supported by forge, you are on your own.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.