2025-03-26 03:05:00 +11:00

128 lines
5.2 KiB
Diff

--- a/net/minecraft/world/level/block/entity/TileEntityBeacon.java
+++ b/net/minecraft/world/level/block/entity/TileEntityBeacon.java
@@ -50,6 +50,11 @@
import net.minecraft.world.level.levelgen.HeightMap;
import net.minecraft.world.phys.AxisAlignedBB;
+// CraftBukkit start
+import org.bukkit.craftbukkit.potion.CraftPotionUtil;
+import org.bukkit.potion.PotionEffect;
+// CraftBukkit end
+
public class TileEntityBeacon extends TileEntity implements ITileInventory, INamableTileEntity, BeaconBeamOwner {
private static final int MAX_LEVELS = 4;
@@ -75,6 +80,15 @@
public IChatBaseComponent name;
public ChestLock lockKey;
private final IContainerProperties dataAccess;
+ // CraftBukkit start - add fields and methods
+ public PotionEffect getPrimaryEffect() {
+ return (this.primaryPower != null) ? CraftPotionUtil.toBukkit(new MobEffect(this.primaryPower, getLevel(this.levels), getAmplification(levels, primaryPower, secondaryPower), true, true)) : null;
+ }
+
+ public PotionEffect getSecondaryEffect() {
+ return (hasSecondaryEffect(levels, primaryPower, secondaryPower)) ? CraftPotionUtil.toBukkit(new MobEffect(this.secondaryPower, getLevel(this.levels), getAmplification(levels, primaryPower, secondaryPower), true, true)) : null;
+ }
+ // CraftBukkit end
@Nullable
static Holder<MobEffectList> filterEffect(@Nullable Holder<MobEffectList> holder) {
@@ -251,32 +265,72 @@
super.setRemoved();
}
- private static void applyEffects(World world, BlockPosition blockposition, int i, @Nullable Holder<MobEffectList> holder, @Nullable Holder<MobEffectList> holder1) {
- if (!world.isClientSide && holder != null) {
- double d0 = (double) (i * 10 + 10);
+ // CraftBukkit start - split into components
+ private static int getAmplification(int i, @Nullable Holder<MobEffectList> holder, @Nullable Holder<MobEffectList> holder1) {
+ {
int j = 0;
if (i >= 4 && Objects.equals(holder, holder1)) {
j = 1;
}
+ return j;
+ }
+ }
+
+ private static int getLevel(int i) {
+ {
int k = (9 + i * 2) * 20;
+ return k;
+ }
+ }
+
+ public static List getHumansInRange(World world, BlockPosition blockposition, int i) {
+ {
+ double d0 = (double) (i * 10 + 10);
+
AxisAlignedBB axisalignedbb = (new AxisAlignedBB(blockposition)).inflate(d0).expandTowards(0.0D, (double) world.getHeight(), 0.0D);
List<EntityHuman> list = world.<EntityHuman>getEntitiesOfClass(EntityHuman.class, axisalignedbb);
+ return list;
+ }
+ }
+
+ private static void applyEffect(List<EntityHuman> list, @Nullable Holder<MobEffectList> holder, int k, int j) {
+ {
for (EntityHuman entityhuman : list) {
- entityhuman.addEffect(new MobEffect(holder, k, j, true, true));
+ entityhuman.addEffect(new MobEffect(holder, k, j, true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
}
+ }
+ }
+ private static boolean hasSecondaryEffect(int i, @Nullable Holder<MobEffectList> holder, @Nullable Holder<MobEffectList> holder1) {
+ {
if (i >= 4 && !Objects.equals(holder, holder1) && holder1 != null) {
- for (EntityHuman entityhuman1 : list) {
- entityhuman1.addEffect(new MobEffect(holder1, k, 0, true, true));
- }
+ return true;
}
+ return false;
}
}
+ private static void applyEffects(World world, BlockPosition blockposition, int i, @Nullable Holder<MobEffectList> holder, @Nullable Holder<MobEffectList> holder1) {
+ if (!world.isClientSide && holder != null) {
+ int j = getAmplification(i, holder, holder1);
+
+ int k = getLevel(i);
+ List list = getHumansInRange(world, blockposition, i);
+
+ applyEffect(list, holder, k, j);
+
+ if (hasSecondaryEffect(i, holder, holder1)) {
+ applyEffect(list, holder1, k, 0);
+ }
+ }
+
+ }
+ // CraftBukkit end
+
public static void playSound(World world, BlockPosition blockposition, SoundEffect soundeffect) {
world.playSound((Entity) null, blockposition, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
@@ -311,7 +365,7 @@
Set set = TileEntityBeacon.VALID_EFFECTS;
Objects.requireNonNull(set);
- return (Holder) optional.filter(set::contains).orElse((Object) null);
+ return (Holder) optional.orElse((Object) null); // CraftBukkit - persist manually set non-default beacon effects (SPIGOT-3598)
}
@Override
@@ -319,6 +373,7 @@
super.loadAdditional(nbttagcompound, holderlookup_a);
this.primaryPower = loadEffect(nbttagcompound, "primary_effect");
this.secondaryPower = loadEffect(nbttagcompound, "secondary_effect");
+ this.levels = nbttagcompound.getIntOr("Levels", this.levels); // CraftBukkit - SPIGOT-5053, use where available
this.name = parseCustomNameSafe(nbttagcompound.get("CustomName"), holderlookup_a);
this.lockKey = ChestLock.fromTag(nbttagcompound, holderlookup_a);
}