diff --git a/README.md b/README.md index 56c6bcdd45..f5859bdb7c 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Progress ------ -- [x] Rectify Forge (38a5400a8) +- [x] Rectify Forge (160f3f88f) - [x] Start patch craftbukkit(bc6a175e) bukkit(f4f2ef4c) spigot(a19903d2) - [x] Beta release - [ ] The nms patch is compatible with mcp diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/EarlyLoadingException.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/EarlyLoadingException.java index 905e609303..56753b54ed 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/EarlyLoadingException.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/EarlyLoadingException.java @@ -29,8 +29,6 @@ */ public class EarlyLoadingException extends RuntimeException { public static class ExceptionData { - - private final IModInfo modInfo; private final String i18message; private final Object[] args; diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/LanguageLoadingProvider.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/LanguageLoadingProvider.java index a8074054d6..a55813f069 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/LanguageLoadingProvider.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/LanguageLoadingProvider.java @@ -170,7 +170,7 @@ public IModLanguageProvider findLanguage(ModFile mf, String modLoader, VersionRa LOGGER.error("Missing language {} version {} wanted by {}", modLoader, modLoaderVersion, languageFileName); throw new EarlyLoadingException("Missing language "+modLoader, null, Collections.singletonList(new EarlyLoadingException.ExceptionData("fml.language.missingversion", modLoader, modLoaderVersion, languageFileName, "null"))); } - if (!modLoaderVersion.containsVersion(mlw.getVersion())) { + if (!VersionSupportMatrix.testVersionSupportMatrix(modLoaderVersion, modLoader, "languageloader", (llid, range) -> range.containsVersion(mlw.getVersion()))) { LOGGER.error("Missing language {} version {} wanted by {}, found {}", modLoader, modLoaderVersion, languageFileName, mlw.getVersion()); throw new EarlyLoadingException("Missing language "+ modLoader + " matching range "+modLoaderVersion + " found "+mlw.getVersion(), null, Collections.singletonList(new EarlyLoadingException.ExceptionData("fml.language.missingversion", modLoader, modLoaderVersion, languageFileName, mlw.getVersion()))); } diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/ModSorter.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/ModSorter.java index aa4d39198f..bb613313e2 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/ModSorter.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/ModSorter.java @@ -36,17 +36,11 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import java.util.AbstractMap; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; +import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; import static net.minecraftforge.fml.loading.LogMarkers.LOADING; @@ -65,26 +59,41 @@ private ModSorter(final List modFiles) public static LoadingModList sort(List mods) { final ModSorter ms = new ModSorter(mods); - EarlyLoadingException earlyLoadingException = null; try { - ms.findLanguages(); ms.buildUniqueList(); - ms.verifyDependencyVersions(); - ms.sort(); - } catch (EarlyLoadingException ele) { - earlyLoadingException = ele; - ms.sortedList = Collections.emptyList(); + } catch (EarlyLoadingException e) { + // We cannot build any list with duped mods. We have to abort immediately and report it + return LoadingModList.of(Collections.emptyList(), Collections.emptyList(), e); + } + // try and locate languages and validate dependencies + List missingLangs = ms.findLanguages(); + List missingDeps = ms.verifyDependencyVersions(); + final List failedList = Stream.concat(missingLangs.stream(), missingDeps.stream()).collect(Collectors.toList()); + // if we miss one or the other, we abort now + if (!failedList.isEmpty()) { + return LoadingModList.of(Collections.emptyList(), Collections.emptyList(), new EarlyLoadingException("failure to validate mod list", null, failedList)); + } else { + // Otherwise, lets try and sort the modlist and proceed + EarlyLoadingException earlyLoadingException = null; try { - ms.buildUniqueList(); - } catch (EarlyLoadingException ele2) { - //IGNORE + ms.sort(); + } catch (EarlyLoadingException e) { + earlyLoadingException = e; } + return LoadingModList.of(ms.modFiles, ms.sortedList, earlyLoadingException); } - return LoadingModList.of(ms.modFiles, ms.sortedList, earlyLoadingException); } - private void findLanguages() { - modFiles.forEach(ModFile::identifyLanguage); + private List findLanguages() { + List errorData = new ArrayList<>(); + modFiles.forEach(modFile -> { + try { + modFile.identifyLanguage(); + } catch (EarlyLoadingException e) { + errorData.addAll(e.getAllData()); + } + }); + return errorData; } @SuppressWarnings("UnstableApiUsage") @@ -218,7 +227,7 @@ private Map.Entry selectNewestModInfo(Map.Entry(fullList.getKey(), modInfoList.get(0)); } - private void verifyDependencyVersions() + private List verifyDependencyVersions() { final Map modVersions = modFiles .stream() @@ -242,24 +251,24 @@ private void verifyDependencyVersions() LOGGER.debug(LOADING, "Found {} mandatory requirements", mandatoryModVersions.size()); final Set missingVersions = mandatoryModVersions .stream() - .filter(mv->this.modVersionMatches(mv, modVersions)) + .filter(mv->this.modVersionNotContained(mv, modVersions)) .collect(Collectors.toSet()); LOGGER.debug(LOADING, "Found {} mandatory mod requirements missing", missingVersions.size()); if (!missingVersions.isEmpty()) { - final List exceptionData = missingVersions + return missingVersions .stream() - .map(mv -> new EarlyLoadingException.ExceptionData("fml.modloading.missingdependency", mv.getOwner(), + .map(mv -> new ExceptionData("fml.modloading.missingdependency", mv.getOwner(), mv.getModId(), mv.getOwner().getModId(), mv.getVersionRange(), modVersions.getOrDefault(mv.getModId(), new DefaultArtifactVersion("null")))) .collect(Collectors.toList()); - throw new EarlyLoadingException("Missing mods", null, exceptionData); } + return Collections.emptyList(); } - private boolean modVersionMatches(final IModInfo.ModVersion mv, final Map modVersions) + private boolean modVersionNotContained(final IModInfo.ModVersion mv, final Map modVersions) { - return !(modVersions.containsKey(mv.getModId()) && - (mv.getVersionRange().containsVersion(modVersions.get(mv.getModId())) || modVersions.get(mv.getModId()).toString().equals("NONE"))); + return !(VersionSupportMatrix.testVersionSupportMatrix(mv.getVersionRange(), mv.getModId(), "mod", (modId, range) -> modVersions.containsKey(modId) && + (range.containsVersion(modVersions.get(modId)) || modVersions.get(modId).toString().equals("NONE")))); } } diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/VersionSupportMatrix.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/VersionSupportMatrix.java new file mode 100644 index 0000000000..737cb6b5ce --- /dev/null +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/VersionSupportMatrix.java @@ -0,0 +1,24 @@ +package net.minecraftforge.fml.loading; + +import net.minecraftforge.forgespi.language.MavenVersionAdapter; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.VersionRange; + +import java.util.HashMap; +import java.util.function.BiPredicate; + +public class VersionSupportMatrix { + private static final HashMap overrideVersions = new HashMap<>(); + static { + final ArtifactVersion version = new DefaultArtifactVersion(FMLLoader.mcVersion); + if (MavenVersionAdapter.createFromVersionSpec("[1.16.4]").containsVersion(version)) { + overrideVersions.put("languageloader.javafml", new DefaultArtifactVersion("34")); // we also work with javafml 34 + overrideVersions.put("mod.minecraft", new DefaultArtifactVersion("1.16.3")); // we work with anything declaring 1.16.3 + overrideVersions.put("mod.forge", new DefaultArtifactVersion("34.1.42")); // we work with anything that supports forge 34.1.42 + } + } + public static boolean testVersionSupportMatrix(VersionRange declaredRange, String lookupId, String type, BiPredicate standardLookup) { + return standardLookup.test(lookupId, declaredRange) || overrideVersions.containsKey(type +"." +lookupId) && declaredRange.containsVersion(overrideVersions.get(type +"." +lookupId)); + } +} diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/log4j/ForgeHighlight.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/log4j/ForgeHighlight.java new file mode 100644 index 0000000000..0f50882da8 --- /dev/null +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/log4j/ForgeHighlight.java @@ -0,0 +1,73 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.fml.loading.log4j; + +import net.minecrell.terminalconsole.HighlightErrorConverter; +import net.minecrell.terminalconsole.TerminalConsoleAppender; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.pattern.ConverterKeys; +import org.apache.logging.log4j.core.pattern.HighlightConverter; +import org.apache.logging.log4j.core.pattern.PatternConverter; +import org.apache.logging.log4j.status.StatusLogger; +import org.apache.logging.log4j.util.PerformanceSensitive; + +import javax.annotation.Nullable; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * A wrapper for {@link HighlightConverter} that auto-disables ANSI when the terminal doesn't support it. + * Ansi support is determined by TerminalConsoleAppender + */ +@Plugin(name = "highlightForge", category = PatternConverter.CATEGORY) +@ConverterKeys("highlightForge") +@PerformanceSensitive("allocation") +public class ForgeHighlight { + protected static final Logger LOGGER = StatusLogger.getLogger(); + + /** + * Gets a new instance of the {@link HighlightErrorConverter} with the + * specified options. + * + * @param config The current configuration + * @param options The pattern options + * @return The new instance + */ + public static @Nullable HighlightConverter newInstance(Configuration config, String[] options) { + try { + Method method = TerminalConsoleAppender.class.getDeclaredMethod("initializeTerminal"); + method.setAccessible(true); + method.invoke(null); + } catch (ReflectiveOperationException e) { + LOGGER.warn("Failed to invoke initializeTerminal on TCA", e); + } + if (!TerminalConsoleAppender.isAnsiSupported() && Arrays.stream(options).noneMatch(s -> s.equals("disableAnsi=true"))) { + List optionList = new ArrayList<>(); + optionList.add(options[0]); + optionList.add("disableAnsi=true"); + options = optionList.toArray(new String[0]); + } + return HighlightConverter.newInstance(config, options); + } +} diff --git a/src/main/java/net/minecraftforge/client/event/ClientPlayerChangeGameModeEvent.java b/src/main/java/net/minecraftforge/client/event/ClientPlayerChangeGameModeEvent.java index a315f84472..64cbd70d7c 100644 --- a/src/main/java/net/minecraftforge/client/event/ClientPlayerChangeGameModeEvent.java +++ b/src/main/java/net/minecraftforge/client/event/ClientPlayerChangeGameModeEvent.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.event; import net.minecraft.client.network.play.NetworkPlayerInfo; diff --git a/src/main/java/net/minecraftforge/client/model/generators/CustomLoaderBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/CustomLoaderBuilder.java index ba5b4f3ed3..d870254b63 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/CustomLoaderBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/CustomLoaderBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/CompositeModelBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/CompositeModelBuilder.java index 65638705cc..57742df792 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/CompositeModelBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/CompositeModelBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/DynamicBucketModelBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/DynamicBucketModelBuilder.java index 2c47b87d7a..99c4765105 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/DynamicBucketModelBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/DynamicBucketModelBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/ItemLayersModelBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/ItemLayersModelBuilder.java index 712ec2e3a3..aaa9c81a32 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/ItemLayersModelBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/ItemLayersModelBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/MultiLayerModelBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/MultiLayerModelBuilder.java index be690db5d6..5a83e0576e 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/MultiLayerModelBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/MultiLayerModelBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/OBJLoaderBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/OBJLoaderBuilder.java index 343dd3c274..255748560d 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/OBJLoaderBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/OBJLoaderBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/SeparatePerspectiveModelBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/SeparatePerspectiveModelBuilder.java index 401b52ab1e..fe7d5c497a 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/SeparatePerspectiveModelBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/SeparatePerspectiveModelBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java index d144982419..60ff7fae5c 100644 --- a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java +++ b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -327,7 +327,7 @@ public static void firePlayerSavingEvent(PlayerEntity player, File playerDirecto public static void firePlayerLoadingEvent(PlayerEntity player, PlayerData playerFileData, String uuidString) { - MinecraftForge.EVENT_BUS.post(new PlayerEvent.LoadFromFile(player, playerFileData.getPlayerDir(), uuidString)); + MinecraftForge.EVENT_BUS.post(new PlayerEvent.LoadFromFile(player, playerFileData.getPlayerDataFolder(), uuidString)); } @Nullable diff --git a/src/main/java/net/minecraftforge/fluids/FluidStack.java b/src/main/java/net/minecraftforge/fluids/FluidStack.java index cf364bd156..3a3dbcf98a 100644 --- a/src/main/java/net/minecraftforge/fluids/FluidStack.java +++ b/src/main/java/net/minecraftforge/fluids/FluidStack.java @@ -19,12 +19,15 @@ package net.minecraftforge.fluids; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.Registry; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.util.Constants; import net.minecraftforge.registries.ForgeRegistries; @@ -36,6 +39,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Optional; + /** * ItemStack substitute for Fluids. * @@ -50,6 +55,18 @@ public class FluidStack public static final FluidStack EMPTY = new FluidStack(Fluids.EMPTY, 0); + public static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + Registry.FLUID.fieldOf("FluidName").forGetter(FluidStack::getFluid), + Codec.INT.fieldOf("Amount").forGetter(FluidStack::getAmount), + CompoundNBT.CODEC.optionalFieldOf("Tag").forGetter(stack -> Optional.ofNullable(stack.getTag())) + ).apply(instance, (fluid, amount, tag) -> { + FluidStack stack = new FluidStack(fluid, amount); + tag.ifPresent(stack::setTag); + return stack; + }) + ); + private boolean isEmpty; private int amount; private CompoundNBT tag; diff --git a/src/main/java/net/minecraftforge/registries/ForgeRegistry.java b/src/main/java/net/minecraftforge/registries/ForgeRegistry.java index e474ea2b41..3af4d89937 100644 --- a/src/main/java/net/minecraftforge/registries/ForgeRegistry.java +++ b/src/main/java/net/minecraftforge/registries/ForgeRegistry.java @@ -841,7 +841,7 @@ Map getOverrideOwners() public static class Snapshot { - private static final Comparator sorter = (a, b) -> a.compareNamespaced(b); + private static final Comparator sorter = (a,b) -> a.compareNamespaced(b); public final Map ids = Maps.newTreeMap(sorter); public final Map aliases = Maps.newTreeMap(sorter); public final Set blocked = Sets.newTreeSet();