mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
205 lines
11 KiB
Diff
205 lines
11 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/net/minecraft/world/entity/animal/Wolf.java b/net/minecraft/world/entity/animal/Wolf.java
|
|
index 539eba7148be12eb05c907ed86b0cea975424874..966fe4544212cc831ae617bc2eb05189102ff470 100644
|
|
--- a/net/minecraft/world/entity/animal/Wolf.java
|
|
+++ b/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 - Configurable chance for wolves to spawn rabid
|
|
+ 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 - Configurable chance for wolves to spawn rabid
|
|
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;
|
|
@@ -159,6 +190,31 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
|
|
return this.level().purpurConfig.wolfBreedingTicks;
|
|
}
|
|
// Purpur end - Make entity breeding times configurable
|
|
+ // Purpur start - Configurable chance for wolves to spawn rabid
|
|
+ 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);
|
|
+ }
|
|
+ }
|
|
+ // Purpur end - Configurable chance for wolves to spawn rabid
|
|
@Override
|
|
protected void registerGoals() {
|
|
this.goalSelector.addGoal(1, new FloatGoal(this));
|
|
@@ -166,6 +222,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 - Configurable chance for wolves to spawn rabid
|
|
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));
|
|
@@ -179,7 +236,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));
|
|
@@ -228,6 +285,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 - Configurable chance for wolves to spawn rabid
|
|
this.getVariant().unwrapKey().ifPresent((resourcekey) -> {
|
|
nbt.putString("variant", resourcekey.location().toString());
|
|
});
|
|
@@ -245,6 +303,10 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
|
|
if (nbt.contains("CollarColor", 99)) {
|
|
this.setCollarColor(DyeColor.byId(nbt.getInt("CollarColor")));
|
|
}
|
|
+ // Purpur start - Configurable chance for wolves to spawn rabid
|
|
+ this.isRabid = nbt.getBoolean("Purpur.IsRabid");
|
|
+ this.updatePathfinders(false);
|
|
+ // Purpur end - Configurable chance for wolves to spawn rabid
|
|
|
|
this.readPersistentAngerSaveData(this.level(), nbt);
|
|
}
|
|
@@ -263,6 +325,10 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
|
|
}
|
|
|
|
this.setVariant(holder1);
|
|
+ // Purpur start - Configurable chance for wolves to spawn rabid
|
|
+ this.isRabid = world.getLevel().purpurConfig.wolfNaturalRabid > 0.0D && random.nextDouble() <= world.getLevel().purpurConfig.wolfNaturalRabid;
|
|
+ this.updatePathfinders(false);
|
|
+ // Purpur end - Configurable chance for wolves to spawn rabid
|
|
return super.finalizeSpawn(world, difficulty, spawnReason, (SpawnGroupData) entityData);
|
|
}
|
|
|
|
@@ -306,6 +372,11 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
|
|
public void tick() {
|
|
super.tick();
|
|
if (this.isAlive()) {
|
|
+ // Purpur start - Configurable chance for wolves to spawn rabid
|
|
+ if (this.age % 300 == 0 && this.isRabid()) {
|
|
+ this.addEffect(new net.minecraft.world.effect.MobEffectInstance(net.minecraft.world.effect.MobEffects.CONFUSION, 400));
|
|
+ }
|
|
+ // Purpur end - Configurable chance for wolves to spawn rabid
|
|
this.interestedAngleO = this.interestedAngle;
|
|
if (this.isInterested()) {
|
|
this.interestedAngle += (1.0F - this.interestedAngle) * 0.4F;
|
|
@@ -536,6 +607,20 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder<Hol
|
|
itemstack.consume(1, player);
|
|
this.tryToTame(player);
|
|
return InteractionResult.SUCCESS_SERVER;
|
|
+ // Purpur start - Configurable chance for wolves to spawn rabid
|
|
+ } 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()).sendParticlesSource(((ServerLevel) level()).players(), null, ParticleTypes.HAPPY_VILLAGER,
|
|
+ false, true,
|
|
+ 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);
|
|
+ }
|
|
+ return InteractionResult.SUCCESS_SERVER;
|
|
+ // Purpur end - Configurable chance for wolves to spawn rabid
|
|
} 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..001f131117c277e46f4a94f73da36d1b219fe3cd 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftWolf.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftWolf.java
|
|
@@ -146,4 +146,15 @@ public class CraftWolf extends CraftTameableAnimal implements Wolf {
|
|
return this.getKey().hashCode();
|
|
}
|
|
}
|
|
+ // Purpur start - Configurable chance for wolves to spawn rabid
|
|
+ @Override
|
|
+ public boolean isRabid() {
|
|
+ return getHandle().isRabid();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setRabid(boolean isRabid) {
|
|
+ getHandle().setRabid(isRabid);
|
|
+ }
|
|
+ // Purpur end - Configurable chance for wolves to spawn rabid
|
|
}
|
|
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);
|
|
}
|
|
|