aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/world/entity/ExperienceOrb.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/entity/ExperienceOrb.java.patch')
-rw-r--r--patch-remap/mache-spigotflower/net/minecraft/world/entity/ExperienceOrb.java.patch356
1 files changed, 356 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/entity/ExperienceOrb.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/entity/ExperienceOrb.java.patch
new file mode 100644
index 0000000000..efa96db50e
--- /dev/null
+++ b/patch-remap/mache-spigotflower/net/minecraft/world/entity/ExperienceOrb.java.patch
@@ -0,0 +1,356 @@
+--- a/net/minecraft/world/entity/ExperienceOrb.java
++++ b/net/minecraft/world/entity/ExperienceOrb.java
+@@ -20,6 +20,12 @@
+ import net.minecraft.world.level.entity.EntityTypeTest;
+ import net.minecraft.world.phys.AABB;
+ import net.minecraft.world.phys.Vec3;
++// CraftBukkit start
++import org.bukkit.craftbukkit.event.CraftEventFactory;
++import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
++import org.bukkit.event.entity.EntityTargetEvent;
++import org.bukkit.event.player.PlayerExpCooldownChangeEvent;
++// CraftBukkit end
+
+ public class ExperienceOrb extends Entity {
+
+@@ -30,38 +36,36 @@
+ private static final double ORB_MERGE_DISTANCE = 0.5D;
+ private int age;
+ private int health;
+- private int value;
++ public int value;
+ private int count;
+ private Player followingPlayer;
+
+- public ExperienceOrb(Level level, double d0, double d1, double d2, int i) {
++ public ExperienceOrb(Level level, double x, double d1, double y, int i) {
+ this(EntityType.EXPERIENCE_ORB, level);
+- this.setPos(d0, d1, d2);
++ this.setPos(x, d1, y);
+ this.setYRot((float) (this.random.nextDouble() * 360.0D));
+ this.setDeltaMovement((this.random.nextDouble() * 0.20000000298023224D - 0.10000000149011612D) * 2.0D, this.random.nextDouble() * 0.2D * 2.0D, (this.random.nextDouble() * 0.20000000298023224D - 0.10000000149011612D) * 2.0D);
+ this.value = i;
+ }
+
+- public ExperienceOrb(EntityType<? extends ExperienceOrb> entitytype, Level level) {
+- super(entitytype, level);
++ public ExperienceOrb(EntityType<? extends ExperienceOrb> entityType, Level level) {
++ super(entityType, level);
+ this.health = 5;
+ this.count = 1;
+ }
+
+ @Override
+- @Override
+ protected Entity.MovementEmission getMovementEmission() {
+ return Entity.MovementEmission.NONE;
+ }
+
+ @Override
+- @Override
+ protected void defineSynchedData() {}
+
+ @Override
+- @Override
+ public void tick() {
+ super.tick();
++ Player prevTarget = this.followingPlayer;// CraftBukkit - store old target
+ this.xo = this.getX();
+ this.yo = this.getY();
+ this.zo = this.getZ();
+@@ -87,18 +91,33 @@
+ this.followingPlayer = null;
+ }
+
+- if (this.followingPlayer != null) {
+- Vec3 vec3 = new Vec3(this.followingPlayer.getX() - this.getX(), this.followingPlayer.getY() + (double) this.followingPlayer.getEyeHeight() / 2.0D - this.getY(), this.followingPlayer.getZ() - this.getZ());
+- double d0 = vec3.lengthSqr();
++ // CraftBukkit start
++ boolean cancelled = false;
++ if (this.followingPlayer != prevTarget) {
++ EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(this, followingPlayer, (followingPlayer != null) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.FORGOT_TARGET);
++ LivingEntity target = (event.getTarget() == null) ? null : ((org.bukkit.craftbukkit.entity.CraftLivingEntity) event.getTarget()).getHandle();
++ cancelled = event.isCancelled();
+
++ if (cancelled) {
++ followingPlayer = prevTarget;
++ } else {
++ followingPlayer = (target instanceof Player) ? (Player) target : null;
++ }
++ }
++
++ if (this.followingPlayer != null && !cancelled) {
++ // CraftBukkit end
++ Vec3 vec3d = new Vec3(this.followingPlayer.getX() - this.getX(), this.followingPlayer.getY() + (double) this.followingPlayer.getEyeHeight() / 2.0D - this.getY(), this.followingPlayer.getZ() - this.getZ());
++ double d0 = vec3d.lengthSqr();
++
+ if (d0 < 64.0D) {
+ double d1 = 1.0D - Math.sqrt(d0) / 8.0D;
+
+- this.setDeltaMovement(this.getDeltaMovement().add(vec3.normalize().scale(d1 * d1 * 0.1D)));
++ this.setDeltaMovement(this.getDeltaMovement().add(vec3d.normalize().scale(d1 * d1 * 0.1D)));
+ }
+ }
+
+- this.move(MoverType.SELF, this.getDeltaMovement());
++ this.move(EnumMoveType.SELF, this.getDeltaMovement());
+ float f = 0.98F;
+
+ if (this.onGround()) {
+@@ -118,7 +137,6 @@
+ }
+
+ @Override
+- @Override
+ protected BlockPos getBlockPosBelowThatAffectsMyMovement() {
+ return this.getOnPos(0.999999F);
+ }
+@@ -133,78 +151,76 @@
+ Iterator iterator = list.iterator();
+
+ while (iterator.hasNext()) {
+- ExperienceOrb experienceorb = (ExperienceOrb) iterator.next();
++ ExperienceOrb entityexperienceorb = (ExperienceOrb) iterator.next();
+
+- this.merge(experienceorb);
++ this.merge(entityexperienceorb);
+ }
+ }
+
+ }
+
+- public static void award(ServerLevel serverlevel, Vec3 vec3, int i) {
+- while (i > 0) {
+- int j = getExperienceValue(i);
++ public static void award(ServerLevel level, Vec3 pos, int amount) {
++ while (amount > 0) {
++ int j = getExperienceValue(amount);
+
+- i -= j;
+- if (!tryMergeToExisting(serverlevel, vec3, j)) {
+- serverlevel.addFreshEntity(new ExperienceOrb(serverlevel, vec3.x(), vec3.y(), vec3.z(), j));
++ amount -= j;
++ if (!tryMergeToExisting(level, pos, j)) {
++ level.addFreshEntity(new ExperienceOrb(level, pos.x(), pos.y(), pos.z(), j));
+ }
+ }
+
+ }
+
+- private static boolean tryMergeToExisting(ServerLevel serverlevel, Vec3 vec3, int i) {
+- AABB aabb = AABB.ofSize(vec3, 1.0D, 1.0D, 1.0D);
+- int j = serverlevel.getRandom().nextInt(40);
+- List<ExperienceOrb> list = serverlevel.getEntities(EntityTypeTest.forClass(ExperienceOrb.class), aabb, (experienceorb) -> {
+- return canMerge(experienceorb, j, i);
++ private static boolean tryMergeToExisting(ServerLevel level, Vec3 pos, int amount) {
++ AABB axisalignedbb = AABB.ofSize(pos, 1.0D, 1.0D, 1.0D);
++ int j = level.getRandom().nextInt(40);
++ List<ExperienceOrb> list = level.getEntities(EntityTypeTest.forClass(ExperienceOrb.class), axisalignedbb, (entityexperienceorb) -> {
++ return canMerge(entityexperienceorb, j, amount);
+ });
+
+ if (!list.isEmpty()) {
+- ExperienceOrb experienceorb = (ExperienceOrb) list.get(0);
++ ExperienceOrb entityexperienceorb = (ExperienceOrb) list.get(0);
+
+- ++experienceorb.count;
+- experienceorb.age = 0;
++ ++entityexperienceorb.count;
++ entityexperienceorb.age = 0;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+- private boolean canMerge(ExperienceOrb experienceorb) {
+- return experienceorb != this && canMerge(experienceorb, this.getId(), this.value);
++ private boolean canMerge(ExperienceOrb orb) {
++ return orb != this && canMerge(orb, this.getId(), this.value);
+ }
+
+- private static boolean canMerge(ExperienceOrb experienceorb, int i, int j) {
+- return !experienceorb.isRemoved() && (experienceorb.getId() - i) % 40 == 0 && experienceorb.value == j;
++ private static boolean canMerge(ExperienceOrb orb, int amount, int other) {
++ return !orb.isRemoved() && (orb.getId() - amount) % 40 == 0 && orb.value == other;
+ }
+
+- private void merge(ExperienceOrb experienceorb) {
+- this.count += experienceorb.count;
+- this.age = Math.min(this.age, experienceorb.age);
+- experienceorb.discard();
++ private void merge(ExperienceOrb orb) {
++ this.count += orb.count;
++ this.age = Math.min(this.age, orb.age);
++ orb.discard();
+ }
+
+ private void setUnderwaterMovement() {
+- Vec3 vec3 = this.getDeltaMovement();
++ Vec3 vec3d = this.getDeltaMovement();
+
+- this.setDeltaMovement(vec3.x * 0.9900000095367432D, Math.min(vec3.y + 5.000000237487257E-4D, 0.05999999865889549D), vec3.z * 0.9900000095367432D);
++ this.setDeltaMovement(vec3d.x * 0.9900000095367432D, Math.min(vec3d.y + 5.000000237487257E-4D, 0.05999999865889549D), vec3d.z * 0.9900000095367432D);
+ }
+
+ @Override
+- @Override
+ protected void doWaterSplashEffect() {}
+
+ @Override
+- @Override
+- public boolean hurt(DamageSource damagesource, float f) {
+- if (this.isInvulnerableTo(damagesource)) {
++ public boolean hurt(DamageSource source, float amount) {
++ if (this.isInvulnerableTo(source)) {
+ return false;
+ } else if (this.level().isClientSide) {
+ return true;
+ } else {
+ this.markHurt();
+- this.health = (int) ((float) this.health - f);
++ this.health = (int) ((float) this.health - amount);
+ if (this.health <= 0) {
+ this.discard();
+ }
+@@ -214,34 +230,31 @@
+ }
+
+ @Override
+- @Override
+- public void addAdditionalSaveData(CompoundTag compoundtag) {
+- compoundtag.putShort("Health", (short) this.health);
+- compoundtag.putShort("Age", (short) this.age);
+- compoundtag.putShort("Value", (short) this.value);
+- compoundtag.putInt("Count", this.count);
++ public void addAdditionalSaveData(CompoundTag compound) {
++ compound.putShort("Health", (short) this.health);
++ compound.putShort("Age", (short) this.age);
++ compound.putShort("Value", (short) this.value);
++ compound.putInt("Count", this.count);
+ }
+
+ @Override
+- @Override
+- public void readAdditionalSaveData(CompoundTag compoundtag) {
+- this.health = compoundtag.getShort("Health");
+- this.age = compoundtag.getShort("Age");
+- this.value = compoundtag.getShort("Value");
+- this.count = Math.max(compoundtag.getInt("Count"), 1);
++ public void readAdditionalSaveData(CompoundTag compound) {
++ this.health = compound.getShort("Health");
++ this.age = compound.getShort("Age");
++ this.value = compound.getShort("Value");
++ this.count = Math.max(compound.getInt("Count"), 1);
+ }
+
+ @Override
+- @Override
+- public void playerTouch(Player player) {
++ public void playerTouch(Player entity) {
+ if (!this.level().isClientSide) {
+- if (player.takeXpDelay == 0) {
+- player.takeXpDelay = 2;
+- player.take(this, 1);
+- int i = this.repairPlayerItems(player, this.value);
++ if (entity.takeXpDelay == 0) {
++ entity.takeXpDelay = CraftEventFactory.callPlayerXpCooldownEvent(entity, 2, PlayerExpCooldownChangeEvent.ChangeReason.PICKUP_ORB).getNewCooldown(); // CraftBukkit - entityhuman.takeXpDelay = 2;
++ entity.take(this, 1);
++ int i = this.repairPlayerItems(entity, this.value);
+
+ if (i > 0) {
+- player.giveExperiencePoints(i);
++ entity.giveExperiencePoints(CraftEventFactory.callPlayerExpChangeEvent(entity, i).getAmount()); // CraftBukkit - this.value -> event.getAmount()
+ }
+
+ --this.count;
+@@ -253,28 +266,36 @@
+ }
+ }
+
+- private int repairPlayerItems(Player player, int i) {
++ private int repairPlayerItems(Player player, int repairAmount) {
+ Entry<EquipmentSlot, ItemStack> entry = EnchantmentHelper.getRandomItemWith(Enchantments.MENDING, player, ItemStack::isDamaged);
+
+ if (entry != null) {
+ ItemStack itemstack = (ItemStack) entry.getValue();
+- int j = Math.min(this.xpToDurability(i), itemstack.getDamageValue());
++ int j = Math.min(this.xpToDurability(repairAmount), itemstack.getDamageValue());
++ // CraftBukkit start
++ org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(player, this, itemstack, entry.getKey(), j);
++ j = event.getRepairAmount();
++ if (event.isCancelled()) {
++ return repairAmount;
++ }
++ // CraftBukkit end
+
+ itemstack.setDamageValue(itemstack.getDamageValue() - j);
+- int k = i - this.durabilityToXp(j);
++ int k = repairAmount - this.durabilityToXp(j);
++ this.value = k; // CraftBukkit - update exp value of orb for PlayerItemMendEvent calls
+
+ return k > 0 ? this.repairPlayerItems(player, k) : 0;
+ } else {
+- return i;
++ return repairAmount;
+ }
+ }
+
+- private int durabilityToXp(int i) {
+- return i / 2;
++ private int durabilityToXp(int durability) {
++ return durability / 2;
+ }
+
+- private int xpToDurability(int i) {
+- return i * 2;
++ private int xpToDurability(int xp) {
++ return xp * 2;
+ }
+
+ public int getValue() {
+@@ -285,24 +306,39 @@
+ return this.value >= 2477 ? 10 : (this.value >= 1237 ? 9 : (this.value >= 617 ? 8 : (this.value >= 307 ? 7 : (this.value >= 149 ? 6 : (this.value >= 73 ? 5 : (this.value >= 37 ? 4 : (this.value >= 17 ? 3 : (this.value >= 7 ? 2 : (this.value >= 3 ? 1 : 0)))))))));
+ }
+
+- public static int getExperienceValue(int i) {
+- return i >= 2477 ? 2477 : (i >= 1237 ? 1237 : (i >= 617 ? 617 : (i >= 307 ? 307 : (i >= 149 ? 149 : (i >= 73 ? 73 : (i >= 37 ? 37 : (i >= 17 ? 17 : (i >= 7 ? 7 : (i >= 3 ? 3 : 1)))))))));
++ public static int getExperienceValue(int expValue) {
++ // CraftBukkit start
++ if (expValue > 162670129) return expValue - 100000;
++ if (expValue > 81335063) return 81335063;
++ if (expValue > 40667527) return 40667527;
++ if (expValue > 20333759) return 20333759;
++ if (expValue > 10166857) return 10166857;
++ if (expValue > 5083423) return 5083423;
++ if (expValue > 2541701) return 2541701;
++ if (expValue > 1270849) return 1270849;
++ if (expValue > 635413) return 635413;
++ if (expValue > 317701) return 317701;
++ if (expValue > 158849) return 158849;
++ if (expValue > 79423) return 79423;
++ if (expValue > 39709) return 39709;
++ if (expValue > 19853) return 19853;
++ if (expValue > 9923) return 9923;
++ if (expValue > 4957) return 4957;
++ // CraftBukkit end
++ return expValue >= 2477 ? 2477 : (expValue >= 1237 ? 1237 : (expValue >= 617 ? 617 : (expValue >= 307 ? 307 : (expValue >= 149 ? 149 : (expValue >= 73 ? 73 : (expValue >= 37 ? 37 : (expValue >= 17 ? 17 : (expValue >= 7 ? 7 : (expValue >= 3 ? 3 : 1)))))))));
+ }
+
+ @Override
+- @Override
+ public boolean isAttackable() {
+ return false;
+ }
+
+ @Override
+- @Override
+ public Packet<ClientGamePacketListener> getAddEntityPacket() {
+ return new ClientboundAddExperienceOrbPacket(this);
+ }
+
+ @Override
+- @Override
+ public SoundSource getSoundSource() {
+ return SoundSource.AMBIENT;
+ }