mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Beacon API - custom effect ranges
This commit is contained in:
parent
2d042873d8
commit
5b1f73e2dc
2 changed files with 77 additions and 7 deletions
|
@ -19,7 +19,7 @@
|
|||
|
||||
public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Nameable {
|
||||
|
||||
@@ -71,7 +77,16 @@
|
||||
@@ -71,7 +77,36 @@
|
||||
public Component name;
|
||||
public LockCode lockKey;
|
||||
private final ContainerData dataAccess;
|
||||
|
@ -32,11 +32,40 @@
|
|||
+ 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
|
||||
+ // Paper start - Custom beacon ranges
|
||||
+ private final String PAPER_RANGE_TAG = "Paper.Range";
|
||||
+ private double effectRange = -1;
|
||||
+
|
||||
+ public double getEffectRange() {
|
||||
+ if (this.effectRange < 0) {
|
||||
+ return this.levels * 10 + 10;
|
||||
+ } else {
|
||||
+ return effectRange;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public void setEffectRange(double range) {
|
||||
+ this.effectRange = range;
|
||||
+ }
|
||||
+
|
||||
+ public void resetEffectRange() {
|
||||
+ this.effectRange = -1;
|
||||
+ }
|
||||
+ // Paper end - Custom beacon ranges
|
||||
+
|
||||
@Nullable
|
||||
static Holder<MobEffect> filterEffect(@Nullable Holder<MobEffect> effect) {
|
||||
return BeaconBlockEntity.VALID_EFFECTS.contains(effect) ? effect : null;
|
||||
@@ -251,39 +266,86 @@
|
||||
@@ -186,7 +221,7 @@
|
||||
}
|
||||
|
||||
if (blockEntity.levels > 0 && !blockEntity.beamSections.isEmpty()) {
|
||||
- BeaconBlockEntity.applyEffects(world, pos, blockEntity.levels, blockEntity.primaryPower, blockEntity.secondaryPower);
|
||||
+ BeaconBlockEntity.applyEffects(world, pos, blockEntity.levels, blockEntity.primaryPower, blockEntity.secondaryPower, blockEntity); // Paper - Custom beacon ranges
|
||||
BeaconBlockEntity.playSound(world, pos, SoundEvents.BEACON_AMBIENT);
|
||||
}
|
||||
}
|
||||
@@ -251,39 +286,96 @@
|
||||
super.setRemoved();
|
||||
}
|
||||
|
||||
|
@ -67,8 +96,13 @@
|
|||
+ }
|
||||
+
|
||||
+ public static List getHumansInRange(Level world, BlockPos blockposition, int i) {
|
||||
+ // Paper start - Custom beacon ranges
|
||||
+ return BeaconBlockEntity.getHumansInRange(world, blockposition, i, null);
|
||||
+ }
|
||||
+ public static List getHumansInRange(Level world, BlockPos blockposition, int i, @Nullable BeaconBlockEntity blockEntity) {
|
||||
+ // Paper end - Custom beacon ranges
|
||||
+ {
|
||||
+ double d0 = (double) (i * 10 + 10);
|
||||
+ double d0 = blockEntity != null ? blockEntity.getEffectRange() : (i * 10 + 10); // Paper - Custom beacon ranges
|
||||
+
|
||||
+ AABB axisalignedbb = (new AABB(blockposition)).inflate(d0).expandTowards(0.0D, (double) world.getHeight(), 0.0D);
|
||||
List<Player> list = world.getEntitiesOfClass(Player.class, axisalignedbb);
|
||||
|
@ -118,12 +152,17 @@
|
|||
}
|
||||
|
||||
+ private static void applyEffects(Level world, BlockPos pos, int beaconLevel, @Nullable Holder<MobEffect> primaryEffect, @Nullable Holder<MobEffect> secondaryEffect) {
|
||||
+ // Paper start - Custom beacon ranges
|
||||
+ BeaconBlockEntity.applyEffects(world, pos, beaconLevel, primaryEffect, secondaryEffect, null);
|
||||
+ }
|
||||
+ private static void applyEffects(Level world, BlockPos pos, int beaconLevel, @Nullable Holder<MobEffect> primaryEffect, @Nullable Holder<MobEffect> secondaryEffect, @Nullable BeaconBlockEntity blockEntity) {
|
||||
+ // Paper end - Custom beacon ranges
|
||||
+ if (!world.isClientSide && primaryEffect != null) {
|
||||
+ double d0 = (double) (beaconLevel * 10 + 10);
|
||||
+ byte b0 = BeaconBlockEntity.getAmplification(beaconLevel, primaryEffect, secondaryEffect);
|
||||
+
|
||||
+ int j = BeaconBlockEntity.getLevel(beaconLevel);
|
||||
+ List list = BeaconBlockEntity.getHumansInRange(world, pos, beaconLevel);
|
||||
+ List list = BeaconBlockEntity.getHumansInRange(world, pos, beaconLevel, blockEntity); // Paper - Custom beacon ranges
|
||||
+
|
||||
+ BeaconBlockEntity.applyEffect(list, primaryEffect, j, b0, true, pos); // Paper - BeaconEffectEvent
|
||||
+
|
||||
|
@ -138,7 +177,7 @@
|
|||
public static void playSound(Level world, BlockPos pos, SoundEvent sound) {
|
||||
world.playSound((Player) null, pos, sound, SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
}
|
||||
@@ -316,7 +378,7 @@
|
||||
@@ -316,7 +408,7 @@
|
||||
if (nbt.contains(key, 8)) {
|
||||
ResourceLocation minecraftkey = ResourceLocation.tryParse(nbt.getString(key));
|
||||
|
||||
|
@ -147,7 +186,7 @@
|
|||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -327,6 +389,7 @@
|
||||
@@ -327,11 +419,13 @@
|
||||
super.loadAdditional(nbt, registries);
|
||||
this.primaryPower = BeaconBlockEntity.loadEffect(nbt, "primary_effect");
|
||||
this.secondaryPower = BeaconBlockEntity.loadEffect(nbt, "secondary_effect");
|
||||
|
@ -155,3 +194,17 @@
|
|||
if (nbt.contains("CustomName", 8)) {
|
||||
this.name = parseCustomNameSafe(nbt.getString("CustomName"), registries);
|
||||
}
|
||||
|
||||
this.lockKey = LockCode.fromTag(nbt, registries);
|
||||
+ this.effectRange = nbt.contains(PAPER_RANGE_TAG, 6) ? nbt.getDouble(PAPER_RANGE_TAG) : -1; // Paper - Custom beacon ranges
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -345,6 +439,7 @@
|
||||
}
|
||||
|
||||
this.lockKey.addToTag(nbt, registries);
|
||||
+ nbt.putDouble(PAPER_RANGE_TAG, this.effectRange); // Paper - Custom beacon ranges
|
||||
}
|
||||
|
||||
public void setCustomName(@Nullable Component customName) {
|
||||
|
|
|
@ -42,7 +42,7 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
|
|||
if (tileEntity instanceof BeaconBlockEntity) {
|
||||
BeaconBlockEntity beacon = (BeaconBlockEntity) tileEntity;
|
||||
|
||||
Collection<Player> nms = BeaconBlockEntity.getHumansInRange(beacon.getLevel(), beacon.getBlockPos(), beacon.levels);
|
||||
Collection<Player> nms = BeaconBlockEntity.getHumansInRange(beacon.getLevel(), beacon.getBlockPos(), beacon.levels, beacon); // Paper - Custom beacon ranges
|
||||
Collection<LivingEntity> bukkit = new ArrayList<LivingEntity>(nms.size());
|
||||
|
||||
for (Player human : nms) {
|
||||
|
@ -145,4 +145,21 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
|
|||
public CraftBeacon copy(Location location) {
|
||||
return new CraftBeacon(this, location);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public double getEffectRange() {
|
||||
return this.getSnapshot().getEffectRange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEffectRange(double range) {
|
||||
this.getSnapshot().setEffectRange(range);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetEffectRange() {
|
||||
this.getSnapshot().resetEffectRange();
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue