mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Add StructureGenerateEvent (#137)
Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com> Co-authored-by: Nahuel <nahueldolores@hotmail.com>
This commit is contained in:
112
patches/api/0038-Add-StructureGenerateEvent.patch
Normal file
112
patches/api/0038-Add-StructureGenerateEvent.patch
Normal file
@@ -0,0 +1,112 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Nahuel <nahueldolores@hotmail.com>
|
||||
Date: Sat, 9 Jan 2021 15:33:52 +0100
|
||||
Subject: [PATCH] Add StructureGenerateEvent
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com>
|
||||
|
||||
diff --git a/src/main/java/net/pl3x/purpur/event/world/StructureGenerateEvent.java b/src/main/java/net/pl3x/purpur/event/world/StructureGenerateEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..e77f45f761368da9b230c425d975a717cf4d10fd
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/event/world/StructureGenerateEvent.java
|
||||
@@ -0,0 +1,68 @@
|
||||
+package net.pl3x.purpur.event.world;
|
||||
+
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.StructureType;
|
||||
+import org.bukkit.World;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.world.WorldEvent;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+public class StructureGenerateEvent extends WorldEvent implements Cancellable {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+
|
||||
+ @NotNull
|
||||
+ private final StructureType structureType;
|
||||
+ private final int chunkX;
|
||||
+ private final int chunkZ;
|
||||
+
|
||||
+ private boolean cancel = false;
|
||||
+
|
||||
+ public StructureGenerateEvent(@NotNull World world,
|
||||
+ @NotNull StructureType structureType, int chunkX, int chunkZ) {
|
||||
+ super(!Bukkit.isPrimaryThread(), world); // Structure generation is not necessarily on the main thread as of 1.16.
|
||||
+ this.structureType = structureType;
|
||||
+ this.chunkX = chunkX;
|
||||
+ this.chunkZ = chunkZ;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ @Override
|
||||
+ public World getWorld() {
|
||||
+ return super.getWorld();
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public StructureType getStructureType() {
|
||||
+ return structureType;
|
||||
+ }
|
||||
+
|
||||
+ public int getChunkX() {
|
||||
+ return chunkX;
|
||||
+ }
|
||||
+
|
||||
+ public int getChunkZ() {
|
||||
+ return chunkZ;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCancelled(boolean cancel) {
|
||||
+ this.cancel = cancel;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCancelled() {
|
||||
+ return this.cancel;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ @Override
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/event/world/WorldEvent.java b/src/main/java/org/bukkit/event/world/WorldEvent.java
|
||||
index cffeff33f007d3b03b7c862b25be453f705da739..1fa083d53dce161ef9e9f19407f230c94b2d7d15 100644
|
||||
--- a/src/main/java/org/bukkit/event/world/WorldEvent.java
|
||||
+++ b/src/main/java/org/bukkit/event/world/WorldEvent.java
|
||||
@@ -10,6 +10,13 @@ import org.jetbrains.annotations.NotNull;
|
||||
public abstract class WorldEvent extends Event {
|
||||
private final World world;
|
||||
|
||||
+ // Purpur start
|
||||
+ public WorldEvent(boolean isAsync, @NotNull final World world) {
|
||||
+ super(isAsync);
|
||||
+ this.world = world;
|
||||
+ }
|
||||
+ // Purpur end
|
||||
+
|
||||
public WorldEvent(@NotNull final World world) {
|
||||
this.world = world;
|
||||
}
|
||||
64
patches/server/0168-Add-StructureGenerateEvent.patch
Normal file
64
patches/server/0168-Add-StructureGenerateEvent.patch
Normal file
@@ -0,0 +1,64 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Nahuel <nahueldolores@hotmail.com>
|
||||
Date: Sat, 9 Jan 2021 15:36:59 +0100
|
||||
Subject: [PATCH] Add StructureGenerateEvent
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com>
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/ChunkGenerator.java b/src/main/java/net/minecraft/server/ChunkGenerator.java
|
||||
index 9a6fef215052f9c513b23024968995c97863a453..a26616d479e79729cbf4838df90612f074a47a04 100644
|
||||
--- a/src/main/java/net/minecraft/server/ChunkGenerator.java
|
||||
+++ b/src/main/java/net/minecraft/server/ChunkGenerator.java
|
||||
@@ -234,6 +234,14 @@ public abstract class ChunkGenerator {
|
||||
if (structuresettingsfeature != null) {
|
||||
StructureStart<?> structurestart1 = structurefeature.a(iregistrycustom, this, this.b, definedstructuremanager, i, chunkcoordintpair, biomebase, j, structuresettingsfeature);
|
||||
|
||||
+ // Purpur start
|
||||
+ if (new net.pl3x.purpur.event.world.StructureGenerateEvent(
|
||||
+ structuremanager.getWorld().getWorld(),
|
||||
+ org.bukkit.StructureType.getStructureTypes().get(structurefeature.getFeature().getRegistryKey().toLowerCase()),
|
||||
+ chunkcoordintpair.x,
|
||||
+ chunkcoordintpair.z
|
||||
+ ).callEvent())
|
||||
+ // Purpur end
|
||||
structuremanager.a(SectionPosition.a(ichunkaccess.getPos(), 0), structurefeature.d, structurestart1, ichunkaccess);
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/StructureFeature.java b/src/main/java/net/minecraft/server/StructureFeature.java
|
||||
index 8e3c0c3783b767c2ba603b3b50200ac76a7fc33e..379665ae55e76afb03b20d1b81c57347af1137db 100644
|
||||
--- a/src/main/java/net/minecraft/server/StructureFeature.java
|
||||
+++ b/src/main/java/net/minecraft/server/StructureFeature.java
|
||||
@@ -11,7 +11,7 @@ public class StructureFeature<FC extends WorldGenFeatureConfiguration, F extends
|
||||
}, StructureGenerator::h);
|
||||
public static final Codec<Supplier<StructureFeature<?, ?>>> b = RegistryFileCodec.a(IRegistry.av, StructureFeature.a);
|
||||
public static final Codec<List<Supplier<StructureFeature<?, ?>>>> c = RegistryFileCodec.b(IRegistry.av, StructureFeature.a);
|
||||
- public final F d;
|
||||
+ public final F d; public final F getFeature() { return this.d; } // Purpur - OBFHELPER
|
||||
public final FC e;
|
||||
|
||||
public StructureFeature(F f0, FC fc) {
|
||||
diff --git a/src/main/java/net/minecraft/server/StructureGenerator.java b/src/main/java/net/minecraft/server/StructureGenerator.java
|
||||
index a62c87bceab2c9700a7b3925f208b0ffa2b9b393..8fc283f014783b76afda83097201bb7938a1f9fa 100644
|
||||
--- a/src/main/java/net/minecraft/server/StructureGenerator.java
|
||||
+++ b/src/main/java/net/minecraft/server/StructureGenerator.java
|
||||
@@ -235,6 +235,7 @@ public abstract class StructureGenerator<C extends WorldGenFeatureConfiguration>
|
||||
|
||||
public abstract StructureGenerator.a<C> a();
|
||||
|
||||
+ public final String getRegistryKey() { return this.i(); } // Purpur - OBFHELPER
|
||||
public String i() {
|
||||
return (String) StructureGenerator.a.inverse().get(this);
|
||||
}
|
||||
Reference in New Issue
Block a user