Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions src/main/java/org/cloudburstmc/server/player/CloudPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.cloudburstmc.api.level.Difficulty;
import org.cloudburstmc.api.level.Location;
import org.cloudburstmc.api.level.chunk.Chunk;
import org.cloudburstmc.api.level.gamerule.GameRuleMap;
import org.cloudburstmc.api.level.gamerule.GameRules;
import org.cloudburstmc.api.locale.TextContainer;
import org.cloudburstmc.api.permission.Permission;
Expand Down Expand Up @@ -1316,25 +1317,23 @@ protected void processMovement(int tickDiff) {
this.speed = Vector3f.ZERO;
}

if (!revert && (this.isFoodEnabled() || this.getServer().getDifficulty() == Difficulty.PEACEFUL)) {
if (!revert) {
if ((this.isSurvival() || this.isAdventure())/* && !this.getRiddingOn() instanceof Entity*/) {

//UpdateFoodExpLevel
if (distance >= 0.05) {
double jump = 0;
double swimming = this.isInsideOfWater() ? 0.015 * distance : 0;
if (swimming != 0) distance = 0;
if (this.isSprinting()) { //Running
if (this.inAirTicks == 3 && swimming == 0) {
jump = 0.7;
}
this.getFoodData().updateFoodExpLevel(0.06 * distance + jump + swimming);
} else {
if (this.inAirTicks == 3 && swimming == 0) {
jump = 0.2;
}
this.getFoodData().updateFoodExpLevel(0.01 * distance + jump + swimming);
double jump = 0;
double swimming = this.isInsideOfWater() ? 0.01 * distance : 0;
if (swimming != 0) distance = 0;
if (this.isSprinting()) { //Running
if (this.inAirTicks == 3 && swimming == 0) {
jump = 0.2;
}
this.getFoodData().updateFoodExpLevel(0.1 * distance + jump + swimming);
} else {
if (this.inAirTicks == 3 && swimming == 0) {
jump = 0.05;
}
this.getFoodData().updateFoodExpLevel(jump + swimming);
}
}
}
Expand Down Expand Up @@ -1408,14 +1407,24 @@ public boolean onUpdate(int currentTick) {
this.entityBaseTick(tickDiff);

if (this.getServer().getDifficulty() == Difficulty.PEACEFUL && this.getLevel().getGameRules().get(GameRules.NATURAL_REGENERATION)) {
if (this.getHealth() < this.getMaxHealth() && this.ticksLived % 20 == 0) {
this.heal(1);
if (this.getHealth() < this.getMaxHealth() && !this.server.isHardcore() && this.level.getGameRules().contains(GameRules.NATURAL_REGENERATION)) {
if (this.getServer().getDifficulty().equals(Difficulty.EASY)) {
if (this.ticksLived % 20 == 0) {
this.heal(1);
}
PlayerFood foodData = this.getFoodData();
if (foodData.getLevel() < 20 && this.ticksLived % 10 == 0) {
foodData.addFoodLevel(1, 0);
}
}
}

PlayerFood foodData = this.getFoodData();

if (foodData.getLevel() < 20 && this.ticksLived % 10 == 0) {
foodData.addFoodLevel(1, 0);
if (this.ticksLived % 80 == 0 && this.getFoodData().getLevel() >= 18) {
this.heal(1);
if (!this.getServer().getDifficulty().equals(Difficulty.EASY) &&
!this.getServer().getDifficulty().equals(Difficulty.PEACEFUL)) {
this.getFoodData().updateFoodExpLevel(0.6);
}
}
}

Expand Down Expand Up @@ -2271,14 +2280,15 @@ public boolean attack(EntityDamageEvent source) {
if (source instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
if (damager instanceof CloudPlayer) {
((CloudPlayer) damager).getFoodData().updateFoodExpLevel(0.3);
((CloudPlayer) damager).getFoodData().updateFoodExpLevel(0.1);
}
}
EntityEventPacket packet = new EntityEventPacket();
packet.setRuntimeEntityId(this.getRuntimeId());
packet.setType(EntityEventType.HURT);
this.sendPacket(packet);
}
this.getFoodData().updateFoodExpLevel(0.1);
return true;
} else {
return false;
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/cloudburstmc/server/player/PlayerFood.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void useHunger(int amount) {
float newSfl = sfl - amount;
if (newSfl < 0) newSfl = 0;
this.setFoodSaturationLevel(newSfl);
this.sendFoodLevel();
} else {
this.setLevel(foodLevel - amount);
}
Expand Down Expand Up @@ -177,7 +178,12 @@ public void updateFoodExpLevel(double use) {
if (this.getPlayer().hasEffect(EffectTypes.SATURATION)) return;
this.foodExpLevel += use;
if (this.foodExpLevel > 4) {
this.useHunger(1);
if (!this.getPlayer().isFoodEnabled()) {
// Hack to get around the client reducing food despite us not sending the attribute
this.sendFoodLevel();
} else {
this.useHunger(1);
}
this.foodExpLevel = 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import com.nukkitx.protocol.bedrock.data.SoundEvent;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
import com.nukkitx.protocol.bedrock.data.inventory.InventoryActionData;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.data.inventory.ItemStackRequest;
import com.nukkitx.protocol.bedrock.data.inventory.*;
import com.nukkitx.protocol.bedrock.data.skin.SerializedSkin;
import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler;
import com.nukkitx.protocol.bedrock.packet.*;
Expand Down