refactor code
This commit is contained in:
+1
-1
@@ -1,9 +1,9 @@
|
|||||||
package io.nanachiyo0721.shiroha.commands.bar;
|
package io.nanachiyo0721.shiroha.commands.bar;
|
||||||
|
|
||||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
|
||||||
import io.nanachiyo0721.shiroha.commands.bar.sub.ConfigEditCommand;
|
import io.nanachiyo0721.shiroha.commands.bar.sub.ConfigEditCommand;
|
||||||
import io.nanachiyo0721.shiroha.commands.bar.sub.ToggleCommand;
|
import io.nanachiyo0721.shiroha.commands.bar.sub.ToggleCommand;
|
||||||
import io.nanachiyo0721.shiroha.enums.EnumBarType;
|
import io.nanachiyo0721.shiroha.enums.EnumBarType;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.leavesmc.leaves.command.CommandNode;
|
import org.leavesmc.leaves.command.CommandNode;
|
||||||
|
|||||||
+3
-3
@@ -6,12 +6,12 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
|
||||||
import io.papermc.paper.command.brigadier.Commands;
|
|
||||||
import io.papermc.paper.command.brigadier.PaperCommands;
|
|
||||||
import io.nanachiyo0721.shiroha.commands.bar.BarCommand;
|
import io.nanachiyo0721.shiroha.commands.bar.BarCommand;
|
||||||
import io.nanachiyo0721.shiroha.enums.EnumBarType;
|
import io.nanachiyo0721.shiroha.enums.EnumBarType;
|
||||||
import io.nanachiyo0721.shiroha.functions.bars.TickableStatusBarList;
|
import io.nanachiyo0721.shiroha.functions.bars.TickableStatusBarList;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import io.papermc.paper.command.brigadier.Commands;
|
||||||
|
import io.papermc.paper.command.brigadier.PaperCommands;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ package io.nanachiyo0721.shiroha.config;
|
|||||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||||
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
import io.nanachiyo0721.shiroha.config.flags.*;
|
|
||||||
import io.papermc.paper.threadedregions.RegionizedServer;
|
|
||||||
import io.nanachiyo0721.shiroha.api.config.ShirohaConfigsInstance;
|
|
||||||
import io.nanachiyo0721.shiroha.api.config.ConfigDataPair;
|
import io.nanachiyo0721.shiroha.api.config.ConfigDataPair;
|
||||||
|
import io.nanachiyo0721.shiroha.api.config.ShirohaConfigsInstance;
|
||||||
import io.nanachiyo0721.shiroha.commands.config.ConfigCommand;
|
import io.nanachiyo0721.shiroha.commands.config.ConfigCommand;
|
||||||
|
import io.nanachiyo0721.shiroha.config.flags.*;
|
||||||
import io.nanachiyo0721.shiroha.enums.EnumConfigCategory;
|
import io.nanachiyo0721.shiroha.enums.EnumConfigCategory;
|
||||||
import io.nanachiyo0721.shiroha.utils.ClassScanUtil;
|
import io.nanachiyo0721.shiroha.utils.ClassScanUtil;
|
||||||
|
import io.papermc.paper.threadedregions.RegionizedServer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|||||||
+1
-1
@@ -7,9 +7,9 @@ import io.nanachiyo0721.shiroha.config.flags.ConfigClassInfo;
|
|||||||
import io.nanachiyo0721.shiroha.config.flags.ConfigInfo;
|
import io.nanachiyo0721.shiroha.config.flags.ConfigInfo;
|
||||||
import io.nanachiyo0721.shiroha.config.flags.DoNotLoad;
|
import io.nanachiyo0721.shiroha.config.flags.DoNotLoad;
|
||||||
import io.nanachiyo0721.shiroha.config.flags.HotReloadUnsupported;
|
import io.nanachiyo0721.shiroha.config.flags.HotReloadUnsupported;
|
||||||
|
import io.nanachiyo0721.shiroha.data.BufferedLinearRegionFileFlusher;
|
||||||
import io.nanachiyo0721.shiroha.enums.EnumConfigCategory;
|
import io.nanachiyo0721.shiroha.enums.EnumConfigCategory;
|
||||||
import io.nanachiyo0721.shiroha.enums.EnumRegionFormat;
|
import io.nanachiyo0721.shiroha.enums.EnumRegionFormat;
|
||||||
import io.nanachiyo0721.shiroha.data.BufferedLinearRegionFileFlusher;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|||||||
+8
-6
@@ -467,8 +467,8 @@ public class BufferedLinearRegionFile implements io.nanachiyo0721.shiroha.data.R
|
|||||||
// later, and the not-yet-synced swap data is not dropped on the floor
|
// later, and the not-yet-synced swap data is not dropped on the floor
|
||||||
// since we hold the write lock and any read/write/sync ops is currently blocked all along the close logic, acquiring the locks inside sync is a disaster
|
// since we hold the write lock and any read/write/sync ops is currently blocked all along the close logic, acquiring the locks inside sync is a disaster
|
||||||
try {
|
try {
|
||||||
this.syncToMasterFile(true, true, true, true);
|
this.syncToMasterFile(true, true, true, true);
|
||||||
}catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
failure = ex;
|
failure = ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,13 +477,15 @@ public class BufferedLinearRegionFile implements io.nanachiyo0721.shiroha.data.R
|
|||||||
|
|
||||||
this.swapFileChannel.close();
|
this.swapFileChannel.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (failure == null) failure = ex; else failure.addSuppressed(ex);
|
if (failure == null) failure = ex;
|
||||||
|
else failure.addSuppressed(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.masterFileParser.closeNoLock();
|
this.masterFileParser.closeNoLock();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (failure == null) failure = e; else failure.addSuppressed(e);
|
if (failure == null) failure = e;
|
||||||
|
else failure.addSuppressed(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalize
|
// finalize
|
||||||
@@ -492,10 +494,10 @@ public class BufferedLinearRegionFile implements io.nanachiyo0721.shiroha.data.R
|
|||||||
if (failure != null) {
|
if (failure != null) {
|
||||||
throw failure;
|
throw failure;
|
||||||
}
|
}
|
||||||
}finally {
|
} finally {
|
||||||
this.regionObjectLock.writeLock().unlock();
|
this.regionObjectLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
}finally {
|
} finally {
|
||||||
this.masterFileParser.masterFileLock.writeLock().unlock();
|
this.masterFileParser.masterFileLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,12 +1,12 @@
|
|||||||
package io.nanachiyo0721.shiroha.functions.bars.impl;
|
package io.nanachiyo0721.shiroha.functions.bars.impl;
|
||||||
|
|
||||||
import ca.spottedleaf.common.time.TickData;
|
import ca.spottedleaf.common.time.TickData;
|
||||||
import io.papermc.paper.threadedregions.ThreadedRegionizer;
|
|
||||||
import io.papermc.paper.threadedregions.TickRegionScheduler;
|
|
||||||
import io.papermc.paper.threadedregions.TickRegions;
|
|
||||||
import io.nanachiyo0721.shiroha.config.modules.function.RegionBarConfig;
|
import io.nanachiyo0721.shiroha.config.modules.function.RegionBarConfig;
|
||||||
import io.nanachiyo0721.shiroha.enums.EnumStatusBarDisplay;
|
import io.nanachiyo0721.shiroha.enums.EnumStatusBarDisplay;
|
||||||
import io.nanachiyo0721.shiroha.functions.bars.TickableStatusBar;
|
import io.nanachiyo0721.shiroha.functions.bars.TickableStatusBar;
|
||||||
|
import io.papermc.paper.threadedregions.ThreadedRegionizer;
|
||||||
|
import io.papermc.paper.threadedregions.TickRegionScheduler;
|
||||||
|
import io.papermc.paper.threadedregions.TickRegions;
|
||||||
import net.kyori.adventure.bossbar.BossBar;
|
import net.kyori.adventure.bossbar.BossBar;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|||||||
+3
-3
@@ -1,12 +1,12 @@
|
|||||||
package io.nanachiyo0721.shiroha.functions.bars.impl;
|
package io.nanachiyo0721.shiroha.functions.bars.impl;
|
||||||
|
|
||||||
import ca.spottedleaf.common.time.TickData;
|
import ca.spottedleaf.common.time.TickData;
|
||||||
import io.papermc.paper.threadedregions.ThreadedRegionizer;
|
|
||||||
import io.papermc.paper.threadedregions.TickRegionScheduler;
|
|
||||||
import io.papermc.paper.threadedregions.TickRegions;
|
|
||||||
import io.nanachiyo0721.shiroha.config.modules.function.TpsBarConfig;
|
import io.nanachiyo0721.shiroha.config.modules.function.TpsBarConfig;
|
||||||
import io.nanachiyo0721.shiroha.enums.EnumStatusBarDisplay;
|
import io.nanachiyo0721.shiroha.enums.EnumStatusBarDisplay;
|
||||||
import io.nanachiyo0721.shiroha.functions.bars.TickableStatusBar;
|
import io.nanachiyo0721.shiroha.functions.bars.TickableStatusBar;
|
||||||
|
import io.papermc.paper.threadedregions.ThreadedRegionizer;
|
||||||
|
import io.papermc.paper.threadedregions.TickRegionScheduler;
|
||||||
|
import io.papermc.paper.threadedregions.TickRegions;
|
||||||
import net.kyori.adventure.bossbar.BossBar;
|
import net.kyori.adventure.bossbar.BossBar;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|||||||
+9
-9
@@ -23,12 +23,12 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一个简单的基于folia的RegionizedTaskQueue引用计数的轻量ticket区块加载器
|
* 一个简单的基于folia的RegionizedTaskQueue引用计数的轻量ticket区块加载器
|
||||||
* 用于在folia传送门搜索的高频率scheduleChunkLoad的调用下减少ticket操作从而减轻锁负载
|
* 用于在folia传送门搜索的高频率scheduleChunkLoad的调用下减少ticket操作从而减轻锁负载
|
||||||
* 大部分内容物均取自folia的RegionizedTaskQueue(引用计数), ttl机制取自我的优化)
|
* 大部分内容物均取自folia的RegionizedTaskQueue(引用计数), ttl机制取自我的优化)
|
||||||
*
|
*
|
||||||
* @see io.papermc.paper.threadedregions.RegionizedTaskQueue
|
* @see io.papermc.paper.threadedregions.RegionizedTaskQueue
|
||||||
* @see net.minecraft.world.entity.Entity#findOrCreatePortalAsync(ServerLevel, BlockPos, ServerLevel, Entity.PortalType, CallbackCompletable)
|
* @see net.minecraft.world.entity.Entity#findOrCreatePortalAsync(ServerLevel, BlockPos, ServerLevel, Entity.PortalType, CallbackCompletable)
|
||||||
*/
|
*/
|
||||||
public class ReferenceCountingChunkLoader {
|
public class ReferenceCountingChunkLoader {
|
||||||
private static final long MAX_CHUNK_TTL_TICKS = 2L;
|
private static final long MAX_CHUNK_TTL_TICKS = 2L;
|
||||||
@@ -164,7 +164,7 @@ public class ReferenceCountingChunkLoader {
|
|||||||
RegionizedServer.getInstance().taskQueue.queueChunkTask(this.world, chunkX, chunkZ, () -> {
|
RegionizedServer.getInstance().taskQueue.queueChunkTask(this.world, chunkX, chunkZ, () -> {
|
||||||
try {
|
try {
|
||||||
callback.accept(cached);
|
callback.accept(cached);
|
||||||
}finally {
|
} finally {
|
||||||
this.decrementReference(increased, coord);
|
this.decrementReference(increased, coord);
|
||||||
}
|
}
|
||||||
}, priority);
|
}, priority);
|
||||||
@@ -179,7 +179,7 @@ public class ReferenceCountingChunkLoader {
|
|||||||
increased.cached = chunk;
|
increased.cached = chunk;
|
||||||
|
|
||||||
callback.accept(chunk);
|
callback.accept(chunk);
|
||||||
}finally {
|
} finally {
|
||||||
this.decrementReference(increased, coord);
|
this.decrementReference(increased, coord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,7 +264,7 @@ public class ReferenceCountingChunkLoader {
|
|||||||
|
|
||||||
public boolean addCount() {
|
public boolean addCount() {
|
||||||
int failures = 0;
|
int failures = 0;
|
||||||
for (long curr = this.referenceCount.get();;) {
|
for (long curr = this.referenceCount.get(); ; ) {
|
||||||
for (int i = 0; i < failures; ++i) {
|
for (int i = 0; i < failures; ++i) {
|
||||||
Thread.onSpinWait();
|
Thread.onSpinWait();
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ public class ReferenceCountingChunkLoader {
|
|||||||
|
|
||||||
if (curr == (curr = this.referenceCount.compareAndExchange(curr, curr + 1L))) {
|
if (curr == (curr = this.referenceCount.compareAndExchange(curr, curr + 1L))) {
|
||||||
int ttlFailures = 0;
|
int ttlFailures = 0;
|
||||||
for (long currTTL = this.referenceTTL.get();;) {
|
for (long currTTL = this.referenceTTL.get(); ; ) {
|
||||||
for (int i = 0; i < ttlFailures; i++) {
|
for (int i = 0; i < ttlFailures; i++) {
|
||||||
Thread.onSpinWait();
|
Thread.onSpinWait();
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -96,11 +96,11 @@ public class CheckAndCacheBlockChecker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChunkSize(){
|
public int getChunkSize() {
|
||||||
return this.chunkSections2MaybeContainsMatchingBlock.numChunks;
|
return this.chunkSections2MaybeContainsMatchingBlock.numChunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasUnloadedPossibleChunks(){
|
public boolean hasUnloadedPossibleChunks() {
|
||||||
return this.unloadedPossibleChunkSections > 0;
|
return this.unloadedPossibleChunkSections > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,14 +129,14 @@ public class CheckAndCacheBlockChecker {
|
|||||||
return this.chunkSections2MaybeContainsMatchingBlock.getChunkAccess(blockPos);
|
return this.chunkSections2MaybeContainsMatchingBlock.getChunkAccess(blockPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldStop(){
|
public boolean shouldStop() {
|
||||||
return this.chunkSections2MaybeContainsMatchingBlock.hasNoTrueChunkSections();
|
return this.chunkSections2MaybeContainsMatchingBlock.hasNoTrueChunkSections();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkPosition(BlockPos blockPos) {
|
public boolean checkPosition(BlockPos blockPos) {
|
||||||
if(!this.chunkSections2MaybeContainsMatchingBlock.getChunkSectionBit(blockPos)) return false;
|
if (!this.chunkSections2MaybeContainsMatchingBlock.getChunkSectionBit(blockPos)) return false;
|
||||||
ChunkAccess chunkAccess = this.chunkSections2MaybeContainsMatchingBlock.getChunkAccess(blockPos);
|
ChunkAccess chunkAccess = this.chunkSections2MaybeContainsMatchingBlock.getChunkAccess(blockPos);
|
||||||
if(chunkAccess == null) {
|
if (chunkAccess == null) {
|
||||||
if (!this.shouldChunkLoad) {
|
if (!this.shouldChunkLoad) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -35,12 +35,12 @@ public class CommonBlockSearchesCheckAndCache {
|
|||||||
public static Optional<BlockPos> blockPosFindClosestMatch(LevelReader levelReader, LivingEntity livingEntity,
|
public static Optional<BlockPos> blockPosFindClosestMatch(LevelReader levelReader, LivingEntity livingEntity,
|
||||||
int horizontalRange, int verticalRange,
|
int horizontalRange, int verticalRange,
|
||||||
Predicate<BlockState> blockStatePredicate,
|
Predicate<BlockState> blockStatePredicate,
|
||||||
boolean shouldChunkLoad){
|
boolean shouldChunkLoad) {
|
||||||
BlockPos mobPos = livingEntity.blockPosition();
|
BlockPos mobPos = livingEntity.blockPosition();
|
||||||
CheckAndCacheBlockChecker checker = new CheckAndCacheBlockChecker(
|
CheckAndCacheBlockChecker checker = new CheckAndCacheBlockChecker(
|
||||||
mobPos, horizontalRange, verticalRange, levelReader, blockStatePredicate, shouldChunkLoad);
|
mobPos, horizontalRange, verticalRange, levelReader, blockStatePredicate, shouldChunkLoad);
|
||||||
checker.initializeChunks();
|
checker.initializeChunks();
|
||||||
if(checker.shouldStop()) {
|
if (checker.shouldStop()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
return BlockPos.findClosestMatch(mobPos, horizontalRange, verticalRange, checker::checkPosition);
|
return BlockPos.findClosestMatch(mobPos, horizontalRange, verticalRange, checker::checkPosition);
|
||||||
|
|||||||
+3
-3
@@ -34,7 +34,7 @@ public class NonPOISearchDistances {
|
|||||||
return getVanillaSortOrderInt(getRing(dX, dZ), dX, dZ);
|
return getVanillaSortOrderInt(getRing(dX, dZ), dX, dZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getRing(final int dX, final int dZ){
|
public static int getRing(final int dX, final int dZ) {
|
||||||
return Math.max(Math.abs(dX), Math.abs(dZ));
|
return Math.max(Math.abs(dX), Math.abs(dZ));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,8 +58,8 @@ public class NonPOISearchDistances {
|
|||||||
* You can convert to longs if you somehow exceed that, but also seriously consider POIs instead.
|
* You can convert to longs if you somehow exceed that, but also seriously consider POIs instead.
|
||||||
*
|
*
|
||||||
* @param ring Which square ring the block is at relative to the center
|
* @param ring Which square ring the block is at relative to the center
|
||||||
* @param dX Relative x position of the block to the center
|
* @param dX Relative x position of the block to the center
|
||||||
* @param dZ Relative z position of the block to the center
|
* @param dZ Relative z position of the block to the center
|
||||||
*/
|
*/
|
||||||
public static int getVanillaSortOrderInt(final int ring, final int dX, final int dZ) {
|
public static int getVanillaSortOrderInt(final int ring, final int dX, final int dZ) {
|
||||||
return (ring << 16 | Math.abs(dX) << 9 | Math.abs(dZ) << 1) - ((dX > 0 ? 1 : 0) << 8 | (dZ > 0 ? 1 : 0));
|
return (ring << 16 | Math.abs(dX) << 9 | Math.abs(dZ) << 1) - ((dX > 0 ? 1 : 0) << 8 | (dZ > 0 ? 1 : 0));
|
||||||
|
|||||||
@@ -25,12 +25,15 @@ public class Pos {
|
|||||||
public static int getYSize(LevelHeightAccessor view) {
|
public static int getYSize(LevelHeightAccessor view) {
|
||||||
return view.getHeight();
|
return view.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMinY(LevelHeightAccessor view) {
|
public static int getMinY(LevelHeightAccessor view) {
|
||||||
return view.getMinY();
|
return view.getMinY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxYInclusive(LevelHeightAccessor view) {
|
public static int getMaxYInclusive(LevelHeightAccessor view) {
|
||||||
return view.getMaxY();
|
return view.getMaxY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxYExclusive(LevelHeightAccessor view) {
|
public static int getMaxYExclusive(LevelHeightAccessor view) {
|
||||||
return view.getMaxY() + 1;
|
return view.getMaxY() + 1;
|
||||||
}
|
}
|
||||||
@@ -39,7 +42,7 @@ public class Pos {
|
|||||||
return 15 + getMinInSectionCoord(sectionCoord);
|
return 15 + getMinInSectionCoord(sectionCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxYInSectionIndex(LevelHeightAccessor view, int sectionIndex){
|
public static int getMaxYInSectionIndex(LevelHeightAccessor view, int sectionIndex) {
|
||||||
return getMaxInSectionCoord(SectionYCoord.fromSectionIndex(view, sectionIndex));
|
return getMaxInSectionCoord(SectionYCoord.fromSectionIndex(view, sectionIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,12 +69,15 @@ public class Pos {
|
|||||||
public static int getNumYSections(LevelHeightAccessor view) {
|
public static int getNumYSections(LevelHeightAccessor view) {
|
||||||
return view.getSectionsCount();
|
return view.getSectionsCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMinYSection(LevelHeightAccessor view) {
|
public static int getMinYSection(LevelHeightAccessor view) {
|
||||||
return view.getMinSectionY();
|
return view.getMinSectionY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxYSectionInclusive(LevelHeightAccessor view) {
|
public static int getMaxYSectionInclusive(LevelHeightAccessor view) {
|
||||||
return view.getMaxSectionY();
|
return view.getMaxSectionY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxYSectionExclusive(LevelHeightAccessor view) {
|
public static int getMaxYSectionExclusive(LevelHeightAccessor view) {
|
||||||
return view.getMaxSectionY() + 1;
|
return view.getMaxSectionY() + 1;
|
||||||
}
|
}
|
||||||
@@ -79,6 +85,7 @@ public class Pos {
|
|||||||
public static int fromSectionIndex(LevelHeightAccessor view, int sectionCoord) {
|
public static int fromSectionIndex(LevelHeightAccessor view, int sectionCoord) {
|
||||||
return sectionCoord + SectionYCoord.getMinYSection(view);
|
return sectionCoord + SectionYCoord.getMinYSection(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int fromBlockCoord(int blockCoord) {
|
public static int fromBlockCoord(int blockCoord) {
|
||||||
return SectionPos.blockToSectionCoord(blockCoord);
|
return SectionPos.blockToSectionCoord(blockCoord);
|
||||||
}
|
}
|
||||||
@@ -88,12 +95,15 @@ public class Pos {
|
|||||||
public static int getNumYSections(LevelHeightAccessor view) {
|
public static int getNumYSections(LevelHeightAccessor view) {
|
||||||
return view.getSectionsCount();
|
return view.getSectionsCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMinYSectionIndex(LevelHeightAccessor view) {
|
public static int getMinYSectionIndex(LevelHeightAccessor view) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxYSectionIndexInclusive(LevelHeightAccessor view) {
|
public static int getMaxYSectionIndexInclusive(LevelHeightAccessor view) {
|
||||||
return view.getSectionsCount() - 1;
|
return view.getSectionsCount() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxYSectionIndexExclusive(LevelHeightAccessor view) {
|
public static int getMaxYSectionIndexExclusive(LevelHeightAccessor view) {
|
||||||
return view.getSectionsCount();
|
return view.getSectionsCount();
|
||||||
}
|
}
|
||||||
@@ -102,6 +112,7 @@ public class Pos {
|
|||||||
public static int fromSectionCoord(LevelHeightAccessor view, int sectionCoord) {
|
public static int fromSectionCoord(LevelHeightAccessor view, int sectionCoord) {
|
||||||
return sectionCoord - SectionYCoord.getMinYSection(view);
|
return sectionCoord - SectionYCoord.getMinYSection(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int fromBlockCoord(LevelHeightAccessor view, int blockCoord) {
|
public static int fromBlockCoord(LevelHeightAccessor view, int blockCoord) {
|
||||||
return fromSectionCoord(view, SectionPos.blockToSectionCoord(blockCoord));
|
return fromSectionCoord(view, SectionPos.blockToSectionCoord(blockCoord));
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -50,7 +50,7 @@ public class FixedChunkAccessSectionBitBuffer {
|
|||||||
this.numSections = yLength * xLength * zLength;
|
this.numSections = yLength * xLength * zLength;
|
||||||
|
|
||||||
this.chunkSectionBits = new BitSet(numSections);
|
this.chunkSectionBits = new BitSet(numSections);
|
||||||
this.chunkAccesses = new ArrayList<>(Collections.nCopies(xLength * zLength,null));
|
this.chunkAccesses = new ArrayList<>(Collections.nCopies(xLength * zLength, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public FixedChunkAccessSectionBitBuffer(BlockPos center, int horizontalRangeInclusive, int verticalRangeInclusive) {
|
public FixedChunkAccessSectionBitBuffer(BlockPos center, int horizontalRangeInclusive, int verticalRangeInclusive) {
|
||||||
@@ -102,11 +102,11 @@ public class FixedChunkAccessSectionBitBuffer {
|
|||||||
return this.getChunkIndex(ChunkPos.getX(chunkPos), ChunkPos.getZ(chunkPos));
|
return this.getChunkIndex(ChunkPos.getX(chunkPos), ChunkPos.getZ(chunkPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChunkAccess getChunkAccess(long chunkPos){
|
public ChunkAccess getChunkAccess(long chunkPos) {
|
||||||
return this.chunkAccesses.get(this.getChunkIndex(chunkPos));
|
return this.chunkAccesses.get(this.getChunkIndex(chunkPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChunkAccess getChunkAccess(BlockPos blockPos){
|
public ChunkAccess getChunkAccess(BlockPos blockPos) {
|
||||||
return this.getChunkAccess(ChunkPos.pack(blockPos));
|
return this.getChunkAccess(ChunkPos.pack(blockPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,14 +118,14 @@ public class FixedChunkAccessSectionBitBuffer {
|
|||||||
this.setChunkAccess(ChunkPos.pack(blockPos), chunkAccess);
|
this.setChunkAccess(ChunkPos.pack(blockPos), chunkAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNoTrueChunkSections(){
|
public boolean hasNoTrueChunkSections() {
|
||||||
return this.chunkSectionBits.nextSetBit(0) == -1;
|
return this.chunkSectionBits.nextSetBit(0) == -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LongIterable getChunkPosInRange() {
|
public LongIterable getChunkPosInRange() {
|
||||||
return new LongIterable() {
|
return new LongIterable() {
|
||||||
@Override
|
@Override
|
||||||
public @NotNull LongIterator iterator(){
|
public @NotNull LongIterator iterator() {
|
||||||
return getChunkPosInRangeIterator();
|
return getChunkPosInRangeIterator();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -141,7 +141,7 @@ public class FixedChunkAccessSectionBitBuffer {
|
|||||||
int z = zMin;
|
int z = zMin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long nextLong () {
|
public long nextLong() {
|
||||||
long result = ChunkPos.pack(x, z);
|
long result = ChunkPos.pack(x, z);
|
||||||
if (z < zMax) {
|
if (z < zMax) {
|
||||||
z++;
|
z++;
|
||||||
@@ -153,7 +153,7 @@ public class FixedChunkAccessSectionBitBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext(){
|
public boolean hasNext() {
|
||||||
return x <= xMax;
|
return x <= xMax;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -162,7 +162,7 @@ public class FixedChunkAccessSectionBitBuffer {
|
|||||||
public IntIterable getSectionYInRange() {
|
public IntIterable getSectionYInRange() {
|
||||||
return new IntIterable() {
|
return new IntIterable() {
|
||||||
@Override
|
@Override
|
||||||
public @NotNull IntIterator iterator(){
|
public @NotNull IntIterator iterator() {
|
||||||
return getSectionYInRangeIterator();
|
return getSectionYInRangeIterator();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -175,12 +175,12 @@ public class FixedChunkAccessSectionBitBuffer {
|
|||||||
int y = yMin;
|
int y = yMin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int nextInt(){
|
public int nextInt() {
|
||||||
return y++;
|
return y++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext(){
|
public boolean hasNext() {
|
||||||
return y < yLimit;
|
return y < yLimit;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user