diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/bar/BarSubcommand.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/bar/BarSubcommand.java index 7cb239e..4dbacc4 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/bar/BarSubcommand.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/bar/BarSubcommand.java @@ -1,9 +1,9 @@ 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.ToggleCommand; import io.nanachiyo0721.shiroha.enums.EnumBarType; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.command.CommandNode; diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/bar/sub/ToggleCommand.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/bar/sub/ToggleCommand.java index 934c787..6911ffa 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/bar/sub/ToggleCommand.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/commands/bar/sub/ToggleCommand.java @@ -6,12 +6,12 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestions; 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.enums.EnumBarType; 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.format.TextColor; import org.bukkit.Bukkit; diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/config/ConfigsInstance.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/config/ConfigsInstance.java index 7455985..cfad375 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/config/ConfigsInstance.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/config/ConfigsInstance.java @@ -3,13 +3,13 @@ package io.nanachiyo0721.shiroha.config; import com.electronwill.nightconfig.core.UnmodifiableConfig; import com.electronwill.nightconfig.core.file.CommentedFileConfig; 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.ShirohaConfigsInstance; import io.nanachiyo0721.shiroha.commands.config.ConfigCommand; +import io.nanachiyo0721.shiroha.config.flags.*; import io.nanachiyo0721.shiroha.enums.EnumConfigCategory; import io.nanachiyo0721.shiroha.utils.ClassScanUtil; +import io.papermc.paper.threadedregions.RegionizedServer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/config/modules/function/RegionFormatConfig.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/config/modules/function/RegionFormatConfig.java index bfa939f..977e46f 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/config/modules/function/RegionFormatConfig.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/config/modules/function/RegionFormatConfig.java @@ -7,9 +7,9 @@ import io.nanachiyo0721.shiroha.config.flags.ConfigClassInfo; import io.nanachiyo0721.shiroha.config.flags.ConfigInfo; import io.nanachiyo0721.shiroha.config.flags.DoNotLoad; import io.nanachiyo0721.shiroha.config.flags.HotReloadUnsupported; +import io.nanachiyo0721.shiroha.data.BufferedLinearRegionFileFlusher; import io.nanachiyo0721.shiroha.enums.EnumConfigCategory; import io.nanachiyo0721.shiroha.enums.EnumRegionFormat; -import io.nanachiyo0721.shiroha.data.BufferedLinearRegionFileFlusher; import net.minecraft.server.MinecraftServer; import org.jetbrains.annotations.Nullable; diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/data/BufferedLinearRegionFile.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/data/BufferedLinearRegionFile.java index 5decea6..e1a7f33 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/data/BufferedLinearRegionFile.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/data/BufferedLinearRegionFile.java @@ -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 // 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 { - this.syncToMasterFile(true, true, true, true); - }catch (IOException ex) { + this.syncToMasterFile(true, true, true, true); + } catch (IOException ex) { failure = ex; } @@ -477,13 +477,15 @@ public class BufferedLinearRegionFile implements io.nanachiyo0721.shiroha.data.R this.swapFileChannel.close(); } catch (IOException ex) { - if (failure == null) failure = ex; else failure.addSuppressed(ex); + if (failure == null) failure = ex; + else failure.addSuppressed(ex); } try { this.masterFileParser.closeNoLock(); } catch (IOException e) { - if (failure == null) failure = e; else failure.addSuppressed(e); + if (failure == null) failure = e; + else failure.addSuppressed(e); } // finalize @@ -492,10 +494,10 @@ public class BufferedLinearRegionFile implements io.nanachiyo0721.shiroha.data.R if (failure != null) { throw failure; } - }finally { + } finally { this.regionObjectLock.writeLock().unlock(); } - }finally { + } finally { this.masterFileParser.masterFileLock.writeLock().unlock(); } } diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/functions/bars/impl/RegionBar.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/functions/bars/impl/RegionBar.java index 903f443..d9e8e48 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/functions/bars/impl/RegionBar.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/functions/bars/impl/RegionBar.java @@ -1,12 +1,12 @@ package io.nanachiyo0721.shiroha.functions.bars.impl; 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.enums.EnumStatusBarDisplay; 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.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/functions/bars/impl/TpsBar.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/functions/bars/impl/TpsBar.java index 8eecd9d..b1ba026 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/functions/bars/impl/TpsBar.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/functions/bars/impl/TpsBar.java @@ -1,12 +1,12 @@ package io.nanachiyo0721.shiroha.functions.bars.impl; 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.enums.EnumStatusBarDisplay; 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.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; diff --git a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/ReferenceCountingChunkLoader.java b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/ReferenceCountingChunkLoader.java index 142827f..2781f3a 100644 --- a/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/ReferenceCountingChunkLoader.java +++ b/shiroha-server/src/main/java/io/nanachiyo0721/shiroha/utils/ReferenceCountingChunkLoader.java @@ -23,12 +23,12 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; /** - * 一个简单的基于folia的RegionizedTaskQueue引用计数的轻量ticket区块加载器 - * 用于在folia传送门搜索的高频率scheduleChunkLoad的调用下减少ticket操作从而减轻锁负载 - * 大部分内容物均取自folia的RegionizedTaskQueue(引用计数), ttl机制取自我的优化) - * + * 一个简单的基于folia的RegionizedTaskQueue引用计数的轻量ticket区块加载器 + * 用于在folia传送门搜索的高频率scheduleChunkLoad的调用下减少ticket操作从而减轻锁负载 + * 大部分内容物均取自folia的RegionizedTaskQueue(引用计数), ttl机制取自我的优化) + * * @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 { private static final long MAX_CHUNK_TTL_TICKS = 2L; @@ -164,7 +164,7 @@ public class ReferenceCountingChunkLoader { RegionizedServer.getInstance().taskQueue.queueChunkTask(this.world, chunkX, chunkZ, () -> { try { callback.accept(cached); - }finally { + } finally { this.decrementReference(increased, coord); } }, priority); @@ -179,7 +179,7 @@ public class ReferenceCountingChunkLoader { increased.cached = chunk; callback.accept(chunk); - }finally { + } finally { this.decrementReference(increased, coord); } } @@ -264,7 +264,7 @@ public class ReferenceCountingChunkLoader { public boolean addCount() { int failures = 0; - for (long curr = this.referenceCount.get();;) { + for (long curr = this.referenceCount.get(); ; ) { for (int i = 0; i < failures; ++i) { Thread.onSpinWait(); } @@ -275,7 +275,7 @@ public class ReferenceCountingChunkLoader { if (curr == (curr = this.referenceCount.compareAndExchange(curr, curr + 1L))) { int ttlFailures = 0; - for (long currTTL = this.referenceTTL.get();;) { + for (long currTTL = this.referenceTTL.get(); ; ) { for (int i = 0; i < ttlFailures; i++) { Thread.onSpinWait(); } diff --git a/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/CheckAndCacheBlockChecker.java b/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/CheckAndCacheBlockChecker.java index e71122b..872cef9 100644 --- a/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/CheckAndCacheBlockChecker.java +++ b/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/CheckAndCacheBlockChecker.java @@ -96,11 +96,11 @@ public class CheckAndCacheBlockChecker { } } - public int getChunkSize(){ + public int getChunkSize() { return this.chunkSections2MaybeContainsMatchingBlock.numChunks; } - public boolean hasUnloadedPossibleChunks(){ + public boolean hasUnloadedPossibleChunks() { return this.unloadedPossibleChunkSections > 0; } @@ -129,14 +129,14 @@ public class CheckAndCacheBlockChecker { return this.chunkSections2MaybeContainsMatchingBlock.getChunkAccess(blockPos); } - public boolean shouldStop(){ + public boolean shouldStop() { return this.chunkSections2MaybeContainsMatchingBlock.hasNoTrueChunkSections(); } 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); - if(chunkAccess == null) { + if (chunkAccess == null) { if (!this.shouldChunkLoad) { return false; } diff --git a/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/CommonBlockSearchesCheckAndCache.java b/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/CommonBlockSearchesCheckAndCache.java index 9fcbed0..44fc0a5 100644 --- a/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/CommonBlockSearchesCheckAndCache.java +++ b/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/CommonBlockSearchesCheckAndCache.java @@ -35,12 +35,12 @@ public class CommonBlockSearchesCheckAndCache { public static Optional blockPosFindClosestMatch(LevelReader levelReader, LivingEntity livingEntity, int horizontalRange, int verticalRange, Predicate blockStatePredicate, - boolean shouldChunkLoad){ + boolean shouldChunkLoad) { BlockPos mobPos = livingEntity.blockPosition(); CheckAndCacheBlockChecker checker = new CheckAndCacheBlockChecker( mobPos, horizontalRange, verticalRange, levelReader, blockStatePredicate, shouldChunkLoad); checker.initializeChunks(); - if(checker.shouldStop()) { + if (checker.shouldStop()) { return Optional.empty(); } return BlockPos.findClosestMatch(mobPos, horizontalRange, verticalRange, checker::checkPosition); diff --git a/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/NonPOISearchDistances.java b/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/NonPOISearchDistances.java index 58d94d4..5297e15 100644 --- a/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/NonPOISearchDistances.java +++ b/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/ai/non_poi_block_search/NonPOISearchDistances.java @@ -34,7 +34,7 @@ public class NonPOISearchDistances { 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)); } @@ -58,8 +58,8 @@ public class NonPOISearchDistances { * 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 dX Relative x position of the block to the center - * @param dZ Relative z 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 */ 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)); diff --git a/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/util/Pos.java b/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/util/Pos.java index e4ba7b1..62e4d61 100644 --- a/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/util/Pos.java +++ b/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/util/Pos.java @@ -25,12 +25,15 @@ public class Pos { public static int getYSize(LevelHeightAccessor view) { return view.getHeight(); } + public static int getMinY(LevelHeightAccessor view) { return view.getMinY(); } + public static int getMaxYInclusive(LevelHeightAccessor view) { return view.getMaxY(); } + public static int getMaxYExclusive(LevelHeightAccessor view) { return view.getMaxY() + 1; } @@ -39,7 +42,7 @@ public class Pos { 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)); } @@ -66,12 +69,15 @@ public class Pos { public static int getNumYSections(LevelHeightAccessor view) { return view.getSectionsCount(); } + public static int getMinYSection(LevelHeightAccessor view) { return view.getMinSectionY(); } + public static int getMaxYSectionInclusive(LevelHeightAccessor view) { return view.getMaxSectionY(); } + public static int getMaxYSectionExclusive(LevelHeightAccessor view) { return view.getMaxSectionY() + 1; } @@ -79,6 +85,7 @@ public class Pos { public static int fromSectionIndex(LevelHeightAccessor view, int sectionCoord) { return sectionCoord + SectionYCoord.getMinYSection(view); } + public static int fromBlockCoord(int blockCoord) { return SectionPos.blockToSectionCoord(blockCoord); } @@ -88,12 +95,15 @@ public class Pos { public static int getNumYSections(LevelHeightAccessor view) { return view.getSectionsCount(); } + public static int getMinYSectionIndex(LevelHeightAccessor view) { return 0; } + public static int getMaxYSectionIndexInclusive(LevelHeightAccessor view) { return view.getSectionsCount() - 1; } + public static int getMaxYSectionIndexExclusive(LevelHeightAccessor view) { return view.getSectionsCount(); } @@ -102,6 +112,7 @@ public class Pos { public static int fromSectionCoord(LevelHeightAccessor view, int sectionCoord) { return sectionCoord - SectionYCoord.getMinYSection(view); } + public static int fromBlockCoord(LevelHeightAccessor view, int blockCoord) { return fromSectionCoord(view, SectionPos.blockToSectionCoord(blockCoord)); } diff --git a/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/util/collections/FixedChunkAccessSectionBitBuffer.java b/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/util/collections/FixedChunkAccessSectionBitBuffer.java index 6aefb6a..4bc1869 100644 --- a/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/util/collections/FixedChunkAccessSectionBitBuffer.java +++ b/shiroha-server/src/main/java/net/caffeinemc/mods/lithium/common/util/collections/FixedChunkAccessSectionBitBuffer.java @@ -50,7 +50,7 @@ public class FixedChunkAccessSectionBitBuffer { this.numSections = yLength * xLength * zLength; 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) { @@ -102,11 +102,11 @@ public class FixedChunkAccessSectionBitBuffer { 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)); } - public ChunkAccess getChunkAccess(BlockPos blockPos){ + public ChunkAccess getChunkAccess(BlockPos blockPos) { return this.getChunkAccess(ChunkPos.pack(blockPos)); } @@ -118,14 +118,14 @@ public class FixedChunkAccessSectionBitBuffer { this.setChunkAccess(ChunkPos.pack(blockPos), chunkAccess); } - public boolean hasNoTrueChunkSections(){ + public boolean hasNoTrueChunkSections() { return this.chunkSectionBits.nextSetBit(0) == -1; } public LongIterable getChunkPosInRange() { return new LongIterable() { @Override - public @NotNull LongIterator iterator(){ + public @NotNull LongIterator iterator() { return getChunkPosInRangeIterator(); } }; @@ -141,7 +141,7 @@ public class FixedChunkAccessSectionBitBuffer { int z = zMin; @Override - public long nextLong () { + public long nextLong() { long result = ChunkPos.pack(x, z); if (z < zMax) { z++; @@ -153,7 +153,7 @@ public class FixedChunkAccessSectionBitBuffer { } @Override - public boolean hasNext(){ + public boolean hasNext() { return x <= xMax; } }; @@ -162,7 +162,7 @@ public class FixedChunkAccessSectionBitBuffer { public IntIterable getSectionYInRange() { return new IntIterable() { @Override - public @NotNull IntIterator iterator(){ + public @NotNull IntIterator iterator() { return getSectionYInRangeIterator(); } }; @@ -175,12 +175,12 @@ public class FixedChunkAccessSectionBitBuffer { int y = yMin; @Override - public int nextInt(){ + public int nextInt() { return y++; } @Override - public boolean hasNext(){ + public boolean hasNext() { return y < yLimit; } };