PaperMC/patches/server/0422-Beacon-API-custom-effect-ranges.patch

132 lines
6.7 KiB
Diff
Raw Permalink Normal View History

2021-06-14 18:58:00 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 24 Jun 2020 12:39:08 -0600
Subject: [PATCH] Beacon API - custom effect ranges
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
2024-10-23 17:13:43 +02:00
index 8332296663b845df1d09d403b49a4769b2d54afc..dc3171b1493d7c4c8ddf1c79587c4e27bd819c17 100644
2021-06-14 18:58:00 +02:00
--- a/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
2024-04-24 15:46:45 +02:00
@@ -86,6 +86,26 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
2021-06-14 18:58:00 +02:00
return (BeaconBlockEntity.hasSecondaryEffect(this.levels, this.primaryPower, this.secondaryPower)) ? CraftPotionUtil.toBukkit(new MobEffectInstance(this.secondaryPower, BeaconBlockEntity.getLevel(this.levels), BeaconBlockEntity.getAmplification(this.levels, this.primaryPower, this.secondaryPower), true, true)) : null;
}
// CraftBukkit end
+ // Paper start - Custom beacon ranges
2021-06-14 18:58:00 +02:00
+ private final String PAPER_RANGE_TAG = "Paper.Range";
+ private double effectRange = -1;
+
+ public double getEffectRange() {
+ if (this.effectRange < 0) {
+ return this.levels * 10 + 10;
+ } else {
+ return effectRange;
+ }
+ }
+
+ public void setEffectRange(double range) {
+ this.effectRange = range;
+ }
+
+ public void resetEffectRange() {
+ this.effectRange = -1;
+ }
+ // Paper end - Custom beacon ranges
2021-06-14 18:58:00 +02:00
@Nullable
2024-04-24 15:46:45 +02:00
static Holder<MobEffect> filterEffect(@Nullable Holder<MobEffect> effect) {
@@ -201,7 +221,7 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
2021-07-02 21:51:49 +02:00
}
if (blockEntity.levels > 0 && !blockEntity.beamSections.isEmpty()) {
- BeaconBlockEntity.applyEffects(world, pos, blockEntity.levels, blockEntity.primaryPower, blockEntity.secondaryPower);
+ BeaconBlockEntity.applyEffects(world, pos, blockEntity.levels, blockEntity.primaryPower, blockEntity.secondaryPower, blockEntity); // Paper - Custom beacon ranges
2021-07-02 21:51:49 +02:00
BeaconBlockEntity.playSound(world, pos, SoundEvents.BEACON_AMBIENT);
}
}
2024-04-24 15:46:45 +02:00
@@ -287,8 +307,13 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
2021-06-14 18:58:00 +02:00
}
public static List getHumansInRange(Level world, BlockPos blockposition, int i) {
+ // Paper start - Custom beacon ranges
2021-06-14 18:58:00 +02:00
+ return BeaconBlockEntity.getHumansInRange(world, blockposition, i, null);
+ }
+ public static List getHumansInRange(Level world, BlockPos blockposition, int i, @Nullable BeaconBlockEntity blockEntity) {
+ // Paper end - Custom beacon ranges
2021-06-14 18:58:00 +02:00
{
- double d0 = (double) (i * 10 + 10);
+ double d0 = blockEntity != null ? blockEntity.getEffectRange() : (i * 10 + 10); // Paper - Custom beacon ranges
2021-06-14 18:58:00 +02:00
AABB axisalignedbb = (new AABB(blockposition)).inflate(d0).expandTowards(0.0D, (double) world.getHeight(), 0.0D);
List<Player> list = world.getEntitiesOfClass(Player.class, axisalignedbb);
2024-04-24 15:46:45 +02:00
@@ -329,12 +354,17 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
2021-07-02 21:51:49 +02:00
}
2024-04-24 15:46:45 +02:00
private static void applyEffects(Level world, BlockPos pos, int beaconLevel, @Nullable Holder<MobEffect> primaryEffect, @Nullable Holder<MobEffect> secondaryEffect) {
+ // Paper start - Custom beacon ranges
2021-07-02 21:51:49 +02:00
+ BeaconBlockEntity.applyEffects(world, pos, beaconLevel, primaryEffect, secondaryEffect, null);
+ }
2024-04-26 05:15:07 +02:00
+ private static void applyEffects(Level world, BlockPos pos, int beaconLevel, @Nullable Holder<MobEffect> primaryEffect, @Nullable Holder<MobEffect> secondaryEffect, @Nullable BeaconBlockEntity blockEntity) {
+ // Paper end - Custom beacon ranges
2021-07-02 21:51:49 +02:00
if (!world.isClientSide && primaryEffect != null) {
double d0 = (double) (beaconLevel * 10 + 10);
byte b0 = BeaconBlockEntity.getAmplification(beaconLevel, primaryEffect, secondaryEffect);
int j = BeaconBlockEntity.getLevel(beaconLevel);
- List list = BeaconBlockEntity.getHumansInRange(world, pos, beaconLevel);
+ List list = BeaconBlockEntity.getHumansInRange(world, pos, beaconLevel, blockEntity); // Paper - Custom beacon ranges
2021-07-02 21:51:49 +02:00
BeaconBlockEntity.applyEffect(list, primaryEffect, j, b0, true, pos); // Paper - BeaconEffectEvent
2024-04-24 15:46:45 +02:00
@@ -395,6 +425,7 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
2021-06-14 18:58:00 +02:00
}
2024-10-23 17:13:43 +02:00
this.lockKey = LockCode.fromTag(nbt, registries);
+ this.effectRange = nbt.contains(PAPER_RANGE_TAG, 6) ? nbt.getDouble(PAPER_RANGE_TAG) : -1; // Paper - Custom beacon ranges
2021-06-14 18:58:00 +02:00
}
@Override
2024-04-24 15:46:45 +02:00
@@ -408,6 +439,7 @@ public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Name
2021-06-14 18:58:00 +02:00
}
2024-10-23 17:13:43 +02:00
this.lockKey.addToTag(nbt, registries);
+ nbt.putDouble(PAPER_RANGE_TAG, this.effectRange); // Paper - Custom beacon ranges
2021-06-14 18:58:00 +02:00
}
public void setCustomName(@Nullable Component customName) {
2021-06-14 18:58:00 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
2024-10-23 17:13:43 +02:00
index 8021ac39cb9c1ff45123d51e6f13b840d1290bb2..275d4f9e07ff7383b18238071e067b7f44483ece 100644
2021-06-14 18:58:00 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
2024-10-23 17:13:43 +02:00
@@ -42,7 +42,7 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
2021-07-02 21:51:49 +02:00
if (tileEntity instanceof BeaconBlockEntity) {
BeaconBlockEntity beacon = (BeaconBlockEntity) tileEntity;
- Collection<Player> nms = BeaconBlockEntity.getHumansInRange(beacon.getLevel(), beacon.getBlockPos(), beacon.levels);
+ Collection<Player> nms = BeaconBlockEntity.getHumansInRange(beacon.getLevel(), beacon.getBlockPos(), beacon.levels, beacon); // Paper - Custom beacon ranges
2021-07-02 21:51:49 +02:00
Collection<LivingEntity> bukkit = new ArrayList<LivingEntity>(nms.size());
for (Player human : nms) {
2024-10-23 17:13:43 +02:00
@@ -145,4 +145,21 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
2024-04-24 15:46:45 +02:00
public CraftBeacon copy(Location location) {
return new CraftBeacon(this, location);
2021-06-14 18:58:00 +02:00
}
+
+ // Paper start
+ @Override
+ public double getEffectRange() {
+ return this.getSnapshot().getEffectRange();
+ }
+
+ @Override
+ public void setEffectRange(double range) {
+ this.getSnapshot().setEffectRange(range);
+ }
+
+ @Override
+ public void resetEffectRange() {
+ this.getSnapshot().resetEffectRange();
+ }
+ // Paper end
}