Add phantom creative and insomniac controls

This commit is contained in:
William Blake Galbreath 2020-04-25 15:13:41 -05:00
parent 56752585e8
commit 8a71e1c7da
3 changed files with 23 additions and 9 deletions

View file

@ -1,7 +1,10 @@
--- a/net/minecraft/world/entity/EntitySelector.java
+++ b/net/minecraft/world/entity/EntitySelector.java
@@ -29,6 +29,11 @@
@@ -27,8 +27,14 @@
};
public static final Predicate<Entity> CAN_BE_COLLIDED_WITH = EntitySelector.NO_SPECTATORS.and(Entity::canBeCollidedWith);
public static final Predicate<Entity> CAN_BE_PICKED = EntitySelector.NO_SPECTATORS.and(Entity::isPickable);
+ public static Predicate<Player> IS_INSOMNIAC = (player) -> net.minecraft.util.Mth.clamp(((net.minecraft.server.level.ServerPlayer) player).getStats().getValue(net.minecraft.stats.Stats.CUSTOM.get(net.minecraft.stats.Stats.TIME_SINCE_REST)), 1, Integer.MAX_VALUE) >= 72000; // Paper - Add phantom creative and insomniac controls
private EntitySelector() {}
+ // Paper start - Affects Spawning API
@ -12,7 +15,7 @@
public static Predicate<Entity> withinDistance(double x, double y, double z, double max) {
double d4 = max * max;
@@ -43,9 +48,9 @@
@@ -43,9 +49,9 @@
Team.CollisionRule scoreboardteambase_enumteampush = scoreboardteam == null ? Team.CollisionRule.ALWAYS : scoreboardteam.getCollisionRule();
return (Predicate) (scoreboardteambase_enumteampush == Team.CollisionRule.NEVER ? Predicates.alwaysFalse() : EntitySelector.NO_SPECTATORS.and((entity1) -> {

View file

@ -24,10 +24,12 @@
}
@Override
@@ -219,6 +229,17 @@
return predicate.test(world, this, target);
}
@@ -217,7 +227,18 @@
boolean canAttack(ServerLevel world, LivingEntity target, TargetingConditions predicate) {
return predicate.test(world, this, target);
+ }
+
+ // Paper start
+ @Nullable
+ java.util.UUID spawningEntity;
@ -35,14 +37,13 @@
+ @Nullable
+ public java.util.UUID getSpawningEntity() {
+ return this.spawningEntity;
+ }
}
+ public void setSpawningEntity(java.util.UUID entity) { this.spawningEntity = entity; }
+ // Paper end
+
private static enum AttackPhase {
CIRCLE, SWOOP;
@@ -522,14 +543,14 @@
@@ -522,14 +543,15 @@
List<Player> list = worldserver.getNearbyPlayers(this.attackTargeting, Phantom.this, Phantom.this.getBoundingBox().inflate(16.0D, 64.0D, 16.0D));
if (!list.isEmpty()) {
@ -55,6 +56,7 @@
if (Phantom.this.canAttack(worldserver, entityhuman, TargetingConditions.DEFAULT)) {
- Phantom.this.setTarget(entityhuman);
+ if (!level().paperConfig().entities.behavior.phantomsOnlyAttackInsomniacs || EntitySelector.IS_INSOMNIAC.test(entityhuman)) // Paper - Add phantom creative and insomniac controls
+ Phantom.this.setTarget(entityhuman, org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); // CraftBukkit - reason
return true;
}

View file

@ -1,5 +1,14 @@
--- a/net/minecraft/world/level/levelgen/PhantomSpawner.java
+++ b/net/minecraft/world/level/levelgen/PhantomSpawner.java
@@ -48,7 +48,7 @@
while (iterator.hasNext()) {
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
- if (!entityplayer.isSpectator()) {
+ if (!entityplayer.isSpectator() && (!world.paperConfig().entities.behavior.phantomsDoNotSpawnOnCreativePlayers || !entityplayer.isCreative())) { // Paper - Add phantom creative and insomniac controls
BlockPos blockposition = entityplayer.blockPosition();
if (!world.dimensionType().hasSkyLight() || blockposition.getY() >= world.getSeaLevel() && world.canSeeSky(blockposition)) {
@@ -69,12 +69,22 @@
int k = 1 + randomsource.nextInt(difficultydamagescaler.getDifficulty().getId() + 1);