Files
Purpur/patches/server/0110-Configurable-chance-for-wolves-to-spawn-rabid.patch
granny 7f6f667142 Updated Upstream (Pufferfish)
Upstream has released updates that appear to apply and compile correctly

Pufferfish Changes:
pufferfish-gg/Pufferfish@f05b0e9 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@9a82b86 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@c6ec7a0 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@c789f72 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@9ddaa1a Updated Upstream (Paper)
pufferfish-gg/Pufferfish@3554f78 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@a9e9d99 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@09a2f81 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@63ce67d Updated Upstream (Paper)
pufferfish-gg/Pufferfish@8abd47b Updated Upstream (Paper)
pufferfish-gg/Pufferfish@3415da0 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@cfa3c61 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@0a8641d 1.21.3 Update
pufferfish-gg/Pufferfish@784d72f Updated Upstream (Paper)
pufferfish-gg/Pufferfish@40e1ad0 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@95ef348 Make iterator counting in IteratorSafeOrderedReferenceSet thread-safe for async mob spawning (#109)
pufferfish-gg/Pufferfish@34c0042 Updated Upstream (Paper)
2024-11-30 20:49:52 -08:00

206 lines
10 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Encode42 <me@encode42.dev>
Date: Tue, 8 Dec 2020 17:15:15 -0500
Subject: [PATCH] Configurable chance for wolves to spawn rabid
Configurable chance to spawn a wolf that is rabid.
Rabid wolves attack all players, mobs, and animals.
diff --git a/src/main/java/net/minecraft/world/entity/animal/Wolf.java b/src/main/java/net/minecraft/world/entity/animal/Wolf.java
index bb2e5e97d33ffaf95a6c88b3c077de1a89a60c6e..34ca92be146bec3d2f6e46f473c3e68b0a97b168 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Wolf.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Wolf.java
@@ -103,6 +103,37 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
return entitytypes == EntityType.SHEEP || entitytypes == EntityType.RABBIT || entitytypes == EntityType.FOX;
};
+ // Purpur start - rabid wolf spawn chance
+ private boolean isRabid = false;
+ private static final TargetingConditions.Selector RABID_PREDICATE = (entity, ignored) -> entity instanceof net.minecraft.server.level.ServerPlayer || entity instanceof net.minecraft.world.entity.Mob;
+ private final net.minecraft.world.entity.ai.goal.Goal PATHFINDER_VANILLA = new NonTameRandomTargetGoal<>(this, Animal.class, false, PREY_SELECTOR);
+ private final net.minecraft.world.entity.ai.goal.Goal PATHFINDER_RABID = new NonTameRandomTargetGoal<>(this, LivingEntity.class, false, RABID_PREDICATE);
+ private static final class AvoidRabidWolfGoal extends AvoidEntityGoal<Wolf> {
+ private final Wolf wolf;
+
+ public AvoidRabidWolfGoal(Wolf wolf, float distance, double minSpeed, double maxSpeed) {
+ super(wolf, Wolf.class, distance, minSpeed, maxSpeed);
+ this.wolf = wolf;
+ }
+
+ @Override
+ public boolean canUse() {
+ return super.canUse() && !this.wolf.isRabid() && this.toAvoid != null && this.toAvoid.isRabid(); // wolves which are not rabid run away from rabid wolves
+ }
+
+ @Override
+ public void start() {
+ this.wolf.setTarget(null);
+ super.start();
+ }
+
+ @Override
+ public void tick() {
+ this.wolf.setTarget(null);
+ super.tick();
+ }
+ }
+ // Purpur end
private static final float START_HEALTH = 8.0F;
private static final float TAME_HEALTH = 40.0F;
private static final float ARMOR_REPAIR_UNIT = 0.125F;
@@ -157,6 +188,30 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
return this.level().purpurConfig.wolfBreedingTicks;
}
+ public boolean isRabid() {
+ return this.isRabid;
+ }
+
+ public void setRabid(boolean isRabid) {
+ this.isRabid = isRabid;
+ updatePathfinders(true);
+ }
+
+ public void updatePathfinders(boolean modifyEffects) {
+ this.targetSelector.removeGoal(PATHFINDER_VANILLA);
+ this.targetSelector.removeGoal(PATHFINDER_RABID);
+ if (this.isRabid) {
+ setOwnerUUID(null);
+ setTame(false, true);
+ this.targetSelector.addGoal(5, PATHFINDER_RABID);
+ if (modifyEffects) this.addEffect(new net.minecraft.world.effect.MobEffectInstance(net.minecraft.world.effect.MobEffects.CONFUSION, 1200));
+ } else {
+ this.targetSelector.addGoal(5, PATHFINDER_VANILLA);
+ this.stopBeingAngry();
+ if (modifyEffects) this.removeEffect(net.minecraft.world.effect.MobEffects.CONFUSION);
+ }
+ }
+
@Override
protected void registerGoals() {
this.goalSelector.addGoal(1, new FloatGoal(this));
@@ -164,6 +219,7 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
this.goalSelector.addGoal(1, new TamableAnimal.TamableAnimalPanicGoal(1.5D, DamageTypeTags.PANIC_ENVIRONMENTAL_CAUSES));
this.goalSelector.addGoal(2, new SitWhenOrderedToGoal(this));
this.goalSelector.addGoal(3, new Wolf.WolfAvoidEntityGoal<>(this, Llama.class, 24.0F, 1.5D, 1.5D));
+ this.goalSelector.addGoal(3, new AvoidRabidWolfGoal(this, 24.0F, 1.5D, 1.5D)); // Purpur
this.goalSelector.addGoal(4, new LeapAtTargetGoal(this, 0.4F));
this.goalSelector.addGoal(5, new MeleeAttackGoal(this, 1.0D, true));
this.goalSelector.addGoal(6, new FollowOwnerGoal(this, 1.0D, 10.0F, 2.0F));
@@ -177,7 +233,7 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
this.targetSelector.addGoal(2, new OwnerHurtTargetGoal(this));
this.targetSelector.addGoal(3, (new HurtByTargetGoal(this, new Class[0])).setAlertOthers());
this.targetSelector.addGoal(4, new NearestAttackableTargetGoal<>(this, Player.class, 10, true, false, this::isAngryAt));
- this.targetSelector.addGoal(5, new NonTameRandomTargetGoal<>(this, Animal.class, false, Wolf.PREY_SELECTOR));
+ // this.targetSelector.addGoal(5, new NonTameRandomTargetGoal<>(this, Animal.class, false, Wolf.PREY_SELECTOR)); // Purpur - moved to updatePathfinders()
this.targetSelector.addGoal(6, new NonTameRandomTargetGoal<>(this, Turtle.class, false, Turtle.BABY_ON_LAND_SELECTOR));
this.targetSelector.addGoal(7, new NearestAttackableTargetGoal<>(this, AbstractSkeleton.class, false));
this.targetSelector.addGoal(8, new ResetUniversalAngerTargetGoal<>(this, true));
@@ -226,6 +282,7 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
public void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt);
nbt.putByte("CollarColor", (byte) this.getCollarColor().getId());
+ nbt.putBoolean("Purpur.IsRabid", this.isRabid); // Purpur
this.getVariant().unwrapKey().ifPresent((resourcekey) -> {
nbt.putString("variant", resourcekey.location().toString());
});
@@ -243,6 +300,10 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
if (nbt.contains("CollarColor", 99)) {
this.setCollarColor(DyeColor.byId(nbt.getInt("CollarColor")));
}
+ // Purpur start
+ this.isRabid = nbt.getBoolean("Purpur.IsRabid");
+ this.updatePathfinders(false);
+ // Purpur end
this.readPersistentAngerSaveData(this.level(), nbt);
}
@@ -261,6 +322,12 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
}
this.setVariant(holder1);
+
+ // Purpur start
+ this.isRabid = world.getLevel().purpurConfig.wolfNaturalRabid > 0.0D && random.nextDouble() <= world.getLevel().purpurConfig.wolfNaturalRabid;
+ this.updatePathfinders(false);
+ // Purpur end
+
return super.finalizeSpawn(world, difficulty, spawnReason, (SpawnGroupData) entityData);
}
@@ -304,6 +371,11 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
public void tick() {
super.tick();
if (this.isAlive()) {
+ // Purpur start
+ if (this.age % 300 == 0 && this.isRabid()) {
+ this.addEffect(new net.minecraft.world.effect.MobEffectInstance(net.minecraft.world.effect.MobEffects.CONFUSION, 400));
+ }
+ // Purpur end
this.interestedAngleO = this.interestedAngle;
if (this.isInterested()) {
this.interestedAngle += (1.0F - this.interestedAngle) * 0.4F;
@@ -534,6 +606,19 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
itemstack.consume(1, player);
this.tryToTame(player);
return InteractionResult.SUCCESS_SERVER;
+ // Purpur start
+ } else if (this.level().purpurConfig.wolfMilkCuresRabies && itemstack.getItem() == Items.MILK_BUCKET && this.isRabid()) {
+ if (!player.isCreative()) {
+ player.setItemInHand(hand, new ItemStack(Items.BUCKET));
+ }
+ this.setRabid(false);
+ for (int i = 0; i < 10; ++i) {
+ ((ServerLevel) level()).sendParticles(((ServerLevel) level()).players(), null, ParticleTypes.HAPPY_VILLAGER,
+ getX() + random.nextFloat(), getY() + (random.nextFloat() * 1.5), getZ() + random.nextFloat(), 1,
+ random.nextGaussian() * 0.05D, random.nextGaussian() * 0.05D, random.nextGaussian() * 0.05D, 0, true);
+ }
+ return InteractionResult.SUCCESS_SERVER;
+ // Purpur end
} else {
return super.mobInteract(player, hand);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftWolf.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftWolf.java
index ecd33b4add46acbe4e4f8879c0601220423d66ca..1506a8c0fa490726eb4a4ae14f3aa194dc81d9ab 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftWolf.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftWolf.java
@@ -146,4 +146,16 @@ public class CraftWolf extends CraftTameableAnimal implements Wolf {
return this.getKey().hashCode();
}
}
+
+ // Purpur start
+ @Override
+ public boolean isRabid() {
+ return getHandle().isRabid();
+ }
+
+ @Override
+ public void setRabid(boolean isRabid) {
+ getHandle().setRabid(isRabid);
+ }
+ // Purpur end
}
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index 09bf59c95f57f5beb718e74d99a6399317cf1222..ece3de874b4ad6dd9f17190281dcad2eab6a3097 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -2064,6 +2064,8 @@ public class PurpurWorldConfig {
public boolean wolfControllable = true;
public double wolfMaxHealth = 8.0D;
public double wolfScale = 1.0D;
+ public boolean wolfMilkCuresRabies = true;
+ public double wolfNaturalRabid = 0.0D;
public int wolfBreedingTicks = 6000;
private void wolfSettings() {
wolfRidable = getBoolean("mobs.wolf.ridable", wolfRidable);
@@ -2076,6 +2078,8 @@ public class PurpurWorldConfig {
}
wolfMaxHealth = getDouble("mobs.wolf.attributes.max_health", wolfMaxHealth);
wolfScale = Mth.clamp(getDouble("mobs.wolf.attributes.scale", wolfScale), 0.0625D, 16.0D);
+ wolfMilkCuresRabies = getBoolean("mobs.wolf.milk-cures-rabid-wolves", wolfMilkCuresRabies);
+ wolfNaturalRabid = getDouble("mobs.wolf.spawn-rabid-chance", wolfNaturalRabid);
wolfBreedingTicks = getInt("mobs.wolf.breeding-delay-ticks", wolfBreedingTicks);
}