3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-30 18:10:06 +01:00
Paper/nms-patches/TileEntityBeacon.patch

135 Zeilen
4.9 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/TileEntityBeacon.java
+++ b/net/minecraft/server/TileEntityBeacon.java
2018-12-25 22:00:00 +01:00
@@ -8,6 +8,13 @@
2018-07-15 02:00:00 +02:00
import java.util.stream.Collectors;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
2016-07-18 09:40:07 +02:00
+import org.bukkit.craftbukkit.potion.CraftPotionUtil;
+import org.bukkit.entity.HumanEntity;
2016-07-18 09:40:07 +02:00
+import org.bukkit.potion.PotionEffect;
+// CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public class TileEntityBeacon extends TileEntity implements ITileInventory, ITickable {
2016-02-29 22:32:46 +01:00
public static final MobEffectList[][] a = new MobEffectList[][] { { MobEffects.FASTER_MOVEMENT, MobEffects.FASTER_DIG}, { MobEffects.RESISTANCE, MobEffects.JUMP}, { MobEffects.INCREASE_DAMAGE}, { MobEffects.REGENERATION}};
2019-04-23 04:00:00 +02:00
@@ -24,6 +31,15 @@
public IChatBaseComponent customName;
public ChestLock chestLock;
private final IContainerProperties containerProperties;
+ // CraftBukkit start - add fields and methods
2016-07-18 09:40:07 +02:00
+ public PotionEffect getPrimaryEffect() {
2016-11-17 02:41:03 +01:00
+ return (this.primaryEffect != null) ? CraftPotionUtil.toBukkit(new MobEffect(this.primaryEffect, getLevel(), getAmplification(), true, true)) : null;
2016-07-18 09:40:07 +02:00
+ }
+
+ public PotionEffect getSecondaryEffect() {
2016-11-17 02:41:03 +01:00
+ return (hasSecondaryEffect()) ? CraftPotionUtil.toBukkit(new MobEffect(this.secondaryEffect, getLevel(), getAmplification(), true, true)) : null;
2016-07-18 09:40:07 +02:00
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
public TileEntityBeacon() {
2018-08-26 04:00:00 +02:00
super(TileEntityTypes.BEACON);
2019-04-25 04:00:00 +02:00
@@ -187,39 +203,78 @@
2019-04-23 04:00:00 +02:00
2016-07-18 09:40:07 +02:00
}
2018-12-13 01:00:00 +01:00
- private void applyEffects() {
2019-04-23 04:00:00 +02:00
- if (!this.world.isClientSide && this.primaryEffect != null) {
2016-11-17 02:41:03 +01:00
- double d0 = (double) (this.levels * 10 + 10);
2016-07-18 09:40:07 +02:00
+ // CraftBukkit start - split into components
+ private byte getAmplification() {
+ {
byte b0 = 0;
2016-11-17 02:41:03 +01:00
if (this.levels >= 4 && this.primaryEffect == this.secondaryEffect) {
2016-07-18 09:40:07 +02:00
b0 = 1;
}
+ return b0;
+ }
+ }
+
+ private int getLevel() {
+ {
2016-11-17 02:41:03 +01:00
int i = (9 + this.levels * 2) * 20;
2016-07-18 09:40:07 +02:00
+ return i;
+ }
+ }
+
+ public List getHumansInRange() {
+ {
2016-11-17 02:41:03 +01:00
+ double d0 = (double) (this.levels * 10 + 10);
2016-07-18 09:40:07 +02:00
+
2019-05-14 02:00:00 +02:00
AxisAlignedBB axisalignedbb = (new AxisAlignedBB(this.position)).g(d0).b(0.0D, (double) this.world.getBuildHeight(), 0.0D);
2018-12-25 22:00:00 +01:00
List<EntityHuman> list = this.world.a(EntityHuman.class, axisalignedbb);
2016-07-18 09:40:07 +02:00
+
+ 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();
2016-11-17 02:41:03 +01:00
- 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);
2016-07-18 09:40:07 +02:00
}
+ }
+ }
+ private boolean hasSecondaryEffect() {
+ {
2016-11-17 02:41:03 +01:00
if (this.levels >= 4 && this.primaryEffect != this.secondaryEffect && this.secondaryEffect != null) {
2016-07-18 09:40:07 +02:00
- iterator = list.iterator();
2019-04-23 04:00:00 +02:00
-
2017-10-13 12:47:55 +02:00
- while (iterator.hasNext()) {
- entityhuman = (EntityHuman) iterator.next();
- entityhuman.addEffect(new MobEffect(this.secondaryEffect, i, 0, true, true));
- }
2019-04-23 04:00:00 +02:00
+ return true;
}
2016-07-18 09:40:07 +02:00
+ return false;
2019-04-23 04:00:00 +02:00
}
}
2018-12-13 01:00:00 +01:00
+ private void applyEffects() {
2019-04-23 04:00:00 +02:00
+ if (!this.world.isClientSide && this.primaryEffect != null) {
+ double d0 = (double) (this.levels * 10 + 10);
2016-07-18 09:40:07 +02:00
+ byte b0 = getAmplification();
+
+ int i = getLevel();
+ List list = getHumansInRange();
+
2016-11-17 02:41:03 +01:00
+ applyEffect(list, this.primaryEffect, i, b0);
2017-10-13 12:47:55 +02:00
+
2016-07-18 09:40:07 +02:00
+ if (hasSecondaryEffect()) {
2016-11-17 02:41:03 +01:00
+ applyEffect(list, this.secondaryEffect, i, 0);
2019-04-23 04:00:00 +02:00
+ }
+ }
+
+ }
2016-07-18 09:40:07 +02:00
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
+
public void a(SoundEffect soundeffect) {
this.world.a((EntityHuman) null, this.position, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
2019-04-25 04:00:00 +02:00
@@ -249,8 +304,10 @@
2019-04-23 04:00:00 +02:00
@Override
public void load(NBTTagCompound nbttagcompound) {
super.load(nbttagcompound);
2019-04-23 04:00:00 +02:00
- 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"));
+ // Craftbukkit end
2019-04-23 04:00:00 +02:00
if (nbttagcompound.hasKeyOfType("CustomName", 8)) {
this.customName = IChatBaseComponent.ChatSerializer.a(nbttagcompound.getString("CustomName"));
}