mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-22 21:20:12 +00:00
Cleanup Tag Loading, this migrates thins to more of a vanilla style. (#7898)
This commit is contained in:
1 parent
a336e443f7
commit
d17f10d80c
27 files changed
+178
-590
No files matched your search
@@ -77,19 +77,11 @@
|
||||
if (mobeffect != null) {
|
||||
MobEffectInstance mobeffectinstance = new MobEffectInstance(mobeffect, p_105130_.m_133625_(), p_105130_.m_133624_(), p_105130_.m_133627_(), p_105130_.m_133626_(), p_105130_.m_133628_());
|
||||
mobeffectinstance.m_19562_(p_105130_.m_133619_());
|
||||
@@ -1228,11 +_,14 @@
|
||||
public void m_5859_(ClientboundUpdateTagsPacket p_105134_) {
|
||||
PacketUtils.m_131363_(p_105134_, this, this.f_104888_);
|
||||
TagContainer tagcontainer = TagContainer.m_144449_(this.f_104903_, p_105134_.m_179482_());
|
||||
- Multimap<ResourceKey<? extends Registry<?>>, ResourceLocation> multimap = StaticTags.m_13283_(tagcontainer);
|
||||
+ boolean vanillaConnection = net.minecraftforge.fmllegacy.network.NetworkHooks.isVanillaConnection(f_104885_);
|
||||
+ Multimap<ResourceKey<? extends Registry<?>>, ResourceLocation> multimap = vanillaConnection ? StaticTags.m_13283_(net.minecraftforge.common.ForgeTagHandler.withNoCustom(tagcontainer)) : StaticTags.validateVanillaTags(tagcontainer);//Forge: If we are connecting to vanilla validate all tags to properly validate custom tags the client may "require", and if we are connecting to forge only validate the vanilla tag types as the custom tag types get synced in a separate packet so may still arrive
|
||||
if (!multimap.isEmpty()) {
|
||||
@@ -1233,6 +_,7 @@
|
||||
f_104883_.warn("Incomplete server tags, disconnecting. Missing: {}", (Object)multimap);
|
||||
this.f_104885_.m_129507_(new TranslatableComponent("multiplayer.disconnect.missing_tags"));
|
||||
} else {
|
||||
+ net.minecraftforge.common.ForgeTagHandler.resetCachedTagCollections(true, vanillaConnection);
|
||||
+ tagcontainer = TagContainer.reinjectOptionalTags(tagcontainer);
|
||||
+ tagcontainer = net.minecraftforge.common.ForgeTagHandler.reinjectOptionalTags(tagcontainer);
|
||||
this.f_104895_ = tagcontainer;
|
||||
if (!this.f_104885_.m_129531_()) {
|
||||
tagcontainer.m_13431_();
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
--- a/net/minecraft/data/tags/GameEventTagsProvider.java
|
||||
+++ b/net/minecraft/data/tags/GameEventTagsProvider.java
|
||||
@@ -8,8 +_,12 @@
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
|
||||
public class GameEventTagsProvider extends TagsProvider<GameEvent> {
|
||||
+ @Deprecated
|
||||
public GameEventTagsProvider(DataGenerator p_176826_) {
|
||||
super(p_176826_, Registry.f_175412_);
|
||||
+ }
|
||||
+ public GameEventTagsProvider(DataGenerator p_126517_, String modId, @javax.annotation.Nullable net.minecraftforge.common.data.ExistingFileHelper existingFileHelper) {
|
||||
+ super(p_126517_, Registry.f_175412_, modId, existingFileHelper);
|
||||
}
|
||||
|
||||
protected void m_6577_() {
|
||||
@@ -8,11 +8,3 @@
|
||||
}
|
||||
|
||||
public ServerFunctionLibrary m_136157_() {
|
||||
@@ -94,6 +_,7 @@
|
||||
|
||||
public void m_136179_() {
|
||||
this.f_136148_.m_13480_().m_13431_();
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.TagsUpdatedEvent.CustomTagTypes(f_136148_.m_13480_()));
|
||||
}
|
||||
|
||||
public void close() {
|
||||
@@ -16,17 +16,14 @@
|
||||
GameRules gamerules = serverlevel1.m_46469_();
|
||||
boolean flag = gamerules.m_46207_(GameRules.f_46156_);
|
||||
boolean flag1 = gamerules.m_46207_(GameRules.f_46145_);
|
||||
@@ -158,8 +_,10 @@
|
||||
@@ -158,6 +_,7 @@
|
||||
servergamepacketlistenerimpl.m_141995_(new ClientboundChangeDifficultyPacket(leveldata.m_5472_(), leveldata.m_5474_()));
|
||||
servergamepacketlistenerimpl.m_141995_(new ClientboundPlayerAbilitiesPacket(p_11263_.m_150110_()));
|
||||
servergamepacketlistenerimpl.m_141995_(new ClientboundSetCarriedItemPacket(p_11263_.m_150109_().f_35977_));
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.OnDatapackSyncEvent(this, p_11263_));
|
||||
servergamepacketlistenerimpl.m_141995_(new ClientboundUpdateRecipesPacket(this.f_11195_.m_129894_().m_44051_()));
|
||||
servergamepacketlistenerimpl.m_141995_(new ClientboundUpdateTagsPacket(this.f_11195_.m_129895_().m_144442_(this.f_11206_)));
|
||||
+ net.minecraftforge.fmllegacy.network.NetworkHooks.syncCustomTagTypes(p_11263_, this.f_11195_.m_129895_());
|
||||
this.m_11289_(p_11263_);
|
||||
p_11263_.m_8951_().m_12850_();
|
||||
p_11263_.m_8952_().m_12789_(p_11263_);
|
||||
@@ -174,7 +_,7 @@
|
||||
|
||||
this.m_11264_(mutablecomponent.m_130940_(ChatFormatting.YELLOW), ChatType.SYSTEM, Util.f_137441_);
|
||||
@@ -113,16 +110,14 @@
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -785,7 +_,9 @@
|
||||
@@ -785,6 +_,7 @@
|
||||
playeradvancements.m_135981_(this.f_11195_.m_129889_());
|
||||
}
|
||||
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.OnDatapackSyncEvent(this, null));
|
||||
this.m_11268_(new ClientboundUpdateTagsPacket(this.f_11195_.m_129895_().m_144442_(this.f_11206_)));
|
||||
+ net.minecraftforge.fmllegacy.network.NetworkHooks.syncCustomTagTypes(this.f_11195_.m_129895_());
|
||||
ClientboundUpdateRecipesPacket clientboundupdaterecipespacket = new ClientboundUpdateRecipesPacket(this.f_11195_.m_129894_().m_44051_());
|
||||
|
||||
for(ServerPlayer serverplayer : this.f_11196_) {
|
||||
@@ -797,5 +_,13 @@
|
||||
|
||||
public boolean m_11316_() {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
--- a/net/minecraft/tags/GameEventTags.java
|
||||
+++ b/net/minecraft/tags/GameEventTags.java
|
||||
@@ -12,6 +_,14 @@
|
||||
return f_144301_.m_13244_(p_144308_);
|
||||
}
|
||||
|
||||
+ public static net.minecraftforge.common.Tags.IOptionalNamedTag<GameEvent> createOptional(net.minecraft.resources.ResourceLocation name) {
|
||||
+ return createOptional(name, null);
|
||||
+ }
|
||||
+
|
||||
+ public static net.minecraftforge.common.Tags.IOptionalNamedTag<GameEvent> createOptional(net.minecraft.resources.ResourceLocation name, @javax.annotation.Nullable java.util.Set<java.util.function.Supplier<GameEvent>> defaults) {
|
||||
+ return f_144301_.createOptional(name, defaults);
|
||||
+ }
|
||||
+
|
||||
public static TagCollection<GameEvent> m_144306_() {
|
||||
return f_144301_.m_13246_();
|
||||
}
|
||||
@@ -4,11 +4,11 @@
|
||||
private final String f_144327_;
|
||||
private TagCollection<T> f_13227_ = TagCollection.m_13410_();
|
||||
private final List<StaticTagHelper.Wrapper<T>> f_13228_ = Lists.newArrayList();
|
||||
+ private static java.util.Map<ResourceLocation, List<StaticTagHelper.Wrapper<?>>> toAdd = com.google.common.collect.Maps.newHashMap();
|
||||
+ @Nullable private static java.util.Map<ResourceLocation, List<StaticTagHelper.Wrapper<?>>> toAdd = com.google.common.collect.Maps.newHashMap();
|
||||
|
||||
public StaticTagHelper(ResourceKey<? extends Registry<T>> p_144329_, String p_144330_) {
|
||||
this.f_144326_ = p_144329_;
|
||||
@@ -24,9 +_,46 @@
|
||||
@@ -24,9 +_,60 @@
|
||||
}
|
||||
|
||||
public Tag.Named<T> m_13244_(String p_13245_) {
|
||||
@@ -55,13 +55,8 @@
|
||||
+ namedtag.m_13260_(f_13227_::m_13404_);
|
||||
+ this.f_13228_.add(namedtag);
|
||||
+ return namedtag;
|
||||
}
|
||||
|
||||
public void m_13232_() {
|
||||
@@ -47,13 +_,31 @@
|
||||
});
|
||||
}
|
||||
|
||||
+ }
|
||||
+
|
||||
+ public TagCollection<T> reinjectOptionalTags(TagCollection<T> tagCollection) {
|
||||
+ java.util.Map<ResourceLocation, Tag<T>> currentTags = tagCollection.m_5643_();
|
||||
+ java.util.Map<ResourceLocation, Tag<T>> missingOptionals = this.f_13228_.stream().filter(e -> e instanceof OptionalNamedTag && !currentTags.containsKey(e.m_6979_())).collect(Collectors.toMap(Wrapper::m_6979_, namedTag -> {
|
||||
@@ -74,16 +69,11 @@
|
||||
+ return TagCollection.m_13396_(missingOptionals);
|
||||
+ }
|
||||
+ return tagCollection;
|
||||
+ }
|
||||
+
|
||||
public TagCollection<T> m_13246_() {
|
||||
return this.f_13227_;
|
||||
}
|
||||
|
||||
+ public List<? extends Tag.Named<T>> getWrappers() {
|
||||
+ return this.f_13228_;
|
||||
+ }
|
||||
+
|
||||
public void m_13232_() {
|
||||
@@ -53,7 +_,7 @@
|
||||
|
||||
public Set<ResourceLocation> m_13247_(TagContainer p_13248_) {
|
||||
TagCollection<T> tagcollection = p_13248_.m_144452_(this.f_144326_);
|
||||
- Set<ResourceLocation> set = this.f_13228_.stream().map(StaticTagHelper.Wrapper::m_6979_).collect(Collectors.toSet());
|
||||
@@ -108,7 +98,7 @@
|
||||
+
|
||||
+ @Override
|
||||
+ public String toString() {
|
||||
+ return "NamedTag[" + m_6979_().toString() + ']';
|
||||
+ return "NamedTag[" + m_6979_() + ']';
|
||||
+ }
|
||||
+ @Override public boolean equals(Object o) { return (o == this) || (o instanceof Tag.Named && java.util.Objects.equals(this.m_6979_(), ((Tag.Named<T>)o).m_6979_())); }
|
||||
+ @Override public int hashCode() { return m_6979_().hashCode(); }
|
||||
@@ -138,7 +128,7 @@
|
||||
+
|
||||
+ @Override
|
||||
+ public String toString() {
|
||||
+ return "OptionalNamedTag[" + m_6979_().toString() + ']';
|
||||
+ return "OptionalNamedTag[" + m_6979_() + ']';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,42 +21,20 @@
|
||||
return statictaghelper;
|
||||
}
|
||||
}
|
||||
@@ -55,11 +_,29 @@
|
||||
|
||||
private static void m_144356_() {
|
||||
Set<ResourceKey<?>> set = m_144355_().stream().map(StaticTagHelper::m_144338_).collect(Collectors.toSet());
|
||||
- if (!Sets.difference(f_144340_, set).isEmpty()) {
|
||||
+ if (!Sets.difference(set, f_144340_).isEmpty()) { // Forge: Fix bug with extra tag collections crashing
|
||||
throw new IllegalStateException("Missing helper registrations");
|
||||
}
|
||||
@@ -54,10 +_,16 @@
|
||||
}
|
||||
|
||||
private static void m_144356_() {
|
||||
+ if (true) { m_144355_(); return; } //FORGE this check is unnecessary as the 2 collections are patched back into a map above. Still need to 'clinit' them though.
|
||||
Set<ResourceKey<?>> set = m_144355_().stream().map(StaticTagHelper::m_144338_).collect(Collectors.toSet());
|
||||
if (!Sets.difference(f_144340_, set).isEmpty()) {
|
||||
throw new IllegalStateException("Missing helper registrations");
|
||||
}
|
||||
+ }
|
||||
+
|
||||
+ @javax.annotation.Nullable
|
||||
+ public static StaticTagHelper<?> get(ResourceLocation rl) {
|
||||
+ return HELPER_MAP.get(ResourceKey.m_135788_(rl));
|
||||
+ }
|
||||
+
|
||||
+ public static Multimap<ResourceKey<? extends Registry<?>>, ResourceLocation> validateVanillaTags(TagContainer tagCollectionSupplier) {
|
||||
+ Multimap<ResourceKey<? extends Registry<?>>, ResourceLocation> multimap = HashMultimap.create();
|
||||
+ f_13264_.forEach((tagHelper) -> {
|
||||
+ if (!net.minecraftforge.common.ForgeTagHandler.getCustomTagTypeNames().contains(tagHelper.m_144338_().m_135782_()))
|
||||
+ multimap.putAll(tagHelper.m_144338_(), tagHelper.m_13247_(tagCollectionSupplier));
|
||||
+ });
|
||||
+ return multimap;
|
||||
+ }
|
||||
+
|
||||
+ public static void fetchCustomTagTypes(TagContainer tagCollectionSupplier) {
|
||||
+ net.minecraftforge.common.ForgeTagHandler.getCustomTagTypeNames().forEach(tagRegistry -> HELPER_MAP.get(ResourceKey.m_135788_(tagRegistry)).m_13242_(tagCollectionSupplier));
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
public static void m_144349_(Consumer<StaticTagHelper<?>> p_144350_) {
|
||||
f_13264_.forEach(p_144350_);
|
||||
}
|
||||
@@ -70,6 +_,7 @@
|
||||
f_13264_.forEach((p_144344_) -> {
|
||||
p_144344_.m_144336_(tagcontainer$builder);
|
||||
});
|
||||
+ net.minecraftforge.common.ForgeTagHandler.populateTagCollectionManager();
|
||||
return tagcontainer$builder.m_144485_();
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,18 @@
|
||||
--- a/net/minecraft/tags/TagContainer.java
|
||||
+++ b/net/minecraft/tags/TagContainer.java
|
||||
@@ -15,7 +_,7 @@
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
-public class TagContainer {
|
||||
+public class TagContainer implements net.minecraftforge.common.extensions.IForgeTagContainer {
|
||||
static final Logger f_144432_ = LogManager.getLogger();
|
||||
public static final TagContainer f_13420_ = new TagContainer(ImmutableMap.of());
|
||||
public final Map<ResourceKey<? extends Registry<?>>, TagCollection<?>> f_144433_;
|
||||
@@ -74,6 +_,7 @@
|
||||
public void m_13431_() {
|
||||
StaticTags.m_13269_(this);
|
||||
Blocks.m_50758_();
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.TagsUpdatedEvent.VanillaTagTypes(this));
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.TagsUpdatedEvent(this));
|
||||
}
|
||||
|
||||
public Map<ResourceKey<? extends Registry<?>>, TagCollection.NetworkPayload> m_144442_(final RegistryAccess p_144443_) {
|
||||
@@ -108,6 +_,13 @@
|
||||
f_144432_.error("Unknown registry {}", (Object)p_144447_);
|
||||
}
|
||||
|
||||
+ }
|
||||
+
|
||||
+ public static TagContainer reinjectOptionalTags(TagContainer tagCollectionSupplier) {
|
||||
+ TagContainer.Builder builder = new TagContainer.Builder();
|
||||
+ //noinspection unchecked,rawtypes
|
||||
+ StaticTags.m_144349_(h -> builder.m_144486_(h.m_144338_(), h.reinjectOptionalTags(tagCollectionSupplier.m_144452_((ResourceKey) h.m_144338_()))));
|
||||
+ return builder.m_144485_();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@@ -81,6 +_,7 @@
|
||||
this.m_144436_(new TagContainer.CollectionConsumer() {
|
||||
public <T> void m_142574_(ResourceKey<? extends Registry<T>> p_144481_, TagCollection<T> p_144482_) {
|
||||
Optional<? extends Registry<T>> optional = p_144443_.m_6632_(p_144481_);
|
||||
+ optional = net.minecraftforge.common.ForgeTagHandler.getWrapperRegistry(p_144481_, optional);
|
||||
if (optional.isPresent()) {
|
||||
map.put(p_144481_, p_144482_.m_144411_(optional.get()));
|
||||
} else {
|
||||
@@ -8,34 +8,20 @@
|
||||
private TagContainer f_13478_ = TagContainer.f_13420_;
|
||||
|
||||
public TagManager(RegistryAccess p_144572_) {
|
||||
@@ -40,15 +_,16 @@
|
||||
}
|
||||
|
||||
});
|
||||
- return CompletableFuture.allOf(list.stream().map((p_144591_) -> {
|
||||
- return p_144591_.f_144598_;
|
||||
- }).toArray((p_144574_) -> {
|
||||
- return new CompletableFuture[p_144574_];
|
||||
- })).thenCompose(p_13482_::m_6769_).thenAcceptAsync((p_144594_) -> {
|
||||
+ CompletableFuture<java.util.List<net.minecraftforge.common.ForgeTagHandler.TagCollectionReaderInfo>> customTagTypeResults = net.minecraftforge.common.ForgeTagHandler.getCustomTagTypeReloadResults(p_13483_, p_13486_, customTagTypeReaders);
|
||||
+ List<CompletableFuture<?>> futures = Lists.newArrayList();
|
||||
+ list.stream().map(li -> li.f_144598_).forEach(futures::add);
|
||||
+ futures.add(customTagTypeResults);
|
||||
+ return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new)).thenCompose(p_13482_::m_6769_).thenAcceptAsync((p_144594_) -> {
|
||||
TagContainer.Builder tagcontainer$builder = new TagContainer.Builder();
|
||||
list.forEach((p_144586_) -> {
|
||||
p_144586_.m_144602_(tagcontainer$builder);
|
||||
});
|
||||
+ net.minecraftforge.common.ForgeTagHandler.updateCustomTagTypes(customTagTypeResults.join());
|
||||
TagContainer tagcontainer = tagcontainer$builder.m_144485_();
|
||||
Multimap<ResourceKey<? extends Registry<?>>, ResourceLocation> multimap = StaticTags.m_13283_(tagcontainer);
|
||||
if (!multimap.isEmpty()) {
|
||||
@@ -56,6 +_,8 @@
|
||||
@@ -56,6 +_,7 @@
|
||||
return p_144596_.getKey() + ":" + p_144596_.getValue();
|
||||
}).sorted().collect(Collectors.joining(",")));
|
||||
} else {
|
||||
+ tagcontainer = TagContainer.reinjectOptionalTags(tagcontainer);
|
||||
+ net.minecraftforge.common.ForgeTagHandler.reinjectOptionalTagsCustomTypes();
|
||||
+ tagcontainer = net.minecraftforge.common.ForgeTagHandler.reinjectOptionalTags(tagcontainer);
|
||||
SerializationTags.m_13202_(tagcontainer);
|
||||
this.f_13478_ = tagcontainer;
|
||||
}
|
||||
@@ -73,6 +_,8 @@
|
||||
}, p_144577_);
|
||||
return new TagManager.LoaderInfo<>(p_144578_, completablefuture);
|
||||
} else {
|
||||
+ if (net.minecraftforge.common.ForgeTagHandler.getCustomTagTypeNames().contains(p_144578_.m_144338_().m_135782_()))
|
||||
+ return new TagManager.LoaderInfo<>(p_144578_, CompletableFuture.supplyAsync(() -> ((TagLoader<T>) customTagTypeReaders.get(p_144578_.m_144338_().m_135782_())).m_144544_(p_144576_), p_144577_));
|
||||
f_144568_.warn("Can't find registry for {}", (Object)p_144578_.m_144338_());
|
||||
return null;
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
-public class Potion {
|
||||
+public class Potion extends net.minecraftforge.registries.ForgeRegistryEntry<Potion> {
|
||||
+ private final net.minecraftforge.common.util.ReverseTagWrapper<Potion> reverseTags = new net.minecraftforge.common.util.ReverseTagWrapper<Potion>(this, () -> net.minecraft.tags.SerializationTags.m_13199_().m_144452_(Registry.f_122905_));
|
||||
+ private final net.minecraftforge.common.util.ReverseTagWrapper<Potion> reverseTags = new net.minecraftforge.common.util.ReverseTagWrapper<>(this, () -> net.minecraft.tags.SerializationTags.m_13199_().m_144452_(Registry.f_122905_));
|
||||
private final String f_43481_;
|
||||
private final ImmutableList<MobEffectInstance> f_43482_;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
-public abstract class Enchantment {
|
||||
+public abstract class Enchantment extends net.minecraftforge.registries.ForgeRegistryEntry<Enchantment> {
|
||||
+ private final net.minecraftforge.common.util.ReverseTagWrapper<Enchantment> reverseTags = new net.minecraftforge.common.util.ReverseTagWrapper<>(this, () -> net.minecraft.tags.SerializationTags.m_13199_().getCustomTypeCollection(net.minecraftforge.registries.ForgeRegistries.ENCHANTMENTS));
|
||||
+ private final net.minecraftforge.common.util.ReverseTagWrapper<Enchantment> reverseTags = new net.minecraftforge.common.util.ReverseTagWrapper<>(this, () -> net.minecraft.tags.SerializationTags.m_13199_().m_144452_(net.minecraftforge.registries.ForgeRegistries.Keys.ENCHANTMENTS));
|
||||
private final EquipmentSlot[] f_44671_;
|
||||
private final Enchantment.Rarity f_44674_;
|
||||
public final EnchantmentCategory f_44672_;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
private final BlockEntityType.BlockEntitySupplier<? extends T> f_58914_;
|
||||
private final Set<Block> f_58915_;
|
||||
private final Type<?> f_58916_;
|
||||
+ private final net.minecraftforge.common.util.ReverseTagWrapper<BlockEntityType<?>> reverseTags = new net.minecraftforge.common.util.ReverseTagWrapper<>(this, () -> net.minecraft.tags.SerializationTags.m_13199_().getCustomTypeCollection(net.minecraftforge.registries.ForgeRegistries.BLOCK_ENTITIES));
|
||||
+ private final net.minecraftforge.common.util.ReverseTagWrapper<BlockEntityType<?>> reverseTags = new net.minecraftforge.common.util.ReverseTagWrapper<>(this, () -> net.minecraft.tags.SerializationTags.m_13199_().m_144452_(net.minecraftforge.registries.ForgeRegistries.Keys.BLOCK_ENTITY_TYPES));
|
||||
|
||||
@Nullable
|
||||
public static ResourceLocation m_58954_(BlockEntityType<?> p_58955_) {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
--- a/net/minecraft/world/level/gameevent/GameEvent.java
|
||||
+++ b/net/minecraft/world/level/gameevent/GameEvent.java
|
||||
@@ -51,10 +_,15 @@
|
||||
public static final int f_157788_ = 16;
|
||||
private final String f_157789_;
|
||||
private final int f_157790_;
|
||||
+ private final net.minecraftforge.common.util.ReverseTagWrapper<GameEvent> reverseTags = new net.minecraftforge.common.util.ReverseTagWrapper<>(this, net.minecraft.tags.GameEventTags::m_144306_);
|
||||
|
||||
public GameEvent(String p_157819_, int p_157820_) {
|
||||
this.f_157789_ = p_157819_;
|
||||
this.f_157790_ = p_157820_;
|
||||
+ }
|
||||
+
|
||||
+ public java.util.Set<net.minecraft.resources.ResourceLocation> getTags() {
|
||||
+ return reverseTags.getTagNames();
|
||||
}
|
||||
|
||||
public String m_157821_() {
|
||||
+2
-1
@@ -3,6 +3,7 @@
|
||||
"values": [
|
||||
"minecraft:barrel",
|
||||
"minecraft:chest",
|
||||
"minecraft:ender_chest"
|
||||
"minecraft:ender_chest",
|
||||
"minecraft:trapped_chest"
|
||||
]
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public class ForgeInternalHandler
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public synchronized void tagsUpdated(TagsUpdatedEvent.VanillaTagTypes event)
|
||||
public synchronized void tagsUpdated(TagsUpdatedEvent event)
|
||||
{
|
||||
ForgeHooks.updateBurns();
|
||||
}
|
||||
|
||||
@@ -21,31 +21,25 @@ package net.minecraftforge.common;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.Tag.Named;
|
||||
import net.minecraft.tags.TagCollection;
|
||||
import net.minecraft.tags.TagContainer;
|
||||
import net.minecraft.tags.TagLoader;
|
||||
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.tags.StaticTagHelper;
|
||||
import net.minecraft.tags.StaticTags;
|
||||
import net.minecraft.tags.Tag.Named;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagContainer;
|
||||
import net.minecraft.tags.TagLoader;
|
||||
import net.minecraftforge.common.Tags.IOptionalNamedTag;
|
||||
import net.minecraftforge.common.extensions.IForgeTagContainer;
|
||||
import net.minecraftforge.fmllegacy.network.FMLPlayMessages.SyncCustomTagTypes;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
@@ -55,20 +49,19 @@ import org.apache.logging.log4j.Logger;
|
||||
public class ForgeTagHandler
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static Map<ResourceLocation, TagCollection<?>> customTagTypes = Collections.emptyMap();
|
||||
private static Set<ResourceLocation> customTagTypeNames = Collections.emptySet();
|
||||
private static boolean tagTypesSet = false;
|
||||
|
||||
@Nullable
|
||||
private static <T extends IForgeRegistryEntry<T>> StaticTagHelper<T> getTagRegistry(IForgeRegistry<T> registry)
|
||||
private static <T extends IForgeRegistryEntry<T>> StaticTagHelper<T> getTagHelper(IForgeRegistry<T> registry)
|
||||
{
|
||||
return (StaticTagHelper<T>) StaticTags.get(registry.getRegistryName());
|
||||
}
|
||||
|
||||
private static void validateRegistrySupportsTags(IForgeRegistry<?> registry)
|
||||
{
|
||||
//Note: We also check against getTagRegistry in case someone decides to use the helpers for tag creation for types supported by vanilla
|
||||
if (getTagRegistry(registry) == null && (!(registry instanceof ForgeRegistry) || ((ForgeRegistry<?>) registry).getTagFolder() == null))
|
||||
//Note: We also check against getTagHelper in case someone decides to use the helpers for tag creation for types supported by vanilla
|
||||
if (getTagHelper(registry) == null && (!(registry instanceof ForgeRegistry) || ((ForgeRegistry<?>) registry).getTagFolder() == null))
|
||||
{
|
||||
throw new IllegalArgumentException("Registry " + registry.getRegistryName() + " does not support tag types.");
|
||||
}
|
||||
@@ -88,7 +81,7 @@ public class ForgeTagHandler
|
||||
validateRegistrySupportsTags(registry);
|
||||
if (tagTypesSet)
|
||||
{
|
||||
StaticTagHelper<T> tagRegistry = getTagRegistry(registry);
|
||||
StaticTagHelper<T> tagRegistry = getTagHelper(registry);
|
||||
if (tagRegistry == null) throw new IllegalArgumentException("Registry " + registry.getRegistryName() + " does not support tag types.");
|
||||
return tagRegistry.bind(name.toString());
|
||||
}
|
||||
@@ -124,7 +117,7 @@ public class ForgeTagHandler
|
||||
validateRegistrySupportsTags(registry);
|
||||
if (tagTypesSet)
|
||||
{
|
||||
StaticTagHelper<T> tagRegistry = getTagRegistry(registry);
|
||||
StaticTagHelper<T> tagRegistry = getTagHelper(registry);
|
||||
if (tagRegistry == null) throw new IllegalArgumentException("Registry " + registry.getRegistryName() + " does not support tag types.");
|
||||
return tagRegistry.createOptional(name, defaults);
|
||||
}
|
||||
@@ -197,27 +190,17 @@ public class ForgeTagHandler
|
||||
return customTagTypeNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a map of registry name to tag collection for all custom tag types.
|
||||
*
|
||||
* @apiNote Prefer interacting with this via the current {@link IForgeTagContainer} and using one of the forge extension getCustomTypeCollection methods
|
||||
*/
|
||||
public static Map<ResourceLocation, TagCollection<?>> getCustomTagTypes()
|
||||
{
|
||||
return customTagTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the set containing the resource locations representing the registry name of each forge registry that supports custom tag types.
|
||||
*
|
||||
* @apiNote Internal: Calling this manually <strong>WILL</strong> cause a crash to occur as it can only be called once, and is done so by
|
||||
* forge after all registries have been initialized.
|
||||
*/
|
||||
public static void setCustomTagTypes(Set<ResourceLocation> customTagTypes)
|
||||
public static void setCustomTagTypes(Set<ResourceLocation> customTagTypesNames)
|
||||
{
|
||||
if (tagTypesSet) throw new RuntimeException("Custom tag types have already been set, this method should only be called by forge, and after registries are initialized");
|
||||
tagTypesSet = true;
|
||||
customTagTypeNames = ImmutableSet.copyOf(customTagTypes);
|
||||
customTagTypeNames = ImmutableSet.copyOf(customTagTypesNames);
|
||||
//Add the static references for custom tag types to the proper tag registries
|
||||
// Note: If this ends up being a hotspot due to lots of mods having lots of statically registered tags
|
||||
// that get loaded/registered before the new registry event is fired/processed everywhere then this
|
||||
@@ -228,7 +211,7 @@ public class ForgeTagHandler
|
||||
/**
|
||||
* Creates a map for custom tag type to tag reader
|
||||
*
|
||||
* @apiNote Internal: For use by NetworkTagManager
|
||||
* @apiNote Internal: For use by TagManager
|
||||
*/
|
||||
public static Map<ResourceLocation, TagLoader<?>> createCustomTagTypeReaders()
|
||||
{
|
||||
@@ -246,166 +229,35 @@ public class ForgeTagHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the cached collections for the various custom tag types.
|
||||
* Wraps the forge registry if it supports tags into the internal registry for use in serialization
|
||||
*
|
||||
* @apiNote Internal: For use in TagContainer
|
||||
*/
|
||||
@SuppressWarnings({"OptionalUsedAsFieldOrParameterType", "unchecked"})
|
||||
public static <T> Optional<? extends Registry<T>> getWrapperRegistry(ResourceKey<? extends Registry<T>> key, Optional<? extends Registry<T>> vanillaReg)
|
||||
{
|
||||
if (vanillaReg.isPresent())
|
||||
return vanillaReg;
|
||||
|
||||
ForgeRegistry<?> reg = RegistryManager.ACTIVE.getRegistry(key.location());
|
||||
if (reg == null || reg.getTagFolder() == null)
|
||||
return Optional.empty();
|
||||
|
||||
if (reg.getDefaultKey() == null)
|
||||
return Optional.of((Registry<T>) GameData.getWrapper(reg.getRegistryKey(), Lifecycle.stable()));
|
||||
return Optional.of((Registry<T>) GameData.getWrapper(reg.getRegistryKey(), Lifecycle.stable(), "ignored"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to reinject missing optional tags.
|
||||
*
|
||||
* @apiNote Internal
|
||||
*/
|
||||
public static void resetCachedTagCollections(boolean makeEmpty, boolean withOptional)
|
||||
public static TagContainer reinjectOptionalTags(TagContainer tagCollectionSupplier)
|
||||
{
|
||||
ImmutableMap.Builder<ResourceLocation, TagCollection<?>> builder = ImmutableMap.builder();
|
||||
for (ResourceLocation registryName : customTagTypeNames)
|
||||
{
|
||||
StaticTagHelper<?> tagRegistry = StaticTags.get(registryName);
|
||||
if (tagRegistry != null)
|
||||
{
|
||||
if (makeEmpty)
|
||||
{
|
||||
if (withOptional)
|
||||
builder.put(registryName, tagRegistry.reinjectOptionalTags(TagCollection.of(Collections.emptyMap())));
|
||||
else
|
||||
builder.put(registryName, TagCollection.of(Collections.emptyMap()));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.put(registryName, TagCollection.of(tagRegistry.getWrappers().stream().distinct().collect(Collectors.toMap(Named::getName, namedTag -> namedTag))));
|
||||
}
|
||||
}
|
||||
}
|
||||
customTagTypes = builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to ensure that all custom tag types have a defaulted collection when vanilla is initializing a defaulted TagCollectionManager
|
||||
*
|
||||
* @apiNote Internal: For use by TagCollectionManager
|
||||
*/
|
||||
public static void populateTagCollectionManager()
|
||||
{
|
||||
//Default the tag collections
|
||||
resetCachedTagCollections(false, false);
|
||||
if (!customTagTypes.isEmpty())
|
||||
{
|
||||
LOGGER.debug("Populated the TagCollectionManager with {} extra types", customTagTypes.size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the custom tag types' tags from reloading via NetworkTagManager
|
||||
*
|
||||
* @apiNote Internal: For use by NetworkTagManager
|
||||
*/
|
||||
public static void updateCustomTagTypes(List<TagCollectionReaderInfo> tagCollectionReaders)
|
||||
{
|
||||
ImmutableMap.Builder<ResourceLocation, TagCollection<?>> builder = ImmutableMap.builder();
|
||||
for (TagCollectionReaderInfo info : tagCollectionReaders)
|
||||
{
|
||||
builder.put(info.tagType, info.reader.build(info.tagBuilders));
|
||||
}
|
||||
customTagTypes = builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the custom tag types' tags from packet
|
||||
*
|
||||
* @apiNote Internal
|
||||
*/
|
||||
public static void updateCustomTagTypes(SyncCustomTagTypes packet)
|
||||
{
|
||||
customTagTypes = packet.getCustomTagTypes();
|
||||
reinjectOptionalTagsCustomTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the completable future containing the reload results for all custom tag types.
|
||||
*
|
||||
* @apiNote Internal: For use by NetworkTagManager
|
||||
*/
|
||||
public static CompletableFuture<List<TagCollectionReaderInfo>> getCustomTagTypeReloadResults(ResourceManager resourceManager, Executor backgroundExecutor, Map<ResourceLocation, TagLoader<?>> readers)
|
||||
{
|
||||
CompletableFuture<List<TagCollectionReaderInfo>> customResults = CompletableFuture.completedFuture(new ArrayList<>());
|
||||
for (Entry<ResourceLocation, TagLoader<?>> entry : readers.entrySet())
|
||||
{
|
||||
CompletableFuture<Map<ResourceLocation, Tag.Builder>> collectionFuture =
|
||||
CompletableFuture.supplyAsync(() -> entry.getValue().load(resourceManager), backgroundExecutor);
|
||||
customResults = customResults.thenCombine(collectionFuture, (results, result) -> {
|
||||
results.add(new TagCollectionReaderInfo(entry.getKey(), entry.getValue(), result));
|
||||
return results;
|
||||
});
|
||||
}
|
||||
return customResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all the missing optional tags back into the custom tag types tag collections
|
||||
*
|
||||
* @apiNote Internal
|
||||
*/
|
||||
public static void reinjectOptionalTagsCustomTypes()
|
||||
{
|
||||
ImmutableMap.Builder<ResourceLocation, TagCollection<?>> builder = ImmutableMap.builder();
|
||||
for (Entry<ResourceLocation, TagCollection<?>> entry : customTagTypes.entrySet())
|
||||
{
|
||||
ResourceLocation registry = entry.getKey();
|
||||
StaticTagHelper<?> tagRegistry = StaticTags.get(registry);
|
||||
TagCollection<?> tagCollection = entry.getValue();
|
||||
builder.put(registry, tagRegistry == null ? tagCollection : tagRegistry.reinjectOptionalTags((TagCollection) tagCollection));
|
||||
}
|
||||
customTagTypes = builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link IForgeTagContainer} with empty custom tag type collections to allow for checking if the client is requiring any tags of custom tag types.
|
||||
*
|
||||
* @apiNote Internal: For use with validating missing tags when connecting to a vanilla server
|
||||
*/
|
||||
public static TagContainer withNoCustom(TagContainer tagCollectionSupplier)
|
||||
{
|
||||
ImmutableMap.Builder<ResourceLocation, TagCollection<?>> builder = ImmutableMap.builder();
|
||||
for (ResourceLocation registryName : customTagTypeNames)
|
||||
{
|
||||
StaticTagHelper<?> tagRegistry = StaticTags.get(registryName);
|
||||
if (tagRegistry != null)
|
||||
{
|
||||
builder.put(registryName, TagCollection.of(Collections.emptyMap()));
|
||||
}
|
||||
}
|
||||
return withSpecificCustom(tagCollectionSupplier, builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link IForgeTagContainer} with specific custom tag types for testing if any tags are missing.
|
||||
*
|
||||
* @apiNote Internal
|
||||
*/
|
||||
public static TagContainer withSpecificCustom(TagContainer tagCollectionSupplier, Map<ResourceLocation, TagCollection<?>> customTagTypes)
|
||||
{
|
||||
return new TagContainer(tagCollectionSupplier.collections)
|
||||
{
|
||||
@Override
|
||||
public Map<ResourceLocation, TagCollection<?>> getCustomTagTypes()
|
||||
{
|
||||
return customTagTypes;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper storage class for keeping track of various data for all custom tag types in the NetworkTagReader to make the code easier to read.
|
||||
*
|
||||
* @apiNote Internal: For use by NetworkTagManager
|
||||
*/
|
||||
public static class TagCollectionReaderInfo
|
||||
{
|
||||
|
||||
private final ResourceLocation tagType;
|
||||
private final TagLoader<?> reader;
|
||||
private final Map<ResourceLocation, Tag.Builder> tagBuilders;
|
||||
|
||||
private TagCollectionReaderInfo(ResourceLocation tagType, TagLoader<?> reader, Map<ResourceLocation, Tag.Builder> tagBuilders)
|
||||
{
|
||||
this.tagType = tagType;
|
||||
this.reader = reader;
|
||||
this.tagBuilders = tagBuilders;
|
||||
}
|
||||
TagContainer.Builder builder = new TagContainer.Builder();
|
||||
//noinspection unchecked,rawtypes
|
||||
StaticTags.visitHelpers(h -> builder.add(h.getKey(), h.reinjectOptionalTags(tagCollectionSupplier.getOrEmpty((ResourceKey) h.getKey()))));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
public abstract class ForgeRegistryTagsProvider<T extends IForgeRegistryEntry<T>> extends TagsProvider<T>
|
||||
{
|
||||
//TODO add game event tags here when they become a forge registry
|
||||
//Special handling for vanilla tag types in case someone decides to use the ForgeRegistryTagsProvider instead of one of the vanilla subtypes
|
||||
private static final Map<IForgeRegistry<?>, String> vanillaTypes = ImmutableMap.<IForgeRegistry<?>, String>builder()
|
||||
.put(ForgeRegistries.BLOCKS, "blocks")
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
*
|
||||
* 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.common.extensions;
|
||||
|
||||
import java.util.Map;
|
||||
import net.minecraft.tags.TagCollection;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.ForgeTagHandler;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
public interface IForgeTagContainer
|
||||
{
|
||||
/**
|
||||
* Gets the tag map of registry names to tag collections for the various custom tag types.
|
||||
*
|
||||
* @apiNote Prefer using one of the getCustomTypeCollection methods
|
||||
*/
|
||||
default Map<ResourceLocation, TagCollection<?>> getCustomTagTypes()
|
||||
{
|
||||
return ForgeTagHandler.getCustomTagTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link TagCollection} for a forge registry with the given name, or throws an exception if the registry doesn't support custom tag types.
|
||||
* @param regName Name of the forge registry
|
||||
* @return The tag collection
|
||||
*/
|
||||
default TagCollection<?> getCustomTypeCollection(ResourceLocation regName)
|
||||
{
|
||||
if (!ForgeTagHandler.getCustomTagTypeNames().contains(regName)) throw new IllegalArgumentException("Registry " + regName + ", does not support custom tag types");
|
||||
return getCustomTagTypes().get(regName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link TagCollection} for a forge registry, or throws an exception if the registry doesn't support custom tag types.
|
||||
* @param reg Forge registry
|
||||
* @return The tag collection
|
||||
*/
|
||||
default <T extends IForgeRegistryEntry<T>> TagCollection<T> getCustomTypeCollection(IForgeRegistry<T> reg)
|
||||
{
|
||||
return (TagCollection<T>) getCustomTypeCollection(reg.getRegistryName());
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,14 @@
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.tags.TagContainer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
/**
|
||||
* Fired on the client when {@link ITagCollectionSupplier} has all of its tags synced from the server to the client (just after a client has connected).
|
||||
* Fired on the server when {@link ITagCollectionSupplier} has read all tags from disk (during a data reload).
|
||||
* Fired on the client when :
|
||||
* {@link TagContainer} has all of its tags synced from the server to the client (just after a client has connected).
|
||||
* The integrated server is about to be created see {@link net.minecraft.client.Minecraft#doLoadLevel}
|
||||
* Fired on the server when {@link TagContainer} has read all tags from disk, during initial load and after the reload command is used
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}
|
||||
* On the client, this event fires on the Client Thread.
|
||||
* On the server, this event may be fired on the Server Thread, or an async reloader thread.
|
||||
@@ -45,26 +48,4 @@ public class TagsUpdatedEvent extends Event
|
||||
{
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired after the Vanilla Tag types have been processed
|
||||
*/
|
||||
public static class VanillaTagTypes extends TagsUpdatedEvent
|
||||
{
|
||||
public VanillaTagTypes(TagContainer manager)
|
||||
{
|
||||
super(manager);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired after any custom tag types have been processed
|
||||
*/
|
||||
public static class CustomTagTypes extends TagsUpdatedEvent
|
||||
{
|
||||
public CustomTagTypes(TagContainer manager)
|
||||
{
|
||||
super(manager);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,49 +19,27 @@
|
||||
|
||||
package net.minecraftforge.fmllegacy.network;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.inventory.MenuAccess;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.TagCollection;
|
||||
import net.minecraft.tags.TagContainer;
|
||||
import net.minecraft.tags.StaticTags;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.ForgeTagHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.TagsUpdatedEvent;
|
||||
import net.minecraftforge.fmllegacy.LogicalSidedProvider;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.fmllegacy.common.registry.IEntityAdditionalSpawnData;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class FMLPlayMessages
|
||||
{
|
||||
@@ -326,113 +304,4 @@ public class FMLPlayMessages
|
||||
return additionalData;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SyncCustomTagTypes
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private final Map<ResourceLocation, TagCollection<?>> customTagTypeCollections;
|
||||
|
||||
SyncCustomTagTypes(Map<ResourceLocation, TagCollection<?>> customTagTypeCollections)
|
||||
{
|
||||
this.customTagTypeCollections = customTagTypeCollections;
|
||||
}
|
||||
|
||||
public Map<ResourceLocation, TagCollection<?>> getCustomTagTypes()
|
||||
{
|
||||
return customTagTypeCollections;
|
||||
}
|
||||
|
||||
public static void encode(SyncCustomTagTypes msg, FriendlyByteBuf buf)
|
||||
{
|
||||
buf.writeVarInt(msg.customTagTypeCollections.size());
|
||||
msg.customTagTypeCollections.forEach((registryName, modded) -> forgeTagCollectionWrite(buf, registryName, modded.getAllTags()));
|
||||
}
|
||||
|
||||
private static <T> void forgeTagCollectionWrite(FriendlyByteBuf buf, ResourceLocation registryName, Map<ResourceLocation, Tag<T>> tags)
|
||||
{
|
||||
buf.writeResourceLocation(registryName);
|
||||
buf.writeVarInt(tags.size());
|
||||
tags.forEach((name, tag) -> {
|
||||
buf.writeResourceLocation(name);
|
||||
List<T> elements = tag.getValues();
|
||||
buf.writeVarInt(elements.size());
|
||||
for (T element : elements)
|
||||
{
|
||||
buf.writeResourceLocation(((IForgeRegistryEntry<?>) element).getRegistryName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static SyncCustomTagTypes decode(FriendlyByteBuf buf)
|
||||
{
|
||||
ImmutableMap.Builder<ResourceLocation, TagCollection<?>> builder = ImmutableMap.builder();
|
||||
int size = buf.readVarInt();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
ResourceLocation regName = buf.readResourceLocation();
|
||||
IForgeRegistry<?> registry = RegistryManager.ACTIVE.getRegistry(regName);
|
||||
if (registry != null)
|
||||
{
|
||||
builder.put(regName, readTagCollection(buf, registry));
|
||||
}
|
||||
}
|
||||
return new SyncCustomTagTypes(builder.build());
|
||||
}
|
||||
|
||||
private static <T extends IForgeRegistryEntry<T>> TagCollection<T> readTagCollection(FriendlyByteBuf buf, IForgeRegistry<T> registry)
|
||||
{
|
||||
Map<ResourceLocation, Tag<T>> tags = Maps.newHashMap();
|
||||
int totalTags = buf.readVarInt();
|
||||
for (int i = 0; i < totalTags; i++)
|
||||
{
|
||||
ImmutableSet.Builder<T> elementBuilder = ImmutableSet.builder();
|
||||
ResourceLocation name = buf.readResourceLocation();
|
||||
int totalElements = buf.readVarInt();
|
||||
for (int j = 0; j < totalElements; j++)
|
||||
{
|
||||
T element = registry.getValue(buf.readResourceLocation());
|
||||
if (element != null)
|
||||
{
|
||||
elementBuilder.add(element);
|
||||
}
|
||||
}
|
||||
tags.put(name, Tag.fromSet(elementBuilder.build()));
|
||||
}
|
||||
return TagCollection.of(tags);
|
||||
}
|
||||
|
||||
public static void handle(SyncCustomTagTypes msg, Supplier<NetworkEvent.Context> ctx)
|
||||
{
|
||||
ctx.get().enqueueWork(() -> {
|
||||
if (Minecraft.getInstance().level != null)
|
||||
{
|
||||
TagContainer tagCollectionSupplier = Minecraft.getInstance().level.getTagManager();
|
||||
//Validate that all the tags exist using the tag type collections from the packet
|
||||
// We mimic vanilla in that we validate before updating the actual stored tags so that it can gracefully fallback
|
||||
// to the last working set of tags
|
||||
//Note: We gracefully ignore any tag types the server may have that we don't as they won't be in our tag registry
|
||||
// so they won't be validated
|
||||
//Override and use the tags from the packet to test for validation before we actually set them
|
||||
Multimap<ResourceKey<? extends Registry<?>>, ResourceLocation> missingTags = StaticTags.getAllMissingTags(ForgeTagHandler.withSpecificCustom(tagCollectionSupplier, msg.customTagTypeCollections));
|
||||
if (missingTags.isEmpty())
|
||||
{
|
||||
//If we have no missing tags, update the custom tag types
|
||||
ForgeTagHandler.updateCustomTagTypes(msg);
|
||||
if (!ctx.get().getNetworkManager().isMemoryConnection())
|
||||
{
|
||||
//And if everything hasn't already been set due to being in single player
|
||||
// Fetch and update the custom tag types. We skip vanilla tag types as they have already been fetched
|
||||
// And fire an event that the custom tag types have been updated
|
||||
StaticTags.fetchCustomTagTypes(tagCollectionSupplier);
|
||||
MinecraftForge.EVENT_BUS.post(new TagsUpdatedEvent.CustomTagTypes(tagCollectionSupplier));
|
||||
}
|
||||
} else {
|
||||
LOGGER.warn("Incomplete server tags, disconnecting. Missing: {}", missingTags);
|
||||
ctx.get().getNetworkManager().disconnect(new TranslatableComponent("multiplayer.disconnect.missing_tags"));
|
||||
}
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,6 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.tags.TagCollection;
|
||||
import net.minecraft.tags.TagContainer;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.common.extensions.IForgeTagContainer;
|
||||
import net.minecraftforge.fml.util.thread.EffectiveSide;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -234,33 +233,6 @@ public class NetworkHooks
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, c));
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs the custom tag types attached to a {@link IForgeTagContainer} to all connected players.
|
||||
* @param tagCollectionSupplier The tag collection supplier containing the custom tags
|
||||
*/
|
||||
public static void syncCustomTagTypes(TagContainer tagCollectionSupplier)
|
||||
{
|
||||
Map<ResourceLocation, TagCollection<?>> customTagTypes = tagCollectionSupplier.getCustomTagTypes();
|
||||
if (!customTagTypes.isEmpty())
|
||||
{
|
||||
FMLNetworkConstants.playChannel.send(PacketDistributor.ALL.noArg(), new FMLPlayMessages.SyncCustomTagTypes(customTagTypes));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs the custom tag types attached to a {@link IForgeTagContainer} to the given player.
|
||||
* @param player The player to sync the custom tags to.
|
||||
* @param tagCollectionSupplier The tag collection supplier containing the custom tags
|
||||
*/
|
||||
public static void syncCustomTagTypes(ServerPlayer player, TagContainer tagCollectionSupplier)
|
||||
{
|
||||
Map<ResourceLocation, TagCollection<?>> customTagTypes = tagCollectionSupplier.getCustomTagTypes();
|
||||
if (!customTagTypes.isEmpty())
|
||||
{
|
||||
FMLNetworkConstants.playChannel.sendTo(new FMLPlayMessages.SyncCustomTagTypes(customTagTypes), player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FMLConnectionData getConnectionData(Connection mgr)
|
||||
{
|
||||
|
||||
@@ -97,19 +97,6 @@ class NetworkInitialization {
|
||||
consumer(FMLPlayMessages.OpenContainer::handle).
|
||||
add();
|
||||
|
||||
//TODO Dimensions..
|
||||
// playChannel.messageBuilder(FMLPlayMessages.DimensionInfoMessage.class, 2)
|
||||
// .decoder(FMLPlayMessages.DimensionInfoMessage::decode)
|
||||
// .encoder(FMLPlayMessages.DimensionInfoMessage::encode)
|
||||
// .consumer(FMLPlayMessages.DimensionInfoMessage::handle)
|
||||
// .add();
|
||||
|
||||
playChannel.messageBuilder(FMLPlayMessages.SyncCustomTagTypes.class, 3).
|
||||
decoder(FMLPlayMessages.SyncCustomTagTypes::decode).
|
||||
encoder(FMLPlayMessages.SyncCustomTagTypes::encode).
|
||||
consumer(FMLPlayMessages.SyncCustomTagTypes::handle).
|
||||
add();
|
||||
|
||||
return playChannel;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,18 +21,25 @@ package net.minecraftforge.network;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypes;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.game.ClientboundCommandsPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagCollection;
|
||||
import net.minecraftforge.common.ForgeTagHandler;
|
||||
import net.minecraftforge.fmllegacy.network.NetworkHooks;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@@ -58,6 +65,7 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
|
||||
ImmutableMap.<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>>builder()
|
||||
.put(handler(ClientboundUpdateAttributesPacket.class, VanillaConnectionNetworkFilter::filterEntityProperties))
|
||||
.put(handler(ClientboundCommandsPacket.class, VanillaConnectionNetworkFilter::filterCommandList))
|
||||
.put(handler(ClientboundUpdateTagsPacket.class, VanillaConnectionNetworkFilter::filterCustomTagTypes))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
@@ -99,4 +107,15 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
|
||||
});
|
||||
return new ClientboundCommandsPacket(newRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters out custom tag types that the vanilla client won't recognize.
|
||||
* It prevents a rare error from logging and reduces the packet size
|
||||
*/
|
||||
private static ClientboundUpdateTagsPacket filterCustomTagTypes(ClientboundUpdateTagsPacket packet) {
|
||||
Map<ResourceKey<? extends Registry<?>>, TagCollection.NetworkPayload> tags = packet.getTags()
|
||||
.entrySet().stream().filter(e -> !ForgeTagHandler.getCustomTagTypeNames().contains(e.getKey().location()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
return new ClientboundUpdateTagsPacket(tags);
|
||||
}
|
||||
}
|
||||
@@ -404,7 +404,7 @@ public class GameData
|
||||
{
|
||||
LOGGER.debug(REGISTRIES, "Registering custom tag type for: {}", registryName);
|
||||
customTagTypes.add(registryName);
|
||||
StaticTags.create(ResourceKey.createRegistryKey(registryName), entry.getValue().getTagFolder());
|
||||
StaticTags.create(ResourceKey.createRegistryKey(registryName), "tags/" + entry.getValue().getTagFolder());
|
||||
}
|
||||
}
|
||||
ForgeTagHandler.setCustomTagTypes(customTagTypes);
|
||||
|
||||
@@ -205,6 +205,7 @@ public net.minecraft.tags.Tag$BuilderEntry <init>(Lnet/minecraft/tags/Tag$Entry;
|
||||
public net.minecraft.tags.BlockTags m_13116_(Ljava/lang/String;)Lnet/minecraft/tags/Tag$Named; # bind
|
||||
public net.minecraft.tags.EntityTypeTags m_13127_(Ljava/lang/String;)Lnet/minecraft/tags/Tag$Named; # bind
|
||||
public net.minecraft.tags.FluidTags m_13134_(Ljava/lang/String;)Lnet/minecraft/tags/Tag$Named; # bind
|
||||
public net.minecraft.tags.GameEventTags m_144307_(Ljava/lang/String;)Lnet/minecraft/tags/Tag$Named; # bind
|
||||
public net.minecraft.tags.ItemTags m_13194_(Ljava/lang/String;)Lnet/minecraft/tags/Tag$Named; # bind
|
||||
protected net.minecraft.tags.StaticTagHelper$Wrapper f_13251_ # tag
|
||||
public net.minecraft.tags.TagContainer <init>(Ljava/util/Map;)V # constructor
|
||||
|
||||
@@ -16,6 +16,7 @@ net/minecraft/client/resources/model/WeightedBakedModel.getQuads(Lnet/minecraft/
|
||||
net/minecraft/data/tags/BlockTagsProvider.<init>(Lnet/minecraft/data/DataGenerator;Ljava/lang/String;Lnet/minecraftforge/common/data/ExistingFileHelper;)V=|p_126511_,modId,existingFileHelper
|
||||
net/minecraft/data/tags/EntityTypeTagsProvider.<init>(Lnet/minecraft/data/DataGenerator;Ljava/lang/String;Lnet/minecraftforge/common/data/ExistingFileHelper;)V=|p_126517_,modId,existingFileHelper
|
||||
net/minecraft/data/tags/FluidTagsProvider.<init>(Lnet/minecraft/data/DataGenerator;Ljava/lang/String;Lnet/minecraftforge/common/data/ExistingFileHelper;)V=|p_126523_,modId,existingFileHelper
|
||||
net/minecraft/data/tags/GameEventTagsProvider.<init>(Lnet/minecraft/data/DataGenerator;Ljava/lang/String;Lnet/minecraftforge/common/data/ExistingFileHelper;)V=|p_126517_,modId,existingFileHelper
|
||||
net/minecraft/data/tags/ItemTagsProvider.<init>(Lnet/minecraft/data/DataGenerator;Lnet/minecraft/data/tags/BlockTagsProvider;Ljava/lang/String;Lnet/minecraftforge/common/data/ExistingFileHelper;)V=|p_126530_,p_126531_,modId,existingFileHelper
|
||||
net/minecraft/data/tags/TagsProvider.<init>(Lnet/minecraft/data/DataGenerator;Lnet/minecraft/core/Registry;Ljava/lang/String;Lnet/minecraftforge/common/data/ExistingFileHelper;)V=|p_126546_,p_126547_,modId,existingFileHelper
|
||||
net/minecraft/data/tags/TagsProvider.<init>(Lnet/minecraft/data/DataGenerator;Lnet/minecraft/core/Registry;Ljava/lang/String;Lnet/minecraftforge/common/data/ExistingFileHelper;Ljava/lang/String;)V=|p_126546_,p_126547_,modId,existingFileHelper,folder
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
|
||||
package net.minecraftforge.debug.misc;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
@@ -68,10 +68,11 @@ public class CustomTagTypesTest
|
||||
private static final ResourceLocation customRegistryName = new ResourceLocation(MODID, "custom_type_registry");
|
||||
private static final DeferredRegister<Custom> CUSTOMS = DeferredRegister.create(Custom.class, MODID);
|
||||
private static final RegistryObject<Custom> CUSTOM = CUSTOMS.register("custom", Custom::new);
|
||||
private static final ResourceKey<? extends Registry<Custom>> CUSTOM_KEY = ResourceKey.createRegistryKey(customRegistryName);
|
||||
private static final Supplier<IForgeRegistry<Custom>> CUSTOM_REG = CUSTOMS.makeRegistry(customRegistryName.getPath(),
|
||||
() -> new RegistryBuilder<Custom>().tagFolder(MODID + "/custom_types"));
|
||||
private static final Tag.Named<Custom> TESTS = ForgeTagHandler.createOptionalTag(customRegistryName, new ResourceLocation(MODID, "tests"), Sets.newHashSet(CUSTOM));
|
||||
private static final Tag.Named<Item> OPTIONAL_TEST = ItemTags.createOptional(new ResourceLocation(MODID, "optional_test"), Sets.newHashSet(() -> Items.BONE));
|
||||
private static final Tag.Named<Custom> TESTS = ForgeTagHandler.createOptionalTag(customRegistryName, new ResourceLocation(MODID, "tests"), Set.of(CUSTOM));
|
||||
private static final Tag.Named<Item> OPTIONAL_TEST = ItemTags.createOptional(new ResourceLocation(MODID, "optional_test"), Set.of(() -> Items.BONE));
|
||||
private static final Tag.Named<Enchantment> FIRE = ForgeTagHandler.createOptionalTag(ForgeRegistries.ENCHANTMENTS, new ResourceLocation(MODID, "fire"));
|
||||
private static final Tag.Named<Potion> DAMAGE = ForgeTagHandler.createOptionalTag(ForgeRegistries.POTIONS, new ResourceLocation(MODID, "damage"));
|
||||
private static final Tag.Named<BlockEntityType<?>> STORAGE = ForgeTagHandler.createOptionalTag(ForgeRegistries.BLOCK_ENTITIES, new ResourceLocation(MODID, "storage"));
|
||||
@@ -103,6 +104,7 @@ public class CustomTagTypesTest
|
||||
if (!itemStack.isEmpty())
|
||||
{
|
||||
LOGGER.info("{} {} {}", Items.BONE.getTags(), OPTIONAL_TEST.getValues().size(), SerializationTags.getInstance().getOrEmpty(Registry.ITEM_REGISTRY).getTag(new ResourceLocation(MODID, "optional_test")));
|
||||
LOGGER.info("{} {}", CUSTOM.get().getTags(), TESTS.getValues().size());
|
||||
EnchantmentHelper.getEnchantments(itemStack).forEach((enchantment, level) -> logTagsIfPresent(enchantment.getTags()));
|
||||
if (itemStack.getItem() instanceof PotionItem) logTagsIfPresent(PotionUtils.getPotion(itemStack).getTags());
|
||||
BlockEntity blockEntity = event.getWorld().getBlockEntity(event.getPos());
|
||||
@@ -120,17 +122,12 @@ public class CustomTagTypesTest
|
||||
|
||||
public static class Custom extends ForgeRegistryEntry<Custom>
|
||||
{
|
||||
private final ReverseTagWrapper<Custom> reverseTags = new ReverseTagWrapper<>(this, () -> SerializationTags.getInstance().getCustomTypeCollection(CUSTOM_REG.get()));
|
||||
private final ReverseTagWrapper<Custom> reverseTags = new ReverseTagWrapper<>(this, () -> SerializationTags.getInstance().getOrEmpty(CUSTOM_KEY));
|
||||
|
||||
public Set<ResourceLocation> getTags()
|
||||
{
|
||||
return reverseTags.getTagNames();
|
||||
}
|
||||
|
||||
public boolean isIn(Tag<Custom> tag)
|
||||
{
|
||||
return tag.contains(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomRegistryTags extends ForgeRegistryTagsProvider<Custom>
|
||||
@@ -203,13 +200,13 @@ public class CustomTagTypesTest
|
||||
@Override
|
||||
protected void addTags()
|
||||
{
|
||||
tag(STORAGE).add(BlockEntityType.BARREL, BlockEntityType.CHEST, BlockEntityType.ENDER_CHEST);
|
||||
tag(STORAGE).add(BlockEntityType.BARREL, BlockEntityType.CHEST, BlockEntityType.ENDER_CHEST, BlockEntityType.TRAPPED_CHEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Tile Entity Type Tags";
|
||||
return "Block Entity Type Tags";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user