Skip to content

Commit 9a19308

Browse files
authored
Lock Frozen Ticks API (#7207)
1 parent 0a9602c commit 9a19308

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
3+
Date: Sun, 26 Dec 2021 20:27:49 -0500
4+
Subject: [PATCH] Freeze Tick Lock API
5+
6+
7+
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
8+
index 51ec2e4ec4239659272bba3d6ba2ad73926ebb88..c2c45a93887f99466a8ac4275355ac75c7f901c4 100644
9+
--- a/src/main/java/org/bukkit/entity/Entity.java
10+
+++ b/src/main/java/org/bukkit/entity/Entity.java
11+
@@ -278,6 +278,26 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
12+
*/
13+
boolean isFrozen();
14+
15+
+ // Paper Start - Freeze Tick Lock API
16+
+ /**
17+
+ * Gets if the entity currently has its freeze ticks locked
18+
+ * to a set amount.
19+
+ * <p>
20+
+ * This is only set by plugins
21+
+ *
22+
+ * @return locked or not
23+
+ */
24+
+ boolean isFreezeTickingLocked();
25+
+
26+
+ /**
27+
+ * Sets if the entity currently has its freeze ticks locked,
28+
+ * preventing default vanilla freeze tick modification.
29+
+ *
30+
+ * @param locked prevent vanilla modification or not
31+
+ */
32+
+ void lockFreezeTicks(boolean locked);
33+
+ // Paper End - Freeze Tick Lock API
34+
+
35+
/**
36+
* Mark the entity's removal.
37+
*/
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
3+
Date: Sun, 26 Dec 2021 20:27:43 -0500
4+
Subject: [PATCH] Freeze Tick Lock API
5+
6+
7+
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
8+
index eac13465c8c1827953a8b1bb2feb4d7f92c773fb..4584dcec835f97e94dcf12788b66703075dafe45 100644
9+
--- a/src/main/java/net/minecraft/world/entity/Entity.java
10+
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
11+
@@ -332,6 +332,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
12+
private org.bukkit.util.Vector origin;
13+
@javax.annotation.Nullable
14+
private UUID originWorld;
15+
+ public boolean freezeLocked = false; // Paper - Freeze Tick Lock API
16+
17+
public void setOrigin(@javax.annotation.Nonnull Location location) {
18+
this.origin = location.toVector();
19+
@@ -758,7 +759,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
20+
this.setRemainingFireTicks(this.remainingFireTicks - 1);
21+
}
22+
23+
- if (this.getTicksFrozen() > 0) {
24+
+ if (this.getTicksFrozen() > 0 && !freezeLocked) { // Paper - Freeze Tick Lock API
25+
this.setTicksFrozen(0);
26+
this.level.levelEvent((Player) null, 1009, this.blockPosition, 1);
27+
}
28+
@@ -2158,6 +2159,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
29+
if (fromNetherPortal) {
30+
nbt.putBoolean("Paper.FromNetherPortal", true);
31+
}
32+
+ if (freezeLocked) {
33+
+ nbt.putBoolean("Paper.FreezeLock", true);
34+
+ }
35+
// Paper end
36+
return nbt;
37+
} catch (Throwable throwable) {
38+
@@ -2326,6 +2330,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
39+
if (spawnReason == null) {
40+
spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT;
41+
}
42+
+ if (nbt.contains("Paper.FreezeLock")) {
43+
+ freezeLocked = nbt.getBoolean("Paper.FreezeLock");
44+
+ }
45+
// Paper end
46+
47+
} catch (Throwable throwable) {
48+
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
49+
index 44a32fd2c08a09af0bba01547847b8594a7cd077..25338fe4cfdc683ca4c01487e166a1649c6f640b 100644
50+
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
51+
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
52+
@@ -3299,7 +3299,7 @@ public abstract class LivingEntity extends Entity {
53+
boolean flag1 = this.getType().is(EntityTypeTags.FREEZE_HURTS_EXTRA_TYPES);
54+
int i;
55+
56+
- if (!this.level.isClientSide && !this.isDeadOrDying()) {
57+
+ if (!this.level.isClientSide && !this.isDeadOrDying() && !freezeLocked) { // Paper - Freeze Tick Lock API
58+
i = this.getTicksFrozen();
59+
if (this.isInPowderSnow && this.canFreeze()) {
60+
this.setTicksFrozen(Math.min(this.getTicksRequiredToFreeze(), i + 1));
61+
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
62+
index 69223b13e894d86d9529f2ef8b60a08a1f7a9267..a3673e2943f251e056ecf84a9bff2de12efdb52a 100644
63+
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
64+
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
65+
@@ -660,6 +660,17 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
66+
return this.getHandle().isFullyFrozen();
67+
}
68+
69+
+ // Paper Start - Freeze Tick Lock API
70+
+ @Override
71+
+ public boolean isFreezeTickingLocked() {
72+
+ return this.entity.freezeLocked;
73+
+ }
74+
+
75+
+ @Override
76+
+ public void lockFreezeTicks(boolean locked) {
77+
+ this.entity.freezeLocked = locked;
78+
+ }
79+
+ // Paper end - Freeze Tick Lock API
80+
@Override
81+
public void remove() {
82+
this.entity.discard();

0 commit comments

Comments
 (0)