Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-17 03:50:08 +01:00
77a5779e24
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 2ec53f49 PR-1050: Fix empty result check for Complex Recipes 10671012 PR-1044: Add CrafterCraftEvent 4d87ffe0 Use correct method in JavaDoc ae5e5817 SPIGOT-7850: Add API for Bogged shear state 46b6d445 SPIGOT-7837: Support data pack banner patterns d5d0cefc Fix JavaDoc error b3c2b83d PR-1036: Add API for InventoryView derivatives 1fe2c75a SPIGOT-7809: Add ShieldMeta CraftBukkit Changes: 8ee6fd1b8 SPIGOT-7857: Improve ItemMeta block data deserialization 8f26c30c6 SPIGOT-7857: Fix spurious internal NBT tag when deserializing BlockStateMeta 759061b93 SPIGOT-7855: Fire does not spread or burn blocks 00fc9fb64 SPIGOT-7853: AnvilInventory#getRepairCost() always returns 0 7501e2e04 PR-1450: Add CrafterCraftEvent 8c51673e7 SPIGOT-5731: PortalCreateEvent#getEntity returns null for nether portals ignited by flint and steel d53d0d0b1 PR-1456: Fix inverted logic in CraftCrafterView#setSlotDisabled 682a678c8 SPIGOT-7850: Add API for Bogged shear state fccf5243a SPIGOT-7837: Support data pack banner patterns 9c3bd4390 PR-1431: Add API for InventoryView derivatives 0cc6acbc4 SPIGOT-7849: Fix FoodComponent serialize with "using-converts-to" using null 2c5474952 Don't rely on tags for CraftItemMetas 20d107e46 SPIGOT-7846: Fix ItemMeta for hanging signs 76f59e315 Remove redundant clone in Dropper InventoryMoveItemEvent e61a53d25 SPIGOT-7817: Call InventoryMoveItemEvent for Crafters 894682e2d SPIGOT-7839: Remove redundant Java version checks 2c12b2187 SPIGOT-7809: Add ShieldMeta and fix setting shield base colours Spigot Changes: fb8fb722 Rebuild patches 34bd42b7 SPIGOT-7835: Fix issue with custom hopper settings
74 Zeilen
3.9 KiB
Diff
74 Zeilen
3.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Lukas Planz <lukas.planz@web.de>
|
|
Date: Tue, 5 Sep 2023 20:34:20 +0200
|
|
Subject: [PATCH] Add experience points API
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
index 950ce40d268d89ff3c503116081db6c9ccd65329..454b29d8c9e42e328933aa578f49d28f1e77898a 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -1869,7 +1869,7 @@ public abstract class Player extends LivingEntity {
|
|
}
|
|
|
|
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); // 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) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 51b524d3c7cd5e0f59056c1fd8f71171732945b8..1490d15f1ffa83653b20a4bb47584c4c554a3384 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1921,6 +1921,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) {
|