mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-25 18:09:17 +00:00
[ci skip] cleanup
This commit is contained in:
@@ -22,7 +22,7 @@ import org.dreeam.leaf.config.modules.misc.SentryDSN;
|
||||
|
||||
public class PufferfishSentryAppender extends AbstractAppender {
|
||||
|
||||
private static final org.apache.logging.log4j.Logger logger = LogManager.getLogger(PufferfishSentryAppender.class.getSimpleName());
|
||||
private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(PufferfishSentryAppender.class.getSimpleName());
|
||||
private static final Gson GSON = new Gson();
|
||||
private final Level logLevel;
|
||||
|
||||
@@ -37,13 +37,13 @@ public class PufferfishSentryAppender extends AbstractAppender {
|
||||
try {
|
||||
logException(logEvent);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to log event with sentry", e);
|
||||
LOGGER.warn("Failed to log event with sentry", e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
logBreadcrumb(logEvent);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to log event with sentry", e);
|
||||
LOGGER.warn("Failed to log event with sentry", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class PufferfishSentryAppender extends AbstractAppender {
|
||||
|
||||
private Result filter(String loggerName) {
|
||||
return loggerName != null && loggerName.startsWith("gg.castaway.pufferfish.sentry") ? Result.DENY
|
||||
: Result.NEUTRAL;
|
||||
: Result.NEUTRAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class SentryManager {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(SentryManager.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(SentryManager.class);
|
||||
|
||||
private SentryManager() {
|
||||
|
||||
@@ -20,7 +20,7 @@ public class SentryManager {
|
||||
return;
|
||||
}
|
||||
if (logLevel == null) {
|
||||
logger.error("Invalid log level, defaulting to WARN.");
|
||||
LOGGER.error("Invalid log level, defaulting to WARN.");
|
||||
logLevel = Level.WARN;
|
||||
}
|
||||
try {
|
||||
@@ -34,9 +34,9 @@ public class SentryManager {
|
||||
PufferfishSentryAppender appender = new PufferfishSentryAppender(logLevel);
|
||||
appender.start();
|
||||
((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).addAppender(appender);
|
||||
logger.info("Sentry logging started!");
|
||||
LOGGER.info("Sentry logging started!");
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to initialize sentry!", e);
|
||||
LOGGER.warn("Failed to initialize sentry!", e);
|
||||
initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,11 @@ package gg.pufferfish.pufferfish.util;
|
||||
import com.google.common.collect.Queues;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class AsyncExecutor implements Runnable {
|
||||
|
||||
|
||||
@@ -4,14 +4,7 @@ import java.util.Iterator;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class IterableWrapper<T> implements Iterable<T> {
|
||||
|
||||
private final Iterator<T> iterator;
|
||||
|
||||
public IterableWrapper(Iterator<T> iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
public record IterableWrapper<T>(Iterator<T> iterator) implements Iterable<T> {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package gg.pufferfish.pufferfish.util;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Long2ObjectOpenHashMapWrapper<V> extends Long2ObjectOpenHashMap<V> {
|
||||
|
||||
private final Map<Long, V> backingMap;
|
||||
|
||||
public Long2ObjectOpenHashMapWrapper(Map<Long, V> map) {
|
||||
backingMap = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V put(Long key, V value) {
|
||||
return backingMap.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
return backingMap.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
return backingMap.remove(key);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public V putIfAbsent(Long key, V value) {
|
||||
return backingMap.putIfAbsent(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return backingMap.size();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public interface EquipmentEntity {
|
||||
|
||||
void onEquipmentReplaced(ItemStack oldStack, ItemStack newStack);
|
||||
|
||||
interface EquipmentTrackingEntity {
|
||||
@@ -13,4 +14,4 @@ public interface EquipmentEntity {
|
||||
interface TickableEnchantmentTrackingEntity extends ChangeSubscriber.EnchantmentSubscriber<ItemStack> {
|
||||
void updateHasTickableEnchantments(ItemStack oldStack, ItemStack newStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.caffeinemc.mods.lithium.common.util.change_tracking;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public interface ChangePublisher<T> {
|
||||
|
||||
void subscribe(ChangeSubscriber<T> subscriber, int subscriberData);
|
||||
|
||||
int unsubscribe(ChangeSubscriber<T> subscriber);
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public interface ChangeSubscriber<T> {
|
||||
@@ -28,6 +29,7 @@ public interface ChangeSubscriber<T> {
|
||||
return new Multi<>(subscribers, subscriberDatas);
|
||||
}
|
||||
}
|
||||
|
||||
static <T> ChangeSubscriber<T> without(ChangeSubscriber<T> prevSubscriber, ChangeSubscriber<T> removedSubscriber) {
|
||||
return without(prevSubscriber, removedSubscriber, 0, false);
|
||||
}
|
||||
@@ -90,7 +92,8 @@ public interface ChangeSubscriber<T> {
|
||||
|
||||
/**
|
||||
* Notify the subscriber that the publisher will be changed immediately after this call.
|
||||
* @param publisher The publisher that is about to change
|
||||
*
|
||||
* @param publisher The publisher that is about to change
|
||||
* @param subscriberData The data associated with the subscriber, given when the subscriber was added
|
||||
*/
|
||||
void notify(@Nullable T publisher, int subscriberData);
|
||||
@@ -99,7 +102,7 @@ public interface ChangeSubscriber<T> {
|
||||
* Notify the subscriber about being unsubscribed from the publisher. Used when the publisher becomes invalid.
|
||||
* The subscriber should not attempt to unsubscribe itself from the publisher in this method.
|
||||
*
|
||||
* @param publisher The publisher unsubscribed from
|
||||
* @param publisher The publisher unsubscribed from
|
||||
* @param subscriberData The data associated with the subscriber, given when the subscriber was added
|
||||
*/
|
||||
void forceUnsubscribe(T publisher, int subscriberData);
|
||||
@@ -108,9 +111,10 @@ public interface ChangeSubscriber<T> {
|
||||
|
||||
/**
|
||||
* Notify the subscriber that the publisher's count data will be changed immediately after this call.
|
||||
* @param publisher The publisher that is about to change
|
||||
*
|
||||
* @param publisher The publisher that is about to change
|
||||
* @param subscriberData The data associated with the subscriber, given when the subscriber was added
|
||||
* @param newCount The new count of the publisher
|
||||
* @param newCount The new count of the publisher
|
||||
*/
|
||||
void notifyCount(T publisher, int subscriberData, int newCount);
|
||||
}
|
||||
@@ -119,7 +123,8 @@ public interface ChangeSubscriber<T> {
|
||||
|
||||
/**
|
||||
* Notify the subscriber that the publisher's enchantment data has been changed immediately before this call.
|
||||
* @param publisher The publisher that has changed
|
||||
*
|
||||
* @param publisher The publisher that has changed
|
||||
* @param subscriberData The data associated with the subscriber, given when the subscriber was added
|
||||
*/
|
||||
void notifyAfterEnchantmentChange(T publisher, int subscriberData);
|
||||
@@ -187,4 +192,4 @@ public interface ChangeSubscriber<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,15 @@ import java.util.function.Consumer;
|
||||
|
||||
// Original project: https://github.com/thebrightspark/AsyncLocator
|
||||
public class AsyncLocator {
|
||||
|
||||
private static final ExecutorService LOCATING_EXECUTOR_SERVICE;
|
||||
|
||||
private AsyncLocator() {}
|
||||
private AsyncLocator() {
|
||||
}
|
||||
|
||||
public static class AsyncLocatorThread extends TickThread {
|
||||
private static final AtomicInteger THREAD_COUNTER = new AtomicInteger(0);
|
||||
|
||||
public AsyncLocatorThread(Runnable run, String name) {
|
||||
super(run, name, THREAD_COUNTER.incrementAndGet());
|
||||
}
|
||||
@@ -37,23 +40,23 @@ public class AsyncLocator {
|
||||
static {
|
||||
int threads = org.dreeam.leaf.config.modules.async.AsyncLocator.asyncLocatorThreads;
|
||||
LOCATING_EXECUTOR_SERVICE = new ThreadPoolExecutor(
|
||||
1,
|
||||
threads,
|
||||
org.dreeam.leaf.config.modules.async.AsyncLocator.asyncLocatorKeepalive,
|
||||
TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(),
|
||||
new ThreadFactoryBuilder()
|
||||
.setThreadFactory(
|
||||
r -> new AsyncLocatorThread(r, "Leaf Async Locator Thread") {
|
||||
@Override
|
||||
public void run() {
|
||||
r.run();
|
||||
}
|
||||
}
|
||||
)
|
||||
.setNameFormat("Leaf Async Locator Thread - %d")
|
||||
.setPriority(Thread.NORM_PRIORITY - 2)
|
||||
.build()
|
||||
1,
|
||||
threads,
|
||||
org.dreeam.leaf.config.modules.async.AsyncLocator.asyncLocatorKeepalive,
|
||||
TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(),
|
||||
new ThreadFactoryBuilder()
|
||||
.setThreadFactory(
|
||||
r -> new AsyncLocatorThread(r, "Leaf Async Locator Thread") {
|
||||
@Override
|
||||
public void run() {
|
||||
r.run();
|
||||
}
|
||||
}
|
||||
)
|
||||
.setNameFormat("Leaf Async Locator Thread - %d")
|
||||
.setPriority(Thread.NORM_PRIORITY - 2)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -68,15 +71,15 @@ public class AsyncLocator {
|
||||
* and returns a {@link LocateTask} with the futures for it.
|
||||
*/
|
||||
public static LocateTask<BlockPos> locate(
|
||||
ServerLevel level,
|
||||
TagKey<Structure> structureTag,
|
||||
BlockPos pos,
|
||||
int searchRadius,
|
||||
boolean skipKnownStructures
|
||||
ServerLevel level,
|
||||
TagKey<Structure> structureTag,
|
||||
BlockPos pos,
|
||||
int searchRadius,
|
||||
boolean skipKnownStructures
|
||||
) {
|
||||
CompletableFuture<BlockPos> completableFuture = new CompletableFuture<>();
|
||||
Future<?> future = LOCATING_EXECUTOR_SERVICE.submit(
|
||||
() -> doLocateLevel(completableFuture, level, structureTag, pos, searchRadius, skipKnownStructures)
|
||||
() -> doLocateLevel(completableFuture, level, structureTag, pos, searchRadius, skipKnownStructures)
|
||||
);
|
||||
return new LocateTask<>(level.getServer(), completableFuture, future);
|
||||
}
|
||||
@@ -87,41 +90,41 @@ public class AsyncLocator {
|
||||
* {@link LocateTask} with the futures for it.
|
||||
*/
|
||||
public static LocateTask<Pair<BlockPos, Holder<Structure>>> locate(
|
||||
ServerLevel level,
|
||||
HolderSet<Structure> structureSet,
|
||||
BlockPos pos,
|
||||
int searchRadius,
|
||||
boolean skipKnownStructures
|
||||
ServerLevel level,
|
||||
HolderSet<Structure> structureSet,
|
||||
BlockPos pos,
|
||||
int searchRadius,
|
||||
boolean skipKnownStructures
|
||||
) {
|
||||
CompletableFuture<Pair<BlockPos, Holder<Structure>>> completableFuture = new CompletableFuture<>();
|
||||
Future<?> future = LOCATING_EXECUTOR_SERVICE.submit(
|
||||
() -> doLocateChunkGenerator(completableFuture, level, structureSet, pos, searchRadius, skipKnownStructures)
|
||||
() -> doLocateChunkGenerator(completableFuture, level, structureSet, pos, searchRadius, skipKnownStructures)
|
||||
);
|
||||
return new LocateTask<>(level.getServer(), completableFuture, future);
|
||||
}
|
||||
|
||||
private static void doLocateLevel(
|
||||
CompletableFuture<BlockPos> completableFuture,
|
||||
ServerLevel level,
|
||||
TagKey<Structure> structureTag,
|
||||
BlockPos pos,
|
||||
int searchRadius,
|
||||
boolean skipExistingChunks
|
||||
CompletableFuture<BlockPos> completableFuture,
|
||||
ServerLevel level,
|
||||
TagKey<Structure> structureTag,
|
||||
BlockPos pos,
|
||||
int searchRadius,
|
||||
boolean skipExistingChunks
|
||||
) {
|
||||
BlockPos foundPos = level.findNearestMapStructure(structureTag, pos, searchRadius, skipExistingChunks);
|
||||
completableFuture.complete(foundPos);
|
||||
}
|
||||
|
||||
private static void doLocateChunkGenerator(
|
||||
CompletableFuture<Pair<BlockPos, Holder<Structure>>> completableFuture,
|
||||
ServerLevel level,
|
||||
HolderSet<Structure> structureSet,
|
||||
BlockPos pos,
|
||||
int searchRadius,
|
||||
boolean skipExistingChunks
|
||||
CompletableFuture<Pair<BlockPos, Holder<Structure>>> completableFuture,
|
||||
ServerLevel level,
|
||||
HolderSet<Structure> structureSet,
|
||||
BlockPos pos,
|
||||
int searchRadius,
|
||||
boolean skipExistingChunks
|
||||
) {
|
||||
Pair<BlockPos, Holder<Structure>> foundPair = level.getChunkSource().getGenerator()
|
||||
.findNearestMapStructure(level, structureSet, pos, searchRadius, skipExistingChunks);
|
||||
.findNearestMapStructure(level, structureSet, pos, searchRadius, skipExistingChunks);
|
||||
completableFuture.complete(foundPair);
|
||||
}
|
||||
|
||||
@@ -161,4 +164,4 @@ public class AsyncLocator {
|
||||
completableFuture.cancel(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class AsyncPath extends Path {
|
||||
*/
|
||||
public synchronized void process() {
|
||||
if (this.processState == PathProcessState.COMPLETED ||
|
||||
this.processState == PathProcessState.PROCESSING) {
|
||||
this.processState == PathProcessState.PROCESSING) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public class AsyncPath extends Path {
|
||||
*/
|
||||
private void checkProcessed() {
|
||||
if (this.processState == PathProcessState.WAITING ||
|
||||
this.processState == PathProcessState.PROCESSING) { // Block if we are on processing
|
||||
this.processState == PathProcessState.PROCESSING) { // Block if we are on processing
|
||||
this.process();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ import java.util.function.Consumer;
|
||||
public class AsyncPathProcessor {
|
||||
|
||||
private static final Executor pathProcessingExecutor = new ThreadPoolExecutor(
|
||||
1,
|
||||
org.dreeam.leaf.config.modules.async.AsyncPathfinding.asyncPathfindingMaxThreads,
|
||||
org.dreeam.leaf.config.modules.async.AsyncPathfinding.asyncPathfindingKeepalive, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(),
|
||||
new ThreadFactoryBuilder()
|
||||
.setNameFormat("Leaf Async Pathfinding Thread - %d")
|
||||
.setPriority(Thread.NORM_PRIORITY - 2)
|
||||
.build()
|
||||
1,
|
||||
org.dreeam.leaf.config.modules.async.AsyncPathfinding.asyncPathfindingMaxThreads,
|
||||
org.dreeam.leaf.config.modules.async.AsyncPathfinding.asyncPathfindingKeepalive, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(),
|
||||
new ThreadFactoryBuilder()
|
||||
.setNameFormat("Leaf Async Pathfinding Thread - %d")
|
||||
.setPriority(Thread.NORM_PRIORITY - 2)
|
||||
.build()
|
||||
);
|
||||
|
||||
protected static CompletableFuture<Void> queue(@NotNull AsyncPath path) {
|
||||
@@ -42,7 +42,7 @@ public class AsyncPathProcessor {
|
||||
public static void awaitProcessing(@Nullable Path path, Consumer<@Nullable Path> afterProcessing) {
|
||||
if (path != null && !path.isProcessed() && path instanceof AsyncPath asyncPath) {
|
||||
asyncPath.postProcessing(() ->
|
||||
MinecraftServer.getServer().scheduleOnMain(() -> afterProcessing.accept(path))
|
||||
MinecraftServer.getServer().scheduleOnMain(() -> afterProcessing.accept(path))
|
||||
);
|
||||
} else {
|
||||
afterProcessing.accept(path);
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class NodeEvaluatorCache {
|
||||
|
||||
private static final Map<NodeEvaluatorFeatures, MultiThreadedQueue<NodeEvaluator>> threadLocalNodeEvaluators = new ConcurrentHashMap<>();
|
||||
private static final Map<NodeEvaluator, NodeEvaluatorGenerator> nodeEvaluatorToGenerator = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ import net.minecraft.world.level.pathfinder.NodeEvaluator;
|
||||
import net.minecraft.world.level.pathfinder.SwimNodeEvaluator;
|
||||
|
||||
public record NodeEvaluatorFeatures(
|
||||
NodeEvaluatorType type,
|
||||
boolean canPassDoors,
|
||||
boolean canFloat,
|
||||
boolean canWalkOverFences,
|
||||
boolean canOpenDoors,
|
||||
boolean allowBreaching
|
||||
NodeEvaluatorType type,
|
||||
boolean canPassDoors,
|
||||
boolean canFloat,
|
||||
boolean canWalkOverFences,
|
||||
boolean canOpenDoors,
|
||||
boolean allowBreaching
|
||||
) {
|
||||
public static NodeEvaluatorFeatures fromNodeEvaluator(NodeEvaluator nodeEvaluator) {
|
||||
NodeEvaluatorType type = NodeEvaluatorType.fromNodeEvaluator(nodeEvaluator);
|
||||
|
||||
@@ -4,8 +4,5 @@ import net.minecraft.world.level.pathfinder.NodeEvaluator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface NodeEvaluatorGenerator {
|
||||
|
||||
@NotNull
|
||||
NodeEvaluator generate(NodeEvaluatorFeatures nodeEvaluatorFeatures);
|
||||
|
||||
}
|
||||
@NotNull NodeEvaluator generate(NodeEvaluatorFeatures nodeEvaluatorFeatures);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import ca.spottedleaf.moonrise.common.misc.NearbyPlayers;
|
||||
import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel;
|
||||
import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup;
|
||||
import ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerEntity;
|
||||
import ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerTrackedEntity;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.FullChunkStatus;
|
||||
@@ -67,7 +66,7 @@ public class MultithreadedTracker {
|
||||
|
||||
if (tracker == null) continue;
|
||||
|
||||
((EntityTrackerTrackedEntity) tracker).moonrise$tick(nearbyPlayers.getChunk(entity.chunkPosition()));
|
||||
tracker.moonrise$tick(nearbyPlayers.getChunk(entity.chunkPosition()));
|
||||
tracker.serverEntity.sendChanges();
|
||||
}
|
||||
});
|
||||
@@ -89,7 +88,7 @@ public class MultithreadedTracker {
|
||||
|
||||
if (tracker == null) continue;
|
||||
|
||||
((EntityTrackerTrackedEntity) tracker).moonrise$tick(nearbyPlayers.getChunk(entity.chunkPosition()));
|
||||
tracker.moonrise$tick(nearbyPlayers.getChunk(entity.chunkPosition()));
|
||||
sendChangesTasks[index++] = () -> tracker.serverEntity.sendChanges(); // Collect send changes to task array
|
||||
}
|
||||
|
||||
|
||||
@@ -198,9 +198,9 @@ public class LeafConfig {
|
||||
|
||||
private static List<String> buildSparkExtraConfigs() {
|
||||
List<String> extraConfigs = new ArrayList<>(Arrays.asList(
|
||||
"config/leaf-global.yml",
|
||||
"config/gale-global.yml",
|
||||
"config/gale-world-defaults.yml"
|
||||
"config/leaf-global.yml",
|
||||
"config/gale-global.yml",
|
||||
"config/gale-world-defaults.yml"
|
||||
));
|
||||
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
@@ -212,7 +212,7 @@ public class LeafConfig {
|
||||
|
||||
private static String[] buildSparkHiddenPaths() {
|
||||
return new String[]{
|
||||
SentryDSN.sentryDsnConfigPath // Hide Sentry DSN key
|
||||
SentryDSN.sentryDsnConfigPath // Hide Sentry DSN key
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -15,19 +15,19 @@ public class LeafGlobalConfig {
|
||||
protected static final boolean isCN = CURRENT_REGION.equals("CN");
|
||||
|
||||
public LeafGlobalConfig(boolean init) throws Exception {
|
||||
configFile = ConfigFile.loadConfig(new File(LeafConfig.I_CONFIG_FOLDER, LeafConfig.I_GLOBAL_CONFIG_FILE));
|
||||
configFile.set("config-version", 3.0);
|
||||
configFile.addComments("config-version", pickStringRegionBased("""
|
||||
Leaf Config
|
||||
GitHub Repo: https://github.com/Winds-Studio/Leaf
|
||||
Discord: https://discord.com/invite/gfgAwdSEuM""",
|
||||
"""
|
||||
Leaf Config
|
||||
GitHub Repo: https://github.com/Winds-Studio/Leaf
|
||||
QQ Group: 619278377"""));
|
||||
configFile = ConfigFile.loadConfig(new File(LeafConfig.I_CONFIG_FOLDER, LeafConfig.I_GLOBAL_CONFIG_FILE));
|
||||
configFile.set("config-version", 3.0);
|
||||
configFile.addComments("config-version", pickStringRegionBased("""
|
||||
Leaf Config
|
||||
GitHub Repo: https://github.com/Winds-Studio/Leaf
|
||||
Discord: https://discord.com/invite/gfgAwdSEuM""",
|
||||
"""
|
||||
Leaf Config
|
||||
GitHub Repo: https://github.com/Winds-Studio/Leaf
|
||||
QQ Group: 619278377"""));
|
||||
|
||||
// Pre-structure to force order
|
||||
structureConfig();
|
||||
// Pre-structure to force order
|
||||
structureConfig();
|
||||
}
|
||||
|
||||
protected void structureConfig() {
|
||||
|
||||
@@ -42,7 +42,8 @@ public class LagCompensation {
|
||||
public static final int MAX_TPS = 20;
|
||||
public static final int FULL_TICK = 50;
|
||||
|
||||
private TPSCalculator() {}
|
||||
private TPSCalculator() {
|
||||
}
|
||||
|
||||
public static void onTick() {
|
||||
if (currentTick != null) {
|
||||
@@ -111,4 +112,4 @@ public class LagCompensation {
|
||||
allMissedTicks = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PositionalBiomeGetter implements Supplier<Holder<Biome>> {
|
||||
|
||||
private final Function<BlockPos, Holder<Biome>> biomeGetter;
|
||||
private final BlockPos.MutableBlockPos pos;
|
||||
private int nextX, nextY, nextZ;
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.BitSet;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
public class CachedOrNewBitsGetter {
|
||||
|
||||
private static final IntFunction<BitSet> bitSetConstructor = BitSet::new;
|
||||
|
||||
public static ThreadLocal<Int2ObjectOpenHashMap<BitSet>> BITSETS = ThreadLocal.withInitial(Int2ObjectOpenHashMap::new);
|
||||
|
||||
@@ -2,17 +2,20 @@ package org.dreeam.leaf.util.cache;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
import it.unimi.dsi.fastutil.longs.LongList;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
/**
|
||||
* @author 2No2Name, original implemenation by SuperCoder7979 and Gegy1000
|
||||
*/
|
||||
public class IterateOutwardsCache {
|
||||
|
||||
//POS_ZERO must not be replaced with BlockPos.ORIGIN, otherwise iterateOutwards at BlockPos.ORIGIN will not use the cache
|
||||
public static final BlockPos POS_ZERO = new BlockPos(0,0,0);
|
||||
public static final BlockPos POS_ZERO = new BlockPos(0, 0, 0);
|
||||
|
||||
|
||||
private final ConcurrentHashMap<Long, LongArrayList> table;
|
||||
@@ -68,4 +71,4 @@ public class IterateOutwardsCache {
|
||||
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package org.dreeam.leaf.util.cache;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.LongIterator;
|
||||
import it.unimi.dsi.fastutil.longs.LongList;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
/**
|
||||
@@ -22,7 +24,7 @@ public class LongList2BlockPosMutableIterable implements Iterable<BlockPos> {
|
||||
|
||||
@Override
|
||||
public Iterator<BlockPos> iterator() {
|
||||
return new Iterator<BlockPos>() {
|
||||
return new Iterator<>() {
|
||||
|
||||
private final LongIterator it = LongList2BlockPosMutableIterable.this.positions.iterator();
|
||||
private final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
|
||||
@@ -36,11 +38,10 @@ public class LongList2BlockPosMutableIterable implements Iterable<BlockPos> {
|
||||
public net.minecraft.core.BlockPos next() {
|
||||
long nextPos = this.it.nextLong();
|
||||
return this.pos.set(
|
||||
LongList2BlockPosMutableIterable.this.xOffset + BlockPos.getX(nextPos),
|
||||
LongList2BlockPosMutableIterable.this.yOffset + BlockPos.getY(nextPos),
|
||||
LongList2BlockPosMutableIterable.this.zOffset + BlockPos.getZ(nextPos));
|
||||
LongList2BlockPosMutableIterable.this.xOffset + BlockPos.getX(nextPos),
|
||||
LongList2BlockPosMutableIterable.this.yOffset + BlockPos.getY(nextPos),
|
||||
LongList2BlockPosMutableIterable.this.zOffset + BlockPos.getZ(nextPos));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.function.Function;
|
||||
* Backed by an {@link Object2ObjectOpenHashMap}, with string keys interned to save memory.
|
||||
*/
|
||||
public class StringCanonizingOpenHashMap<T> extends Object2ObjectOpenHashMap<String, T> {
|
||||
|
||||
private static final Interner<String> KEY_INTERNER = Interner.newWeakInterner();
|
||||
|
||||
private static String intern(String key) {
|
||||
@@ -49,10 +50,12 @@ public class StringCanonizingOpenHashMap<T> extends Object2ObjectOpenHashMap<Str
|
||||
public static <T> StringCanonizingOpenHashMap<T> deepCopy(StringCanonizingOpenHashMap<T> incomingMap, Function<T, T> deepCopier) {
|
||||
StringCanonizingOpenHashMap<T> newMap = new StringCanonizingOpenHashMap<>(incomingMap.size(), 0.8f);
|
||||
ObjectIterator<Entry<String, T>> iterator = incomingMap.object2ObjectEntrySet().fastIterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, T> entry = iterator.next();
|
||||
newMap.putWithoutInterning(entry.getKey(), deepCopier.apply(entry.getValue()));
|
||||
}
|
||||
|
||||
return newMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,11 @@ import net.minecraft.util.Mth;
|
||||
* from {@link Mth}. Validation is performed during runtime to ensure that the table is correct.
|
||||
*
|
||||
* @author coderbot16 Author of the original (and very clever) implementation in Rust:
|
||||
* https://gitlab.com/coderbot16/i73/-/tree/master/i73-trig/src
|
||||
* <a href="https://gitlab.com/coderbot16/i73/-/tree/master/i73-trig/src"></a>
|
||||
* @author jellysquid3 Additional optimizations, port to Java
|
||||
*/
|
||||
public class CompactSineLUT {
|
||||
|
||||
private static final int[] SINE_TABLE_INT = new int[16384 + 1];
|
||||
private static final float SINE_TABLE_MIDPOINT;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.random.RandomGeneratorFactory;
|
||||
|
||||
|
||||
public class FasterRandomSource implements BitRandomSource {
|
||||
|
||||
private static final int INT_BITS = 48;
|
||||
private static final long SEED_MASK = 0xFFFFFFFFFFFFL;
|
||||
private static final long MULTIPLIER = 25214903917L;
|
||||
@@ -75,7 +76,7 @@ public class FasterRandomSource implements BitRandomSource {
|
||||
@Override
|
||||
public RandomSource fromHashOf(String seed) {
|
||||
int i = seed.hashCode();
|
||||
return new FasterRandomSource((long)i ^ this.seed);
|
||||
return new FasterRandomSource((long) i ^ this.seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,12 +6,12 @@ public class LeafVersionFetcher extends AbstractPaperVersionFetcher {
|
||||
|
||||
public LeafVersionFetcher() {
|
||||
super(
|
||||
"ver/1.21.3",
|
||||
"https://github.com/Winds-Studio/Leaf",
|
||||
"Winds-Studio",
|
||||
"Leaf",
|
||||
"Winds-Studio",
|
||||
"Leaf"
|
||||
"ver/1.21.3",
|
||||
"https://github.com/Winds-Studio/Leaf",
|
||||
"Winds-Studio",
|
||||
"Leaf",
|
||||
"Winds-Studio",
|
||||
"Leaf"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class LeavesLogger extends Logger {
|
||||
|
||||
public static final LeavesLogger LOGGER = new LeavesLogger();
|
||||
|
||||
private LeavesLogger() {
|
||||
|
||||
@@ -49,8 +49,8 @@ public class AppleSkinProtocol {
|
||||
|
||||
@ProtocolHandler.PlayerLeave
|
||||
public static void onPlayerLoggedOut(@NotNull ServerPlayer player) {
|
||||
subscribedChannels.remove(player);
|
||||
resetPlayerData(player);
|
||||
subscribedChannels.remove(player);
|
||||
resetPlayerData(player);
|
||||
}
|
||||
|
||||
@ProtocolHandler.MinecraftRegister(ignoreId = true)
|
||||
@@ -62,45 +62,45 @@ public class AppleSkinProtocol {
|
||||
|
||||
@ProtocolHandler.Ticker
|
||||
public static void tick() {
|
||||
if (MinecraftServer.getServer().getTickCount() % org.dreeam.leaf.config.modules.network.ProtocolSupport.appleskinSyncTickInterval != 0) {
|
||||
return;
|
||||
}
|
||||
if (MinecraftServer.getServer().getTickCount() % org.dreeam.leaf.config.modules.network.ProtocolSupport.appleskinSyncTickInterval != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry<ServerPlayer, Set<String>> entry : subscribedChannels.entrySet()) {
|
||||
ServerPlayer player = entry.getKey();
|
||||
FoodData data = player.getFoodData();
|
||||
for (Map.Entry<ServerPlayer, Set<String>> entry : subscribedChannels.entrySet()) {
|
||||
ServerPlayer player = entry.getKey();
|
||||
FoodData data = player.getFoodData();
|
||||
|
||||
for (String channel : entry.getValue()) {
|
||||
switch (channel) {
|
||||
case "saturation" -> {
|
||||
float saturation = data.getSaturationLevel();
|
||||
Float previousSaturation = previousSaturationLevels.get(player);
|
||||
if (previousSaturation == null || saturation != previousSaturation) {
|
||||
ProtocolUtils.sendPayloadPacket(player, SATURATION_KEY, buf -> buf.writeFloat(saturation));
|
||||
previousSaturationLevels.put(player, saturation);
|
||||
}
|
||||
for (String channel : entry.getValue()) {
|
||||
switch (channel) {
|
||||
case "saturation" -> {
|
||||
float saturation = data.getSaturationLevel();
|
||||
Float previousSaturation = previousSaturationLevels.get(player);
|
||||
if (previousSaturation == null || saturation != previousSaturation) {
|
||||
ProtocolUtils.sendPayloadPacket(player, SATURATION_KEY, buf -> buf.writeFloat(saturation));
|
||||
previousSaturationLevels.put(player, saturation);
|
||||
}
|
||||
}
|
||||
|
||||
case "exhaustion" -> {
|
||||
float exhaustion = data.exhaustionLevel;
|
||||
Float previousExhaustion = previousExhaustionLevels.get(player);
|
||||
if (previousExhaustion == null || Math.abs(exhaustion - previousExhaustion) >= MINIMUM_EXHAUSTION_CHANGE_THRESHOLD) {
|
||||
ProtocolUtils.sendPayloadPacket(player, EXHAUSTION_KEY, buf -> buf.writeFloat(exhaustion));
|
||||
previousExhaustionLevels.put(player, exhaustion);
|
||||
}
|
||||
case "exhaustion" -> {
|
||||
float exhaustion = data.exhaustionLevel;
|
||||
Float previousExhaustion = previousExhaustionLevels.get(player);
|
||||
if (previousExhaustion == null || Math.abs(exhaustion - previousExhaustion) >= MINIMUM_EXHAUSTION_CHANGE_THRESHOLD) {
|
||||
ProtocolUtils.sendPayloadPacket(player, EXHAUSTION_KEY, buf -> buf.writeFloat(exhaustion));
|
||||
previousExhaustionLevels.put(player, exhaustion);
|
||||
}
|
||||
}
|
||||
|
||||
case "natural_regeneration" -> {
|
||||
boolean regeneration = player.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION);
|
||||
Boolean previousRegeneration = previousNaturalRegeneration.get(player);
|
||||
if (previousRegeneration == null || regeneration != previousRegeneration) {
|
||||
ProtocolUtils.sendPayloadPacket(player, NATURAL_REGENERATION_KEY, buf -> buf.writeBoolean(regeneration));
|
||||
previousNaturalRegeneration.put(player, regeneration);
|
||||
}
|
||||
case "natural_regeneration" -> {
|
||||
boolean regeneration = player.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION);
|
||||
Boolean previousRegeneration = previousNaturalRegeneration.get(player);
|
||||
if (previousRegeneration == null || regeneration != previousRegeneration) {
|
||||
ProtocolUtils.sendPayloadPacket(player, NATURAL_REGENERATION_KEY, buf -> buf.writeBoolean(regeneration));
|
||||
previousNaturalRegeneration.put(player, regeneration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ProtocolHandler.ReloadServer
|
||||
|
||||
@@ -57,29 +57,29 @@ public class AsteorBarProtocol {
|
||||
|
||||
@ProtocolHandler.Ticker
|
||||
public static void tick() {
|
||||
for (ServerPlayer player : players) {
|
||||
FoodData data = player.getFoodData();
|
||||
for (ServerPlayer player : players) {
|
||||
FoodData data = player.getFoodData();
|
||||
|
||||
float saturation = data.getSaturationLevel();
|
||||
Float previousSaturation = previousSaturationLevels.get(player.getUUID());
|
||||
if (previousSaturation == null || saturation != previousSaturation) {
|
||||
ProtocolUtils.sendPayloadPacket(player, NETWORK_KEY, buf -> {
|
||||
buf.writeByte(1);
|
||||
buf.writeFloat(saturation);
|
||||
});
|
||||
previousSaturationLevels.put(player.getUUID(), saturation);
|
||||
}
|
||||
|
||||
float exhaustion = data.exhaustionLevel;
|
||||
Float previousExhaustion = previousExhaustionLevels.get(player.getUUID());
|
||||
if (previousExhaustion == null || Math.abs(exhaustion - previousExhaustion) >= THRESHOLD) {
|
||||
ProtocolUtils.sendPayloadPacket(player, NETWORK_KEY, buf -> {
|
||||
buf.writeByte(0);
|
||||
buf.writeFloat(exhaustion);
|
||||
});
|
||||
previousExhaustionLevels.put(player.getUUID(), exhaustion);
|
||||
}
|
||||
float saturation = data.getSaturationLevel();
|
||||
Float previousSaturation = previousSaturationLevels.get(player.getUUID());
|
||||
if (previousSaturation == null || saturation != previousSaturation) {
|
||||
ProtocolUtils.sendPayloadPacket(player, NETWORK_KEY, buf -> {
|
||||
buf.writeByte(1);
|
||||
buf.writeFloat(saturation);
|
||||
});
|
||||
previousSaturationLevels.put(player.getUUID(), saturation);
|
||||
}
|
||||
|
||||
float exhaustion = data.exhaustionLevel;
|
||||
Float previousExhaustion = previousExhaustionLevels.get(player.getUUID());
|
||||
if (previousExhaustion == null || Math.abs(exhaustion - previousExhaustion) >= THRESHOLD) {
|
||||
ProtocolUtils.sendPayloadPacket(player, NETWORK_KEY, buf -> {
|
||||
buf.writeByte(0);
|
||||
buf.writeFloat(exhaustion);
|
||||
});
|
||||
previousExhaustionLevels.put(player.getUUID(), exhaustion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ProtocolHandler.ReloadServer
|
||||
|
||||
@@ -7,7 +7,6 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.dreeam.leaf.config.modules.network.ProtocolSupport;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.leavesmc.leaves.protocol.chatimage.ChatImageIndex;
|
||||
@@ -36,7 +35,7 @@ public class ChatImageProtocol {
|
||||
}
|
||||
|
||||
public record FileInfoChannelPacket(
|
||||
String message) implements LeavesCustomPayload<LeavesProtocolManager.LeavesPayload> {
|
||||
String message) implements LeavesCustomPayload<LeavesProtocolManager.LeavesPayload> {
|
||||
private static final ResourceLocation FILE_INFO = ChatImageProtocol.id("file_info");
|
||||
|
||||
@New
|
||||
@@ -56,7 +55,7 @@ public class ChatImageProtocol {
|
||||
}
|
||||
|
||||
public record DownloadFileChannelPacket(
|
||||
String message) implements LeavesCustomPayload<LeavesProtocolManager.LeavesPayload> {
|
||||
String message) implements LeavesCustomPayload<LeavesProtocolManager.LeavesPayload> {
|
||||
private static final ResourceLocation DOWNLOAD_FILE_CHANNEL = ChatImageProtocol.id("download_file_channel");
|
||||
|
||||
@New
|
||||
@@ -77,7 +76,7 @@ public class ChatImageProtocol {
|
||||
}
|
||||
|
||||
public record FileChannelPacket(
|
||||
String message) implements LeavesCustomPayload<LeavesProtocolManager.LeavesPayload> {
|
||||
String message) implements LeavesCustomPayload<LeavesProtocolManager.LeavesPayload> {
|
||||
private static final ResourceLocation FILE_CHANNEL = ChatImageProtocol.id("file_channel");
|
||||
|
||||
@New
|
||||
|
||||
@@ -315,7 +315,8 @@ public class LeavesProtocolManager {
|
||||
}
|
||||
}
|
||||
|
||||
public record ErrorPayload(ResourceLocation id, String[] protocolID, String[] packetID) implements LeavesCustomPayload<ErrorPayload> {
|
||||
public record ErrorPayload(ResourceLocation id, String[] protocolID,
|
||||
String[] packetID) implements LeavesCustomPayload<ErrorPayload> {
|
||||
@Override
|
||||
public void write(@NotNull FriendlyByteBuf buf) {
|
||||
}
|
||||
@@ -333,7 +334,8 @@ public class LeavesProtocolManager {
|
||||
}
|
||||
}
|
||||
|
||||
public record LeavesPayload(FriendlyByteBuf data, ResourceLocation id) implements LeavesCustomPayload<LeavesPayload> {
|
||||
public record LeavesPayload(FriendlyByteBuf data,
|
||||
ResourceLocation id) implements LeavesCustomPayload<LeavesPayload> {
|
||||
|
||||
@New
|
||||
public LeavesPayload(ResourceLocation location, FriendlyByteBuf buf) {
|
||||
@@ -347,7 +349,7 @@ public class LeavesProtocolManager {
|
||||
}
|
||||
|
||||
public record FabricRegisterPayload(
|
||||
Set<ResourceLocation> channels) implements LeavesCustomPayload<FabricRegisterPayload> {
|
||||
Set<ResourceLocation> channels) implements LeavesCustomPayload<FabricRegisterPayload> {
|
||||
|
||||
public static final ResourceLocation CHANNEL = ResourceLocation.withDefaultNamespace("register");
|
||||
|
||||
|
||||
@@ -154,8 +154,8 @@ public class JadeProtocol {
|
||||
|
||||
try {
|
||||
shearableBlocks = Collections.unmodifiableList(LootTableMineableCollector.execute(
|
||||
MinecraftServer.getServer().reloadableRegistries().lookup().lookupOrThrow(Registries.LOOT_TABLE),
|
||||
Items.SHEARS.getDefaultInstance()
|
||||
MinecraftServer.getServer().reloadableRegistries().lookup().lookupOrThrow(Registries.LOOT_TABLE),
|
||||
Items.SHEARS.getDefaultInstance()
|
||||
));
|
||||
} catch (Throwable ignore) {
|
||||
shearableBlocks = List.of();
|
||||
|
||||
@@ -46,5 +46,4 @@ public interface BlockAccessor extends Accessor<BlockHitResult> {
|
||||
|
||||
BlockAccessor build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -134,15 +134,15 @@ public class BlockAccessorImpl extends AccessorImpl<BlockHitResult> implements B
|
||||
|
||||
public record SyncData(boolean showDetails, BlockHitResult hit, BlockState blockState, ItemStack fakeBlock) {
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.BOOL,
|
||||
SyncData::showDetails,
|
||||
StreamCodec.of(FriendlyByteBuf::writeBlockHitResult, FriendlyByteBuf::readBlockHitResult),
|
||||
SyncData::hit,
|
||||
ByteBufCodecs.idMapper(Block.BLOCK_STATE_REGISTRY),
|
||||
SyncData::blockState,
|
||||
ItemStack.OPTIONAL_STREAM_CODEC,
|
||||
SyncData::fakeBlock,
|
||||
SyncData::new
|
||||
ByteBufCodecs.BOOL,
|
||||
SyncData::showDetails,
|
||||
StreamCodec.of(FriendlyByteBuf::writeBlockHitResult, FriendlyByteBuf::readBlockHitResult),
|
||||
SyncData::hit,
|
||||
ByteBufCodecs.idMapper(Block.BLOCK_STATE_REGISTRY),
|
||||
SyncData::blockState,
|
||||
ItemStack.OPTIONAL_STREAM_CODEC,
|
||||
SyncData::fakeBlock,
|
||||
SyncData::new
|
||||
);
|
||||
|
||||
public BlockAccessor unpack(ServerPlayer player) {
|
||||
@@ -151,13 +151,13 @@ public class BlockAccessorImpl extends AccessorImpl<BlockHitResult> implements B
|
||||
blockEntity = Suppliers.memoize(() -> player.level().getBlockEntity(hit.getBlockPos()));
|
||||
}
|
||||
return new Builder()
|
||||
.level(player.level())
|
||||
.player(player)
|
||||
.showDetails(showDetails)
|
||||
.hit(hit)
|
||||
.blockState(blockState)
|
||||
.blockEntity(blockEntity)
|
||||
.build();
|
||||
.level(player.level())
|
||||
.player(player)
|
||||
.showDetails(showDetails)
|
||||
.hit(hit)
|
||||
.blockState(blockState)
|
||||
.blockEntity(blockEntity)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +41,4 @@ public interface EntityAccessor extends Accessor<EntityHitResult> {
|
||||
|
||||
EntityAccessor build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,26 +98,26 @@ public class EntityAccessorImpl extends AccessorImpl<EntityHitResult> implements
|
||||
|
||||
public record SyncData(boolean showDetails, int id, int partIndex, Vec3 hitVec) {
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.BOOL,
|
||||
SyncData::showDetails,
|
||||
ByteBufCodecs.VAR_INT,
|
||||
SyncData::id,
|
||||
ByteBufCodecs.VAR_INT,
|
||||
SyncData::partIndex,
|
||||
ByteBufCodecs.VECTOR3F.map(Vec3::new, Vec3::toVector3f),
|
||||
SyncData::hitVec,
|
||||
SyncData::new
|
||||
ByteBufCodecs.BOOL,
|
||||
SyncData::showDetails,
|
||||
ByteBufCodecs.VAR_INT,
|
||||
SyncData::id,
|
||||
ByteBufCodecs.VAR_INT,
|
||||
SyncData::partIndex,
|
||||
ByteBufCodecs.VECTOR3F.map(Vec3::new, Vec3::toVector3f),
|
||||
SyncData::hitVec,
|
||||
SyncData::new
|
||||
);
|
||||
|
||||
public EntityAccessor unpack(ServerPlayer player) {
|
||||
Supplier<Entity> entity = Suppliers.memoize(() -> CommonUtil.getPartEntity(player.level().getEntity(id), partIndex));
|
||||
return new EntityAccessorImpl.Builder()
|
||||
.level(player.level())
|
||||
.player(player)
|
||||
.showDetails(showDetails)
|
||||
.entity(entity)
|
||||
.hit(Suppliers.memoize(() -> new EntityHitResult(entity.get(), hitVec)))
|
||||
.build();
|
||||
.level(player.level())
|
||||
.player(player)
|
||||
.showDetails(showDetails)
|
||||
.entity(entity)
|
||||
.hit(Suppliers.memoize(() -> new EntityHitResult(entity.get(), hitVec)))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,19 +20,20 @@ import java.util.Objects;
|
||||
|
||||
import static org.leavesmc.leaves.protocol.jade.JadeProtocol.entityDataProviders;
|
||||
|
||||
public record RequestEntityPayload(EntityAccessorImpl.SyncData data, List<@Nullable IServerDataProvider<EntityAccessor>> dataProviders) implements LeavesCustomPayload<RequestEntityPayload> {
|
||||
public record RequestEntityPayload(EntityAccessorImpl.SyncData data,
|
||||
List<@Nullable IServerDataProvider<EntityAccessor>> dataProviders) implements LeavesCustomPayload<RequestEntityPayload> {
|
||||
|
||||
private static final ResourceLocation PACKET_REQUEST_ENTITY = JadeProtocol.id("request_entity");
|
||||
private static final StreamCodec<RegistryFriendlyByteBuf, RequestEntityPayload> CODEC = StreamCodec.composite(
|
||||
EntityAccessorImpl.SyncData.STREAM_CODEC,
|
||||
RequestEntityPayload::data,
|
||||
ByteBufCodecs.<ByteBuf, IServerDataProvider<EntityAccessor>>list()
|
||||
.apply(ByteBufCodecs.idMapper(
|
||||
$ -> Objects.requireNonNull(entityDataProviders.idMapper()).byId($),
|
||||
$ -> Objects.requireNonNull(entityDataProviders.idMapper()).getIdOrThrow($)
|
||||
)),
|
||||
RequestEntityPayload::dataProviders,
|
||||
RequestEntityPayload::new);
|
||||
EntityAccessorImpl.SyncData.STREAM_CODEC,
|
||||
RequestEntityPayload::data,
|
||||
ByteBufCodecs.<ByteBuf, IServerDataProvider<EntityAccessor>>list()
|
||||
.apply(ByteBufCodecs.idMapper(
|
||||
$ -> Objects.requireNonNull(entityDataProviders.idMapper()).byId($),
|
||||
$ -> Objects.requireNonNull(entityDataProviders.idMapper()).getIdOrThrow($)
|
||||
)),
|
||||
RequestEntityPayload::dataProviders,
|
||||
RequestEntityPayload::new);
|
||||
|
||||
|
||||
@Override
|
||||
@@ -50,4 +51,4 @@ public record RequestEntityPayload(EntityAccessorImpl.SyncData data, List<@Nulla
|
||||
public ResourceLocation id() {
|
||||
return PACKET_REQUEST_ENTITY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,22 +19,23 @@ import java.util.Map;
|
||||
import static org.leavesmc.leaves.protocol.jade.util.JadeCodec.PRIMITIVE_STREAM_CODEC;
|
||||
|
||||
public record ServerPingPayload(
|
||||
Map<ResourceLocation, Object> serverConfig,
|
||||
List<Block> shearableBlocks,
|
||||
List<ResourceLocation> blockProviderIds,
|
||||
List<ResourceLocation> entityProviderIds) implements LeavesCustomPayload<ServerPingPayload> {
|
||||
|
||||
Map<ResourceLocation, Object> serverConfig,
|
||||
List<Block> shearableBlocks,
|
||||
List<ResourceLocation> blockProviderIds,
|
||||
List<ResourceLocation> entityProviderIds) implements LeavesCustomPayload<ServerPingPayload> {
|
||||
|
||||
private static final ResourceLocation PACKET_SERVER_HANDSHAKE = JadeProtocol.id("server_ping_v1");
|
||||
private static final StreamCodec<RegistryFriendlyByteBuf, ServerPingPayload> CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.map(Maps::newHashMapWithExpectedSize, ResourceLocation.STREAM_CODEC, PRIMITIVE_STREAM_CODEC),
|
||||
ServerPingPayload::serverConfig,
|
||||
ByteBufCodecs.registry(Registries.BLOCK).apply(ByteBufCodecs.list()),
|
||||
ServerPingPayload::shearableBlocks,
|
||||
ByteBufCodecs.<ByteBuf, ResourceLocation>list().apply(ResourceLocation.STREAM_CODEC),
|
||||
ServerPingPayload::blockProviderIds,
|
||||
ByteBufCodecs.<ByteBuf, ResourceLocation>list().apply(ResourceLocation.STREAM_CODEC),
|
||||
ServerPingPayload::entityProviderIds,
|
||||
ServerPingPayload::new);
|
||||
ByteBufCodecs.map(Maps::newHashMapWithExpectedSize, ResourceLocation.STREAM_CODEC, PRIMITIVE_STREAM_CODEC),
|
||||
ServerPingPayload::serverConfig,
|
||||
ByteBufCodecs.registry(Registries.BLOCK).apply(ByteBufCodecs.list()),
|
||||
ServerPingPayload::shearableBlocks,
|
||||
ByteBufCodecs.<ByteBuf, ResourceLocation>list().apply(ResourceLocation.STREAM_CODEC),
|
||||
ServerPingPayload::blockProviderIds,
|
||||
ByteBufCodecs.<ByteBuf, ResourceLocation>list().apply(ResourceLocation.STREAM_CODEC),
|
||||
ServerPingPayload::entityProviderIds,
|
||||
ServerPingPayload::new);
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
@@ -46,4 +47,3 @@ public record ServerPingPayload(
|
||||
return PACKET_SERVER_HANDSHAKE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ public enum ItemStorageExtensionProvider implements IServerExtensionProvider<Ite
|
||||
public static @Nullable Container findContainer(@NotNull Accessor<?> accessor) {
|
||||
Object target = accessor.getTarget();
|
||||
if (target == null && accessor instanceof BlockAccessor blockAccessor &&
|
||||
blockAccessor.getBlock() instanceof WorldlyContainerHolder holder) {
|
||||
blockAccessor.getBlock() instanceof WorldlyContainerHolder holder) {
|
||||
return holder.getContainer(blockAccessor.getBlockState(), accessor.getLevel(), blockAccessor.getPosition());
|
||||
} else if (target instanceof Container container) {
|
||||
return container;
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.Map;
|
||||
public abstract class ItemStorageProvider<T extends Accessor<?>> implements IServerDataProvider<T> {
|
||||
|
||||
private static final StreamCodec<RegistryFriendlyByteBuf, Map.Entry<ResourceLocation, List<ViewGroup<ItemStack>>>> STREAM_CODEC = ViewGroup.listCodec(
|
||||
ItemStack.OPTIONAL_STREAM_CODEC);
|
||||
ItemStack.OPTIONAL_STREAM_CODEC);
|
||||
|
||||
private static final ResourceLocation UNIVERSAL_ITEM_STORAGE = JadeProtocol.mc_id("item_storage");
|
||||
|
||||
@@ -85,4 +85,4 @@ public abstract class ItemStorageProvider<T extends Accessor<?>> implements ISer
|
||||
public int getDefaultPriority() {
|
||||
return 9999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,4 @@ public enum BeehiveProvider implements StreamServerDataProvider<BlockAccessor, B
|
||||
public ResourceLocation getUid() {
|
||||
return MC_BEEHIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,10 @@ public enum BrewingStandProvider implements StreamServerDataProvider<BlockAccess
|
||||
|
||||
public record Data(int fuel, int time) {
|
||||
public static final StreamCodec<ByteBuf, Data> STREAM_CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.VAR_INT,
|
||||
Data::fuel,
|
||||
ByteBufCodecs.VAR_INT,
|
||||
Data::time,
|
||||
Data::new);
|
||||
ByteBufCodecs.VAR_INT,
|
||||
Data::fuel,
|
||||
ByteBufCodecs.VAR_INT,
|
||||
Data::time,
|
||||
Data::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ public enum FurnaceProvider implements StreamServerDataProvider<BlockAccessor, F
|
||||
|
||||
CompoundTag furnaceTag = furnace.saveWithoutMetadata(accessor.getLevel().registryAccess());
|
||||
return new Data(
|
||||
furnaceTag.getInt("CookTime"),
|
||||
furnaceTag.getInt("CookTimeTotal"),
|
||||
List.of(furnace.getItem(0), furnace.getItem(1), furnace.getItem(2)));
|
||||
furnaceTag.getInt("CookTime"),
|
||||
furnaceTag.getInt("CookTimeTotal"),
|
||||
List.of(furnace.getItem(0), furnace.getItem(1), furnace.getItem(2)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,12 +49,12 @@ public enum FurnaceProvider implements StreamServerDataProvider<BlockAccessor, F
|
||||
|
||||
public record Data(int progress, int total, List<ItemStack> inventory) {
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, Data> STREAM_CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.VAR_INT,
|
||||
Data::progress,
|
||||
ByteBufCodecs.VAR_INT,
|
||||
Data::total,
|
||||
ItemStack.OPTIONAL_LIST_STREAM_CODEC,
|
||||
Data::inventory,
|
||||
Data::new);
|
||||
ByteBufCodecs.VAR_INT,
|
||||
Data::progress,
|
||||
ByteBufCodecs.VAR_INT,
|
||||
Data::total,
|
||||
ItemStack.OPTIONAL_LIST_STREAM_CODEC,
|
||||
Data::inventory,
|
||||
Data::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,4 +29,4 @@ public enum HopperLockProvider implements StreamServerDataProvider<BlockAccessor
|
||||
public ResourceLocation getUid() {
|
||||
return MC_HOPPER_LOCK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,4 +60,4 @@ public abstract class ObjectNameProvider implements StreamServerDataProvider<Blo
|
||||
public int getDefaultPriority() {
|
||||
return -10100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,18 +17,17 @@ import java.util.List;
|
||||
public enum StatusEffectsProvider implements StreamServerDataProvider<EntityAccessor, List<MobEffectInstance>> {
|
||||
INSTANCE;
|
||||
|
||||
|
||||
private static final StreamCodec<RegistryFriendlyByteBuf, List<MobEffectInstance>> STREAM_CODEC = ByteBufCodecs.<RegistryFriendlyByteBuf, MobEffectInstance>list()
|
||||
.apply(MobEffectInstance.STREAM_CODEC);
|
||||
.apply(MobEffectInstance.STREAM_CODEC);
|
||||
private static final ResourceLocation MC_POTION_EFFECTS = JadeProtocol.mc_id("potion_effects");
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<MobEffectInstance> streamData(@NotNull EntityAccessor accessor) {
|
||||
List<MobEffectInstance> effects = ((LivingEntity) accessor.getEntity()).getActiveEffects()
|
||||
.stream()
|
||||
.filter(MobEffectInstance::isVisible)
|
||||
.toList();
|
||||
.stream()
|
||||
.filter(MobEffectInstance::isVisible)
|
||||
.toList();
|
||||
return effects.isEmpty() ? null : effects;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import java.util.List;
|
||||
|
||||
public interface ToolHandler extends IJadeProvider {
|
||||
|
||||
ItemStack test(BlockState state, Level world, BlockPos pos);
|
||||
ItemStack test(BlockState state, Level world, BlockPos pos);
|
||||
|
||||
List<ItemStack> getTools();
|
||||
List<ItemStack> getTools();
|
||||
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ public class CommonUtil {
|
||||
|
||||
|
||||
public static <T> Map.Entry<ResourceLocation, List<ViewGroup<T>>> getServerExtensionData(
|
||||
Accessor<?> accessor,
|
||||
WrappedHierarchyLookup<IServerExtensionProvider<T>> lookup) {
|
||||
Accessor<?> accessor,
|
||||
WrappedHierarchyLookup<IServerExtensionProvider<T>> lookup) {
|
||||
for (var provider : lookup.wrappedGet(accessor)) {
|
||||
List<ViewGroup<T>> groups;
|
||||
try {
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class HierarchyLookup<T extends IJadeProvider> implements IHierarchyLookup<T> {
|
||||
|
||||
private final Class<?> baseClass;
|
||||
private final Cache<Class<?>, List<T>> resultCache = CacheBuilder.newBuilder().build();
|
||||
private final boolean singleton;
|
||||
@@ -117,9 +118,9 @@ public class HierarchyLookup<T extends IJadeProvider> implements IHierarchyLooku
|
||||
for (T provider : list) {
|
||||
if (set.contains(provider.getUid())) {
|
||||
throw new IllegalStateException("Duplicate UID: %s for %s".formatted(provider.getUid(), list.stream()
|
||||
.filter(p -> p.getUid().equals(provider.getUid()))
|
||||
.map(p -> p.getClass().getName())
|
||||
.toList()
|
||||
.filter(p -> p.getUid().equals(provider.getUid()))
|
||||
.map(p -> p.getClass().getName())
|
||||
.toList()
|
||||
));
|
||||
}
|
||||
set.add(provider.getUid());
|
||||
@@ -127,13 +128,13 @@ public class HierarchyLookup<T extends IJadeProvider> implements IHierarchyLooku
|
||||
});
|
||||
|
||||
objects = ImmutableListMultimap.<Class<?>, T>builder()
|
||||
.orderValuesBy(Comparator.comparingInt(priorityStore::byValue))
|
||||
.putAll(objects)
|
||||
.build();
|
||||
.orderValuesBy(Comparator.comparingInt(priorityStore::byValue))
|
||||
.putAll(objects)
|
||||
.build();
|
||||
|
||||
if (idMapped) {
|
||||
idMapper = createIdMapper();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface IHierarchyLookup<T extends IJadeProvider> {
|
||||
|
||||
default IHierarchyLookup<? extends T> cast() {
|
||||
return this;
|
||||
}
|
||||
@@ -24,8 +25,8 @@ public interface IHierarchyLookup<T extends IJadeProvider> {
|
||||
|
||||
default List<ResourceLocation> mappedIds() {
|
||||
return Streams.stream(Objects.requireNonNull(idMapper()))
|
||||
.map(IJadeProvider::getUid)
|
||||
.toList();
|
||||
.map(IJadeProvider::getUid)
|
||||
.toList();
|
||||
}
|
||||
|
||||
void register(Class<?> clazz, T provider);
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ItemCollector<T> {
|
||||
|
||||
public static final int MAX_SIZE = 54;
|
||||
public static final ItemCollector<?> EMPTY = new ItemCollector<>(null);
|
||||
private static final Predicate<ItemStack> NON_EMPTY = stack -> {
|
||||
@@ -75,7 +76,7 @@ public class ItemCollector<T> {
|
||||
updateCollectingProgress(mergedResult.getFirst());
|
||||
return mergedResult;
|
||||
}
|
||||
List<ItemStack> partialResult = items.object2IntEntrySet().stream().limit(MAX_SIZE ).map(entry -> {
|
||||
List<ItemStack> partialResult = items.object2IntEntrySet().stream().limit(MAX_SIZE).map(entry -> {
|
||||
ItemDefinition def = entry.getKey();
|
||||
return def.toStack(entry.getIntValue());
|
||||
}).toList();
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class ItemIterator<T> {
|
||||
|
||||
public static final AtomicLong version = new AtomicLong();
|
||||
protected final Function<Object, @Nullable T> containerFinder;
|
||||
protected final int fromIndex;
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.network.codec.StreamCodec;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JadeCodec {
|
||||
|
||||
public static final StreamCodec<ByteBuf, Object> PRIMITIVE_STREAM_CODEC = new StreamCodec<>() {
|
||||
@Override
|
||||
public @NotNull Object decode(@NotNull ByteBuf buf) {
|
||||
@@ -52,7 +53,8 @@ public class JadeCodec {
|
||||
ByteBufCodecs.STRING_UTF8.encode(buf, anEnum.name());
|
||||
}
|
||||
case null -> throw new NullPointerException();
|
||||
default -> throw new IllegalArgumentException("Unknown primitive type: %s (%s)".formatted(o, o.getClass()));
|
||||
default ->
|
||||
throw new IllegalArgumentException("Unknown primitive type: %s (%s)".formatted(o, o.getClass()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PairHierarchyLookup<T extends IJadeProvider> implements IHierarchyLookup<T> {
|
||||
|
||||
public final IHierarchyLookup<T> first;
|
||||
public final IHierarchyLookup<T> second;
|
||||
private final Cache<Pair<Class<?>, Class<?>>, List<T>> mergedCache = CacheBuilder.newBuilder().build();
|
||||
@@ -47,8 +48,8 @@ public class PairHierarchyLookup<T extends IJadeProvider> implements IHierarchyL
|
||||
return firstList;
|
||||
}
|
||||
return ImmutableList.sortedCopyOf(
|
||||
Comparator.comparingInt(JadeProtocol.priorities::byValue),
|
||||
Iterables.concat(firstList, secondList)
|
||||
Comparator.comparingInt(JadeProtocol.priorities::byValue),
|
||||
Iterables.concat(firstList, secondList)
|
||||
);
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
@@ -117,4 +118,4 @@ public class PairHierarchyLookup<T extends IJadeProvider> implements IHierarchyL
|
||||
idMapper = createIdMapper();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,24 +12,25 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ViewGroup<T> {
|
||||
|
||||
public static <B extends ByteBuf, T> StreamCodec<B, ViewGroup<T>> codec(StreamCodec<B, T> viewCodec) {
|
||||
return StreamCodec.composite(
|
||||
ByteBufCodecs.<B, T>list().apply(viewCodec),
|
||||
$ -> $.views,
|
||||
ByteBufCodecs.optional(ByteBufCodecs.STRING_UTF8),
|
||||
$ -> Optional.ofNullable($.id),
|
||||
ByteBufCodecs.optional(ByteBufCodecs.COMPOUND_TAG),
|
||||
$ -> Optional.ofNullable($.extraData),
|
||||
ViewGroup::new);
|
||||
ByteBufCodecs.<B, T>list().apply(viewCodec),
|
||||
$ -> $.views,
|
||||
ByteBufCodecs.optional(ByteBufCodecs.STRING_UTF8),
|
||||
$ -> Optional.ofNullable($.id),
|
||||
ByteBufCodecs.optional(ByteBufCodecs.COMPOUND_TAG),
|
||||
$ -> Optional.ofNullable($.extraData),
|
||||
ViewGroup::new);
|
||||
}
|
||||
|
||||
public static <B extends ByteBuf, T> StreamCodec<B, Map.Entry<ResourceLocation, List<ViewGroup<T>>>> listCodec(StreamCodec<B, T> viewCodec) {
|
||||
return StreamCodec.composite(
|
||||
ResourceLocation.STREAM_CODEC,
|
||||
Map.Entry::getKey,
|
||||
ByteBufCodecs.<B, ViewGroup<T>>list().apply(codec(viewCodec)),
|
||||
Map.Entry::getValue,
|
||||
Map::entry);
|
||||
ResourceLocation.STREAM_CODEC,
|
||||
Map.Entry::getKey,
|
||||
ByteBufCodecs.<B, ViewGroup<T>>list().apply(codec(viewCodec)),
|
||||
Map.Entry::getValue,
|
||||
Map::entry);
|
||||
}
|
||||
|
||||
public List<T> views;
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class WrappedHierarchyLookup<T extends IJadeProvider> extends HierarchyLookup<T> {
|
||||
|
||||
public final List<Pair<IHierarchyLookup<T>, Function<Accessor<?>, @Nullable Object>>> overrides = Lists.newArrayList();
|
||||
private boolean empty = true;
|
||||
|
||||
@@ -28,12 +29,12 @@ public class WrappedHierarchyLookup<T extends IJadeProvider> extends HierarchyLo
|
||||
public static <T extends IJadeProvider> WrappedHierarchyLookup<T> forAccessor() {
|
||||
WrappedHierarchyLookup<T> lookup = new WrappedHierarchyLookup<>();
|
||||
lookup.overrides.add(Pair.of(
|
||||
new HierarchyLookup<>(Block.class), accessor -> {
|
||||
if (accessor instanceof BlockAccessor blockAccessor) {
|
||||
return blockAccessor.getBlock();
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
new HierarchyLookup<>(Block.class), accessor -> {
|
||||
if (accessor instanceof BlockAccessor blockAccessor) {
|
||||
return blockAccessor.getBlock();
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
return lookup;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.leavesmc.leaves.protocol.core.LeavesProtocol;
|
||||
import org.leavesmc.leaves.protocol.core.LeavesProtocolManager;
|
||||
import org.leavesmc.leaves.protocol.core.ProtocolHandler;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.exchange.DownloadExchange;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.exchange.Exchange;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class FileStorage {
|
||||
}
|
||||
|
||||
private boolean isDownloading(final ServerPlacement placement) {
|
||||
return SyncmaticaProtocol.getCommunicationManager().getDownloadState(placement);
|
||||
return CommunicationManager.getDownloadState(placement);
|
||||
}
|
||||
|
||||
public File getLocalLitematic(final ServerPlacement placement) {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class PlayerIdentifierProvider {
|
||||
}
|
||||
|
||||
public PlayerIdentifier createOrGet(final ExchangeTarget exchangeTarget) {
|
||||
return createOrGet(SyncmaticaProtocol.getCommunicationManager().getGameProfile(exchangeTarget));
|
||||
return createOrGet(CommunicationManager.getGameProfile(exchangeTarget));
|
||||
}
|
||||
|
||||
public PlayerIdentifier createOrGet(final @NotNull GameProfile gameProfile) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.leavesmc.leaves.protocol.syncmatica.exchange;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.CommunicationManager;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.SyncmaticaProtocol;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -41,10 +39,6 @@ public abstract class AbstractExchange implements Exchange {
|
||||
}
|
||||
}
|
||||
|
||||
public CommunicationManager getManager() {
|
||||
return SyncmaticaProtocol.getCommunicationManager();
|
||||
}
|
||||
|
||||
protected void sendCancelPacket() {
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.CommunicationManager;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.MessageType;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.PacketType;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.ServerPlacement;
|
||||
@@ -101,7 +102,7 @@ public class DownloadExchange extends AbstractExchange {
|
||||
|
||||
@Override
|
||||
protected void onClose() {
|
||||
getManager().setDownloadState(toDownload, false);
|
||||
CommunicationManager.setDownloadState(toDownload, false);
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (final IOException e) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public interface Exchange {
|
||||
|
||||
ExchangeTarget getPartner();
|
||||
|
||||
boolean checkPacket(ResourceLocation id, FriendlyByteBuf packetBuf);
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.CommunicationManager;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.PacketType;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.PlayerIdentifier;
|
||||
import org.leavesmc.leaves.protocol.syncmatica.ServerPlacement;
|
||||
@@ -31,7 +32,7 @@ public class ModifyExchangeServer extends AbstractExchange {
|
||||
public void handle(final @NotNull ResourceLocation id, final @NotNull FriendlyByteBuf packetBuf) {
|
||||
packetBuf.readUUID();
|
||||
if (id.equals(PacketType.MODIFY_FINISH.identifier)) {
|
||||
SyncmaticaProtocol.getCommunicationManager().receivePositionData(placement, packetBuf, getPartner());
|
||||
CommunicationManager.receivePositionData(placement, packetBuf, getPartner());
|
||||
final PlayerIdentifier identifier = SyncmaticaProtocol.getPlayerIdentifierProvider().createOrGet(
|
||||
getPartner()
|
||||
);
|
||||
@@ -43,7 +44,7 @@ public class ModifyExchangeServer extends AbstractExchange {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (getPlacement() == null || SyncmaticaProtocol.getCommunicationManager().getModifier(placement) != null) {
|
||||
if (getPlacement() == null || CommunicationManager.getModifier(placement) != null) {
|
||||
close(true);
|
||||
} else {
|
||||
if (SyncmaticaProtocol.getPlayerIdentifierProvider().createOrGet(this.getPartner()).uuid.equals(placement.getOwner().uuid)) {
|
||||
@@ -58,7 +59,7 @@ public class ModifyExchangeServer extends AbstractExchange {
|
||||
final FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
|
||||
buf.writeUUID(placement.getId());
|
||||
getPartner().sendPacket(PacketType.MODIFY_REQUEST_ACCEPT.identifier, buf);
|
||||
SyncmaticaProtocol.getCommunicationManager().setModifier(placement, this);
|
||||
CommunicationManager.setModifier(placement, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,8 +75,8 @@ public class ModifyExchangeServer extends AbstractExchange {
|
||||
|
||||
@Override
|
||||
protected void onClose() {
|
||||
if (SyncmaticaProtocol.getCommunicationManager().getModifier(placement) == this) {
|
||||
SyncmaticaProtocol.getCommunicationManager().setModifier(placement, null);
|
||||
if (CommunicationManager.getModifier(placement) == this) {
|
||||
CommunicationManager.setModifier(placement, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,14 +112,14 @@ public class Recorder extends Connection {
|
||||
this.savePacket(new ClientboundSelectKnownPacks(knownPackslist), ConnectionProtocol.CONFIGURATION);
|
||||
|
||||
server.getServerResourcePack().ifPresent((info) -> this.savePacket(new ClientboundResourcePackPushPacket(
|
||||
info.id(), info.url(), info.hash(), info.isRequired(), Optional.ofNullable(info.prompt())
|
||||
info.id(), info.url(), info.hash(), info.isRequired(), Optional.ofNullable(info.prompt())
|
||||
)));
|
||||
|
||||
LayeredRegistryAccess<RegistryLayer> layeredregistryaccess = server.registries();
|
||||
DynamicOps<Tag> dynamicOps = layeredregistryaccess.compositeAccess().createSerializationContext(NbtOps.INSTANCE);
|
||||
RegistrySynchronization.packRegistries(dynamicOps, layeredregistryaccess.getAccessFrom(RegistryLayer.WORLDGEN), Set.copyOf(knownPackslist),
|
||||
(key, entries) ->
|
||||
this.savePacket(new ClientboundRegistryDataPacket(key, entries), ConnectionProtocol.CONFIGURATION)
|
||||
(key, entries) ->
|
||||
this.savePacket(new ClientboundRegistryDataPacket(key, entries), ConnectionProtocol.CONFIGURATION)
|
||||
);
|
||||
this.savePacket(new ClientboundUpdateTagsPacket(TagNetworkSerialization.serializeTagsToNetwork(layeredregistryaccess)), ConnectionProtocol.CONFIGURATION);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class RecorderOption {
|
||||
|
||||
private final List<Packet<?>> packets;
|
||||
|
||||
private RecordWeather(Packet<?>... packets) {
|
||||
RecordWeather(Packet<?>... packets) {
|
||||
this.packets = List.of(packets);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,10 +75,10 @@ public class ReplayFile {
|
||||
this.packetStream = new DataOutputStream(new DigestOutputStream(new BufferedOutputStream(new FileOutputStream(packetFile)), crc32));
|
||||
|
||||
this.protocols = Map.of(
|
||||
ConnectionProtocol.STATUS, StatusProtocols.CLIENTBOUND,
|
||||
ConnectionProtocol.LOGIN, LoginProtocols.CLIENTBOUND,
|
||||
ConnectionProtocol.CONFIGURATION, ConfigurationProtocols.CLIENTBOUND,
|
||||
ConnectionProtocol.PLAY, GameProtocols.CLIENTBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(MinecraftServer.getServer().registryAccess()))
|
||||
ConnectionProtocol.STATUS, StatusProtocols.CLIENTBOUND,
|
||||
ConnectionProtocol.LOGIN, LoginProtocols.CLIENTBOUND,
|
||||
ConnectionProtocol.CONFIGURATION, ConfigurationProtocols.CLIENTBOUND,
|
||||
ConnectionProtocol.PLAY, GameProtocols.CLIENTBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(MinecraftServer.getServer().registryAccess()))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.lang.reflect.Type;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDSerializer implements JsonSerializer<UUID> {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(@NotNull UUID src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.toString());
|
||||
|
||||
@@ -12,20 +12,20 @@ import java.util.Collections;
|
||||
public class AFKCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(Commands.literal("afk")
|
||||
.requires((listener) -> listener.hasPermission(2, "bukkit.command.afk"))
|
||||
.executes((context) -> execute(context.getSource(), Collections.singleton(context.getSource().getPlayerOrException())))
|
||||
.then(Commands.argument("targets", EntityArgument.players())
|
||||
.requires(listener -> listener.hasPermission(2, "bukkit.command.afk.other"))
|
||||
.executes((context) -> execute(context.getSource(), EntityArgument.getPlayers(context, "targets")))
|
||||
)
|
||||
.requires((listener) -> listener.hasPermission(2, "bukkit.command.afk"))
|
||||
.executes((context) -> execute(context.getSource(), Collections.singleton(context.getSource().getPlayerOrException())))
|
||||
.then(Commands.argument("targets", EntityArgument.players())
|
||||
.requires(listener -> listener.hasPermission(2, "bukkit.command.afk.other"))
|
||||
.executes((context) -> execute(context.getSource(), EntityArgument.getPlayers(context, "targets")))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static int execute(CommandSourceStack sender, Collection<ServerPlayer> targets) {
|
||||
for (ServerPlayer player : targets) {
|
||||
boolean afk = player.isCommandAfk
|
||||
? !player.commandAfkStatus
|
||||
: !player.isAfk();
|
||||
? !player.commandAfkStatus
|
||||
: !player.isAfk();
|
||||
|
||||
if (afk) player.setAfk(true);
|
||||
|
||||
|
||||
@@ -23,10 +23,6 @@ public enum EnumRegionFileExtension {
|
||||
@Contract(pure = true)
|
||||
public static EnumRegionFileExtension fromName(@NotNull String name) {
|
||||
switch (name.toUpperCase(Locale.ROOT)) {
|
||||
default -> {
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
case "MCA" -> {
|
||||
return MCA;
|
||||
}
|
||||
@@ -34,6 +30,10 @@ public enum EnumRegionFileExtension {
|
||||
case "LINEAR" -> {
|
||||
return LINEAR;
|
||||
}
|
||||
default -> {
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,19 +11,30 @@ import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
|
||||
public interface IRegionFile extends AutoCloseable, ChunkSystemRegionFile {
|
||||
|
||||
Path getPath();
|
||||
|
||||
void flush() throws IOException;
|
||||
|
||||
void clear(ChunkPos pos) throws IOException;
|
||||
|
||||
void close() throws IOException;
|
||||
|
||||
void setOversized(int x, int z, boolean b) throws IOException;
|
||||
|
||||
void write(ChunkPos pos, ByteBuffer buffer) throws IOException;
|
||||
|
||||
boolean hasChunk(ChunkPos pos);
|
||||
|
||||
boolean doesChunkExist(ChunkPos pos) throws Exception;
|
||||
|
||||
boolean isOversized(int x, int z);
|
||||
|
||||
boolean recalculateHeader() throws IOException;
|
||||
|
||||
DataOutputStream getChunkDataOutputStream(ChunkPos pos) throws IOException;
|
||||
|
||||
DataInputStream getChunkDataInputStream(ChunkPos pos) throws IOException;
|
||||
|
||||
CompoundTag getOversizedData(int x, int z) throws IOException;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class IRegionFileFactory {
|
||||
|
||||
@Contract("_, _, _, _ -> new")
|
||||
public static @NotNull IRegionFile getAbstractRegionFile(RegionStorageInfo storageKey, Path directory, Path path, boolean dsync) throws IOException {
|
||||
return getAbstractRegionFile(storageKey, directory, path, RegionFileVersion.getCompressionFormat(), dsync);
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.dreeam.leaf.config.modules.misc.RegionFormatConfig;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class LinearRegionFile implements IRegionFile {
|
||||
|
||||
private static final long SUPERBLOCK = -4323716122432332390L;
|
||||
private static final byte VERSION = 2;
|
||||
private static final int HEADER_SIZE = 32;
|
||||
@@ -226,7 +227,7 @@ public class LinearRegionFile implements IRegionFile {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MoonriseRegionFileIO.RegionDataController.WriteData moonrise$startWrite(CompoundTag data, ChunkPos pos) throws IOException {
|
||||
public MoonriseRegionFileIO.RegionDataController.WriteData moonrise$startWrite(CompoundTag data, ChunkPos pos) {
|
||||
final DataOutputStream out = this.getChunkDataOutputStream(pos);
|
||||
|
||||
return new ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.WriteData(
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.security.SecureRandom;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Globals {
|
||||
|
||||
public static final int WORLD_SEED_LONGS = 16;
|
||||
public static final int WORLD_SEED_BITS = WORLD_SEED_LONGS * 64;
|
||||
|
||||
|
||||
@@ -1,28 +1,29 @@
|
||||
package su.plo.matter;
|
||||
|
||||
public class Hashing {
|
||||
|
||||
// https://en.wikipedia.org/wiki/BLAKE_(hash_function)
|
||||
// https://github.com/bcgit/bc-java/blob/master/core/src/main/java/org/bouncycastle/crypto/digests/Blake2bDigest.java
|
||||
|
||||
private final static long[] blake2b_IV = {
|
||||
0x6a09e667f3bcc908L, 0xbb67ae8584caa73bL, 0x3c6ef372fe94f82bL,
|
||||
0xa54ff53a5f1d36f1L, 0x510e527fade682d1L, 0x9b05688c2b3e6c1fL,
|
||||
0x1f83d9abfb41bd6bL, 0x5be0cd19137e2179L
|
||||
0x6a09e667f3bcc908L, 0xbb67ae8584caa73bL, 0x3c6ef372fe94f82bL,
|
||||
0xa54ff53a5f1d36f1L, 0x510e527fade682d1L, 0x9b05688c2b3e6c1fL,
|
||||
0x1f83d9abfb41bd6bL, 0x5be0cd19137e2179L
|
||||
};
|
||||
|
||||
private final static byte[][] blake2b_sigma = {
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
|
||||
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
|
||||
{7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8},
|
||||
{9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13},
|
||||
{2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9},
|
||||
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11},
|
||||
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10},
|
||||
{6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5},
|
||||
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
|
||||
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
|
||||
{7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8},
|
||||
{9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13},
|
||||
{2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9},
|
||||
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11},
|
||||
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10},
|
||||
{6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5},
|
||||
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0},
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
|
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}
|
||||
};
|
||||
|
||||
public static long[] hashWorldSeed(long[] worldSeed) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class WorldgenCryptoRandom extends WorldgenRandom {
|
||||
|
||||
// hash the world seed to guard against badly chosen world seeds
|
||||
private static final long[] HASHED_ZERO_SEED = Hashing.hashWorldSeed(new long[Globals.WORLD_SEED_LONGS]);
|
||||
private static final ThreadLocal<long[]> LAST_SEEN_WORLD_SEED = ThreadLocal.withInitial(() -> new long[Globals.WORLD_SEED_LONGS]);
|
||||
@@ -33,7 +34,7 @@ public class WorldgenCryptoRandom extends WorldgenRandom {
|
||||
public void setSecureSeed(int x, int z, Globals.Salt typeSalt, long salt) {
|
||||
System.arraycopy(Globals.worldSeed, 0, this.worldSeed, 0, Globals.WORLD_SEED_LONGS);
|
||||
message[0] = ((long) x << 32) | ((long) z & 0xffffffffL);
|
||||
message[1] = ((long) Globals.dimension.get() << 32) | ((long) salt & 0xffffffffL);
|
||||
message[1] = ((long) Globals.dimension.get() << 32) | (salt & 0xffffffffL);
|
||||
message[2] = typeSalt.ordinal();
|
||||
message[3] = counter = 0;
|
||||
randomBitIndex = MAX_RANDOM_BIT_INDEX;
|
||||
|
||||
Reference in New Issue
Block a user