mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
[1.18.2] Fix tags for custom forge registries. (#8495)
Tag-enabled registries must now be registered to vanilla's root registry. See RegistryBuilder#hasTags. Modded tag-enabled registries have to use the format `data/<namespace>/tags/<registrynamespace>/<registryname>/<tag>.json` This format is to prevent conflicts for registries with the same path but different namespaces EX: Registry name `examplemod:shoe`, tag name `blue_shoes` would be `data/<namespace>/tags/examplemod/shoe/blue_shoes.json` RegistryEvent.NewRegistry has been moved and renamed to NewRegistryEvent. RegistryBuilder#create has been made private. See NewRegistryEvent#create Created new ITagManager system for looking up Forge tags. See IForgeRegistry#tags. Add lookup methods for Holders from forge registries. See IForgeRegistry#getHolder.
This commit is contained in:
1 parent
30f3a7dbba
commit
ad75cb8644
51 files changed
+1621
-531
No files matched your search
+15
-6
@@ -8,8 +8,10 @@ package net.minecraftforge.network.filters;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -17,6 +19,7 @@ import io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypes;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.game.ClientboundCommandsPacket;
|
||||
@@ -25,15 +28,15 @@ import net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagNetworkSerialization;
|
||||
import net.minecraftforge.common.ForgeTagHandler;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.brigadier.tree.RootCommandNode;
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
||||
/**
|
||||
* A filter for impl packets, used to filter/modify parts of vanilla impl messages that
|
||||
@@ -42,8 +45,7 @@ import com.mojang.brigadier.tree.RootCommandNode;
|
||||
@ChannelHandler.Sharable
|
||||
public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
|
||||
{
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
public VanillaConnectionNetworkFilter()
|
||||
{
|
||||
@@ -100,8 +102,15 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
|
||||
*/
|
||||
private static ClientboundUpdateTagsPacket filterCustomTagTypes(ClientboundUpdateTagsPacket packet) {
|
||||
Map<ResourceKey<? extends Registry<?>>, TagNetworkSerialization.NetworkPayload> tags = packet.getTags()
|
||||
.entrySet().stream().filter(e -> !ForgeTagHandler.getCustomTagTypeNames().contains(e.getKey().location()))
|
||||
.entrySet().stream().filter(e -> isVanillaRegistry(e.getKey().location()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
return new ClientboundUpdateTagsPacket(tags);
|
||||
}
|
||||
|
||||
private static boolean isVanillaRegistry(ResourceLocation location)
|
||||
{
|
||||
// Checks if the registry name is contained within the static view of vanilla registries both in Registry and builtin registries
|
||||
return RegistryManager.getVanillaRegistryKeys().contains(location)
|
||||
|| RegistryAccess.REGISTRIES.keySet().stream().anyMatch(k -> k.location().equals(location));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user