forked from hpfxd/PandaSpigot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0072-Add-World-Util-Methods.patch
117 lines (108 loc) · 5.27 KB
/
0072-Add-World-Util-Methods.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: mechoriet <[email protected]>
Date: Fri, 17 Jun 2022 18:35:40 +0200
Subject: [PATCH] Add World Util Methods
Co-authored-by: uRyanxD <[email protected]>
Methods that can be used for other patches to help improve logic.
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 03fe76355813497a5db33ad185db0e4b40c6f85a..df28cca6175ff3ddf4992c44a0760ef17310b03e 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -695,6 +695,7 @@ public class Chunk {
}
+ public final int getLightSubtracted(BlockPosition blockposition, int i) { return this.a(blockposition, i); } // PandaSpigot - OBFHELPER
public int a(BlockPosition blockposition, int i) {
int j = blockposition.getX() & 15;
int k = blockposition.getY();
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 084f107bf019b0f2e00d17a470632780db490abc..a429dc5e950a31557d444d0a50ed71d13f13d555 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -93,7 +93,7 @@ public abstract class World implements IBlockAccess {
public final boolean isClientSide;
// CraftBukkit - longhashset
// protected LongHashSet chunkTickList = new LongHashSet(); // Spigot
- private int L;
+ private int L; private int getSkylightSubtracted() { return this.L; } // PandaSpigot - OBFHELPER
public boolean allowMonsters; // CraftBukkit - public
public boolean allowAnimals; // CraftBukkit - public
private boolean M;
@@ -175,6 +175,12 @@ public abstract class World implements IBlockAccess {
return (CraftServer) Bukkit.getServer();
}
+ // PandaSpigot start
+ public Chunk getChunkIfLoaded(BlockPosition position) {
+ return ((ChunkProviderServer) this.chunkProvider).getChunkIfLoaded(position.getX() >> 4, position.getZ() >> 4);
+ }
+ // PandaSpigot end
+
public Chunk getChunkIfLoaded(int x, int z) {
return ((ChunkProviderServer) this.chunkProvider).getChunkIfLoaded(x, z);
}
@@ -652,10 +658,46 @@ public abstract class World implements IBlockAccess {
}
}
+ // PandaSpigot start - test if meets light level, return faster
+ // logic copied from below
+ public boolean isLightLevel(BlockPosition blockposition, int level) {
+ if (isValidLocation(blockposition)) {
+ if (this.getType(blockposition).getBlock().s()) {
+ if (this.c(blockposition.up(), false) >= level) {
+ return true;
+ }
+ if (this.c(blockposition.east(), false) >= level) {
+ return true;
+ }
+ if (this.c(blockposition.west(), false) >= level) {
+ return true;
+ }
+ if (this.c(blockposition.south(), false) >= level) {
+ return true;
+ }
+ if (this.c(blockposition.north(), false) >= level) {
+ return true;
+ }
+ return false;
+ } else {
+ if (blockposition.getY() >= 256) {
+ blockposition = new BlockPosition(blockposition.getX(), 255, blockposition.getZ());
+ }
+
+ Chunk chunk = this.getChunkAtWorldCoords(blockposition);
+ return chunk.getLightSubtracted(blockposition, this.getSkylightSubtracted()) >= level;
+ }
+ } else {
+ return true;
+ }
+ }
+ // PandaSpigot end
+
public int getLightLevel(BlockPosition blockposition) {
return this.c(blockposition, true);
}
+ public final int getLight(BlockPosition blockposition, boolean checkNeighbors) { return this.c(blockposition, checkNeighbors); } // PandaSpigot - OBFHELPER
public int c(BlockPosition blockposition, boolean flag) {
if (blockposition.getX() >= -30000000 && blockposition.getZ() >= -30000000 && blockposition.getX() < 30000000 && blockposition.getZ() < 30000000) {
if (flag && this.getType(blockposition).getBlock().s()) {
@@ -766,6 +808,22 @@ public abstract class World implements IBlockAccess {
return this.worldProvider.p()[this.getLightLevel(blockposition)];
}
+ // PandaSpigot start - Add getTypeIfLoaded
+ public IBlockData getTypeIfLoaded(BlockPosition blockposition) {
+ if (this.captureTreeGeneration) {
+ for (BlockState previous : this.capturedBlockStates) {
+ if (previous.getX() == blockposition.getX() && previous.getY() == blockposition.getY() && previous.getZ() == blockposition.getZ()) {
+ return CraftMagicNumbers.getBlock(previous.getTypeId()).fromLegacyData(previous.getRawData());
+ }
+ }
+ }
+ Chunk chunk = this.getChunkIfLoaded(blockposition);
+ if (chunk != null) {
+ return this.isValidLocation(blockposition) ? chunk.getBlockData(blockposition) : Blocks.AIR.getBlockData();
+ }
+ return null;
+ }
+ // PandaSpigot end
// Spigot start
public IBlockData getType(BlockPosition blockposition)
{