[1.21.1] ModLoading cleanup and optimisations (#10052)

This commit is contained in:
Paint_Ninja authored and GitHub committed 2024-08-16 22:49:11 +01:00
1 parent f106ff0c21
commit 9714512c31
101 files changed
+837 -841

No files matched your search

@@ -21,7 +21,7 @@ import net.minecraft.world.level.biome.Biome;
public class BiomeManager
{
private static TrackedList<BiomeEntry>[] biomes = setupBiomes();
private static final TrackedList<BiomeEntry>[] biomes = setupBiomes();
private static final List<ResourceKey<Biome>> additionalOverworldBiomes = new ArrayList<>();
private static final List<ResourceKey<Biome>> additionalOverworldBiomesView = Collections.unmodifiableList(additionalOverworldBiomes);
@@ -109,7 +109,7 @@ public final class CreativeModeTabRegistry {
@Override
protected void apply(@NotNull JsonObject data, @NotNull ResourceManager resourceManager, ProfilerFiller p) {
try {
if (data.size() > 0) {
if (!data.isEmpty()) {
JsonArray order = GsonHelper.getAsJsonArray(data, "order");
List<CreativeModeTab> customOrder = new ArrayList<>();
for (JsonElement entry : order) {
@@ -183,8 +183,9 @@ public final class CreativeModeTabRegistry {
DEFAULT_TABS.add(BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabs.OP_BLOCKS));
DEFAULT_TABS.add(BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabs.INVENTORY));
final List<Holder<CreativeModeTab>> indexed = new ArrayList<>();
BuiltInRegistries.CREATIVE_MODE_TAB.holders().filter(c -> !DEFAULT_TABS.contains(c.get())).forEach(indexed::add);
final List<Holder<CreativeModeTab>> indexed = BuiltInRegistries.CREATIVE_MODE_TAB.holders()
.filter(c -> !DEFAULT_TABS.contains(c.get()))
.collect(Collectors.toList());
int vanillaTabs = 10;
for (int i = 0; i < vanillaTabs; i++) { // Vanilla ordering
@@ -632,7 +632,7 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
if (count > currentPath.size())
throw new IllegalArgumentException("Attempted to pop " + count + " elements when we only had: " + currentPath);
for (int x = 0; x < count; x++)
currentPath.remove(currentPath.size() - 1);
currentPath.removeLast();
return this;
}
@@ -644,10 +644,14 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
public ForgeConfigSpec build() {
context.ensureEmpty();
Config valueCfg = Config.of(Config.getDefaultMapCreator(true, true), InMemoryFormat.withSupport(ConfigValue.class::isAssignableFrom));
values.forEach(v -> valueCfg.set(v.getPath(), v));
for (ConfigValue<?> value : values) {
valueCfg.set(value.getPath(), value);
}
ForgeConfigSpec ret = new ForgeConfigSpec(storage, valueCfg, levelComments, levelTranslationKeys);
values.forEach(v -> v.spec = ret);
for (ConfigValue<?> v : values) {
v.spec = ret;
}
return ret;
}
@@ -30,8 +30,8 @@ public class ForgeI18n {
// From FontRenderer.renderCharAtPos
private static final String ALLOWED_CHARS = "\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000";
private static final CharMatcher DISALLOWED_CHAR_MATCHER = CharMatcher.anyOf(ALLOWED_CHARS).negate();
private static Map<String,String> i18n;
private static Map<String,FormatFactory> customFactories;
private static Map<String, String> i18n;
private static final Map<String, FormatFactory> customFactories;
// From StringUtils
private static final Pattern PATTERN_CONTROL_CODE = Pattern.compile("(?i)\\u00A7[0-9A-FK-OR]");
@@ -60,11 +60,11 @@ public class ForgeInternalHandler {
WorldWorkerManager.tick(false);
}
@SubscribeEvent
public void checkSettings(ClientTickEvent event) {
//if (event.phase == Phase.END)
// CloudRenderer.updateCloudSettings();
}
// @SubscribeEvent
// public void checkSettings(ClientTickEvent event) {
// if (event.phase == Phase.END)
// CloudRenderer.updateCloudSettings();
// }
@SubscribeEvent
public void onChunkUnload(ChunkEvent.Unload event) {
@@ -399,7 +399,9 @@ public class ForgeMod {
modEventBus.addListener(this::registerFluids);
modEventBus.addListener(this::registerVanillaDisplayContexts);
modEventBus.register(this);
registries.forEach(r -> r.register(modEventBus));
for (DeferredRegister<?> r : registries) {
r.register(modEventBus);
}
MinecraftForge.EVENT_BUS.addListener(this::serverStopping);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ForgeConfig.clientSpec);
@@ -92,14 +92,14 @@ public class ForgeSpawnEggItem extends SpawnEggItem {
private static class ColorRegisterHandler {
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void registerSpawnEggColors(RegisterColorHandlersEvent.Item event) {
MOD_EGGS.forEach(egg -> {
for (ForgeSpawnEggItem egg : MOD_EGGS) {
event.register((stack, layer) -> {
int color = egg.getColor(layer);
if (FastColor.ARGB32.alpha(color) == 0)
color = FastColor.ARGB32.opaque(color);
return color;
}, egg);
});
}
}
}
}
@@ -29,11 +29,12 @@ public class VillagerTradingManager
static
{
VillagerTrades.TRADES.entrySet().forEach(e ->
{
VillagerTrades.TRADES.forEach((key, value) -> {
Int2ObjectMap<ItemListing[]> copy = new Int2ObjectOpenHashMap<>();
e.getValue().int2ObjectEntrySet().forEach(ent -> copy.put(ent.getIntKey(), Arrays.copyOf(ent.getValue(), ent.getValue().length)));
VANILLA_TRADES.put(e.getKey(), copy);
for (var ent : value.int2ObjectEntrySet()) {
copy.put(ent.getIntKey(), Arrays.copyOf(ent.getValue(), ent.getValue().length));
}
VANILLA_TRADES.put(key, copy);
});
VillagerTrades.WANDERING_TRADER_TRADES.int2ObjectEntrySet().forEach(e -> WANDERER_TRADES.put(e.getIntKey(), Arrays.copyOf(e.getValue(), e.getValue().length)));
}
@@ -71,13 +72,14 @@ public class VillagerTradingManager
{
mutableTrades.put(i, NonNullList.create());
}
trades.int2ObjectEntrySet().forEach(e ->
{
Arrays.stream(e.getValue()).forEach(mutableTrades.get(e.getIntKey())::add);
});
for (var entry : trades.int2ObjectEntrySet()) {
Arrays.stream(entry.getValue()).forEach(mutableTrades.get(entry.getIntKey())::add);
}
MinecraftForge.EVENT_BUS.post(new VillagerTradesEvent(mutableTrades, prof));
Int2ObjectMap<ItemListing[]> newTrades = new Int2ObjectOpenHashMap<>();
mutableTrades.int2ObjectEntrySet().forEach(e -> newTrades.put(e.getIntKey(), e.getValue().toArray(new ItemListing[0])));
for (var entry : mutableTrades.int2ObjectEntrySet()) {
newTrades.put(entry.getIntKey(), entry.getValue().toArray(new ItemListing[0]));
}
VillagerTrades.TRADES.put(prof, newTrades);
}
}
@@ -10,7 +10,7 @@ import java.util.List;
public class WorldWorkerManager
{
private static List<IWorker> workers = new ArrayList<IWorker>();
private static final List<IWorker> workers = new ArrayList<>();
private static long startTime = -1;
private static int index = 0;
@@ -13,6 +13,8 @@ import net.minecraft.commands.arguments.selector.EntitySelectorParser;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Allows modders to register custom entity selectors by assigning an {@link IEntitySelectorType} to a String token. <br>
@@ -21,6 +23,7 @@ import java.util.HashMap;
public class EntitySelectorManager
{
private static final HashMap<String, IEntitySelectorType> REGISTRY = new HashMap<>();
private static final List<String> RESERVED_TOKENS = List.of("p", "a", "r", "s", "e");
/**
* Registers a new {@link IEntitySelectorType} for the given {@code token}.<br>
@@ -34,7 +37,7 @@ public class EntitySelectorManager
throw new IllegalArgumentException("Token must not be empty");
}
if (Arrays.asList("p", "a", "r", "s", "e").contains(token))
if (RESERVED_TOKENS.contains(token))
{
throw new IllegalArgumentException("Token clashes with vanilla @" + token);
}
@@ -78,6 +81,10 @@ public class EntitySelectorManager
*/
public static void fillSelectorSuggestions(SuggestionsBuilder suggestionBuilder)
{
REGISTRY.forEach((token, type) -> suggestionBuilder.suggest("@" + token, type.getSuggestionTooltip()));
for (var entry : REGISTRY.entrySet()) {
String token = entry.getKey();
IEntitySelectorType type = entry.getValue();
suggestionBuilder.suggest("@" + token, type.getSuggestionTooltip());
}
}
}
@@ -7,6 +7,7 @@ package net.minecraftforge.common.crafting;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Stream;
@@ -61,10 +62,10 @@ public class ConditionalRecipe {
}
public static class Builder {
private List<InnerRecipe> recipes = new ArrayList<>();
private List<InnerAdvancement> advancements = new ArrayList<>();
private final List<InnerRecipe> recipes = new ArrayList<>();
private final List<InnerAdvancement> advancements = new ArrayList<>();
private RecipeOutput bouncer = new RecipeOutput() {
private final RecipeOutput bouncer = new RecipeOutput() {
@Override
public void accept(ResourceLocation id, Recipe<?> value, @Nullable AdvancementHolder advancement) {
recipe(id, value, advancement);
@@ -221,7 +222,7 @@ public class ConditionalRecipe {
var count = new Holder<Integer>();
count.value = -1;
var ret = stream.map(entry -> accept(context, ops, count, entry))
.filter(entry -> entry != null)
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
@@ -273,7 +274,7 @@ public class ConditionalRecipe {
}
};
private static class Holder<T> {
private static final class Holder<T> {
private T value;
}
}
@@ -59,7 +59,7 @@ public class SimpleCraftingContainer {
int height = this.rows.size();
if (height == 0)
throw new IllegalStateException("Invalid builder, empty inventory");
int width = this.rows.get(0).length();
int width = this.rows.getFirst().length();
var items = NonNullList.withSize(width * height, ItemStack.EMPTY);
int idx = 0;
@@ -35,7 +35,7 @@ public class CompoundIngredient extends AbstractIngredient {
return new CompoundIngredient(Arrays.asList(children));
}
private List<Ingredient> children;
private final List<Ingredient> children;
private ItemStack[] stacks;
private IntList itemIds;
private final boolean isSimple;
@@ -109,7 +109,7 @@ public class PartialNBTIngredient extends AbstractIngredient {
};
public static class Builder {
private List<ItemLike> items = new ArrayList<>();
private final List<ItemLike> items = new ArrayList<>();
private CompoundTag nbt;
public Builder nbt(CompoundTag value) {
@@ -253,10 +253,10 @@ public abstract class SoundDefinitionsProvider implements DataProvider
private CompletableFuture<?> save(final CachedOutput cache, final Path targetFile)
{
return DataProvider.saveStable(cache, this.mapToJson(this.sounds), targetFile);
return DataProvider.saveStable(cache, mapToJson(this.sounds), targetFile);
}
private JsonObject mapToJson(final Map<String, SoundDefinition> map)
private static JsonObject mapToJson(final Map<String, SoundDefinition> map)
{
final JsonObject obj = new JsonObject();
// namespaces are ignored when serializing
@@ -49,7 +49,11 @@ public abstract class SpriteSourceProvider extends JsonCodecProvider<List<Sprite
protected final void gather(BiConsumer<ResourceLocation, List<SpriteSource>> consumer)
{
addSources();
atlases.forEach((atlas, srcList) -> consumer.accept(atlas, srcList.sources));
for (var entry : atlases.entrySet()) {
ResourceLocation atlas = entry.getKey();
SourceList srcList = entry.getValue();
consumer.accept(atlas, srcList.sources);
}
}
protected abstract void addSources();
@@ -11,8 +11,8 @@ import net.minecraft.world.level.ChunkPos;
// Sorter to load nearby chunks first
public class CenterChunkPosComparator implements java.util.Comparator<ChunkPos>
{
private int x;
private int z;
private final int x;
private final int z;
public CenterChunkPosComparator(ServerPlayer entityplayer)
{
@@ -30,7 +30,7 @@ public class ConcatenatedListView<T> implements List<T>
{
return switch (members.size()) {
case 0 -> List.of();
case 1 -> Collections.unmodifiableList(members.get(0));
case 1 -> Collections.unmodifiableList(members.getFirst());
default -> new ConcatenatedListView<>(members);
};
}
@@ -46,7 +46,7 @@ public class HexDumper {
private static final String HEX = "0123456789ABCDEF";
private final int marked;
private final StringBuilder buf;
private char[] ascii = new char[16];
private final char[] ascii = new char[16];
private int index = 0;
private Instance(int marked, int size) {
@@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
public class LevelCapabilityData extends SavedData {
public static final String ID = "capabilities";
private INBTSerializable<CompoundTag> serializable;
private final INBTSerializable<CompoundTag> serializable;
private CompoundTag capNBT = null;
public LevelCapabilityData(@Nullable INBTSerializable<CompoundTag> serializable) {
@@ -325,7 +325,7 @@ public class MutableHashedLinkedMap<K, V> implements Iterable<Map.Entry<K, V>>
Value apply(Key key, Value left, Value right);
}
private class Entry implements Map.Entry<K, V>
private final class Entry implements Map.Entry<K, V>
{
private final K key;
private V value;
@@ -374,7 +374,7 @@ public class MutableHashedLinkedMap<K, V> implements Iterable<Map.Entry<K, V>>
}
}
private static class BasicStrategy implements Strategy<Object> {
private static final class BasicStrategy implements Strategy<Object> {
@Override
public int hashCode(Object o) {
return Objects.hashCode(o);
@@ -386,7 +386,7 @@ public class MutableHashedLinkedMap<K, V> implements Iterable<Map.Entry<K, V>>
}
}
private static class IdentityStrategy implements Strategy<Object> {
private static final class IdentityStrategy implements Strategy<Object> {
@Override
public int hashCode(Object o) {
return System.identityHashCode(o);
@@ -8,6 +8,7 @@ package net.minecraftforge.common.util;
import java.io.IOException;
import java.io.Writer;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
@@ -25,7 +26,7 @@ public class SortedProperties extends Properties {
@Override
public Set<Map.Entry<Object, Object>> entrySet() {
Set<Map.Entry<Object, Object>> ret = new TreeSet<>((left, right) -> left.getKey().toString().compareTo(right.getKey().toString()));
Set<Map.Entry<Object, Object>> ret = new TreeSet<>(Comparator.comparing(entry -> entry.getKey().toString()));
ret.addAll(super.entrySet());
return ret;
}
@@ -125,9 +125,9 @@ public class TextTable
public static class Column
{
private String header;
private final String header;
private int width;
private Alignment alignment;
private final Alignment alignment;
public Column(String header)
{
@@ -302,19 +302,12 @@ public final class TransformationHelper
Quaternionf ret;
try
{
if (entry.getKey().equals("x"))
{
ret = Axis.XP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
}
else if (entry.getKey().equals("y"))
{
ret = Axis.YP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
}
else if (entry.getKey().equals("z"))
{
ret = Axis.ZP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
}
else throw new JsonParseException("Axis rotation: expected single axis key, got: " + entry.getKey());
ret = switch (entry.getKey()) {
case "x" -> Axis.XP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
case "y" -> Axis.YP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
case "z" -> Axis.ZP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
default -> throw new JsonParseException("Axis rotation: expected single axis key, got: " + entry.getKey());
};
}
catch(ClassCastException ex)
{
@@ -17,10 +17,12 @@ public class BiomeGenerationSettingsBuilder extends BiomeGenerationSettings.Plai
{
public BiomeGenerationSettingsBuilder(BiomeGenerationSettings orig)
{
orig.getCarvingStages().forEach(k -> {
for (GenerationStep.Carving k : orig.getCarvingStages()) {
carvers.put(k, new ArrayList<>());
orig.getCarvers(k).forEach(v -> carvers.get(k).add(v));
});
for (Holder<ConfiguredWorldCarver<?>> v : orig.getCarvers(k)) {
carvers.get(k).add(v);
}
}
orig.features().forEach(l -> {
final ArrayList<Holder<PlacedFeature>> featureList = new ArrayList<>();
l.forEach(featureList::add);