From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: AlphaKR93 Date: Wed, 10 Jan 2024 12:43:26 +0900 Subject: [PATCH] Reduce allocations diff --git a/src/main/java/ca/spottedleaf/starlight/common/light/StarLightEngine.java b/src/main/java/ca/spottedleaf/starlight/common/light/StarLightEngine.java index ad1eeebe6de219143492b94da309cb54ae9e0a5b..f83bdcf5d2d6f676b2dc83bc1fc0a7453fc2b36a 100644 --- a/src/main/java/ca/spottedleaf/starlight/common/light/StarLightEngine.java +++ b/src/main/java/ca/spottedleaf/starlight/common/light/StarLightEngine.java @@ -38,6 +38,7 @@ public abstract class StarLightEngine { AxisDirection.POSITIVE_X, AxisDirection.NEGATIVE_X, AxisDirection.POSITIVE_Z, AxisDirection.NEGATIVE_Z }; + private static final AxisDirection[] EMPTY_DIRECTIONS = new AxisDirection[0]; // Plazma - Reduce allocations protected static enum AxisDirection { @@ -1094,7 +1095,7 @@ public abstract class StarLightEngine { for (int bitset = i, len = Integer.bitCount(i), index = 0; index < len; ++index, bitset ^= IntegerUtil.getTrailingBit(bitset)) { directions.add(AXIS_DIRECTIONS[IntegerUtil.trailingZeros(bitset)]); } - OLD_CHECK_DIRECTIONS[i] = directions.toArray(new AxisDirection[0]); + OLD_CHECK_DIRECTIONS[i] = directions.toArray(EMPTY_DIRECTIONS); // Plazma - Reduce allocations } } diff --git a/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java b/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java index e7fe98ea30ae6d0baea3ec1f9f98a89502a49a12..7663ccd247b9942ccfb7a320b047ee621fc1bebe 100644 --- a/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java +++ b/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketBlockControllerAntiXray.java @@ -97,8 +97,8 @@ public final class ChunkPacketBlockControllerAntiXray extends ChunkPacketBlockCo Set presetBlockStateSet = new LinkedHashSet<>(); // Therefore addAll(Collection) is used, which guarantees this order in the doc presetBlockStateSet.addAll(presetBlockStateList); - presetBlockStates = presetBlockStateSet.isEmpty() ? new BlockState[]{Blocks.DIAMOND_ORE.defaultBlockState()} : presetBlockStateSet.toArray(new BlockState[0]); - presetBlockStatesFull = presetBlockStateSet.isEmpty() ? new BlockState[]{Blocks.DIAMOND_ORE.defaultBlockState()} : presetBlockStateList.toArray(new BlockState[0]); + presetBlockStates = presetBlockStateSet.isEmpty() ? new BlockState[]{Blocks.DIAMOND_ORE.defaultBlockState()} : presetBlockStateSet.toArray(org.plazmamc.plazma.constants.Empty.BLOCK_STATE); // Plazma - Reduce allocations + presetBlockStatesFull = presetBlockStateSet.isEmpty() ? new BlockState[]{Blocks.DIAMOND_ORE.defaultBlockState()} : presetBlockStateList.toArray(org.plazmamc.plazma.constants.Empty.BLOCK_STATE); // Plazma - Reduce allocations presetBlockStatesStone = null; presetBlockStatesDeepslate = null; presetBlockStatesNetherrack = null; diff --git a/src/main/java/com/destroystokyo/paper/util/maplist/ChunkList.java b/src/main/java/com/destroystokyo/paper/util/maplist/ChunkList.java index 554f4d4e63c1431721989e6f502a32ccc53a8807..44b47cd09605d15a1a40e1fa93dfb4b1c3f383bf 100644 --- a/src/main/java/com/destroystokyo/paper/util/maplist/ChunkList.java +++ b/src/main/java/com/destroystokyo/paper/util/maplist/ChunkList.java @@ -17,7 +17,7 @@ public final class ChunkList implements Iterable { this.chunkToIndex.defaultReturnValue(Integer.MIN_VALUE); } - protected static final LevelChunk[] EMPTY_LIST = new LevelChunk[0]; + protected static final LevelChunk[] EMPTY_LIST = new LevelChunk[0]; // Plazma - Reduce allocations (mark on diff) protected LevelChunk[] chunks = EMPTY_LIST; protected int count; diff --git a/src/main/java/com/destroystokyo/paper/util/maplist/EntityList.java b/src/main/java/com/destroystokyo/paper/util/maplist/EntityList.java index 0133ea6feb1ab88f021f66855669f58367e7420b..a04049bc7738225633ac0b01c470cfbfde86c032 100644 --- a/src/main/java/com/destroystokyo/paper/util/maplist/EntityList.java +++ b/src/main/java/com/destroystokyo/paper/util/maplist/EntityList.java @@ -17,9 +17,9 @@ public final class EntityList implements Iterable { this.entityToIndex.defaultReturnValue(Integer.MIN_VALUE); } - protected static final Entity[] EMPTY_LIST = new Entity[0]; + //protected static final Entity[] EMPTY_LIST = new Entity[0]; // Plazma - Reduce allocations - protected Entity[] entities = EMPTY_LIST; + protected Entity[] entities = org.plazmamc.plazma.constants.Empty.ENTITY; // Plazma - Reduce allocations protected int count; public int size() { diff --git a/src/main/java/com/destroystokyo/paper/util/maplist/IBlockDataList.java b/src/main/java/com/destroystokyo/paper/util/maplist/IBlockDataList.java index 277cfd9d1e8fff5d9b5e534b75c3c5162d58b0b7..30d8d9c2dce5e4eb26cc52a03bc395c16c04c256 100644 --- a/src/main/java/com/destroystokyo/paper/util/maplist/IBlockDataList.java +++ b/src/main/java/com/destroystokyo/paper/util/maplist/IBlockDataList.java @@ -20,9 +20,9 @@ public final class IBlockDataList { this.map.defaultReturnValue(Long.MAX_VALUE); } - private static final long[] EMPTY_LIST = new long[0]; + //private static final long[] EMPTY_LIST = new long[0]; // Plazma - Reduce allocations - private long[] byIndex = EMPTY_LIST; + private long[] byIndex = org.plazmamc.plazma.constants.Empty.LONG; // Plazma - Reduce allocations private int size; public static int getLocationKey(final int x, final int y, final int z) { diff --git a/src/main/java/com/destroystokyo/paper/util/maplist/ReferenceList.java b/src/main/java/com/destroystokyo/paper/util/maplist/ReferenceList.java index 190c5f0b02a3d99054704ae1afbffb3498ddffe1..042ea49ec61ee327c0f67ddcf080774042e44c02 100644 --- a/src/main/java/com/destroystokyo/paper/util/maplist/ReferenceList.java +++ b/src/main/java/com/destroystokyo/paper/util/maplist/ReferenceList.java @@ -15,9 +15,9 @@ public final class ReferenceList implements Iterable { this.referenceToIndex.defaultReturnValue(Integer.MIN_VALUE); } - protected static final Object[] EMPTY_LIST = new Object[0]; + //protected static final Object[] EMPTY_LIST = new Object[0]; // Plazma - Reduce allocations - protected Object[] references = EMPTY_LIST; + protected Object[] references = org.plazmamc.plazma.constants.Empty.OBJECT; // Plazma - Reduce allocations protected int count; public int size() { diff --git a/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkTaskScheduler.java b/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkTaskScheduler.java index 049e20407033073b06fcdeb46c38485f4926d778..bbd0b944cef07b2c2a1b1cbecd24fda7a7adec72 100644 --- a/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkTaskScheduler.java +++ b/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkTaskScheduler.java @@ -42,6 +42,7 @@ import java.util.function.Consumer; public final class ChunkTaskScheduler { private static final Logger LOGGER = LogUtils.getClassLogger(); + private static final ChunkInfo[] EMPTY_INFO = new ChunkInfo[0]; // Plazma - Reduce allocations static int newChunkSystemIOThreads; static int newChunkSystemWorkerThreads; @@ -854,7 +855,7 @@ public final class ChunkTaskScheduler { public static ChunkInfo[] getChunkInfos() { synchronized (WAITING_CHUNKS) { - return WAITING_CHUNKS.toArray(new ChunkInfo[0]); + return WAITING_CHUNKS.toArray(EMPTY_INFO); // Plazma - Reduce allocations } } diff --git a/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java b/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java index ae60bd96b5284d54676d8e7e4dd5d170b526ec1e..359c4b080bd47234e569dce7055da03ddb7b1e90 100644 --- a/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java +++ b/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java @@ -14,7 +14,7 @@ public final class VersionCommand implements PaperSubcommand { public boolean execute(final CommandSender sender, final String subCommand, final String[] args) { final @Nullable Command ver = MinecraftServer.getServer().server.getCommandMap().getCommand("version"); if (ver != null) { - ver.execute(sender, "paper", new String[0]); + ver.execute(sender, "paper", org.plazmamc.plazma.constants.Empty.STRING); // Plazma - Reduce allocations } return true; } diff --git a/src/main/java/io/papermc/paper/plugin/manager/DummyBukkitPluginLoader.java b/src/main/java/io/papermc/paper/plugin/manager/DummyBukkitPluginLoader.java index aef19b44075a3b2e8696315baa89117dd8ebb513..60adf262a01933b3d38601f7664111ac7d72465f 100644 --- a/src/main/java/io/papermc/paper/plugin/manager/DummyBukkitPluginLoader.java +++ b/src/main/java/io/papermc/paper/plugin/manager/DummyBukkitPluginLoader.java @@ -30,7 +30,7 @@ import java.util.regex.Pattern; @ApiStatus.Internal public class DummyBukkitPluginLoader implements PluginLoader { - private static final Pattern[] PATTERNS = new Pattern[0]; + private static final Pattern[] PATTERNS = new Pattern[0]; // Plazma - Reduce allocations (mark on diff) @Override public @NotNull Plugin loadPlugin(@NotNull File file) throws InvalidPluginException, UnknownDependencyException { diff --git a/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java b/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java index 3e82ea07ca4194844c5528446e2c4a46ff4acee5..1f432767841756905521b3c3000f1e027b3fffe8 100644 --- a/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java +++ b/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java @@ -47,6 +47,8 @@ import java.util.logging.Level; class PaperPluginInstanceManager { private static final FileProviderSource FILE_PROVIDER_SOURCE = new FileProviderSource("File '%s'"::formatted); + private static final JavaPlugin[] EMPTY_JPLUGIN = new JavaPlugin[0]; // Plazma - Reduce allocations + private static final Plugin[] EMPTY_PLUGIN = new Plugin[0]; // Plazma - Reduce allocations private final List plugins = new ArrayList<>(); private final Map lookupNames = new HashMap<>(); @@ -68,7 +70,7 @@ class PaperPluginInstanceManager { } public @NotNull Plugin[] getPlugins() { - return this.plugins.toArray(new Plugin[0]); + return this.plugins.toArray(EMPTY_PLUGIN); // Plazma - Reduce allocations } public boolean isPluginEnabled(@NotNull String name) { @@ -133,7 +135,7 @@ class PaperPluginInstanceManager { this.server.getLogger().log(Level.SEVERE, "Unknown error occurred while loading plugins through PluginManager.", e); } - return runtimePluginEntrypointHandler.getPluginProviderStorage().getLoaded().toArray(new JavaPlugin[0]); + return runtimePluginEntrypointHandler.getPluginProviderStorage().getLoaded().toArray(EMPTY_JPLUGIN); // Plazma - Reduce allocations } // The behavior of this is that all errors are logged instead of being thrown @@ -150,7 +152,7 @@ class PaperPluginInstanceManager { this.server.getLogger().log(Level.SEVERE, "Unknown error occurred while loading plugins through PluginManager.", e); } - return runtimePluginEntrypointHandler.getPluginProviderStorage().getLoaded().toArray(new JavaPlugin[0]); + return runtimePluginEntrypointHandler.getPluginProviderStorage().getLoaded().toArray(EMPTY_JPLUGIN); // Plazma - Reduce allocations } // Plugins are disabled in order like this inorder to "rougly" prevent diff --git a/src/main/java/io/papermc/paper/util/CollisionUtil.java b/src/main/java/io/papermc/paper/util/CollisionUtil.java index ee8e9c0e3690e78f3cc621ddfca89ea4256d4803..2b27f73896ce11908ff7b488fa65d6251f791e99 100644 --- a/src/main/java/io/papermc/paper/util/CollisionUtil.java +++ b/src/main/java/io/papermc/paper/util/CollisionUtil.java @@ -1149,7 +1149,7 @@ public final class CollisionUtil { } private static final MergedVoxelCoordinateList EMPTY = new MergedVoxelCoordinateList( - new double[] { 0.0 }, 0.0, new int[0], new int[0], 0 + new double[] { 0.0 }, 0.0, org.plazmamc.plazma.constants.Empty.INT, org.plazmamc.plazma.constants.Empty.INT, 0 ); private static int[] getIndices(final int length) { diff --git a/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java b/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java index c78cbec447032de9fe69748591bef6be300160ed..8ca248e844e73685a8d44a966144657315a799aa 100644 --- a/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java +++ b/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java @@ -304,7 +304,7 @@ public final class ChunkEntitySlices { protected static final class BasicEntityList { - protected static final Entity[] EMPTY = new Entity[0]; + //protected static final Entity[] EMPTY = new Entity[0]; // Plazma - Reduce allocations protected static final int DEFAULT_CAPACITY = 4; protected E[] storage; @@ -315,7 +315,7 @@ public final class ChunkEntitySlices { } public BasicEntityList(final int cap) { - this.storage = (E[])(cap <= 0 ? EMPTY : new Entity[cap]); + this.storage = (E[])(cap <= 0 ? org.plazmamc.plazma.constants.Empty.ENTITY : new Entity[cap]); } public boolean isEmpty() { @@ -327,7 +327,7 @@ public final class ChunkEntitySlices { } private void resize() { - if (this.storage == EMPTY) { + if (this.storage == org.plazmamc.plazma.constants.Empty.ENTITY) { this.storage = (E[])new Entity[DEFAULT_CAPACITY]; } else { this.storage = Arrays.copyOf(this.storage, this.storage.length * 2); diff --git a/src/main/java/net/minecraft/CrashReport.java b/src/main/java/net/minecraft/CrashReport.java index 570b379596cc3088745d3f42b3d917f94c2d9c29..b96d89f5ff10e3866b9e4d3566cdb0cf56ab9c1c 100644 --- a/src/main/java/net/minecraft/CrashReport.java +++ b/src/main/java/net/minecraft/CrashReport.java @@ -30,7 +30,7 @@ public class CrashReport { @Nullable private File saveFile; private boolean trackingStackTrace = true; - private StackTraceElement[] uncategorizedStackTrace = new StackTraceElement[0]; + private StackTraceElement[] uncategorizedStackTrace = org.plazmamc.plazma.constants.Empty.TRACE; // Plazma - Reduce allocations private final SystemReport systemReport = new SystemReport(); public CrashReport(String message, Throwable cause) { diff --git a/src/main/java/net/minecraft/CrashReportCategory.java b/src/main/java/net/minecraft/CrashReportCategory.java index 2176171954609fd88f97f93408e14e018c1d6eaa..2a5576dc66a9b1f56e06ba47bef4fe882935c382 100644 --- a/src/main/java/net/minecraft/CrashReportCategory.java +++ b/src/main/java/net/minecraft/CrashReportCategory.java @@ -12,7 +12,7 @@ import net.minecraft.world.level.block.state.BlockState; public class CrashReportCategory { private final String title; private final List entries = Lists.newArrayList(); - private StackTraceElement[] stackTrace = new StackTraceElement[0]; + private StackTraceElement[] stackTrace = org.plazmamc.plazma.constants.Empty.TRACE; // Plazma - Reduce allocations public CrashReportCategory(String title) { this.title = title; diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java index 0bd367235f80c1f0d319a6aa5130d82ad82d895c..ed44bf95ce6e39961af77d045a1f69ffeee62d1b 100644 --- a/src/main/java/net/minecraft/Util.java +++ b/src/main/java/net/minecraft/Util.java @@ -458,7 +458,7 @@ public class Util { } else if (futures.size() == 1) { return futures.get(0).thenApply(List::of); } else { - CompletableFuture completableFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); + CompletableFuture completableFuture = CompletableFuture.allOf(futures.toArray(org.plazmamc.plazma.constants.Empty.FUTURE)); // Plazma - Reduce allocations return completableFuture.thenApply(void_ -> futures.stream().map(CompletableFuture::join).toList()); } } diff --git a/src/main/java/net/minecraft/nbt/ByteArrayTag.java b/src/main/java/net/minecraft/nbt/ByteArrayTag.java index 06648f9751fd8a322d0809ffebf6a544596ee1a4..b0ea87e2ed8f9bf04b33c2ff8a827d4f6f57a435 100644 --- a/src/main/java/net/minecraft/nbt/ByteArrayTag.java +++ b/src/main/java/net/minecraft/nbt/ByteArrayTag.java @@ -175,7 +175,7 @@ public class ByteArrayTag extends CollectionTag { } public void clear() { - this.data = new byte[0]; + this.data = org.plazmamc.plazma.constants.Empty.BYTE; // Plazma - Reduce allocations } @Override diff --git a/src/main/java/net/minecraft/nbt/CompoundTag.java b/src/main/java/net/minecraft/nbt/CompoundTag.java index 4e005b7b062e3231f564d284887ea1c2783a4e7d..059a1e49f0607a4ecd9d558d9423f2f5a71129c6 100644 --- a/src/main/java/net/minecraft/nbt/CompoundTag.java +++ b/src/main/java/net/minecraft/nbt/CompoundTag.java @@ -409,7 +409,7 @@ public class CompoundTag implements Tag { throw new ReportedException(this.createReport(key, ByteArrayTag.TYPE, var3)); } - return new byte[0]; + return org.plazmamc.plazma.constants.Empty.BYTE; // Plazma - Reduce allocations } public int[] getIntArray(String key) { @@ -421,7 +421,7 @@ public class CompoundTag implements Tag { throw new ReportedException(this.createReport(key, IntArrayTag.TYPE, var3)); } - return new int[0]; + return org.plazmamc.plazma.constants.Empty.INT; // Plazma - Reduce allocations } public long[] getLongArray(String key) { @@ -433,7 +433,7 @@ public class CompoundTag implements Tag { throw new ReportedException(this.createReport(key, LongArrayTag.TYPE, var3)); } - return new long[0]; + return org.plazmamc.plazma.constants.Empty.LONG; // Plazma - Reduce allocations } public CompoundTag getCompound(String key) { diff --git a/src/main/java/net/minecraft/nbt/IntArrayTag.java b/src/main/java/net/minecraft/nbt/IntArrayTag.java index ff13d67151c50ea11a45117e524c7524e2b1a202..5048ec707c147b9a5b2dd8736d518d938ba95df0 100644 --- a/src/main/java/net/minecraft/nbt/IntArrayTag.java +++ b/src/main/java/net/minecraft/nbt/IntArrayTag.java @@ -186,7 +186,7 @@ public class IntArrayTag extends CollectionTag { } public void clear() { - this.data = new int[0]; + this.data = org.plazmamc.plazma.constants.Empty.INT; // Plazma - Reduce allocations } @Override diff --git a/src/main/java/net/minecraft/nbt/ListTag.java b/src/main/java/net/minecraft/nbt/ListTag.java index 154bffd341e43be0a0fa710cfbed1a2094f249a3..83c36d4520dfebbf1c2d8d3cec7bd41356804464 100644 --- a/src/main/java/net/minecraft/nbt/ListTag.java +++ b/src/main/java/net/minecraft/nbt/ListTag.java @@ -258,7 +258,7 @@ public class ListTag extends CollectionTag { } } - return new int[0]; + return org.plazmamc.plazma.constants.Empty.INT; // Plazma - Reduce allocations } public long[] getLongArray(int index) { @@ -269,7 +269,7 @@ public class ListTag extends CollectionTag { } } - return new long[0]; + return org.plazmamc.plazma.constants.Empty.LONG; // Plazma - Reduce allocations } public double getDouble(int index) { diff --git a/src/main/java/net/minecraft/nbt/LongArrayTag.java b/src/main/java/net/minecraft/nbt/LongArrayTag.java index 2e5c34ebb94a1536cf09d71bdf052a49ecb9159d..144d3bbe80fc0f459a06017a19929e3e849aabd0 100644 --- a/src/main/java/net/minecraft/nbt/LongArrayTag.java +++ b/src/main/java/net/minecraft/nbt/LongArrayTag.java @@ -185,7 +185,7 @@ public class LongArrayTag extends CollectionTag { @Override public void clear() { - this.data = new long[0]; + this.data = org.plazmamc.plazma.constants.Empty.LONG; // Plazma - Reduce allocations } @Override diff --git a/src/main/java/net/minecraft/nbt/NbtIo.java b/src/main/java/net/minecraft/nbt/NbtIo.java index 9f659af04a5362ae3645d072caa090682760dc9f..d2969c1ce98a958bd25cb8b9c38f6a57a3311701 100644 --- a/src/main/java/net/minecraft/nbt/NbtIo.java +++ b/src/main/java/net/minecraft/nbt/NbtIo.java @@ -277,7 +277,7 @@ public class NbtIo { @Nullable public static CompoundTag read(Path path) throws IOException { - if (!Files.exists(path, new LinkOption[0])) { + if (!Files.exists(path/*, new LinkOption[0]*/)) { // Plazma - Reduce allocations return null; } else { InputStream inputstream = Files.newInputStream(path); diff --git a/src/main/java/net/minecraft/network/CipherBase.java b/src/main/java/net/minecraft/network/CipherBase.java index a2920b8a9eff77d9c5d1d7f70ad3abdacba8f0fa..70d776d5cfdb0612f65d92333d6f872afedc2207 100644 --- a/src/main/java/net/minecraft/network/CipherBase.java +++ b/src/main/java/net/minecraft/network/CipherBase.java @@ -7,8 +7,8 @@ import javax.crypto.ShortBufferException; public class CipherBase { private final Cipher cipher; - private byte[] heapIn = new byte[0]; - private byte[] heapOut = new byte[0]; + private byte[] heapIn = org.plazmamc.plazma.constants.Empty.BYTE; // Plazma - Reduce allocations + private byte[] heapOut = org.plazmamc.plazma.constants.Empty.BYTE; // Plazma - Reduce allocations protected CipherBase(Cipher cipher) { this.cipher = cipher; diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java index 9f274048be29ed54dd91983447beadf076cf7438..ba54c16f194127e3d6affeaa5a75616467e4e6a2 100644 --- a/src/main/java/net/minecraft/network/Connection.java +++ b/src/main/java/net/minecraft/network/Connection.java @@ -316,7 +316,7 @@ public class Connection extends SimpleChannelInboundHandler> { } private void validateListener(ProtocolInfo state, PacketListener listener) { - Validate.notNull(listener, "packetListener", new Object[0]); + Validate.notNull(listener, "packetListener"/*, new Object[0]*/); // Plazma - Reduce allocations PacketFlow enumprotocoldirection = listener.flow(); String s; diff --git a/src/main/java/net/minecraft/network/chat/contents/TranslatableContents.java b/src/main/java/net/minecraft/network/chat/contents/TranslatableContents.java index 4aa6232bf0f72fcde32d257100bd15b1c5192aaa..2bf2ea4242af7d94bbc1a6fa4b255576588608f0 100644 --- a/src/main/java/net/minecraft/network/chat/contents/TranslatableContents.java +++ b/src/main/java/net/minecraft/network/chat/contents/TranslatableContents.java @@ -29,7 +29,7 @@ import net.minecraft.util.ExtraCodecs; import net.minecraft.world.entity.Entity; public class TranslatableContents implements ComponentContents { - public static final Object[] NO_ARGS = new Object[0]; + // public static final Object[] NO_ARGS = new Object[0]; // Plazma - Reduce allocations private static final Codec PRIMITIVE_ARG_CODEC = ExtraCodecs.JAVA.validate(TranslatableContents::filterAllowedArguments); private static final Codec ARG_CODEC = Codec.either(PRIMITIVE_ARG_CODEC, ComponentSerialization.CODEC) .xmap( @@ -69,7 +69,7 @@ public class TranslatableContents implements ComponentContents { } private static Object[] adjustArgs(Optional> args) { - return args.map(list -> list.isEmpty() ? NO_ARGS : list.toArray()).orElse(NO_ARGS); + return args.filter(list -> !list.isEmpty()).map(List::toArray).orElse(org.plazmamc.plazma.constants.Empty.OBJECT); // Plazma - Reduce allocations } private static TranslatableContents create(String key, Optional fallback, Optional> args) { diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java index 1a37654aff9a9c86c9f7af10a1cf721371f0c5ec..0e61f8cb323b2941460cda5bb94d63a126877e5a 100644 --- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java +++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java @@ -66,7 +66,7 @@ public class ClientboundSectionBlocksUpdatePacket implements Packet blockChanges) { this.sectionPos = sectionPos; this.positions = blockChanges.keySet().toShortArray(); - this.states = blockChanges.values().toArray(new BlockState[0]); + this.states = blockChanges.values().toArray(org.plazmamc.plazma.constants.Empty.BLOCK_STATE); // Plazma - Reduce allocations } // Paper end - Multi Block Change API diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index e121cc57ec5bf6f5b1d81e2fd4f551063ac60d64..7b27af22a55d8455b25f80f783dfc3be97f68c25 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -1541,13 +1541,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop loadStatusIcon() { - Optional optional = Optional.of(this.getFile("server-icon.png").toPath()).filter((path) -> { - return Files.isRegularFile(path, new LinkOption[0]); - }).or(() -> { - return this.storageSource.getIconFile().filter((path) -> { - return Files.isRegularFile(path, new LinkOption[0]); - }); - }); + // Plazma start - Reduce allocations + Optional optional = Optional.of(this.getFile("server-icon.png").toPath()).filter(Files::isRegularFile) + .or(() -> this.storageSource.getIconFile().filter(Files::isRegularFile)); + // Plazma end return optional.flatMap((path) -> { try { diff --git a/src/main/java/net/minecraft/server/PlayerAdvancements.java b/src/main/java/net/minecraft/server/PlayerAdvancements.java index ef520d1dd00ae9473c1f34e2df4d8b064fe4d6ea..b3b0c18b48ad8cb1fff320b516f1026fd2dbb1ab 100644 --- a/src/main/java/net/minecraft/server/PlayerAdvancements.java +++ b/src/main/java/net/minecraft/server/PlayerAdvancements.java @@ -130,7 +130,7 @@ public class PlayerAdvancements { } private void load(ServerAdvancementManager advancementLoader) { - if (Files.isRegularFile(this.playerSavePath, new LinkOption[0])) { + if (Files.isRegularFile(this.playerSavePath/*, new LinkOption[0]*/)) { // Plazma - Reduce allocations try { JsonReader jsonreader = new JsonReader(Files.newBufferedReader(this.playerSavePath, StandardCharsets.UTF_8)); diff --git a/src/main/java/net/minecraft/server/RunningOnDifferentThreadException.java b/src/main/java/net/minecraft/server/RunningOnDifferentThreadException.java index 0f52e8a61ca7e57e9f52473dceb9cc3464c0c86d..f54bde32760541a653460682e5a3ddd0b2ceec51 100644 --- a/src/main/java/net/minecraft/server/RunningOnDifferentThreadException.java +++ b/src/main/java/net/minecraft/server/RunningOnDifferentThreadException.java @@ -4,12 +4,12 @@ public final class RunningOnDifferentThreadException extends RuntimeException { public static final RunningOnDifferentThreadException RUNNING_ON_DIFFERENT_THREAD = new RunningOnDifferentThreadException(); private RunningOnDifferentThreadException() { - this.setStackTrace(new StackTraceElement[0]); + this.setStackTrace(org.plazmamc.plazma.constants.Empty.TRACE); // Plazma - Reduce allocations } @Override public synchronized Throwable fillInStackTrace() { - this.setStackTrace(new StackTraceElement[0]); + this.setStackTrace(org.plazmamc.plazma.constants.Empty.TRACE); // Plazma - Reduce allocations return this; } } diff --git a/src/main/java/net/minecraft/server/ServerFunctionLibrary.java b/src/main/java/net/minecraft/server/ServerFunctionLibrary.java index bae0d208b31aa0a6977c30f2f8484ab3c316bc71..981c3023044f3cc6dc22ada20cd4bedcf7a28db3 100644 --- a/src/main/java/net/minecraft/server/ServerFunctionLibrary.java +++ b/src/main/java/net/minecraft/server/ServerFunctionLibrary.java @@ -92,7 +92,7 @@ public class ServerFunctionLibrary implements PreparableReloadListener { }, prepareExecutor)); } - CompletableFuture[] completableFutures = map.values().toArray(new CompletableFuture[0]); + CompletableFuture[] completableFutures = map.values().toArray(org.plazmamc.plazma.constants.Empty.FUTURE); // Plazma - Reduce allocations return CompletableFuture.allOf(completableFutures).handle((unused, ex) -> map); } ); diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java index 4e6fccec4f5ca14562bf5bae495ac36c14982d85..3181459952634fc74f1b5b07b99d4adb888efa08 100644 --- a/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java @@ -122,6 +122,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider public static final int MIN_VIEW_DISTANCE = 2; public static final int MAX_VIEW_DISTANCE = 32; public static final int FORCED_TICKET_LEVEL = ChunkLevel.byStatus(FullChunkStatus.ENTITY_TICKING); + private static final ServerPlayerConnection[] EMPTY = new ServerPlayerConnection[0]; // Plazma - Reduce allocations // Paper - rewrite chunk system public final ServerLevel level; private final ThreadedLevelLightEngine lightEngine; @@ -1361,7 +1362,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider // stuff could have been removed, so we need to check the trackedPlayers set // for players that were removed - for (ServerPlayerConnection conn : this.seenBy.toArray(new ServerPlayerConnection[0])) { // avoid CME + for (ServerPlayerConnection conn : this.seenBy.toArray(EMPTY)) { // avoid CME // Plazma - Reduce allocations if (newTrackerCandidates == null || !newTrackerCandidates.contains(conn.getPlayer())) { this.updatePlayer(conn.getPlayer()); } diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index f72af2feb74626abbdfbfd090c15357457810240..0aaa0e63f7c7ea8fe6cedd5b0c63fbed2fb3e168 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -1439,7 +1439,7 @@ public class ServerLevel extends Level implements WorldGenLevel { public static List getCurrentlyTickingEntities() { Entity ticking = currentlyTickingEntity.get(); - List ret = java.util.Arrays.asList(ticking == null ? new Entity[0] : new Entity[] { ticking }); + List ret = java.util.Arrays.asList(ticking == null ? org.plazmamc.plazma.constants.Empty.ENTITY : new Entity[] { ticking }); // Plazma - Reduce allocations return ret; } diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java index 3b4fadb37eafb2f7b0ce4d6b276d2fdaa8287521..f276fe09f12fd69b09339706faaf2bafd53bc749 100644 --- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java @@ -165,12 +165,12 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, @Override public void handleHello(ServerboundHelloPacket packet) { - Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]); + Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet"/*, new Object[0]*/); // Plazma - Reduce allocations // Paper start - Validate usernames if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() && io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.performUsernameValidation && !this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation) { - Validate.validState(StringUtil.isReasonablePlayerName(packet.name()), "Invalid characters in username", new Object[0]); + Validate.validState(StringUtil.isReasonablePlayerName(packet.name()), "Invalid characters in username"/*, new Object[0]*/); // Plazma - Reduce allocations } // Paper end - Validate usernames this.requestedUsername = packet.name(); @@ -268,7 +268,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, @Override public void handleKey(ServerboundKeyPacket packet) { - Validate.validState(this.state == ServerLoginPacketListenerImpl.State.KEY, "Unexpected key packet", new Object[0]); + Validate.validState(this.state == ServerLoginPacketListenerImpl.State.KEY, "Unexpected key packet"/*, new Object[0]*/); // Plazma - Reduce allocations final String s; @@ -448,7 +448,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, @Override public void handleLoginAcknowledgement(ServerboundLoginAcknowledgedPacket packet) { - Validate.validState(this.state == ServerLoginPacketListenerImpl.State.PROTOCOL_SWITCHING, "Unexpected login acknowledgement packet", new Object[0]); + Validate.validState(this.state == ServerLoginPacketListenerImpl.State.PROTOCOL_SWITCHING, "Unexpected login acknowledgement packet"/*, new Object[0]*/); // Plazma - Reduce allocations this.connection.setupOutboundProtocol(ConfigurationProtocols.CLIENTBOUND); CommonListenerCookie commonlistenercookie = CommonListenerCookie.createInitial((GameProfile) Objects.requireNonNull(this.authenticatedProfile), this.transferred); ServerConfigurationPacketListenerImpl serverconfigurationpacketlistenerimpl = new ServerConfigurationPacketListenerImpl(this.server, this.connection, commonlistenercookie, this.player); // CraftBukkit diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java index c038da20b76c0b7b1c18471b20be01e849d29f3a..c76404dfce176c02b769968de5a5ecc647059ae1 100644 --- a/src/main/java/net/minecraft/server/players/StoredUserList.java +++ b/src/main/java/net/minecraft/server/players/StoredUserList.java @@ -76,7 +76,7 @@ public abstract class StoredUserList> { } public String[] getUserList() { - return (String[]) this.map.keySet().toArray(new String[0]); + return (String[]) this.map.keySet().toArray(org.plazmamc.plazma.constants.Empty.STRING); // Plazma - Reduce allocations } public boolean isEmpty() { diff --git a/src/main/java/net/minecraft/util/MemoryReserve.java b/src/main/java/net/minecraft/util/MemoryReserve.java index 0ee04fe6ff6a4d09754f326526ae04fe7226bab2..5663ce568a1daa638b7387bee8b9917ce1f64d14 100644 --- a/src/main/java/net/minecraft/util/MemoryReserve.java +++ b/src/main/java/net/minecraft/util/MemoryReserve.java @@ -11,6 +11,6 @@ public class MemoryReserve { } public static void release() { - reserve = new byte[0]; + reserve = org.plazmamc.plazma.constants.Empty.BYTE; // Plazma - Reduce allocations } } diff --git a/src/main/java/net/minecraft/util/ZeroBitStorage.java b/src/main/java/net/minecraft/util/ZeroBitStorage.java index 01f5b946fabbe34f31110e75973dab9f39897346..2564c21900df7ca3c58872741ec8f68bce80a903 100644 --- a/src/main/java/net/minecraft/util/ZeroBitStorage.java +++ b/src/main/java/net/minecraft/util/ZeroBitStorage.java @@ -5,7 +5,7 @@ import java.util.function.IntConsumer; import org.apache.commons.lang3.Validate; public class ZeroBitStorage implements BitStorage { - public static final long[] RAW = new long[0]; + // public static final long[] RAW = new long[0]; // Plazma - Reduce allocations private final int size; public ZeroBitStorage(int size) { @@ -33,7 +33,7 @@ public class ZeroBitStorage implements BitStorage { @Override public long[] getRaw() { - return RAW; + return org.plazmamc.plazma.constants.Empty.LONG; // Plazma - Reduce allocations } @Override diff --git a/src/main/java/net/minecraft/util/monitoring/jmx/MinecraftServerStatistics.java b/src/main/java/net/minecraft/util/monitoring/jmx/MinecraftServerStatistics.java index a371f685534bf161f476ccea431fec6a80aca9c1..3ea10630deeb6624afd33c25a7ef023361312b30 100644 --- a/src/main/java/net/minecraft/util/monitoring/jmx/MinecraftServerStatistics.java +++ b/src/main/java/net/minecraft/util/monitoring/jmx/MinecraftServerStatistics.java @@ -43,7 +43,7 @@ public final class MinecraftServerStatistics implements DynamicMBean { .map(MinecraftServerStatistics.AttributeDescription::asMBeanAttributeInfo) .toArray(MBeanAttributeInfo[]::new); this.mBeanInfo = new MBeanInfo( - MinecraftServerStatistics.class.getSimpleName(), "metrics for dedicated server", mBeanAttributeInfos, null, null, new MBeanNotificationInfo[0] + MinecraftServerStatistics.class.getSimpleName(), "metrics for dedicated server", mBeanAttributeInfos, null, null, new MBeanNotificationInfo[0] // Plazma - Reduce allocations ); } diff --git a/src/main/java/net/minecraft/world/entity/animal/Bee.java b/src/main/java/net/minecraft/world/entity/animal/Bee.java index 539170813921de2dfcd7ef84dd7512d73cd27e68..104b89bf617138c301e671d76be8897a41d3b9e0 100644 --- a/src/main/java/net/minecraft/world/entity/animal/Bee.java +++ b/src/main/java/net/minecraft/world/entity/animal/Bee.java @@ -248,7 +248,7 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal { this.goalSelector.addGoal(8, new Bee.BeeWanderGoal()); this.goalSelector.addGoal(9, new FloatGoal(this)); this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur - this.targetSelector.addGoal(1, (new Bee.BeeHurtByOtherGoal(this)).setAlertOthers(new Class[0])); + this.targetSelector.addGoal(1, (new Bee.BeeHurtByOtherGoal(this)).setAlertOthers(/*new Class[0]*/)); // Plazma - Reduce allocations this.targetSelector.addGoal(2, new Bee.BeeBecomeAngryTargetGoal(this)); this.targetSelector.addGoal(3, new ResetUniversalAngerTargetGoal<>(this, true)); } diff --git a/src/main/java/net/minecraft/world/entity/animal/IronGolem.java b/src/main/java/net/minecraft/world/entity/animal/IronGolem.java index 12bc57d36d76f49596df0004fda31a6a678be60c..4968459a1620e8023bba07800e233e172a54b082 100644 --- a/src/main/java/net/minecraft/world/entity/animal/IronGolem.java +++ b/src/main/java/net/minecraft/world/entity/animal/IronGolem.java @@ -117,7 +117,7 @@ public class IronGolem extends AbstractGolem implements NeutralMob { this.goalSelector.addGoal(8, new RandomLookAroundGoal(this)); this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur this.targetSelector.addGoal(1, new DefendVillageTargetGoal(this)); - this.targetSelector.addGoal(2, new HurtByTargetGoal(this, new Class[0])); + this.targetSelector.addGoal(2, new HurtByTargetGoal(this/*, new Class[0]*/)); // Plazma - Reduce allocations this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Player.class, 10, true, false, this::isAngryAt)); this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Mob.class, 5, false, false, (entityliving) -> { return entityliving instanceof Enemy && !(entityliving instanceof Creeper); diff --git a/src/main/java/net/minecraft/world/entity/animal/Panda.java b/src/main/java/net/minecraft/world/entity/animal/Panda.java index 7bd81d073ce4a8d5981f256415d3e99e13da79ba..2dd3feee4b96305549dc65ee4388ceee501b832a 100644 --- a/src/main/java/net/minecraft/world/entity/animal/Panda.java +++ b/src/main/java/net/minecraft/world/entity/animal/Panda.java @@ -347,7 +347,7 @@ public class Panda extends Animal { this.goalSelector.addGoal(13, new FollowParentGoal(this, 1.25D)); this.goalSelector.addGoal(14, new WaterAvoidingRandomStrollGoal(this, 1.0D)); this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur - this.targetSelector.addGoal(1, (new Panda.PandaHurtByTargetGoal(this, new Class[0])).setAlertOthers(new Class[0])); + this.targetSelector.addGoal(1, (new Panda.PandaHurtByTargetGoal(this/*, new Class[0]*/)).setAlertOthers(/*new Class[0]*/)); // Plazma - Reduce allocations } public static AttributeSupplier.Builder createAttributes() { diff --git a/src/main/java/net/minecraft/world/entity/animal/Rabbit.java b/src/main/java/net/minecraft/world/entity/animal/Rabbit.java index 02702390c0b336762ce8c0d38d804e6f24ebbfd4..819fb1da353d36c594023f99f5c8123bc6d77326 100644 --- a/src/main/java/net/minecraft/world/entity/animal/Rabbit.java +++ b/src/main/java/net/minecraft/world/entity/animal/Rabbit.java @@ -458,7 +458,7 @@ public class Rabbit extends Animal implements VariantHolder { if (variant == Rabbit.Variant.EVIL) { this.getAttribute(Attributes.ARMOR).setBaseValue(8.0D); this.goalSelector.addGoal(4, new MeleeAttackGoal(this, 1.4D, true)); - this.targetSelector.addGoal(1, (new HurtByTargetGoal(this, new Class[0])).setAlertOthers()); + this.targetSelector.addGoal(1, (new HurtByTargetGoal(this/*, new Class[0]*/)).setAlertOthers()); // Plazma - Reduce allocations this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true)); this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Wolf.class, true)); if (!this.hasCustomName()) { diff --git a/src/main/java/net/minecraft/world/entity/animal/Wolf.java b/src/main/java/net/minecraft/world/entity/animal/Wolf.java index b12544d1280f39b6c365317a0f4965c8d65b6497..efc7504a01cb0d32a4b6665a5521c8f7f6da25d9 100644 --- a/src/main/java/net/minecraft/world/entity/animal/Wolf.java +++ b/src/main/java/net/minecraft/world/entity/animal/Wolf.java @@ -248,7 +248,7 @@ public class Wolf extends TamableAnimal implements NeutralMob, VariantHolder(this, Player.class, 10, true, false, this::isAngryAt)); // this.targetSelector.addGoal(5, new NonTameRandomTargetGoal<>(this, Animal.class, false, Wolf.PREY_SELECTOR)); // Purpur - moved to updatePathfinders() this.targetSelector.addGoal(6, new NonTameRandomTargetGoal<>(this, Turtle.class, false, Turtle.BABY_ON_LAND_SELECTOR)); diff --git a/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java b/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java index bca7b7192debb3a34a08047010a2438e7b7e2a78..0070e4b4eec5bd211155695e456fd2c403548c57 100644 --- a/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java +++ b/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java @@ -84,7 +84,7 @@ public class Allay extends PathfinderMob implements InventoryCarrier, VibrationS private static final EntityDataAccessor DATA_DANCING = SynchedEntityData.defineId(Allay.class, EntityDataSerializers.BOOLEAN); private static final EntityDataAccessor DATA_CAN_DUPLICATE = SynchedEntityData.defineId(Allay.class, EntityDataSerializers.BOOLEAN); protected static final ImmutableList>> SENSOR_TYPES = ImmutableList.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.NEAREST_PLAYERS, SensorType.HURT_BY, SensorType.NEAREST_ITEMS); - protected static final ImmutableList> MEMORY_TYPES = ImmutableList.of(MemoryModuleType.PATH, MemoryModuleType.LOOK_TARGET, MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, MemoryModuleType.WALK_TARGET, MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE, MemoryModuleType.HURT_BY, MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM, MemoryModuleType.LIKED_PLAYER, MemoryModuleType.LIKED_NOTEBLOCK_POSITION, MemoryModuleType.LIKED_NOTEBLOCK_COOLDOWN_TICKS, MemoryModuleType.ITEM_PICKUP_COOLDOWN_TICKS, MemoryModuleType.IS_PANICKING, new MemoryModuleType[0]); + protected static final ImmutableList> MEMORY_TYPES = ImmutableList.of(MemoryModuleType.PATH, MemoryModuleType.LOOK_TARGET, MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, MemoryModuleType.WALK_TARGET, MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE, MemoryModuleType.HURT_BY, MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM, MemoryModuleType.LIKED_PLAYER, MemoryModuleType.LIKED_NOTEBLOCK_POSITION, MemoryModuleType.LIKED_NOTEBLOCK_COOLDOWN_TICKS, MemoryModuleType.ITEM_PICKUP_COOLDOWN_TICKS, MemoryModuleType.IS_PANICKING/*, new MemoryModuleType[0]*/); // Plazma - Reduce allocations public static final ImmutableList THROW_SOUND_PITCHES = ImmutableList.of(0.5625F, 0.625F, 0.75F, 0.9375F, 1.0F, 1.0F, 1.125F, 1.25F, 1.5F, 1.875F, 2.0F, 2.25F, new Float[]{2.5F, 3.0F, 3.75F, 4.0F}); private final DynamicGameEventListener dynamicVibrationListener; private VibrationSystem.Data vibrationData; diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/phases/EnderDragonPhase.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/phases/EnderDragonPhase.java index 48826eb0a960f7af6dd2ef184a8aed744a1d8f83..32c3ff7331681af1d8dc583cf5208d72035ea150 100644 --- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/phases/EnderDragonPhase.java +++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/phases/EnderDragonPhase.java @@ -5,7 +5,7 @@ import java.util.Arrays; import net.minecraft.world.entity.boss.enderdragon.EnderDragon; public class EnderDragonPhase { - private static EnderDragonPhase[] phases = new EnderDragonPhase[0]; + private static EnderDragonPhase[] phases = new EnderDragonPhase[0]; // Plazma - Reduce allocations (mark on diff) public static final EnderDragonPhase HOLDING_PATTERN = create(DragonHoldingPatternPhase.class, "HoldingPattern"); public static final EnderDragonPhase STRAFE_PLAYER = create(DragonStrafePlayerPhase.class, "StrafePlayer"); public static final EnderDragonPhase LANDING_APPROACH = create(DragonLandingApproachPhase.class, "LandingApproach"); diff --git a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java b/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java index 4a98027a12c2535d1df3a9f6390eb85146398403..de5154d6e8abf4c8d1e74870470de5df2f8f8b0f 100644 --- a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java +++ b/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java @@ -258,7 +258,7 @@ public class WitherBoss extends Monster implements PowerableMob, RangedAttackMob this.goalSelector.addGoal(6, new LookAtPlayerGoal(this, Player.class, 8.0F)); this.goalSelector.addGoal(7, new RandomLookAroundGoal(this)); this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur - this.targetSelector.addGoal(1, new HurtByTargetGoal(this, new Class[0])); + this.targetSelector.addGoal(1, new HurtByTargetGoal(this/*, new Class[0]*/)); // Plazma - Reduce allocations this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, LivingEntity.class, 0, false, false, WitherBoss.LIVING_ENTITY_SELECTOR)); } diff --git a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java index e80307198b051cbcd9f72b36e459276848dcb4c9..7a20324210accd29f495c6c31d3d9eefe6ef0fc0 100644 --- a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java +++ b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java @@ -78,7 +78,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo this.goalSelector.addGoal(6, new LookAtPlayerGoal(this, Player.class, 8.0F)); this.goalSelector.addGoal(6, new RandomLookAroundGoal(this)); this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur - this.targetSelector.addGoal(1, new HurtByTargetGoal(this, new Class[0])); + this.targetSelector.addGoal(1, new HurtByTargetGoal(this/*, new Class[0]*/)); // Plazma - Reduce allocations this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true)); this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, IronGolem.class, true)); this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Turtle.class, 10, true, false, Turtle.BABY_ON_LAND_SELECTOR)); diff --git a/src/main/java/net/minecraft/world/entity/monster/Creeper.java b/src/main/java/net/minecraft/world/entity/monster/Creeper.java index 1829bedfa8084c4932a0e67c36f48f19993e22b6..a45a113bcb7f8d28300f7d31331972550bd96287 100644 --- a/src/main/java/net/minecraft/world/entity/monster/Creeper.java +++ b/src/main/java/net/minecraft/world/entity/monster/Creeper.java @@ -155,7 +155,7 @@ public class Creeper extends Monster implements PowerableMob { this.goalSelector.addGoal(6, new RandomLookAroundGoal(this)); this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, Player.class, true)); - this.targetSelector.addGoal(2, new HurtByTargetGoal(this, new Class[0])); + this.targetSelector.addGoal(2, new HurtByTargetGoal(this/*, new Class[0]*/)); // Plazma - Reduce allocations } public static AttributeSupplier.Builder createAttributes() { diff --git a/src/main/java/net/minecraft/world/entity/monster/EnderMan.java b/src/main/java/net/minecraft/world/entity/monster/EnderMan.java index 5b49a6b1884c33bedafca5cff0214cdfccd87302..045efcbb61c0c492f7dac076b0b63f7e9396523e 100644 --- a/src/main/java/net/minecraft/world/entity/monster/EnderMan.java +++ b/src/main/java/net/minecraft/world/entity/monster/EnderMan.java @@ -133,7 +133,7 @@ public class EnderMan extends Monster implements NeutralMob { this.goalSelector.addGoal(11, new EnderMan.EndermanTakeBlockGoal(this)); this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur this.targetSelector.addGoal(1, new EnderMan.EndermanLookForPlayerGoal(this, this::isAngryAt)); - this.targetSelector.addGoal(2, new HurtByTargetGoal(this, new Class[0])); + this.targetSelector.addGoal(2, new HurtByTargetGoal(this/*, new Class[0]*/)); // Plazma - Reduce allocations this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Endermite.class, 10, true, false, (entityliving) -> entityliving.level().purpurConfig.endermanAggroEndermites && entityliving instanceof Endermite endermite && (!entityliving.level().purpurConfig.endermanAggroEndermitesOnlyIfPlayerSpawned || endermite.isPlayerSpawned()))); // Purpur this.targetSelector.addGoal(4, new ResetUniversalAngerTargetGoal<>(this, false)); } diff --git a/src/main/java/net/minecraft/world/entity/monster/Endermite.java b/src/main/java/net/minecraft/world/entity/monster/Endermite.java index 14d6796a124a85b8cbf5f3b719d89d99e0cf8db5..61f65018d25f450bf9a8b07559e4ca9e600acdb4 100644 --- a/src/main/java/net/minecraft/world/entity/monster/Endermite.java +++ b/src/main/java/net/minecraft/world/entity/monster/Endermite.java @@ -89,7 +89,7 @@ public class Endermite extends Monster { this.goalSelector.addGoal(7, new LookAtPlayerGoal(this, Player.class, 8.0F)); this.goalSelector.addGoal(8, new RandomLookAroundGoal(this)); this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur - this.targetSelector.addGoal(1, (new HurtByTargetGoal(this, new Class[0])).setAlertOthers()); + this.targetSelector.addGoal(1, (new HurtByTargetGoal(this/*, new Class[0]*/)).setAlertOthers()); // Plazma - Reduce allocations this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true)); } diff --git a/src/main/java/net/minecraft/world/entity/monster/Silverfish.java b/src/main/java/net/minecraft/world/entity/monster/Silverfish.java index c713e0b9b90784ad5f043f3a06ef50b5a1769ed1..f8d2c555ba5d268a6b6788863b352f77ee224c69 100644 --- a/src/main/java/net/minecraft/world/entity/monster/Silverfish.java +++ b/src/main/java/net/minecraft/world/entity/monster/Silverfish.java @@ -85,7 +85,7 @@ public class Silverfish extends Monster { this.goalSelector.addGoal(4, new MeleeAttackGoal(this, 1.0D, false)); this.goalSelector.addGoal(5, new Silverfish.SilverfishMergeWithStoneGoal(this)); this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur - this.targetSelector.addGoal(1, (new HurtByTargetGoal(this, new Class[0])).setAlertOthers()); + this.targetSelector.addGoal(1, (new HurtByTargetGoal(this/*, new Class[0]*/)).setAlertOthers()); // Plazma - Reduce allocations this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true)); } diff --git a/src/main/java/net/minecraft/world/entity/monster/Spider.java b/src/main/java/net/minecraft/world/entity/monster/Spider.java index 159740069aba59bffff444d933af32aaf752ba48..e8177af1722f15069f67fd36c9ce150625ba6077 100644 --- a/src/main/java/net/minecraft/world/entity/monster/Spider.java +++ b/src/main/java/net/minecraft/world/entity/monster/Spider.java @@ -96,7 +96,7 @@ public class Spider extends Monster { this.goalSelector.addGoal(6, new LookAtPlayerGoal(this, Player.class, 8.0F)); this.goalSelector.addGoal(6, new RandomLookAroundGoal(this)); this.targetSelector.addGoal(0, new org.purpurmc.purpur.entity.ai.HasRider(this)); // Purpur - this.targetSelector.addGoal(1, new HurtByTargetGoal(this, new Class[0])); + this.targetSelector.addGoal(1, new HurtByTargetGoal(this/*, new Class[0]*/)); // Plazma - Reduce allocations this.targetSelector.addGoal(2, new Spider.SpiderTargetGoal<>(this, Player.class)); this.targetSelector.addGoal(3, new Spider.SpiderTargetGoal<>(this, IronGolem.class)); } diff --git a/src/main/java/net/minecraft/world/entity/monster/Zombie.java b/src/main/java/net/minecraft/world/entity/monster/Zombie.java index d48d22157a89f98c1bbabc70b0bb31187038176d..f2abb8bc0113ff82bb7938b748a9ab2b3b423f26 100644 --- a/src/main/java/net/minecraft/world/entity/monster/Zombie.java +++ b/src/main/java/net/minecraft/world/entity/monster/Zombie.java @@ -163,7 +163,7 @@ public class Zombie extends Monster { this.goalSelector.addGoal(2, new ZombieAttackGoal(this, 1.0D, false)); this.goalSelector.addGoal(6, new MoveThroughVillageGoal(this, 1.0D, true, 4, this::canBreakDoors)); this.goalSelector.addGoal(7, new WaterAvoidingRandomStrollGoal(this, 1.0D)); - this.targetSelector.addGoal(1, (new HurtByTargetGoal(this, new Class[0])).setAlertOthers(ZombifiedPiglin.class)); + this.targetSelector.addGoal(1, (new HurtByTargetGoal(this/*, new Class[0]*/)).setAlertOthers(ZombifiedPiglin.class)); // Plazma - Reduce allocations this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true)); // Purpur start if ( this.level().spigotConfig.zombieAggressiveTowardsVillager ) this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, AbstractVillager.class, false) { // Spigot diff --git a/src/main/java/net/minecraft/world/entity/monster/ZombifiedPiglin.java b/src/main/java/net/minecraft/world/entity/monster/ZombifiedPiglin.java index 5bae3215ee0bf222c3bd77b3131f3d01ac6c9c41..cae9562468fd8ea96ddee93ba5403be52e99d3aa 100644 --- a/src/main/java/net/minecraft/world/entity/monster/ZombifiedPiglin.java +++ b/src/main/java/net/minecraft/world/entity/monster/ZombifiedPiglin.java @@ -118,7 +118,7 @@ public class ZombifiedPiglin extends Zombie implements NeutralMob { protected void addBehaviourGoals() { this.goalSelector.addGoal(2, new ZombieAttackGoal(this, 1.0D, false)); this.goalSelector.addGoal(7, new WaterAvoidingRandomStrollGoal(this, 1.0D)); - this.targetSelector.addGoal(1, pathfinderGoalHurtByTarget = (new HurtByTargetGoal(this, new Class[0])).setAlertOthers()); // Paper - fix PigZombieAngerEvent cancellation + this.targetSelector.addGoal(1, pathfinderGoalHurtByTarget = (new HurtByTargetGoal(this/*, new Class[0]*/)).setAlertOthers()); // Paper - fix PigZombieAngerEvent cancellation // Plazma - Reduce allocations this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, 10, true, false, this::isAngryAt)); this.targetSelector.addGoal(3, new ResetUniversalAngerTargetGoal<>(this, true)); } diff --git a/src/main/java/net/minecraft/world/inventory/SlotRanges.java b/src/main/java/net/minecraft/world/inventory/SlotRanges.java index 7700b63b2ad8a7dcf20f5e0dc8e543ea098cddc0..0adda6c14ab119430240025167058436eef9ba3e 100644 --- a/src/main/java/net/minecraft/world/inventory/SlotRanges.java +++ b/src/main/java/net/minecraft/world/inventory/SlotRanges.java @@ -44,8 +44,8 @@ public class SlotRanges { addSingleSlot(list, "player.cursor", 499); addSlotRange(list, "player.crafting.", 500, 4); }); - public static final Codec CODEC = StringRepresentable.fromValues(() -> SLOTS.toArray(new SlotRange[0])); - private static final Function NAME_LOOKUP = StringRepresentable.createNameLookup(SLOTS.toArray(new SlotRange[0]), name -> name); + public static final Codec CODEC = StringRepresentable.fromValues(() -> SLOTS.toArray(new SlotRange[0])); // Plazma - Reduce allocations (mark on diff) + private static final Function NAME_LOOKUP = StringRepresentable.createNameLookup(SLOTS.toArray(new SlotRange[0]), name -> name); // Plazma - Reduce allocations (mark on diff) private static SlotRange create(String name, int slotId) { return SlotRange.of(name, IntLists.singleton(slotId)); diff --git a/src/main/java/net/minecraft/world/item/crafting/ShapedRecipePattern.java b/src/main/java/net/minecraft/world/item/crafting/ShapedRecipePattern.java index 90a38babcc87a789e4955f1505fa645780d14011..86d38496c101ef60896a1876f006d37654f0c1fd 100644 --- a/src/main/java/net/minecraft/world/item/crafting/ShapedRecipePattern.java +++ b/src/main/java/net/minecraft/world/item/crafting/ShapedRecipePattern.java @@ -88,7 +88,7 @@ public record ShapedRecipePattern(int width, int height, NonNullList } if (pattern.size() == l) { - return new String[0]; + return org.plazmamc.plazma.constants.Empty.STRING; // Plazma - Reduce allocations } else { String[] strings = new String[pattern.size() - l - k]; diff --git a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java index f34159f8d6c51af2341bf49db0d6d6f0417919cf..4c48d0c61860701b688c722594645f36cc799fc7 100644 --- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java +++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java @@ -458,7 +458,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder { @Override public int[] getSlotsForFace(Direction side) { - return side == Direction.DOWN ? new int[]{0} : new int[0]; + return side == Direction.DOWN ? org.plazmamc.plazma.constants.Empty.ZINT : org.plazmamc.plazma.constants.Empty.INT; // Plazma - Reduce allocations } @Override @@ -507,7 +507,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder { @Override public int[] getSlotsForFace(Direction side) { - return side == Direction.UP ? new int[]{0} : new int[0]; + return side == Direction.UP ? org.plazmamc.plazma.constants.Empty.ZINT : org.plazmamc.plazma.constants.Empty.INT; // Plazma - Reduce allocations } @Override @@ -549,7 +549,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder { @Override public int[] getSlotsForFace(Direction side) { - return new int[0]; + return org.plazmamc.plazma.constants.Empty.INT; // Plazma - Reduce allocations } @Override diff --git a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java index c02d638b8f117156c815821207a91c55796f00b2..f76698862e0ec16c89f844d01e8116f12ec696b7 100644 --- a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java @@ -68,7 +68,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit protected static final int SLOT_FUEL = 1; protected static final int SLOT_RESULT = 2; public static final int DATA_LIT_TIME = 0; - private static final int[] SLOTS_FOR_UP = new int[]{0}; + private static final int[] SLOTS_FOR_UP = org.plazmamc.plazma.constants.Empty.ZINT; // Plazma - Reduce allocations private static final int[] SLOTS_FOR_DOWN = new int[]{2, 1}; private static final int[] SLOTS_FOR_SIDES = new int[]{1}; public static final int DATA_LIT_DURATION = 1; diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java index 1362a47943cf1a51a185a15094b1f74c94bf40ef..2490b63cbba49fa0de076f74266866345c01fbca 100644 --- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java +++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java @@ -445,7 +445,7 @@ public class RegionFile implements AutoCloseable { this.path = path; initOversizedState(); // Paper this.version = compressionFormat; - if (!Files.isDirectory(directory, new LinkOption[0])) { + if (!Files.isDirectory(directory/*, new LinkOption[0]*/)) { // Plazma - Reduce allocations throw new IllegalArgumentException("Expected directory, got " + String.valueOf(directory.toAbsolutePath())); } else { this.externalFileDir = directory; @@ -717,7 +717,7 @@ public class RegionFile implements AutoCloseable { private DataInputStream createExternalChunkInputStream(ChunkPos pos, byte flags) throws IOException { Path path = this.getExternalChunkPath(pos); - if (!Files.isRegularFile(path, new LinkOption[0])) { + if (!Files.isRegularFile(path/*, new LinkOption[0]*/)) { // Plazma - Reduce allocations RegionFile.LOGGER.error("External chunk path {} is not file", path); return null; } else { @@ -769,7 +769,7 @@ public class RegionFile implements AutoCloseable { return false; } - if (!Files.isRegularFile(this.getExternalChunkPath(pos), new LinkOption[0])) { + if (!Files.isRegularFile(this.getExternalChunkPath(pos)/*, new LinkOption[0]*/)) { // Plazma - Reduce allocations return false; } } else { diff --git a/src/main/java/net/minecraft/world/level/levelgen/DebugLevelSource.java b/src/main/java/net/minecraft/world/level/levelgen/DebugLevelSource.java index b8e333e79c2d9a1418d86df9f553fa8a76ce852d..b6012d36099132cb6ab381e2bfa96eccef49d142 100644 --- a/src/main/java/net/minecraft/world/level/levelgen/DebugLevelSource.java +++ b/src/main/java/net/minecraft/world/level/levelgen/DebugLevelSource.java @@ -89,7 +89,7 @@ public class DebugLevelSource extends ChunkGenerator { @Override public NoiseColumn getBaseColumn(int x, int z, LevelHeightAccessor world, RandomState noiseConfig) { - return new NoiseColumn(0, new BlockState[0]); + return new NoiseColumn(0, org.plazmamc.plazma.constants.Empty.BLOCK_STATE); // Plazma - Reduce allocations } @Override diff --git a/src/main/java/net/minecraft/world/level/storage/LevelStorageSource.java b/src/main/java/net/minecraft/world/level/storage/LevelStorageSource.java index 427ee4d6f12a7abd8da0c65e0b9081b25824df40..2655ad947d3e6bc1b06911bc7309e14991c04467 100644 --- a/src/main/java/net/minecraft/world/level/storage/LevelStorageSource.java +++ b/src/main/java/net/minecraft/world/level/storage/LevelStorageSource.java @@ -107,7 +107,7 @@ public class LevelStorageSource { } public static DirectoryValidator parseValidator(Path allowedSymlinksFile) { - if (Files.exists(allowedSymlinksFile, new LinkOption[0])) { + if (Files.exists(allowedSymlinksFile/*, new LinkOption[0]*/)) { // Plazma - Reduce allocations try { BufferedReader bufferedreader = Files.newBufferedReader(allowedSymlinksFile); @@ -176,7 +176,7 @@ public class LevelStorageSource { } public LevelStorageSource.LevelCandidates findLevelCandidates() throws LevelStorageException { - if (!Files.isDirectory(this.baseDir, new LinkOption[0])) { + if (!Files.isDirectory(this.baseDir/*, new LinkOption[0]*/)) { // Plazma - Reduce allocations throw new LevelStorageException(Component.translatable("selectWorld.load_folder_access")); } else { try { @@ -185,11 +185,12 @@ public class LevelStorageSource { LevelStorageSource.LevelCandidates convertable_a; try { - List list = stream.filter((path) -> { - return Files.isDirectory(path, new LinkOption[0]); - }).map(LevelStorageSource.LevelDirectory::new).filter((convertable_b) -> { - return Files.isRegularFile(convertable_b.dataFile(), new LinkOption[0]) || Files.isRegularFile(convertable_b.oldDataFile(), new LinkOption[0]); - }).toList(); + // Plazma start - Reduce allocations + List list = stream.filter(Files::isDirectory) + .map(LevelStorageSource.LevelDirectory::new) + .filter(convertable_b -> Files.isRegularFile(convertable_b.dataFile()) || Files.isRegularFile(convertable_b.oldDataFile())) + .toList(); + // Plazma end convertable_a = new LevelStorageSource.LevelCandidates(list); } catch (Throwable throwable) { @@ -301,7 +302,7 @@ public class LevelStorageSource { private LevelSummary readLevelSummary(LevelStorageSource.LevelDirectory save, boolean locked) { Path path = save.dataFile(); - if (Files.exists(path, new LinkOption[0])) { + if (Files.exists(path/*, new LinkOption[0]*/)) { // Plazma - Reduce allocations try { if (Files.isSymbolicLink(path)) { List list = this.worldDirValidator.validateSymlink(path); @@ -400,7 +401,7 @@ public class LevelStorageSource { public boolean levelExists(String name) { try { - return Files.isDirectory(this.getLevelPath(name), new LinkOption[0]); + return Files.isDirectory(this.getLevelPath(name)/*, new LinkOption[0]*/); // Plazma - Reduce allocations } catch (InvalidPathException invalidpathexception) { return false; } @@ -753,7 +754,7 @@ public class LevelStorageSource { } public boolean hasWorldData() { - return Files.exists(this.levelDirectory.dataFile(), new LinkOption[0]) || Files.exists(this.levelDirectory.oldDataFile(), new LinkOption[0]); + return Files.exists(this.levelDirectory.dataFile()/*, new LinkOption[0]*/) || Files.exists(this.levelDirectory.oldDataFile()/*, new LinkOption[0]*/); // Plazma - Reduce allocations } public void close() throws IOException { diff --git a/src/main/java/net/minecraft/world/level/storage/PlayerDataStorage.java b/src/main/java/net/minecraft/world/level/storage/PlayerDataStorage.java index 8ab7ca373a885fbe658013c9c6a2e38d32d77bb2..c6bcfd61b0a848129357d9515de96c8e899c25c7 100644 --- a/src/main/java/net/minecraft/world/level/storage/PlayerDataStorage.java +++ b/src/main/java/net/minecraft/world/level/storage/PlayerDataStorage.java @@ -60,7 +60,7 @@ public class PlayerDataStorage { // s1 = entityhuman.getStringUUID(); // CraftBukkit - used above Path path2 = path.resolve(s1 + "_corrupted_" + LocalDateTime.now().format(PlayerDataStorage.FORMATTER) + s); - if (Files.isRegularFile(path1, new LinkOption[0])) { + if (Files.isRegularFile(path1/*, new LinkOption[0]*/)) { // Plazma - Reduce allocations try { Files.copy(path1, path2, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); } catch (Exception exception) { diff --git a/src/main/java/net/minecraft/world/scores/Team.java b/src/main/java/net/minecraft/world/scores/Team.java index b968d22e149bf9063f14167fe9856868e5933303..cec115cf5e4ad17240497c9cebb3981564a537bc 100644 --- a/src/main/java/net/minecraft/world/scores/Team.java +++ b/src/main/java/net/minecraft/world/scores/Team.java @@ -70,7 +70,7 @@ public abstract class Team { public final int id; public static String[] getAllNames() { - return BY_NAME.keySet().toArray(new String[0]); + return BY_NAME.keySet().toArray(org.plazmamc.plazma.constants.Empty.STRING); // Plazma - Reduce allocations } @Nullable diff --git a/src/main/java/org/bukkit/craftbukkit/bootstrap/Main.java b/src/main/java/org/bukkit/craftbukkit/bootstrap/Main.java index 8a4f95049c63afb28bef6719c77b7a7092e75aae..db6b7cf7f5ad7e991d682eafd353480e9b14faa9 100644 --- a/src/main/java/org/bukkit/craftbukkit/bootstrap/Main.java +++ b/src/main/java/org/bukkit/craftbukkit/bootstrap/Main.java @@ -50,7 +50,7 @@ public class Main { System.exit(0); } - URLClassLoader classLoader = new URLClassLoader(extractedUrls.toArray(new URL[0])); + URLClassLoader classLoader = new URLClassLoader(extractedUrls.toArray(new URL[0])); // Plazma - Reduce allocations (mark on diff) System.out.println("Starting server"); Thread runThread = new Thread(() -> { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 90338017ebcb2a690dff7dad57aa6fbb95e0ff93..abfa1c2172220a16294cf52e78fb6638ec01ea9c 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -502,7 +502,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public void sendTitle(com.destroystokyo.paper.Title title) { Preconditions.checkNotNull(title, "Title is null"); setTitleTimes(title.getFadeIn(), title.getStay(), title.getFadeOut()); - setSubtitle(title.getSubtitle() == null ? new BaseComponent[0] : title.getSubtitle()); + setSubtitle(title.getSubtitle() == null ? org.plazmamc.plazma.constants.Empty.BASE_COMPONENT : title.getSubtitle()); // Plazma - Reduce allocations showTitle(title.getTitle()); } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java index a395c7ce952f4a60a5edf80e8731afa6388d18ea..86d6c952682e10bf961c5752553a707610434679 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java @@ -448,7 +448,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBo throw new IllegalArgumentException("Invalid page number " + page + "/" + CraftMetaBook.this.getPageCount()); } - BaseComponent[] newText = text == null ? new BaseComponent[0] : text; + BaseComponent[] newText = text == null ? org.plazmamc.plazma.constants.Empty.BASE_COMPONENT : text; // Plazma - Reduce allocations CraftMetaBook.this.pages.set(page - 1, this.componentsToPage(newText)); } @@ -461,7 +461,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBo public void addPage(final BaseComponent[]... pages) { for (BaseComponent[] page : pages) { if (page == null) { - page = new BaseComponent[0]; + page = org.plazmamc.plazma.constants.Empty.BASE_COMPONENT; // Plazma - Reduce allocations } CraftMetaBook.this.internalAddPage(this.componentsToPage(page)); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java index 6a6e9a1478a2ead20467bc711d0ad4a9ab3010cb..54d980117255f3b4c95adde4d253eb0775c6f1f5 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java @@ -399,7 +399,7 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta { throw new IllegalArgumentException("Invalid page number " + page + "/" + CraftMetaBookSigned.this.getPageCount()); } - BaseComponent[] newText = text == null ? new BaseComponent[0] : text; + BaseComponent[] newText = text == null ? org.plazmamc.plazma.constants.Empty.BASE_COMPONENT : text; // Plazma - Reduce allocations CraftMetaBookSigned.this.pages.set(page - 1, this.componentsToPage(newText)); } @@ -412,7 +412,7 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta { public void addPage(final BaseComponent[]... pages) { for (BaseComponent[] page : pages) { if (page == null) { - page = new BaseComponent[0]; + page = org.plazmamc.plazma.constants.Empty.BASE_COMPONENT; // Plazma - Reduce allocations } CraftMetaBookSigned.this.internalAddPage(this.componentsToPage(page)); diff --git a/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java b/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java index b25dc23b81687dd4d4e70b3615ffb91f8c03c68b..acb98770b9d01e930642a5794f9179660b411c02 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java +++ b/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java @@ -164,7 +164,7 @@ public final class WeakCollection implements Collection { @Override public Object[] toArray() { - return this.toArray(new Object[0]); + return this.toArray(org.plazmamc.plazma.constants.Empty.OBJECT); // Plazma - Reduce allocations } @Override diff --git a/src/main/java/org/plazmamc/plazma/constants/Empty.java b/src/main/java/org/plazmamc/plazma/constants/Empty.java new file mode 100644 index 0000000000000000000000000000000000000000..8e4c5d912113ebec0272b09f8e01117536eac1e3 --- /dev/null +++ b/src/main/java/org/plazmamc/plazma/constants/Empty.java @@ -0,0 +1,21 @@ +package org.plazmamc.plazma.constants; + +public interface Empty { + + int[] INT = new int[0]; + int[] ZINT = new int[]{0}; + long[] LONG = new long[0]; + byte[] BYTE = new byte[0]; + + Object[] OBJECT = new Object[0]; + String[] STRING = new String[0]; + StackTraceElement[] TRACE = new StackTraceElement[0]; + java.util.concurrent.CompletableFuture[] FUTURE = new java.util.concurrent.CompletableFuture[0]; + + net.minecraft.world.level.block.state.BlockState[] BLOCK_STATE = new net.minecraft.world.level.block.state.BlockState[0]; + net.minecraft.world.entity.Entity[] ENTITY = new net.minecraft.world.entity.Entity[0]; + + @SuppressWarnings("deprecation") + net.md_5.bungee.api.chat.BaseComponent[] BASE_COMPONENT = new net.md_5.bungee.api.chat.BaseComponent[0]; + +} diff --git a/src/main/java/org/purpurmc/purpur/command/PurpurCommand.java b/src/main/java/org/purpurmc/purpur/command/PurpurCommand.java index 2621e54879e9ab0029a875f1d09eee67878b90d5..e7e959368c01de69261618d1eb749bebba3527af 100644 --- a/src/main/java/org/purpurmc/purpur/command/PurpurCommand.java +++ b/src/main/java/org/purpurmc/purpur/command/PurpurCommand.java @@ -57,7 +57,7 @@ public class PurpurCommand extends Command { } else if (args[0].equalsIgnoreCase("version")) { Command verCmd = org.bukkit.Bukkit.getServer().getCommandMap().getCommand("version"); if (verCmd != null) { - return verCmd.execute(sender, commandLabel, new String[0]); + return verCmd.execute(sender, commandLabel, org.plazmamc.plazma.constants.Empty.STRING); // Plazma - Reduce allocations } }