9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2026-01-06 15:41:49 +00:00

All source patches applied and starts

This commit is contained in:
Samsuik
2025-01-16 19:32:46 +00:00
parent 24d7230079
commit 39bba67ec9
171 changed files with 4443 additions and 15 deletions

View File

@@ -0,0 +1,53 @@
--- a/paper-api/build.gradle.kts
+++ b/paper-api/build.gradle.kts
@@ -93,7 +_,7 @@
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
-val generatedApiPath: java.nio.file.Path = layout.projectDirectory.dir("src/generated/java").asFile.toPath()
+val generatedApiPath: java.nio.file.Path = rootProject.layout.projectDirectory.dir("paper-api/src/generated/java").asFile.toPath()
idea {
module {
generatedSourceDirs.add(generatedApiPath.toFile())
@@ -103,6 +_,18 @@
main {
java {
srcDir(generatedApiPath)
+ srcDir(file("../paper-api/src/main/java"))
+ }
+ resources {
+ srcDir(file("../paper-api/src/main/resources"))
+ }
+ }
+ test {
+ java {
+ srcDir(file("../paper-api/src/test/java"))
+ }
+ resources {
+ srcDir(file("../paper-api/src/test/resources"))
}
}
}
@@ -169,7 +_,7 @@
tasks.withType<Javadoc> {
val options = options as StandardJavadocDocletOptions
- options.overview = "src/main/javadoc/overview.html"
+ options.overview = "../paper-api/src/main/javadoc/overview.html"
options.use()
options.isDocFilesSubDirs = true
options.links(
@@ -202,11 +_,11 @@
}
// workaround for https://github.com/gradle/gradle/issues/4046
- inputs.dir("src/main/javadoc").withPropertyName("javadoc-sourceset")
+ inputs.dir("../paper-api/src/main/javadoc").withPropertyName("javadoc-sourceset")
val fsOps = services.fileSystemOperations
doLast {
fsOps.copy {
- from("src/main/javadoc") {
+ from("../paper-api/src/main/javadoc") {
include("**/doc-files/**")
}
into("build/docs/javadoc")

View File

@@ -0,0 +1,23 @@
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -126,6 +_,20 @@
// Paper end
}
+ // Sakura start - customise version command; expose git information
+ @NotNull
+ public static String getGitInformation() {
+ final io.papermc.paper.ServerBuildInfo version = io.papermc.paper.ServerBuildInfo.buildInfo();
+ final String gitBranch = version.gitBranch().orElse("Dev");
+ final String gitCommit = version.gitCommit().orElse("");
+ String branchMsg = " on " + gitBranch;
+ if ("master".equals(gitBranch) || "main".equals(gitBranch)) {
+ branchMsg = ""; // Don't show branch on main/master
+ }
+ return "(Git: " + gitCommit + branchMsg + ")";
+ }
+ // Sakura end - customise version command; expose git information
+
/**
* Gets the name of this server implementation.
*

View File

@@ -0,0 +1,13 @@
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -205,6 +_,10 @@
return new Location(this, x, y, z);
}
// Paper end
+ // Sakura start
+ @NotNull
+ me.samsuik.sakura.local.storage.LocalStorageHandler getStorageHandler();
+ // Sakura end
/**
* Gets the highest non-empty (impassable) block at the given coordinates.

View File

@@ -0,0 +1,51 @@
--- a/src/main/java/org/bukkit/command/defaults/VersionCommand.java
+++ b/src/main/java/org/bukkit/command/defaults/VersionCommand.java
@@ -33,6 +_,11 @@
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
// Paper end - version command 2.0
+// Sakura start - customise version command
+import net.kyori.adventure.text.event.HoverEvent;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
+// Sakura end - customise version command
public class VersionCommand extends BukkitCommand {
private VersionFetcher versionFetcher; // Paper - version command 2.0
@@ -44,6 +_,15 @@
return versionFetcher;
}
+ // Sakura start - customise version command
+ private static final String VERSION_MESSAGE = """
+ <dark_purple>.
+ <dark_purple>| <white>This server is running <gradient:red:light_purple>Sakura</gradient>
+ <dark_purple>| <white>Commit<dark_gray>: \\<<commit>> <gray>targeting </gray>(<yellow>MC</yellow>: <gray><version></gray>)
+ <dark_purple>| <white>Github<dark_gray>: \\<<yellow><click:open_url:'https://github.com/Samsuik/Sakura'>link</click></yellow>>
+ <dark_purple>'""";
+ // Sakura end - customise version command
+
public VersionCommand(@NotNull String name) {
super(name);
@@ -55,11 +_,16 @@
@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) {
- if (!testPermission(sender)) return true;
-
- if (args.length == 0) {
+ // Sakura start - customise version command
+ if (args.length == 0 || !this.testPermission(sender)) {
+ sender.sendMessage(MiniMessage.miniMessage().deserialize(VERSION_MESSAGE,
+ Placeholder.component("commit", Component.text("hover", NamedTextColor.YELLOW)
+ .hoverEvent(HoverEvent.showText(Component.text(Bukkit.getGitInformation())))),
+ Placeholder.unparsed("version", Bukkit.getMinecraftVersion())
+ ));
//sender.sendMessage("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")"); // Paper - moved to setVersionMessage
- sendVersion(sender);
+ //sendVersion(sender);
+ // Sakura end - customise version command
} else {
StringBuilder name = new StringBuilder();

View File

@@ -0,0 +1,25 @@
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -35,6 +_,22 @@
*/
public interface Entity extends Metadatable, CommandSender, Nameable, PersistentDataHolder, net.kyori.adventure.text.event.HoverEventSource<net.kyori.adventure.text.event.HoverEvent.ShowEntity>, net.kyori.adventure.sound.Sound.Emitter { // Paper
+ // Sakura start - entity pushed by fluid api
+ /**
+ * Gets if the entity will be pushed by fluid.
+ *
+ * @return if this entity can be pushed by fluid.
+ */
+ boolean isPushedByFluid();
+
+ /**
+ * Sets if the entity will be pushed by fluid.
+ *
+ * @param state whether entity should be pushed by fluid
+ */
+ void setPushedByFluid(boolean state);
+ // Sakura end - entity pushed by fluid api
+
/**
* Gets the entity's current position
*

View File

@@ -0,0 +1,25 @@
--- a/src/main/java/org/bukkit/entity/FallingBlock.java
+++ b/src/main/java/org/bukkit/entity/FallingBlock.java
@@ -9,6 +_,22 @@
*/
public interface FallingBlock extends Entity {
+ // Sakura start - falling block height parity api
+ /**
+ * Gets if falling block has height parity
+ *
+ * @return parity
+ */
+ boolean getHeightParity();
+
+ /**
+ * Sets falling block height parity
+ *
+ * @param parity value
+ */
+ void setHeightParity(boolean parity);
+ // Sakura end - falling block height parity api
+
/**
* Get the Material of the falling block
*

View File

@@ -0,0 +1,15 @@
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -61,6 +_,12 @@
*/
public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginMessageRecipient, net.kyori.adventure.identity.Identified, net.kyori.adventure.bossbar.BossBarViewer, com.destroystokyo.paper.network.NetworkClient { // Paper
+ // Sakura start - entity tracking range modifier
+ double getTrackingRangeModifier();
+
+ void setTrackingRangeModifier(double mod);
+ // Sakura end - entity tracking range modifier
+
// Paper start
@Override
default net.kyori.adventure.identity.@NotNull Identity identity() {

View File

@@ -0,0 +1,42 @@
package me.samsuik.sakura.entity.merge;
import org.jspecify.annotations.NullMarked;
@NullMarked
public enum MergeLevel {
/**
* Disabled.
*/
NONE(-1),
/**
* "STRICT" merges entities with the same properties, position, momentum and OOE.
* This is considered safe to use, and will not break cannon mechanics.
*/
STRICT(1),
/**
* "LENIENT" merges entities aggressively by tracking the entities that have
* previously merged. This is a hybrid of "SPAWN" and "STRICT" merging, with the
* visuals of "STRICT" merging and better merging potential of "SPAWN" merging.
*/
LENIENT(2),
/**
* "SPAWN" merges entities one gametick after they have spawned. Merging is
* only possible after it has been established that the entity is safe to
* merge by collecting information on the entities that merge together over time.
*/
SPAWN(3);
private final int level;
MergeLevel(int level) {
this.level = level;
}
public boolean atLeast(MergeLevel level) {
return this.getLevel() >= level.getLevel();
}
public int getLevel() {
return this.level;
}
}

View File

@@ -0,0 +1,14 @@
package me.samsuik.sakura.entity.merge;
import org.jspecify.annotations.NullMarked;
@NullMarked
public interface Mergeable {
MergeLevel getMergeLevel();
void setMergeLevel(MergeLevel level);
int getStacked();
void setStacked(int stacked);
}

View File

@@ -0,0 +1,46 @@
package me.samsuik.sakura.local;
import io.papermc.paper.math.Position;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
import org.jspecify.annotations.NullMarked;
@NullMarked
public record LocalRegion(int minX, int minZ, int maxX, int maxZ) {
public static LocalRegion from(BoundingBox boundingBox) {
return of(boundingBox.getMin(), boundingBox.getMax());
}
public static LocalRegion of(Vector min, Vector max) {
return of(min.getBlockX(), min.getBlockZ(), max.getBlockX(), max.getBlockZ());
}
public static LocalRegion of(Position min, Position max) {
return of(min.blockX(), min.blockZ(), max.blockX(), max.blockZ());
}
public static LocalRegion of(int minX, int minZ, int maxX, int maxZ) {
return new LocalRegion(
Math.min(minX, maxX), Math.min(minZ, maxZ),
Math.max(minX, maxX), Math.max(minZ, maxZ)
);
}
public static LocalRegion at(int x, int z, int radius) {
return new LocalRegion(x-radius, z-radius, x+radius, z+radius);
}
public boolean intersects(LocalRegion region) {
return (this.minX < region.minX() && this.maxX > region.minX() || this.maxX > region.maxX() && this.minX < region.maxX())
&& (this.minZ < region.minZ() && this.maxZ > region.minZ() || this.maxZ > region.maxZ() && this.minZ < region.maxZ());
}
public boolean contains(LocalRegion region) {
return this.minX < region.minX() && this.maxX > region.maxX()
&& this.maxZ < region.minZ() && this.maxZ > region.maxZ();
}
public boolean contains(int x, int z) {
return this.minX <= x && this.maxX >= x && this.minZ <= z && this.maxZ >= z;
}
}

View File

@@ -0,0 +1,23 @@
package me.samsuik.sakura.local;
import org.bukkit.NamespacedKey;
import org.jspecify.annotations.NullMarked;
import java.util.function.Supplier;
@NullMarked
public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
LocalValueKey<?> that = (LocalValueKey<?>) o;
return this.key.equals(that.key);
}
@Override
public int hashCode() {
return this.key.hashCode();
}
}

View File

@@ -0,0 +1,25 @@
package me.samsuik.sakura.local;
import me.samsuik.sakura.physics.PhysicsVersion;
import me.samsuik.sakura.redstone.RedstoneImplementation;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
public final class LocalValueKeys {
private static final String NAMESPACE = "sakura";
public static final LocalValueKey<PhysicsVersion> PHYSICS_VERSION = create("physics-version", () -> PhysicsVersion.LATEST);
public static final LocalValueKey<Map<Material, Map.Entry<Integer, Float>>> DURABLE_MATERIALS = create("durable-materials", HashMap::new);
public static final LocalValueKey<RedstoneImplementation> REDSTONE_IMPLEMENTATION = create("redstone-implementation", () -> RedstoneImplementation.VANILLA);
public static final LocalValueKey<Boolean> CONSISTENT_EXPLOSION_RADIUS = create("consistent-radius", () -> false);
public static final LocalValueKey<Boolean> REDSTONE_CACHE = create("redstone-cache", () -> false);
public static final LocalValueKey<Integer> LAVA_FLOW_SPEED = create("lava-flow-speed", () -> -1);
private static <T> LocalValueKey<T> create(String key, Supplier<T> supplier) {
return new LocalValueKey<>(new NamespacedKey(NAMESPACE, key), supplier);
}
}

View File

@@ -0,0 +1,27 @@
package me.samsuik.sakura.local.storage;
import me.samsuik.sakura.local.LocalRegion;
import org.bukkit.Location;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import java.util.List;
import java.util.Optional;
public interface LocalStorageHandler {
default @NonNull Optional<LocalRegion> locate(@NonNull Location location) {
return this.locate(location.blockX(), location.blockZ());
}
@NonNull Optional<LocalRegion> locate(int x, int z);
@Nullable LocalValueStorage get(@NonNull LocalRegion region);
boolean has(@NonNull LocalRegion region);
void put(@NonNull LocalRegion region, @NonNull LocalValueStorage storage);
void remove(@NonNull LocalRegion region);
@NonNull List<LocalRegion> regions();
}

View File

@@ -0,0 +1,50 @@
package me.samsuik.sakura.local.storage;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import me.samsuik.sakura.local.LocalValueKey;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.Map;
import java.util.Optional;
@NullMarked
@SuppressWarnings("unchecked")
public final class LocalValueStorage {
private final Map<LocalValueKey<?>, Object> map = new Object2ObjectOpenHashMap<>();
public <T> void set(LocalValueKey<T> key, T insert) {
this.map.put(key, insert);
}
public void remove(LocalValueKey<?> key) {
this.map.remove(key);
}
public <T> Optional<T> get(LocalValueKey<T> key) {
T value = (T) this.map.get(key);
return Optional.ofNullable(value);
}
public <T> T getOrDefault(LocalValueKey<T> key, T def) {
return (T) this.map.getOrDefault(key, def);
}
public boolean exists(LocalValueKey<?> key) {
return this.map.containsKey(key);
}
@Nullable
public <T> T value(LocalValueKey<T> key) {
return (T) this.map.get(key);
}
public <T> T value(LocalValueKey<T> key, boolean returnDefault) {
T val = (T) this.map.get(key);
if (!returnDefault || val != null)
return val;
// update value
this.set(key, val = key.defaultSupplier().get());
return val;
}
}

View File

@@ -0,0 +1,74 @@
package me.samsuik.sakura.physics;
import org.jspecify.annotations.NullMarked;
@NullMarked
public enum PhysicsVersion {
LEGACY("legacy", 1_0_0), // replicates patched 1.8.8 paper mechanics
v1_8_2("1.8.2", 1_8_2), // vanilla mechanics
v1_9("1.9", 1_9_0),
v1_10("1.10", 1_10_0),
v1_11("1.11", 1_11_0),
v1_12("1.12", 1_12_0),
v1_13("1.13", 1_13_0),
v1_14("1.14", 1_14_0),
v1_16("1.16", 1_16_0),
v1_17("1.17", 1_17_0),
v1_18_2("1.18.2", 1_18_2),
v1_19_3("1.19.3", 1_19_3),
v1_20("1.20", 1_20_0),
v1_21_2("1.21.2", 1_21_2),
LATEST("latest", 9_99_9); // latest version
private final String friendlyName;
private final int version;
PhysicsVersion(String friendlyName, int version) {
this.friendlyName = friendlyName;
this.version = version;
}
public boolean isLegacy() {
return this == LEGACY;
}
public boolean afterOrEqual(int version) {
return this.version >= version;
}
public boolean before(int version) {
return this.version < version;
}
public boolean is(int version) {
return this.version == version;
}
public boolean isWithin(int min, int max) {
return this.version >= min && this.version <= max;
}
public int getVersion() {
return this.version;
}
public String getFriendlyName() {
return this.friendlyName;
}
public static PhysicsVersion from(String string) {
int parsedVersion = Integer.MIN_VALUE;
try {
String versionString = string.replace(".", "");
parsedVersion = Integer.parseInt(versionString);
} catch (NumberFormatException nfe) {
// ignored
}
for (PhysicsVersion ver : values()) {
if (ver.name().equalsIgnoreCase(string) || ver.getFriendlyName().equalsIgnoreCase(string) || ver.is(parsedVersion)) {
return ver;
}
}
return LATEST;
}
}

View File

@@ -0,0 +1,20 @@
package me.samsuik.sakura.redstone;
import org.jspecify.annotations.NullMarked;
@NullMarked
public enum RedstoneImplementation {
VANILLA("vanilla"),
EIGENCRAFT("eigencraft"),
ALTERNATE_CURRENT("alternate-current");
private final String friendlyName;
RedstoneImplementation(String friendlyName) {
this.friendlyName = friendlyName;
}
public String getFriendlyName() {
return this.friendlyName;
}
}