geforkt von Mirrors/Paper
Add experience points API
Dieser Commit ist enthalten in:
Ursprung
15fcde4b3c
Commit
57894618cf
@ -35,7 +35,7 @@
|
||||
public final InventoryMenu inventoryMenu;
|
||||
public AbstractContainerMenu containerMenu;
|
||||
protected FoodData foodData = new FoodData();
|
||||
@@ -181,14 +191,26 @@
|
||||
@@ -181,13 +191,25 @@
|
||||
private Optional<GlobalPos> lastDeathLocation;
|
||||
@Nullable
|
||||
public FishingHook fishing;
|
||||
@ -49,7 +49,7 @@
|
||||
private int currentImpulseContextResetGraceTime;
|
||||
+ public boolean affectsSpawning = true; // Paper - Affects Spawning API
|
||||
+ public net.kyori.adventure.util.TriState flyingFallDamage = net.kyori.adventure.util.TriState.NOT_SET; // Paper - flying fall damage
|
||||
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ public boolean fauxSleeping;
|
||||
+ public int oldLevel = -1;
|
||||
@ -59,10 +59,9 @@
|
||||
+ return (CraftHumanEntity) super.getBukkitEntity();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
|
||||
public Player(Level world, BlockPos pos, float yaw, GameProfile gameProfile) {
|
||||
super(EntityType.PLAYER, world);
|
||||
this.lastItemInMainHand = ItemStack.EMPTY;
|
||||
@@ -244,6 +266,13 @@
|
||||
|
||||
if (this.isSleeping()) {
|
||||
@ -95,10 +94,12 @@
|
||||
}
|
||||
|
||||
private boolean isEquipped(Item item) {
|
||||
@@ -513,6 +542,18 @@
|
||||
|
||||
}
|
||||
@@ -511,7 +540,19 @@
|
||||
super.handleEntityEvent(status);
|
||||
}
|
||||
|
||||
+ }
|
||||
+
|
||||
+ // Paper start - Inventory close reason; unused code, but to keep signatures aligned
|
||||
+ public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
||||
+ closeContainer();
|
||||
@ -108,12 +109,11 @@
|
||||
+ // Paper start - special close for unloaded inventory
|
||||
+ public void closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
||||
+ this.containerMenu = this.inventoryMenu;
|
||||
+ }
|
||||
}
|
||||
+ // Paper end - special close for unloaded inventory
|
||||
+
|
||||
|
||||
public void closeContainer() {
|
||||
this.containerMenu = this.inventoryMenu;
|
||||
}
|
||||
@@ -523,8 +564,14 @@
|
||||
public void rideTick() {
|
||||
if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) {
|
||||
@ -541,9 +541,12 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1664,11 +1828,30 @@
|
||||
@@ -1662,13 +1826,32 @@
|
||||
}
|
||||
|
||||
public int getXpNeededForNextLevel() {
|
||||
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
|
||||
- return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
|
||||
+ return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2); // Paper - diff on change; calculateTotalExperiencePoints
|
||||
}
|
||||
+ // Paper start - send while respecting visibility
|
||||
+ private static void sendSoundEffect(Player fromEntity, double x, double y, double z, SoundEvent soundEffect, SoundSource soundCategory, float volume, float pitch) {
|
||||
|
@ -1933,6 +1933,49 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
Preconditions.checkArgument(exp >= 0, "Total experience points must not be negative (%s)", exp);
|
||||
this.getHandle().totalExperience = exp;
|
||||
}
|
||||
// Paper start
|
||||
@Override
|
||||
public int calculateTotalExperiencePoints() {
|
||||
return calculateTotalExperiencePoints(this.getLevel()) + Math.round(this.getExperiencePointsNeededForNextLevel() * getExp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExperienceLevelAndProgress(final int totalExperience) {
|
||||
Preconditions.checkArgument(totalExperience >= 0, "Total experience points must not be negative (%s)", totalExperience);
|
||||
int level = calculateLevelsForExperiencePoints(totalExperience);
|
||||
int remainingPoints = totalExperience - calculateTotalExperiencePoints(level);
|
||||
|
||||
this.getHandle().experienceLevel = level;
|
||||
this.getHandle().experienceProgress = (float) remainingPoints / this.getExperiencePointsNeededForNextLevel();
|
||||
this.getHandle().lastSentExp = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExperiencePointsNeededForNextLevel() {
|
||||
return this.getHandle().getXpNeededForNextLevel();
|
||||
}
|
||||
|
||||
// See https://minecraft.wiki/w/Experience#Leveling_up for reference
|
||||
private int calculateTotalExperiencePoints(int level) {
|
||||
if (level <= 16) {
|
||||
return (int) (Math.pow(level, 2) + 6 * level);
|
||||
} else if (level <= 31) {
|
||||
return (int) (2.5 * Math.pow(level, 2) - 40.5 * level + 360.0);
|
||||
} else {
|
||||
return (int) (4.5 * Math.pow(level, 2) - 162.5 * level + 2220.0);
|
||||
}
|
||||
}
|
||||
|
||||
private int calculateLevelsForExperiencePoints(int points) {
|
||||
if (points <= 352) { // Level 0-16
|
||||
return (int) Math.floor(Math.sqrt(points + 9) - 3);
|
||||
} else if (points <= 1507) { // Level 17-31
|
||||
return (int) Math.floor(8.1 + Math.sqrt(0.4 * (points - (7839.0 / 40.0))));
|
||||
} else { // 32+
|
||||
return (int) Math.floor((325.0 / 18.0) + Math.sqrt((2.0 / 9.0) * (points - (54215.0 / 72.0))));
|
||||
}
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public void sendExperienceChange(float progress) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren