mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@5e73c55 [ci skip] Add more identifying patch comments PaperMC/Paper@3e20d3a [ci skip] Add more identifying patch comments PaperMC/Paper@f61ebdc Fix issue with kick event causes being passed improperly PaperMC/Paper@106c67a [ci skip] Add more identifying patch comments PaperMC/Paper@cc693ce [ci skip] Add more identifying patch comments, merge related patches PaperMC/Paper@eeb6afc [ci skip] Add more identifying patch comments, merge related patches PaperMC/Paper@1c956ab [ci skip] Add more identifying patch comments, merge related patches PaperMC/Paper@42e88a8 [ci skip] Add more identifying patch comments PaperMC/Paper@8e41ef4 Add visual blockdata api for primed tnt (#10146) PaperMC/Paper@68c3297 [ci skip] Add more identifying patch comments PaperMC/Paper@4a98986 Add back Reduce allocation of Vec3D by entity tracker patch (#10179) PaperMC/Paper@b48d737 Async world data IO saving (#10171) PaperMC/Paper@8d94596 [ci skip] Add more identifying patch comments PaperMC/Paper@f7dd304 [ci skip] Add more identifying patch comments PaperMC/Paper@98e6d20 [ci skip] Add more identifying patch comments PaperMC/Paper@e9e0bc1 [ci skip] Add more identifying patch comments PaperMC/Paper@d9df6bc [ci skip] Add more patch identifying comments, cleanup PaperMC/Paper@27cabc1 [ci skip] Add more patch identifying comments Pufferfish Changes: pufferfish-gg/Pufferfish@8e208d3 Fix Async World Saving attribution
138 lines
7.9 KiB
Diff
138 lines
7.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: montlikadani <montlikada@gmail.com>
|
|
Date: Fri, 13 Nov 2020 17:52:40 +0100
|
|
Subject: [PATCH] Add adjustable breeding cooldown to config
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/Animal.java b/src/main/java/net/minecraft/world/entity/animal/Animal.java
|
|
index 081d1e38b7b1f286e138b0981aaa760e58761215..d94928a78d166dd3d836261b4f99fb4f533019e7 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/Animal.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/Animal.java
|
|
@@ -151,7 +151,7 @@ public abstract class Animal extends AgeableMob {
|
|
if (this.isFood(itemstack)) {
|
|
int i = this.getAge();
|
|
|
|
- if (!this.level().isClientSide && i == 0 && this.canFallInLove()) {
|
|
+ if (!this.level().isClientSide && i == 0 && this.canFallInLove() && (this.level().purpurConfig.animalBreedingCooldownSeconds <= 0 || !this.level().hasBreedingCooldown(player.getUUID(), this.getClass()))) { // Purpur
|
|
final ItemStack breedCopy = itemstack.copy(); // Paper - Fix EntityBreedEvent copying
|
|
this.usePlayerItem(player, hand, itemstack);
|
|
this.setInLove(player, breedCopy); // Paper - Fix EntityBreedEvent copying
|
|
@@ -242,12 +242,20 @@ public abstract class Animal extends AgeableMob {
|
|
AgeableMob entityageable = this.getBreedOffspring(world, other);
|
|
|
|
if (entityageable != null) {
|
|
- entityageable.setBaby(true);
|
|
- entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F);
|
|
- // CraftBukkit start - call EntityBreedEvent
|
|
+ // Purpur start
|
|
ServerPlayer breeder = Optional.ofNullable(this.getLoveCause()).or(() -> {
|
|
return Optional.ofNullable(other.getLoveCause());
|
|
}).orElse(null);
|
|
+ if (breeder != null && world.purpurConfig.animalBreedingCooldownSeconds > 0) {
|
|
+ if (world.hasBreedingCooldown(breeder.getUUID(), this.getClass())) {
|
|
+ return;
|
|
+ }
|
|
+ world.addBreedingCooldown(breeder.getUUID(), this.getClass());
|
|
+ }
|
|
+ entityageable.setBaby(true);
|
|
+ entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F);
|
|
+ // CraftBukkit start - call EntityBreedEvent
|
|
+ // Purpur end
|
|
int experience = this.getRandom().nextInt(7) + 1;
|
|
EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityageable, this, other, breeder, this.breedItem, experience);
|
|
if (entityBreedEvent.isCancelled()) {
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
|
index 1c8653222f07f5aa12639a95c13fdcdfd5dd87c0..29ff1ca5180aee623cd56c7310c2c0843f9a0b0a 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -196,6 +196,49 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
}
|
|
// Paper end - fix and optimise world upgrading
|
|
|
|
+ // Purpur start
|
|
+ private com.google.common.cache.Cache<BreedingCooldownPair, Object> playerBreedingCooldowns;
|
|
+
|
|
+ private com.google.common.cache.Cache<BreedingCooldownPair, Object> getNewBreedingCooldownCache() {
|
|
+ return com.google.common.cache.CacheBuilder.newBuilder().expireAfterWrite(this.purpurConfig.animalBreedingCooldownSeconds, java.util.concurrent.TimeUnit.SECONDS).build();
|
|
+ }
|
|
+
|
|
+ public void resetBreedingCooldowns() {
|
|
+ this.playerBreedingCooldowns = this.getNewBreedingCooldownCache();
|
|
+ }
|
|
+
|
|
+ public boolean hasBreedingCooldown(java.util.UUID player, Class<? extends net.minecraft.world.entity.animal.Animal> animalType) { // Purpur
|
|
+ return this.playerBreedingCooldowns.getIfPresent(new BreedingCooldownPair(player, animalType)) != null;
|
|
+ }
|
|
+
|
|
+ public void addBreedingCooldown(java.util.UUID player, Class<? extends net.minecraft.world.entity.animal.Animal> animalType) {
|
|
+ this.playerBreedingCooldowns.put(new BreedingCooldownPair(player, animalType), new Object());
|
|
+ }
|
|
+
|
|
+ private static final class BreedingCooldownPair {
|
|
+ private final java.util.UUID playerUUID;
|
|
+ private final Class<? extends net.minecraft.world.entity.animal.Animal> animalType;
|
|
+
|
|
+ public BreedingCooldownPair(java.util.UUID playerUUID, Class<? extends net.minecraft.world.entity.animal.Animal> animalType) {
|
|
+ this.playerUUID = playerUUID;
|
|
+ this.animalType = animalType;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean equals(Object o) {
|
|
+ if (this == o) return true;
|
|
+ if (o == null || getClass() != o.getClass()) return false;
|
|
+ BreedingCooldownPair that = (BreedingCooldownPair) o;
|
|
+ return playerUUID.equals(that.playerUUID) && animalType.equals(that.animalType);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int hashCode() {
|
|
+ return java.util.Objects.hash(playerUUID, animalType);
|
|
+ }
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
public CraftWorld getWorld() {
|
|
return this.world;
|
|
}
|
|
@@ -219,6 +262,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot
|
|
this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper - create paper world config
|
|
this.purpurConfig = new org.purpurmc.purpur.PurpurWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName(), env); // Purpur
|
|
+ this.playerBreedingCooldowns = this.getNewBreedingCooldownCache(); // Purpur
|
|
this.generator = gen;
|
|
this.world = new CraftWorld((ServerLevel) this, gen, biomeProvider, env);
|
|
|
|
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
index 6654234cae07b569ff97a51284a459335af300a4..52b9e364056b0b405779965daa634a8b0f1f82e0 100644
|
|
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
@@ -115,6 +115,7 @@ public class PurpurWorldConfig {
|
|
public double voidDamageHeight = -64.0D;
|
|
public double voidDamageDealt = 4.0D;
|
|
public int raidCooldownSeconds = 0;
|
|
+ public int animalBreedingCooldownSeconds = 0;
|
|
private void miscGameplayMechanicsSettings() {
|
|
useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending);
|
|
boatEjectPlayersOnLand = getBoolean("gameplay-mechanics.boat.eject-players-on-land", boatEjectPlayersOnLand);
|
|
@@ -125,6 +126,7 @@ public class PurpurWorldConfig {
|
|
voidDamageHeight = getDouble("gameplay-mechanics.void-damage-height", voidDamageHeight);
|
|
voidDamageDealt = getDouble("gameplay-mechanics.void-damage-dealt", voidDamageDealt);
|
|
raidCooldownSeconds = getInt("gameplay-mechanics.raid-cooldown-seconds", raidCooldownSeconds);
|
|
+ animalBreedingCooldownSeconds = getInt("gameplay-mechanics.animal-breeding-cooldown-seconds", animalBreedingCooldownSeconds);
|
|
}
|
|
|
|
public int daytimeTicks = 12000;
|
|
diff --git a/src/main/java/org/purpurmc/purpur/command/PurpurCommand.java b/src/main/java/org/purpurmc/purpur/command/PurpurCommand.java
|
|
index afdf04f8b22ad0b7c0b41675e44687b49c2f86d6..2621e54879e9ab0029a875f1d09eee67878b90d5 100644
|
|
--- a/src/main/java/org/purpurmc/purpur/command/PurpurCommand.java
|
|
+++ b/src/main/java/org/purpurmc/purpur/command/PurpurCommand.java
|
|
@@ -49,6 +49,7 @@ public class PurpurCommand extends Command {
|
|
PurpurConfig.init((File) console.options.valueOf("purpur-settings"));
|
|
for (ServerLevel level : console.getAllLevels()) {
|
|
level.purpurConfig.init();
|
|
+ level.resetBreedingCooldowns();
|
|
}
|
|
console.server.reloadCount++;
|
|
|