PaperMC/nms-patches/TileEntityBeacon.patch

145 lines
4.7 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/TileEntityBeacon.java
+++ b/net/minecraft/server/TileEntityBeacon.java
2016-11-17 02:41:03 +01:00
@@ -9,6 +9,13 @@
2016-02-29 22:32:46 +01:00
import java.util.Set;
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
+
2016-02-29 22:32:46 +01:00
public class TileEntityBeacon extends TileEntityContainer implements ITickable, IWorldInventory {
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}};
2016-11-17 02:41:03 +01:00
@@ -22,6 +29,38 @@
public MobEffectList secondaryEffect;
private ItemStack inventorySlot;
2016-02-29 22:32:46 +01:00
private String o;
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+
2016-11-17 02:41:03 +01:00
+ public List<ItemStack> getContents() {
+ return Arrays.asList(this.inventorySlot);
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
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() {
this.inventorySlot = ItemStack.a;
@@ -42,41 +81,79 @@
2016-07-18 09:40:07 +02:00
}
- private void E() {
2016-11-17 02:41:03 +01:00
- if (this.j && this.levels > 0 && !this.world.isClientSide && this.primaryEffect != null) {
- 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
+
int j = this.position.getX();
int k = this.position.getY();
int l = this.position.getZ();
2016-11-17 02:41:03 +01:00
AxisAlignedBB axisalignedbb = (new AxisAlignedBB((double) j, (double) k, (double) l, (double) (j + 1), (double) (k + 1), (double) (l + 1))).g(d0).b(0.0D, (double) this.world.getHeight(), 0.0D);
2016-07-18 09:40:07 +02:00
List 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();
2016-11-17 02:41:03 +01:00
- entityhuman.addEffect(new MobEffect(this.primaryEffect, i, b0, true, true));
2016-07-18 09:40:07 +02:00
+ entityhuman.addEffect(new MobEffect(effects, i, b0, true, true));
}
+ }
+ }
+ 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();
+ return true;
+ }
+
+ return false;
+ }
+ }
+
+ private void E() {
2016-11-17 02:41:03 +01:00
+ if (this.j && this.levels > 0 && !this.world.isClientSide && this.primaryEffect != null) {
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);
2016-07-18 09:40:07 +02:00
- while (iterator.hasNext()) {
- entityhuman = (EntityHuman) iterator.next();
2016-11-17 02:41:03 +01:00
- entityhuman.addEffect(new MobEffect(this.secondaryEffect, i, 0, true, true));
2016-07-18 09:40:07 +02:00
- }
+ if (hasSecondaryEffect()) {
2016-11-17 02:41:03 +01:00
+ applyEffect(list, this.secondaryEffect, i, 0);
2016-07-18 09:40:07 +02:00
}
}
}
+ // CraftBukkit end
private void F() {
2016-11-17 02:41:03 +01:00
int i = this.levels;