mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-26 12:36:07 +01:00
136 lines
5.0 KiB
Diff
136 lines
5.0 KiB
Diff
--- a/net/minecraft/server/TileEntityBeacon.java
|
|
+++ b/net/minecraft/server/TileEntityBeacon.java
|
|
@@ -8,6 +8,13 @@
|
|
import java.util.stream.Collectors;
|
|
import javax.annotation.Nullable;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
+import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
|
+import org.bukkit.entity.HumanEntity;
|
|
+import org.bukkit.potion.PotionEffect;
|
|
+// CraftBukkit end
|
|
+
|
|
public class TileEntityBeacon extends TileEntity implements ITileInventory, ITickable {
|
|
|
|
public static final MobEffectList[][] a = new MobEffectList[][]{{MobEffects.FASTER_MOVEMENT, MobEffects.FASTER_DIG}, {MobEffects.RESISTANCE, MobEffects.JUMP}, {MobEffects.INCREASE_DAMAGE}, {MobEffects.REGENERATION}};
|
|
@@ -24,6 +31,15 @@
|
|
public IChatBaseComponent customName;
|
|
public ChestLock chestLock;
|
|
private final IContainerProperties containerProperties;
|
|
+ // CraftBukkit start - add fields and methods
|
|
+ public PotionEffect getPrimaryEffect() {
|
|
+ return (this.primaryEffect != null) ? CraftPotionUtil.toBukkit(new MobEffect(this.primaryEffect, getLevel(), getAmplification(), true, true)) : null;
|
|
+ }
|
|
+
|
|
+ public PotionEffect getSecondaryEffect() {
|
|
+ return (hasSecondaryEffect()) ? CraftPotionUtil.toBukkit(new MobEffect(this.secondaryEffect, getLevel(), getAmplification(), true, true)) : null;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
|
|
public TileEntityBeacon() {
|
|
super(TileEntityTypes.BEACON);
|
|
@@ -192,39 +208,78 @@
|
|
super.al_();
|
|
}
|
|
|
|
- private void applyEffects() {
|
|
- if (!this.world.isClientSide && this.primaryEffect != null) {
|
|
- double d0 = (double) (this.levels * 10 + 10);
|
|
+ // CraftBukkit start - split into components
|
|
+ private byte getAmplification() {
|
|
+ {
|
|
byte b0 = 0;
|
|
|
|
if (this.levels >= 4 && this.primaryEffect == this.secondaryEffect) {
|
|
b0 = 1;
|
|
}
|
|
|
|
+ return b0;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private int getLevel() {
|
|
+ {
|
|
int i = (9 + this.levels * 2) * 20;
|
|
+ return i;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public List getHumansInRange() {
|
|
+ {
|
|
+ double d0 = (double) (this.levels * 10 + 10);
|
|
+
|
|
AxisAlignedBB axisalignedbb = (new AxisAlignedBB(this.position)).g(d0).b(0.0D, (double) this.world.getBuildHeight(), 0.0D);
|
|
List<EntityHuman> list = this.world.a(EntityHuman.class, axisalignedbb);
|
|
+
|
|
+ return list;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void applyEffect(List list, MobEffectList effects, int i, int b0) {
|
|
+ {
|
|
Iterator iterator = list.iterator();
|
|
|
|
EntityHuman entityhuman;
|
|
|
|
while (iterator.hasNext()) {
|
|
entityhuman = (EntityHuman) iterator.next();
|
|
- entityhuman.addEffect(new MobEffect(this.primaryEffect, i, b0, true, true));
|
|
+ entityhuman.addEffect(new MobEffect(effects, i, b0, true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
|
|
}
|
|
+ }
|
|
+ }
|
|
|
|
+ private boolean hasSecondaryEffect() {
|
|
+ {
|
|
if (this.levels >= 4 && this.primaryEffect != this.secondaryEffect && this.secondaryEffect != null) {
|
|
- iterator = list.iterator();
|
|
-
|
|
- while (iterator.hasNext()) {
|
|
- entityhuman = (EntityHuman) iterator.next();
|
|
- entityhuman.addEffect(new MobEffect(this.secondaryEffect, i, 0, true, true));
|
|
- }
|
|
+ return true;
|
|
}
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
+ private void applyEffects() {
|
|
+ if (!this.world.isClientSide && this.primaryEffect != null) {
|
|
+ double d0 = (double) (this.levels * 10 + 10);
|
|
+ byte b0 = getAmplification();
|
|
+
|
|
+ int i = getLevel();
|
|
+ List list = getHumansInRange();
|
|
+
|
|
+ applyEffect(list, this.primaryEffect, i, b0);
|
|
+
|
|
+ if (hasSecondaryEffect()) {
|
|
+ applyEffect(list, this.secondaryEffect, i, 0);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
public void a(SoundEffect soundeffect) {
|
|
this.world.playSound((EntityHuman) null, this.position, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
|
}
|
|
@@ -254,8 +309,11 @@
|
|
@Override
|
|
public void load(IBlockData iblockdata, NBTTagCompound nbttagcompound) {
|
|
super.load(iblockdata, nbttagcompound);
|
|
- this.primaryEffect = b(nbttagcompound.getInt("Primary"));
|
|
- this.secondaryEffect = b(nbttagcompound.getInt("Secondary"));
|
|
+ // CraftBukkit start - persist manually set non-default beacon effects (SPIGOT-3598)
|
|
+ this.primaryEffect = MobEffectList.fromId(nbttagcompound.getInt("Primary"));
|
|
+ this.secondaryEffect = MobEffectList.fromId(nbttagcompound.getInt("Secondary"));
|
|
+ this.levels = nbttagcompound.getInt("Levels"); // SPIGOT-5053, use where available
|
|
+ // CraftBukkit end
|
|
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
|
|
this.customName = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
|
|
}
|