== AT ==
public net.minecraft.server.level.ServerChunkCache mainThread
public net.minecraft.server.level.ServerLevel chunkSource
public org.bukkit.craftbukkit.inventory.CraftItemStack handle
public net.minecraft.server.level.ChunkMap getVisibleChunkIfPresent(J)Lnet/minecraft/server/level/ChunkHolder;
public net.minecraft.server.level.ServerChunkCache mainThreadProcessor
public net.minecraft.server.level.ServerChunkCache$MainThreadExecutor
public net.minecraft.world.level.chunk.LevelChunkSection states
This commit is contained in:
Aikar
2016-03-28 20:55:47 -04:00
parent a82a09d198
commit b01c811c2f
81 changed files with 6261 additions and 473 deletions

View File

@@ -2627,4 +2627,9 @@ public final class CraftServer implements Server {
return this.spigot;
}
// Spigot end
@Override
public double[] getTPS() {
return new double[]{0, 0, 0}; // TODO
}
}

View File

@@ -257,8 +257,8 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override
public Chunk[] getLoadedChunks() {
Long2ObjectLinkedOpenHashMap<ChunkHolder> chunks = this.world.getChunkSource().chunkMap.visibleChunkMap;
return chunks.values().stream().map(ChunkHolder::getFullChunkNow).filter(Objects::nonNull).map(CraftChunk::new).toArray(Chunk[]::new);
List<ChunkHolder> chunks = ca.spottedleaf.moonrise.common.util.ChunkSystem.getVisibleChunkHolders(this.world); // Paper
return chunks.stream().map(ChunkHolder::getFullChunkNow).filter(Objects::nonNull).map(CraftChunk::new).toArray(Chunk[]::new);
}
@Override
@@ -335,7 +335,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override
public boolean refreshChunk(int x, int z) {
ChunkHolder playerChunk = this.world.getChunkSource().chunkMap.visibleChunkMap.get(ChunkPos.asLong(x, z));
ChunkHolder playerChunk = this.world.getChunkSource().chunkMap.getVisibleChunkIfPresent(ChunkPos.asLong(x, z));
if (playerChunk == null) return false;
playerChunk.getTickingChunkFuture().thenAccept(either -> {
@@ -2115,4 +2115,51 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return this.spigot;
}
// Spigot end
// Paper start
@Override
public void getChunkAtAsync(int x, int z, boolean gen, boolean urgent, @NotNull Consumer<? super Chunk> cb) {
ca.spottedleaf.moonrise.common.util.ChunkSystem.scheduleChunkLoad(
this.getHandle(), x, z, gen, ChunkStatus.FULL, true,
urgent ? ca.spottedleaf.concurrentutil.util.Priority.HIGHER : ca.spottedleaf.concurrentutil.util.Priority.NORMAL,
(ChunkAccess chunk) -> {
cb.accept(chunk == null ? null : new CraftChunk((net.minecraft.world.level.chunk.LevelChunk)chunk));
}
);
}
@Override
public void getChunksAtAsync(int minX, int minZ, int maxX, int maxZ, boolean urgent, Runnable cb) {
this.getHandle().loadChunks(
minX, minZ, maxX, maxZ,
urgent ? ca.spottedleaf.concurrentutil.util.Priority.HIGHER : ca.spottedleaf.concurrentutil.util.Priority.NORMAL,
(List<ChunkAccess> chunks) -> {
cb.run();
}
);
}
@Override
public void setViewDistance(final int viewDistance) {
if (viewDistance < 2 || viewDistance > 32) {
throw new IllegalArgumentException("View distance " + viewDistance + " is out of range of [2, 32]");
}
this.getHandle().chunkSource.chunkMap.setServerViewDistance(viewDistance);
}
@Override
public void setSimulationDistance(final int simulationDistance) {
throw new UnsupportedOperationException("Not implemented yet");
}
@Override
public int getSendViewDistance() {
return this.getViewDistance();
}
@Override
public void setSendViewDistance(final int viewDistance) {
throw new UnsupportedOperationException("Not implemented yet");
}
// Paper end
}

View File

@@ -2432,4 +2432,34 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return this.spigot;
}
// Spigot end
@Override
public int getViewDistance() {
return ca.spottedleaf.moonrise.common.util.ChunkSystem.getViewDistance(this.getHandle());
}
@Override
public void setViewDistance(final int viewDistance) {
throw new UnsupportedOperationException("Not implemented yet");
}
@Override
public int getSimulationDistance() {
return ca.spottedleaf.moonrise.common.util.ChunkSystem.getTickViewDistance(this.getHandle());
}
@Override
public void setSimulationDistance(final int simulationDistance) {
throw new UnsupportedOperationException("Not implemented yet");
}
@Override
public int getSendViewDistance() {
return ca.spottedleaf.moonrise.common.util.ChunkSystem.getSendViewDistance(this.getHandle());
}
@Override
public void setSendViewDistance(final int viewDistance) {
throw new UnsupportedOperationException("Not implemented yet");
}
}

View File

@@ -31,6 +31,20 @@ import org.jetbrains.annotations.ApiStatus;
@DelegateDeserialization(ItemStack.class)
public final class CraftItemStack extends ItemStack {
// Paper start - MC Utils
public static net.minecraft.world.item.ItemStack unwrap(ItemStack bukkit) {
if (bukkit instanceof CraftItemStack craftItemStack) {
return craftItemStack.handle != null ? craftItemStack.handle : net.minecraft.world.item.ItemStack.EMPTY;
} else {
return asNMSCopy(bukkit);
}
}
public static net.minecraft.world.item.ItemStack getOrCloneOnMutation(ItemStack old, ItemStack newInstance) {
return old == newInstance ? unwrap(old) : asNMSCopy(newInstance);
}
// Paper end - MC Utils
public static net.minecraft.world.item.ItemStack asNMSCopy(ItemStack original) {
if (original instanceof CraftItemStack) {
CraftItemStack stack = (CraftItemStack) original;

View File

@@ -40,6 +40,17 @@ public final class CraftLocation {
return new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
// Paper start
public static net.minecraft.core.GlobalPos toGlobalPos(Location location) {
return net.minecraft.core.GlobalPos.of(((org.bukkit.craftbukkit.CraftWorld) location.getWorld()).getHandle().dimension(), toBlockPosition(location));
}
public static Location fromGlobalPos(net.minecraft.core.GlobalPos globalPos) {
BlockPos pos = globalPos.pos();
return new org.bukkit.Location(net.minecraft.server.MinecraftServer.getServer().getLevel(globalPos.dimension()).getWorld(), pos.getX(), pos.getY(), pos.getZ());
}
// Paper end
public static Vec3 toVec3D(Location location) {
return new Vec3(location.getX(), location.getY(), location.getZ());
}

View File

@@ -56,6 +56,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.ticks.LevelTickAccess;
import net.minecraft.world.ticks.TickPriority;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.jetbrains.annotations.Nullable;
public abstract class DelegatedGeneratorAccess implements WorldGenLevel {
@@ -788,4 +789,25 @@ public abstract class DelegatedGeneratorAccess implements WorldGenLevel {
public boolean isFluidAtPosition(BlockPos pos, Predicate<FluidState> state) {
return this.handle.isFluidAtPosition(pos, state);
}
// Paper start
@Nullable
@Override
public BlockState getBlockStateIfLoaded(final BlockPos blockposition) {
return this.handle.getBlockStateIfLoaded(blockposition);
}
@Nullable
@Override
public FluidState getFluidIfLoaded(final BlockPos blockposition) {
return this.handle.getFluidIfLoaded(blockposition);
}
@Nullable
@Override
public ChunkAccess getChunkIfLoadedImmediately(final int x, final int z) {
return this.handle.getChunkIfLoadedImmediately(x, z);
}
// Paper end
}

View File

@@ -212,7 +212,23 @@ public class DummyGeneratorAccess implements WorldGenLevel {
public FluidState getFluidState(BlockPos pos) {
return Fluids.EMPTY.defaultFluidState(); // SPIGOT-6634
}
// Paper start - if loaded util
@javax.annotation.Nullable
@Override
public ChunkAccess getChunkIfLoadedImmediately(int x, int z) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public BlockState getBlockStateIfLoaded(BlockPos blockposition) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public FluidState getFluidIfLoaded(BlockPos blockposition) {
throw new UnsupportedOperationException("Not supported yet.");
}
// Paper end
@Override
public WorldBorder getWorldBorder() {
throw new UnsupportedOperationException("Not supported yet.");

View File

@@ -35,6 +35,9 @@ public class ActivationRange
public enum ActivationType
{
WATER, // Paper
FLYING_MONSTER, // Paper
VILLAGER, // Paper
MONSTER,
ANIMAL,
RAIDER,