Add get world and registries

This commit is contained in:
Bjorn Beishline 2026-01-31 18:05:10 -07:00
parent 03e762cd45
commit eebcb0467e
5 changed files with 43 additions and 3 deletions

View File

@ -182,7 +182,9 @@ public class NativePatchBukkit {
long registerEventAddr,
long getAbilitiesAddr,
long setAbilitiesAddr,
long getLocationAddr
long getLocationAddr,
long freeStringAddr,
long getWorldAddr
) {
// void rust_send_message(const char* uuid, const char* message)
sendMessageNative = LINKER.downcallHandle(

View File

@ -38,6 +38,7 @@ import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.patchbukkit.bridge.NativePatchBukkit;
import org.patchbukkit.world.PatchBukkitWorld;
import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.datacomponent.DataComponentType.Valued;
@ -319,8 +320,11 @@ public class PatchBukkitEntity implements Entity {
@Override
public @NotNull World getWorld() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getWorld'");
var world_uuid_str = NativePatchBukkit.getWorld(this.uuid);
UUID world_uuid = UUID.fromString(world_uuid_str);
var world = PatchBukkitWorld.getOrCreate(world_uuid);
return world;
}
@Override

View File

@ -0,0 +1,22 @@
package org.patchbukkit.registry;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Keyed;
import org.bukkit.Registry;
import org.jspecify.annotations.Nullable;
public class PatchBukkitRegistryAccess implements RegistryAccess {
@Override
public <T extends Keyed> @Nullable Registry<T> getRegistry(Class<T> type) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getRegistry'");
}
@Override
public <T extends Keyed> Registry<T> getRegistry(RegistryKey<T> registryKey) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getRegistry'");
}
}

View File

@ -33,6 +33,17 @@ public class PatchBukkitWorld
extends PatchBukkitRegionAccessor
implements World
{
private static final Map<UUID, PatchBukkitWorld> instances = new HashMap<>();
private UUID uuid;
private PatchBukkitWorld(UUID uuid) {
this.uuid = uuid;
}
public static PatchBukkitWorld getOrCreate(UUID uuid) {
return instances.computeIfAbsent(uuid, PatchBukkitWorld::new);
}
@Override
public boolean isVoidDamageEnabled() {

View File

@ -0,0 +1 @@
org.patchbukkit.registry.PatchBukkitRegistryAccess