aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0291-Add-more-LimitedRegion-API.patch
blob: 292f95c8903e16f6b9f8be0bfe1824a973ab1dac (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: dfsek <dfsek@protonmail.com>
Date: Sat, 19 Jun 2021 20:15:29 -0700
Subject: [PATCH] Add more LimitedRegion API


diff --git a/src/main/java/org/bukkit/generator/LimitedRegion.java b/src/main/java/org/bukkit/generator/LimitedRegion.java
index 85faeeeef908243aa5f172284784e7e67995ebfb..e0b249d328f7671894cea94bc00d54ab54aacd36 100644
--- a/src/main/java/org/bukkit/generator/LimitedRegion.java
+++ b/src/main/java/org/bukkit/generator/LimitedRegion.java
@@ -4,6 +4,12 @@ import java.util.List;
 import org.bukkit.Location;
 import org.bukkit.RegionAccessor;
 import org.bukkit.block.BlockState;
+// Paper start
+import org.bukkit.World;
+import org.bukkit.block.BlockState;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.util.Vector;
+// Paper end
 import org.jetbrains.annotations.NotNull;
 
 /**
@@ -53,4 +59,137 @@ public interface LimitedRegion extends RegionAccessor {
      */
     @NotNull
     List<BlockState> getTileEntities();
+
+
+    // Paper start
+    /**
+     * Sets the block at a vector location to the provided {@link BlockData}.
+     *
+     * @param vector {@link Vector} representing the position of the block to set.
+     * @param data   {@link BlockData} to set the block at the provided coordinates to.
+     */
+    default void setBlockData(@NotNull Vector vector, @NotNull BlockData data) {
+        setBlockData(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ(), data);
+    }
+
+    /**
+     * Sets the {@link BlockState} at a location.
+     *
+     * @param x X coordinate.
+     * @param y Y coordinate.
+     * @param z Z coordinate.
+     * @param state The block state.
+     */
+    void setBlockState(int x, int y, int z, @NotNull BlockState state);
+
+    /**
+     * Sets the {@link BlockState} at a location.
+     *
+     * @param location Location to set block state.
+     * @param state The block state.
+     */
+    default void setBlockState(@NotNull Vector location, @NotNull BlockState state) {
+        setBlockState(location.getBlockX(), location.getBlockY(), location.getBlockZ(), state);
+    }
+
+    /**
+     * Gets the {@link BlockState} at a location.
+     *
+     * @param location Location to get block state from.
+     * @return The block state.
+     */
+    @NotNull
+    default BlockState getBlockState(@NotNull Vector location) {
+        return getBlockState(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+    }
+
+    /**
+     * Schedules a block update at (x, y, z).
+     *
+     * @param x X coordinate
+     * @param y Y coordinate
+     * @param z Z coordinate
+     */
+    void scheduleBlockUpdate(int x, int y, int z);
+
+    /**
+     * Schedules a block update at a vector location.
+     *
+     * @param location {@link Vector} representing the position of the block to update.
+     */
+    default void scheduleBlockUpdate(@NotNull Vector location) {
+        scheduleBlockUpdate(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+    }
+
+    /**
+     * Schedules a fluid update at (x, y, z).
+     *
+     * @param x X coordinate
+     * @param y Y coordinate
+     * @param z Z coordinate
+     */
+    void scheduleFluidUpdate(int x, int y, int z);
+
+    /**
+     * Schedules a fluid update at a vector location.
+     *
+     * @param location {@link Vector} representing the position of the block to update.
+     */
+    default void scheduleFluidUpdate(@NotNull Vector location) {
+        scheduleFluidUpdate(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+    }
+
+    /**
+     * Gets the {@link World} object this region represents.
+     * <p>
+     * Do <b>not</b> attempt to read from/write to this world! Doing so during generation <b>will cause a deadlock!</b>
+     *
+     * @return The {@link World} object that this region represents.
+     */
+    @NotNull
+    World getWorld();
+
+    /**
+     * Gets the {@link BlockData} of the block at the provided coordinates.
+     *
+     * @param vector {@link Vector} representing the position of the block to get.
+     * @return {@link BlockData} at the coordinates
+     */
+    @NotNull
+    default BlockData getBlockData(@NotNull Vector vector) {
+        return getBlockData(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
+    }
+
+    /**
+     * Gets the X-coordinate of the chunk in the center of the region.
+     *
+     * @return The center chunk's X coordinate.
+     */
+    int getCenterChunkX();
+
+    /**
+     * Gets the X-coordinate of the block in the center of the region.
+     *
+     * @return The center chunk's X coordinate.
+     */
+    default int getCenterBlockX() {
+        return getCenterChunkX() << 4;
+    }
+
+    /**
+     * Gets the Z-coordinate of the chunk in the center of the region.
+     *
+     * @return The center chunk's Z coordinate.
+     */
+    int getCenterChunkZ();
+
+    /**
+     * Gets the Z-coordinate of the block in the center of the region.
+     *
+     * @return The center chunk's Z coordinate.
+     */
+    default int getCenterBlockZ() {
+        return getCenterChunkZ() << 4;
+    }
+    // Paper end
 }