2024-04-30 06:15:00 +10:00

136 lines
5.7 KiB
Diff

--- a/net/minecraft/world/level/block/entity/TileEntityBeacon.java
+++ b/net/minecraft/world/level/block/entity/TileEntityBeacon.java
@@ -46,6 +46,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 {
private static final int MAX_LEVELS = 4;
@@ -71,6 +76,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,38 +265,77 @@
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 byte getAmplification(int i, @Nullable Holder<MobEffectList> holder, @Nullable Holder<MobEffectList> holder1) {
+ {
byte b0 = 0;
if (i >= 4 && Objects.equals(holder, holder1)) {
b0 = 1;
}
+ return b0;
+ }
+ }
+
+ private static int getLevel(int i) {
+ {
int j = (9 + i * 2) * 20;
+ return j;
+ }
+ }
+
+ 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.getEntitiesOfClass(EntityHuman.class, axisalignedbb);
+
+ return list;
+ }
+ }
+
+ private static void applyEffect(List list, @Nullable Holder<MobEffectList> holder, int j, int b0) {
+ {
Iterator iterator = list.iterator();
EntityHuman entityhuman;
while (iterator.hasNext()) {
entityhuman = (EntityHuman) iterator.next();
- entityhuman.addEffect(new MobEffect(holder, j, b0, true, true));
+ entityhuman.addEffect(new MobEffect(holder, j, b0, 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) {
- iterator = list.iterator();
-
- while (iterator.hasNext()) {
- entityhuman = (EntityHuman) iterator.next();
- entityhuman.addEffect(new MobEffect(holder1, j, 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) {
+ double d0 = (double) (i * 10 + 10);
+ byte b0 = getAmplification(i, holder, holder1);
+
+ int j = getLevel(i);
+ List list = getHumansInRange(world, blockposition, i);
+
+ applyEffect(list, holder, j, b0);
+
+ if (hasSecondaryEffect(i, holder, holder1)) {
+ applyEffect(list, holder1, j, 0);
+ }
}
+
}
+ // CraftBukkit end
public static void playSound(World world, BlockPosition blockposition, SoundEffect soundeffect) {
world.playSound((EntityHuman) null, blockposition, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F);
@@ -316,7 +369,7 @@
if (nbttagcompound.contains(s, 8)) {
MinecraftKey minecraftkey = MinecraftKey.tryParse(nbttagcompound.getString(s));
- return minecraftkey == null ? null : (Holder) BuiltInRegistries.MOB_EFFECT.getHolder(minecraftkey).map(TileEntityBeacon::filterEffect).orElse((Object) null);
+ return minecraftkey == null ? null : (Holder) BuiltInRegistries.MOB_EFFECT.getHolder(minecraftkey).orElse(null); // CraftBukkit - persist manually set non-default beacon effects (SPIGOT-3598)
} else {
return null;
}
@@ -327,6 +380,7 @@
super.loadAdditional(nbttagcompound, holderlookup_a);
this.primaryPower = loadEffect(nbttagcompound, "primary_effect");
this.secondaryPower = loadEffect(nbttagcompound, "secondary_effect");
+ this.levels = nbttagcompound.getInt("Levels"); // CraftBukkit - SPIGOT-5053, use where available
if (nbttagcompound.contains("CustomName", 8)) {
this.name = parseCustomNameSafe(nbttagcompound.getString("CustomName"), holderlookup_a);
}