Add BeaconEffectEvent
This commit is contained in:
@@ -1,17 +1,25 @@
|
|||||||
--- a/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
--- a/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
||||||
+++ b/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
+++ b/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
|
||||||
@@ -45,6 +45,10 @@
|
@@ -1,5 +1,6 @@
|
||||||
|
package net.minecraft.world.level.block.entity;
|
||||||
|
|
||||||
|
+import com.destroystokyo.paper.event.block.BeaconEffectEvent;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import java.util.Collection;
|
||||||
|
@@ -45,6 +46,11 @@
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.levelgen.Heightmap;
|
import net.minecraft.world.level.levelgen.Heightmap;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
+// CraftBukkit start
|
+// CraftBukkit start
|
||||||
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||||
+import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
+import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
||||||
+import org.bukkit.potion.PotionEffect;
|
+import org.bukkit.potion.PotionEffect;
|
||||||
+// CraftBukkit end
|
+// CraftBukkit end
|
||||||
|
|
||||||
public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Nameable {
|
public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Nameable {
|
||||||
|
|
||||||
@@ -71,6 +75,15 @@
|
@@ -71,7 +77,16 @@
|
||||||
public Component name;
|
public Component name;
|
||||||
public LockCode lockKey;
|
public LockCode lockKey;
|
||||||
private final ContainerData dataAccess;
|
private final ContainerData dataAccess;
|
||||||
@@ -19,15 +27,16 @@
|
|||||||
+ public PotionEffect getPrimaryEffect() {
|
+ public PotionEffect getPrimaryEffect() {
|
||||||
+ return (this.primaryPower != null) ? CraftPotionUtil.toBukkit(new MobEffectInstance(this.primaryPower, BeaconBlockEntity.getLevel(this.levels), BeaconBlockEntity.getAmplification(this.levels, this.primaryPower, this.secondaryPower), true, true)) : null;
|
+ return (this.primaryPower != null) ? CraftPotionUtil.toBukkit(new MobEffectInstance(this.primaryPower, BeaconBlockEntity.getLevel(this.levels), BeaconBlockEntity.getAmplification(this.levels, this.primaryPower, this.secondaryPower), true, true)) : null;
|
||||||
+ }
|
+ }
|
||||||
+
|
|
||||||
+ public PotionEffect getSecondaryEffect() {
|
+ public PotionEffect getSecondaryEffect() {
|
||||||
+ return (BeaconBlockEntity.hasSecondaryEffect(this.levels, this.primaryPower, this.secondaryPower)) ? CraftPotionUtil.toBukkit(new MobEffectInstance(this.secondaryPower, BeaconBlockEntity.getLevel(this.levels), BeaconBlockEntity.getAmplification(this.levels, this.primaryPower, this.secondaryPower), true, true)) : null;
|
+ return (BeaconBlockEntity.hasSecondaryEffect(this.levels, this.primaryPower, this.secondaryPower)) ? CraftPotionUtil.toBukkit(new MobEffectInstance(this.secondaryPower, BeaconBlockEntity.getLevel(this.levels), BeaconBlockEntity.getAmplification(this.levels, this.primaryPower, this.secondaryPower), true, true)) : null;
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
|
+
|
||||||
@Nullable
|
@Nullable
|
||||||
static Holder<MobEffect> filterEffect(@Nullable Holder<MobEffect> effect) {
|
static Holder<MobEffect> filterEffect(@Nullable Holder<MobEffect> effect) {
|
||||||
@@ -251,39 +264,78 @@
|
return BeaconBlockEntity.VALID_EFFECTS.contains(effect) ? effect : null;
|
||||||
|
@@ -251,39 +266,86 @@
|
||||||
super.setRemoved();
|
super.setRemoved();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,16 +77,25 @@
|
|||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ private static void applyEffect(List list, @Nullable Holder<MobEffect> holder, int j, int b0) {
|
+ private static void applyEffect(List list, @Nullable Holder<MobEffect> holder, int j, int b0, boolean isPrimary, BlockPos worldPosition) { // Paper - BeaconEffectEvent
|
||||||
+ {
|
+ if (!list.isEmpty()) { // Paper - BeaconEffectEvent
|
||||||
Iterator iterator = list.iterator();
|
Iterator iterator = list.iterator();
|
||||||
|
|
||||||
Player entityhuman;
|
Player entityhuman;
|
||||||
|
+ // Paper start - BeaconEffectEvent
|
||||||
|
+ org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(((Player) list.get(0)).level(), worldPosition);
|
||||||
|
+ PotionEffect effect = CraftPotionUtil.toBukkit(new MobEffectInstance(holder, j, b0, true, true));
|
||||||
|
+ // Paper end - BeaconEffectEvent
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
entityhuman = (Player) iterator.next();
|
- entityhuman = (Player) iterator.next();
|
||||||
- entityhuman.addEffect(new MobEffectInstance(primaryEffect, j, b0, true, true));
|
- entityhuman.addEffect(new MobEffectInstance(primaryEffect, j, b0, true, true));
|
||||||
+ entityhuman.addEffect(new MobEffectInstance(holder, j, b0, true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
|
+ // Paper start - BeaconEffectEvent
|
||||||
|
+ entityhuman = (ServerPlayer) iterator.next();
|
||||||
|
+ BeaconEffectEvent event = new BeaconEffectEvent(block, effect, (org.bukkit.entity.Player) entityhuman.getBukkitEntity(), isPrimary);
|
||||||
|
+ if (CraftEventFactory.callEvent(event).isCancelled()) continue;
|
||||||
|
+ entityhuman.addEffect(new MobEffectInstance(CraftPotionUtil.fromBukkit(event.getEffect())), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
|
||||||
|
+ // Paper end - BeaconEffectEvent
|
||||||
}
|
}
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
@@ -107,10 +125,10 @@
|
|||||||
+ int j = BeaconBlockEntity.getLevel(beaconLevel);
|
+ int j = BeaconBlockEntity.getLevel(beaconLevel);
|
||||||
+ List list = BeaconBlockEntity.getHumansInRange(world, pos, beaconLevel);
|
+ List list = BeaconBlockEntity.getHumansInRange(world, pos, beaconLevel);
|
||||||
+
|
+
|
||||||
+ BeaconBlockEntity.applyEffect(list, primaryEffect, j, b0);
|
+ BeaconBlockEntity.applyEffect(list, primaryEffect, j, b0, true, pos); // Paper - BeaconEffectEvent
|
||||||
+
|
+
|
||||||
+ if (BeaconBlockEntity.hasSecondaryEffect(beaconLevel, primaryEffect, secondaryEffect)) {
|
+ if (BeaconBlockEntity.hasSecondaryEffect(beaconLevel, primaryEffect, secondaryEffect)) {
|
||||||
+ BeaconBlockEntity.applyEffect(list, secondaryEffect, j, 0);
|
+ BeaconBlockEntity.applyEffect(list, secondaryEffect, j, 0, false, pos); // Paper - BeaconEffectEvent
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
@@ -120,7 +138,7 @@
|
|||||||
public static void playSound(Level world, BlockPos pos, SoundEvent sound) {
|
public static void playSound(Level world, BlockPos pos, SoundEvent sound) {
|
||||||
world.playSound((Player) null, pos, sound, SoundSource.BLOCKS, 1.0F, 1.0F);
|
world.playSound((Player) null, pos, sound, SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||||
}
|
}
|
||||||
@@ -316,7 +368,7 @@
|
@@ -316,7 +378,7 @@
|
||||||
if (nbt.contains(key, 8)) {
|
if (nbt.contains(key, 8)) {
|
||||||
ResourceLocation minecraftkey = ResourceLocation.tryParse(nbt.getString(key));
|
ResourceLocation minecraftkey = ResourceLocation.tryParse(nbt.getString(key));
|
||||||
|
|
||||||
@@ -129,7 +147,7 @@
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -327,6 +379,7 @@
|
@@ -327,6 +389,7 @@
|
||||||
super.loadAdditional(nbt, registries);
|
super.loadAdditional(nbt, registries);
|
||||||
this.primaryPower = BeaconBlockEntity.loadEffect(nbt, "primary_effect");
|
this.primaryPower = BeaconBlockEntity.loadEffect(nbt, "primary_effect");
|
||||||
this.secondaryPower = BeaconBlockEntity.loadEffect(nbt, "secondary_effect");
|
this.secondaryPower = BeaconBlockEntity.loadEffect(nbt, "secondary_effect");
|
||||||
|
|||||||
Reference in New Issue
Block a user