Skip to content
Permalink
Browse files

Fixed #247

  • Loading branch information...
DisasterMoo committed Aug 10, 2019
1 parent 7b29bbc commit fe2c2e3e69746c003fc8e9d4b3be33fdbf36e20b
@@ -145,11 +145,20 @@ public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event)
BlockPos blockpos = result.getBlockPos();
IBlockState state = event.getWorld().getBlockState(blockpos);
boolean isFreshWater = BlocksTFC.isFreshWater(state), isSaltWater = BlocksTFC.isSaltWater(state);
if ((isFreshWater && foodStats.attemptDrink(10)) || (isSaltWater && foodStats.attemptDrink(-1)))
if ((isFreshWater && foodStats.attemptDrink(10, true)) || (isSaltWater && foodStats.attemptDrink(-1, true)))
{
//Simulated so client will check if he would drink before updating stats
if (!world.isRemote)
{
player.world.playSound(null, player.getPosition(), SoundEvents.ENTITY_GENERIC_DRINK, SoundCategory.PLAYERS, 1.0f, 1.0f);
if (isFreshWater)
{
foodStats.attemptDrink(10, false);
}
else
{
foodStats.attemptDrink(-1, false);
}
}
event.setCancellationResult(EnumActionResult.SUCCESS);
event.setCanceled(true);
@@ -291,14 +291,17 @@ public float getThirst()
}

@Override
public boolean attemptDrink(float value)
public boolean attemptDrink(float value, boolean simulate)
{
int ticksPassed = (int) (CalendarTFC.TOTAL_TIME.getTicks() - lastDrinkTick);
if (ticksPassed >= 20 && thirst < MAX_PLAYER_THIRST)
{
// One drink every so often
lastDrinkTick = CalendarTFC.TOTAL_TIME.getTicks();
addThirst(value);
if (!simulate)
{
addThirst(value);
}
return true;
}
return false;
@@ -21,9 +21,10 @@
* Used to drink from a water source. Has an internal cooldown
*
* @param value the amount to drink = the value to increase thirst by
* @param simulate determines if this is a simulated drink (eg: the thirst value is not updated, but still checks if this attempt would happen)
* @return true if the player was able to drink (cooldown + not already full)
*/
boolean attemptDrink(float value);
boolean attemptDrink(float value, boolean simulate);

/**
* Used to directly add thirst, i.e. from an external source like a water bottle

0 comments on commit fe2c2e3

Please sign in to comment.
You can’t perform that action at this time.