Fix a few minor issues with custom tag types and fix OptionalNamedTags (#7316)

This commit is contained in:
Richard Freimer 2020-09-23 23:12:11 -04:00 committed by GitHub
parent 37be3aff2d
commit af75547d37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 258 additions and 114 deletions

View file

@ -77,21 +77,23 @@
if (effect != null) { if (effect != null) {
EffectInstance effectinstance = new EffectInstance(effect, p_147260_1_.func_180755_e(), p_147260_1_.func_149428_f(), p_147260_1_.func_186984_g(), p_147260_1_.func_179707_f(), p_147260_1_.func_205527_h()); EffectInstance effectinstance = new EffectInstance(effect, p_147260_1_.func_180755_e(), p_147260_1_.func_149428_f(), p_147260_1_.func_186984_g(), p_147260_1_.func_179707_f(), p_147260_1_.func_205527_h());
effectinstance.func_100012_b(p_147260_1_.func_149429_c()); effectinstance.func_100012_b(p_147260_1_.func_149429_c());
@@ -1388,11 +1401,12 @@ @@ -1388,11 +1401,14 @@
public void func_199723_a(STagsListPacket p_199723_1_) { public void func_199723_a(STagsListPacket p_199723_1_) {
PacketThreadUtil.func_218797_a(p_199723_1_, this, this.field_147299_f); PacketThreadUtil.func_218797_a(p_199723_1_, this, this.field_147299_f);
ITagCollectionSupplier itagcollectionsupplier = p_199723_1_.func_199858_a(); ITagCollectionSupplier itagcollectionsupplier = p_199723_1_.func_199858_a();
- Multimap<ResourceLocation, ResourceLocation> multimap = TagRegistryManager.func_242198_b(itagcollectionsupplier); - Multimap<ResourceLocation, ResourceLocation> multimap = TagRegistryManager.func_242198_b(itagcollectionsupplier);
+ Multimap<ResourceLocation, ResourceLocation> multimap = TagRegistryManager.validateVanillaTags(itagcollectionsupplier); + boolean vanillaConnection = net.minecraftforge.fml.network.NetworkHooks.isVanillaConnection(field_147302_e);
+ Multimap<ResourceLocation, ResourceLocation> multimap = vanillaConnection ? TagRegistryManager.func_242198_b(net.minecraftforge.common.ForgeTagHandler.withNoCustom(itagcollectionsupplier)) : TagRegistryManager.validateVanillaTags(itagcollectionsupplier);//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()) { if (!multimap.isEmpty()) {
field_147301_d.warn("Incomplete server tags, disconnecting. Missing: {}", (Object)multimap); field_147301_d.warn("Incomplete server tags, disconnecting. Missing: {}", (Object)multimap);
this.field_147302_e.func_150718_a(new TranslationTextComponent("multiplayer.disconnect.missing_tags")); this.field_147302_e.func_150718_a(new TranslationTextComponent("multiplayer.disconnect.missing_tags"));
} else { } else {
+ net.minecraftforge.common.ForgeTagHandler.resetCachedTagCollections(); + net.minecraftforge.common.ForgeTagHandler.resetCachedTagCollections(true, vanillaConnection);
+ itagcollectionsupplier = ITagCollectionSupplier.reinjectOptionalTags(itagcollectionsupplier);
this.field_199725_m = itagcollectionsupplier; this.field_199725_m = itagcollectionsupplier;
if (!this.field_147302_e.func_150731_c()) { if (!this.field_147302_e.func_150731_c()) {
itagcollectionsupplier.func_242212_e(); itagcollectionsupplier.func_242212_e();
@@ -1883,10 +1897,12 @@ @@ -1883,10 +1899,12 @@
int l5 = packetbuffer.readInt(); int l5 = packetbuffer.readInt();
this.field_147299_f.field_184132_p.field_229018_q_.func_229022_a_(blockpos8, l3, s10, l5); this.field_147299_f.field_184132_p.field_229018_q_.func_229022_a_(blockpos8, l3, s10, l5);
} else { } else {

View file

@ -8,3 +8,11 @@
} }
public FunctionReloader func_240960_a_() { public FunctionReloader func_240960_a_() {
@@ -81,6 +82,7 @@
public void func_240971_i_() {
this.field_240955_e_.func_242231_a().func_242212_e();
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.TagsUpdatedEvent.CustomTagTypes(field_240955_e_.func_242231_a()));
}
public void close() {

View file

@ -1,11 +1,15 @@
--- a/net/minecraft/tags/BlockTags.java --- a/net/minecraft/tags/BlockTags.java
+++ b/net/minecraft/tags/BlockTags.java +++ b/net/minecraft/tags/BlockTags.java
@@ -97,6 +97,10 @@ @@ -97,6 +97,14 @@
return field_199899_c.func_232937_a_(p_199894_0_); return field_199899_c.func_232937_a_(p_199894_0_);
} }
+ public static net.minecraftforge.common.Tags.IOptionalNamedTag<Block> createOptional(ResourceLocation name) { + public static net.minecraftforge.common.Tags.IOptionalNamedTag<Block> createOptional(ResourceLocation name) {
+ return field_199899_c.createOptional(name, () -> null); + return createOptional(name, null);
+ }
+
+ public static net.minecraftforge.common.Tags.IOptionalNamedTag<Block> createOptional(ResourceLocation name, @javax.annotation.Nullable java.util.Set<java.util.function.Supplier<Block>> defaults) {
+ return field_199899_c.createOptional(name, defaults);
+ } + }
+ +
public static ITagCollection<Block> func_199896_a() { public static ITagCollection<Block> func_199896_a() {

View file

@ -1,11 +1,15 @@
--- a/net/minecraft/tags/EntityTypeTags.java --- a/net/minecraft/tags/EntityTypeTags.java
+++ b/net/minecraft/tags/EntityTypeTags.java +++ b/net/minecraft/tags/EntityTypeTags.java
@@ -16,6 +16,10 @@ @@ -16,6 +16,14 @@
return field_219766_c.func_232937_a_(p_232896_0_); return field_219766_c.func_232937_a_(p_232896_0_);
} }
+ public static net.minecraftforge.common.Tags.IOptionalNamedTag<EntityType<?>> createOptional(ResourceLocation name) { + public static net.minecraftforge.common.Tags.IOptionalNamedTag<EntityType<?>> createOptional(ResourceLocation name) {
+ return field_219766_c.createOptional(name, () -> null); + return createOptional(name, null);
+ }
+
+ public static net.minecraftforge.common.Tags.IOptionalNamedTag<EntityType<?>> createOptional(ResourceLocation name, @javax.annotation.Nullable java.util.Set<java.util.function.Supplier<EntityType<?>>> defaults) {
+ return field_219766_c.createOptional(name, defaults);
+ } + }
+ +
public static ITagCollection<EntityType<?>> func_219762_a() { public static ITagCollection<EntityType<?>> func_219762_a() {

View file

@ -1,11 +1,15 @@
--- a/net/minecraft/tags/FluidTags.java --- a/net/minecraft/tags/FluidTags.java
+++ b/net/minecraft/tags/FluidTags.java +++ b/net/minecraft/tags/FluidTags.java
@@ -13,7 +13,16 @@ @@ -13,7 +13,20 @@
return field_206961_c.func_232937_a_(p_206956_0_); return field_206961_c.func_232937_a_(p_206956_0_);
} }
+ public static net.minecraftforge.common.Tags.IOptionalNamedTag<Fluid> createOptional(ResourceLocation name) { + public static net.minecraftforge.common.Tags.IOptionalNamedTag<Fluid> createOptional(ResourceLocation name) {
+ return field_206961_c.createOptional(name, () -> null); + return createOptional(name, null);
+ }
+
+ public static net.minecraftforge.common.Tags.IOptionalNamedTag<Fluid> createOptional(ResourceLocation name, @javax.annotation.Nullable java.util.Set<java.util.function.Supplier<Fluid>> defaults) {
+ return field_206961_c.createOptional(name, defaults);
+ } + }
+ +
public static List<? extends ITag.INamedTag<Fluid>> func_241280_c_() { public static List<? extends ITag.INamedTag<Fluid>> func_241280_c_() {

View file

@ -17,3 +17,36 @@
} }
default void func_242210_a(PacketBuffer p_242210_1_) { default void func_242210_a(PacketBuffer p_242210_1_) {
@@ -58,4 +59,32 @@
}
};
}
+
+ static ITagCollectionSupplier reinjectOptionalTags(ITagCollectionSupplier tagCollectionSupplier) {
+ ITagCollection<Block> blockTagCollection = BlockTags.field_199899_c.reinjectOptionalTags(tagCollectionSupplier.func_241835_a());
+ ITagCollection<Item> itemTagCollection = ItemTags.field_199906_c.reinjectOptionalTags(tagCollectionSupplier.func_241836_b());
+ ITagCollection<Fluid> fluidTagCollection = FluidTags.field_206961_c.reinjectOptionalTags(tagCollectionSupplier.func_241837_c());
+ ITagCollection<EntityType<?>> entityTypeTagCollection = EntityTypeTags.field_219766_c.reinjectOptionalTags(tagCollectionSupplier.func_241838_d());
+ return new ITagCollectionSupplier() {
+ @Override
+ public ITagCollection<Block> func_241835_a() {
+ return blockTagCollection;
+ }
+
+ @Override
+ public ITagCollection<Item> func_241836_b() {
+ return itemTagCollection;
+ }
+
+ @Override
+ public ITagCollection<Fluid> func_241837_c() {
+ return fluidTagCollection;
+ }
+
+ @Override
+ public ITagCollection<EntityType<?>> func_241838_d() {
+ return entityTypeTagCollection;
+ }
+ };
+ }
}

View file

@ -1,11 +1,15 @@
--- a/net/minecraft/tags/ItemTags.java --- a/net/minecraft/tags/ItemTags.java
+++ b/net/minecraft/tags/ItemTags.java +++ b/net/minecraft/tags/ItemTags.java
@@ -65,6 +65,10 @@ @@ -65,6 +65,14 @@
return field_199906_c.func_232937_a_(p_199901_0_); return field_199906_c.func_232937_a_(p_199901_0_);
} }
+ public static net.minecraftforge.common.Tags.IOptionalNamedTag<Item> createOptional(ResourceLocation name) { + public static net.minecraftforge.common.Tags.IOptionalNamedTag<Item> createOptional(ResourceLocation name) {
+ return field_199906_c.createOptional(name, () -> null); + return createOptional(name, null);
+ }
+
+ public static net.minecraftforge.common.Tags.IOptionalNamedTag<Item> createOptional(ResourceLocation name, @javax.annotation.Nullable java.util.Set<java.util.function.Supplier<Item>> defaults) {
+ return field_199906_c.createOptional(name, defaults);
+ } + }
+ +
public static ITagCollection<Item> func_199903_a() { public static ITagCollection<Item> func_199903_a() {

View file

@ -23,3 +23,12 @@
ITagCollectionSupplier itagcollectionsupplier = ITagCollectionSupplier.func_242209_a(itagcollection, itagcollection1, itagcollection2, itagcollection3); ITagCollectionSupplier itagcollectionsupplier = ITagCollectionSupplier.func_242209_a(itagcollection, itagcollection1, itagcollection2, itagcollection3);
Multimap<ResourceLocation, ResourceLocation> multimap = TagRegistryManager.func_242198_b(itagcollectionsupplier); Multimap<ResourceLocation, ResourceLocation> multimap = TagRegistryManager.func_242198_b(itagcollectionsupplier);
if (!multimap.isEmpty()) { if (!multimap.isEmpty()) {
@@ -43,6 +46,8 @@
return p_232978_0_.getKey() + ":" + p_232978_0_.getValue();
}).sorted().collect(Collectors.joining(",")));
} else {
+ itagcollectionsupplier = ITagCollectionSupplier.reinjectOptionalTags(itagcollectionsupplier);
+ net.minecraftforge.common.ForgeTagHandler.reinjectOptionalTagsCustomTypes();
TagCollectionManager.func_242180_a(itagcollectionsupplier);
this.field_242230_e = itagcollectionsupplier;
}

View file

@ -15,7 +15,7 @@
+ return add(new TagRegistry.NamedTag<>(new ResourceLocation(p_232937_1_))); + return add(new TagRegistry.NamedTag<>(new ResourceLocation(p_232937_1_)));
+ } + }
+ +
+ public net.minecraftforge.common.Tags.IOptionalNamedTag<T> createOptional(ResourceLocation key, @Nullable java.util.function.Supplier<Set<T>> defaults) { + public net.minecraftforge.common.Tags.IOptionalNamedTag<T> createOptional(ResourceLocation key, @Nullable Set<java.util.function.Supplier<T>> defaults) {
+ return add(new TagRegistry.OptionalNamedTag<>(key, defaults)); + return add(new TagRegistry.OptionalNamedTag<>(key, defaults));
+ } + }
+ +
@ -24,8 +24,8 @@
+ return delayedAdd(tagRegistry, new TagRegistry.NamedTag<>(name)); + return delayedAdd(tagRegistry, new TagRegistry.NamedTag<>(name));
+ } + }
+ +
+ /** Call via ForgeTagHandler#createOptionalTag to avoid any exceptions due to calling this after it is safe to call {@link #createOptional(ResourceLocation, java.util.function.Supplier)} */ + /** Call via ForgeTagHandler#createOptionalTag to avoid any exceptions due to calling this after it is safe to call {@link #createOptional(ResourceLocation, Set)} */
+ public static <T> net.minecraftforge.common.Tags.IOptionalNamedTag<T> createDelayedOptional(ResourceLocation tagRegistry, ResourceLocation key, @Nullable java.util.function.Supplier<Set<T>> defaults) { + public static <T> net.minecraftforge.common.Tags.IOptionalNamedTag<T> createDelayedOptional(ResourceLocation tagRegistry, ResourceLocation key, @Nullable Set<java.util.function.Supplier<T>> defaults) {
+ return delayedAdd(tagRegistry, new TagRegistry.OptionalNamedTag<>(key, defaults)); + return delayedAdd(tagRegistry, new TagRegistry.OptionalNamedTag<>(key, defaults));
+ } + }
+ +
@ -53,7 +53,28 @@
this.field_232931_c_.add(namedtag); this.field_232931_c_.add(namedtag);
return namedtag; return namedtag;
} }
@@ -56,7 +94,7 @@ @@ -46,6 +84,20 @@
});
}
+ public ITagCollection<T> reinjectOptionalTags(ITagCollection<T> tagCollection) {
+ java.util.Map<ResourceLocation, ITag<T>> currentTags = tagCollection.func_241833_a();
+ java.util.Map<ResourceLocation, ITag<T>> missingOptionals = this.field_232931_c_.stream().filter(e -> e instanceof OptionalNamedTag && !currentTags.containsKey(e.func_230234_a_())).collect(Collectors.toMap(NamedTag::func_230234_a_, namedTag -> {
+ OptionalNamedTag<T> optionalNamedTag = (OptionalNamedTag<T>) namedTag;
+ optionalNamedTag.defaulted = true;
+ return optionalNamedTag.resolveDefaulted();
+ }));
+ if (!missingOptionals.isEmpty()) {
+ missingOptionals.putAll(currentTags);
+ return ITagCollection.func_242202_a(missingOptionals);
+ }
+ return tagCollection;
+ }
+
public ITagCollection<T> func_232939_b_() {
return this.field_232930_b_;
}
@@ -56,7 +108,7 @@
public Set<ResourceLocation> func_242189_b(ITagCollectionSupplier p_242189_1_) { public Set<ResourceLocation> func_242189_b(ITagCollectionSupplier p_242189_1_) {
ITagCollection<T> itagcollection = this.field_242184_c.apply(p_242189_1_); ITagCollection<T> itagcollection = this.field_242184_c.apply(p_242189_1_);
@ -62,7 +83,7 @@
ImmutableSet<ResourceLocation> immutableset = ImmutableSet.copyOf(itagcollection.func_199908_a()); ImmutableSet<ResourceLocation> immutableset = ImmutableSet.copyOf(itagcollection.func_199908_a());
return Sets.difference(set, immutableset); return Sets.difference(set, immutableset);
} }
@@ -93,5 +131,45 @@ @@ -93,5 +145,40 @@
public List<T> func_230236_b_() { public List<T> func_230236_b_() {
return this.func_232944_c_().func_230236_b_(); return this.func_232944_c_().func_230236_b_();
} }
@ -77,10 +98,10 @@
+ +
+ private static class OptionalNamedTag<T> extends NamedTag<T> implements net.minecraftforge.common.Tags.IOptionalNamedTag<T> { + private static class OptionalNamedTag<T> extends NamedTag<T> implements net.minecraftforge.common.Tags.IOptionalNamedTag<T> {
+ @Nullable + @Nullable
+ private final java.util.function.Supplier<Set<T>> defaults; + private final Set<java.util.function.Supplier<T>> defaults;
+ private boolean defaulted = true; + private boolean defaulted = false;
+ +
+ private OptionalNamedTag(ResourceLocation name, @Nullable java.util.function.Supplier<Set<T>> defaults) { + private OptionalNamedTag(ResourceLocation name, @Nullable Set<java.util.function.Supplier<T>> defaults) {
+ super(name); + super(name);
+ this.defaults = defaults; + this.defaults = defaults;
+ } + }
@ -90,16 +111,11 @@
+ return defaulted; + return defaulted;
+ } + }
+ +
+ @Override + Tag<T> resolveDefaulted() {
+ void func_232943_a_(Function<ResourceLocation, ITag<T>> p_232943_1_) { + if (defaults == null || defaults.isEmpty()) {
+ super.func_232943_a_(p_232943_1_); + return Tag.func_241284_a_();
+ if (this.field_232942_b_ == null) {
+ this.defaulted = true;
+ Set<T> defs = defaults == null ? null : defaults.get();
+ this.field_232942_b_ = defs == null ? Tag.func_241284_a_() : Tag.func_241286_a_(defs);
+ } else {
+ this.defaulted = false;
+ } + }
+ return Tag.func_241286_a_(ImmutableSet.copyOf(defaults.stream().map(java.util.function.Supplier::get).collect(Collectors.toSet())));
+ } + }
+ +
+ @Override + @Override

View file

@ -67,7 +67,6 @@ a012d6d92bab1c91913bd0f2dc0492a0fce916f2 assets/minecraft/blockstates/wall_torch
d2c8e860521c5e738ed0798337f5728d610825ff assets/piston_event_test/models/block/shiftonmove.json d2c8e860521c5e738ed0798337f5728d610825ff assets/piston_event_test/models/block/shiftonmove.json
f51f026a75e27a0a53a76771d553c0e3385a2966 assets/piston_event_test/models/item/shiftonmove.json f51f026a75e27a0a53a76771d553c0e3385a2966 assets/piston_event_test/models/item/shiftonmove.json
cf16f861eaf5815238c2278eb48bde0688cb73b7 assets/scaffolding_test/blockstates/scaffolding_method_test.json cf16f861eaf5815238c2278eb48bde0688cb73b7 assets/scaffolding_test/blockstates/scaffolding_method_test.json
42d3ce7d941eb8b80c3d541b937d0f93c9cf7c3c data/custom_tag_types_test/tags/biomes/oceans.json
862196702dcd5538c5ceb4ac6202e57eb5c8a97f data/custom_tag_types_test/tags/custom_tag_types_test/custom_types/tests.json 862196702dcd5538c5ceb4ac6202e57eb5c8a97f data/custom_tag_types_test/tags/custom_tag_types_test/custom_types/tests.json
4fbaf6f4a3ea05cc071076e27f44ac81f9cc50e3 data/data_gen_test/advancements/conditional.json 4fbaf6f4a3ea05cc071076e27f44ac81f9cc50e3 data/data_gen_test/advancements/conditional.json
ed4cbf1a3a2f5d8969f6346fdc9acdbe81d0c919 data/data_gen_test/recipes/conditional.json ed4cbf1a3a2f5d8969f6346fdc9acdbe81d0c919 data/data_gen_test/recipes/conditional.json

View file

@ -1,15 +0,0 @@
{
"replace": false,
"values": [
"minecraft:ocean",
"minecraft:frozen_ocean",
"minecraft:deep_ocean",
"minecraft:warm_ocean",
"minecraft:lukewarm_ocean",
"minecraft:cold_ocean",
"minecraft:deep_warm_ocean",
"minecraft:deep_lukewarm_ocean",
"minecraft:deep_cold_ocean",
"minecraft:deep_frozen_ocean"
]
}

View file

@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -121,7 +122,7 @@ public class ForgeTagHandler
* @param <T> Type of the registry * @param <T> Type of the registry
* @return An optional tag * @return An optional tag
*/ */
public static <T extends IForgeRegistryEntry<T>> IOptionalNamedTag<T> createOptionalTag(IForgeRegistry<T> registry, ResourceLocation name, @Nullable Supplier<Set<T>> defaults) public static <T extends IForgeRegistryEntry<T>> IOptionalNamedTag<T> createOptionalTag(IForgeRegistry<T> registry, ResourceLocation name, @Nullable Set<Supplier<T>> defaults)
{ {
validateRegistrySupportsTags(registry); validateRegistrySupportsTags(registry);
if (tagTypesSet) if (tagTypesSet)
@ -180,7 +181,7 @@ public class ForgeTagHandler
* @implNote This method only errors instantly if tag types have already been set, otherwise the error is delayed until after registries finish initializing * @implNote This method only errors instantly if tag types have already been set, otherwise the error is delayed until after registries finish initializing
* and we can validate if the custom registry really does support custom tags. * and we can validate if the custom registry really does support custom tags.
*/ */
public static <T extends IForgeRegistryEntry<T>> IOptionalNamedTag<T> createOptionalTag(ResourceLocation registryName, ResourceLocation name, @Nullable Supplier<Set<T>> defaults) public static <T extends IForgeRegistryEntry<T>> IOptionalNamedTag<T> createOptionalTag(ResourceLocation registryName, ResourceLocation name, @Nullable Set<Supplier<T>> defaults)
{ {
if (tagTypesSet) if (tagTypesSet)
{ {
@ -220,6 +221,10 @@ public class ForgeTagHandler
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"); 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; tagTypesSet = true;
customTagTypeNames = ImmutableSet.copyOf(customTagTypes); customTagTypeNames = ImmutableSet.copyOf(customTagTypes);
//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
// potentially should end up being moved into an async processor.
TagRegistry.performDelayedAdd(); TagRegistry.performDelayedAdd();
} }
@ -248,7 +253,7 @@ public class ForgeTagHandler
* *
* @apiNote Internal * @apiNote Internal
*/ */
public static void resetCachedTagCollections() public static void resetCachedTagCollections(boolean makeEmpty, boolean withOptional)
{ {
ImmutableMap.Builder<ResourceLocation, ITagCollection<?>> builder = ImmutableMap.builder(); ImmutableMap.Builder<ResourceLocation, ITagCollection<?>> builder = ImmutableMap.builder();
for (ResourceLocation registryName : customTagTypeNames) for (ResourceLocation registryName : customTagTypeNames)
@ -256,7 +261,17 @@ public class ForgeTagHandler
TagRegistry<?> tagRegistry = TagRegistryManager.get(registryName); TagRegistry<?> tagRegistry = TagRegistryManager.get(registryName);
if (tagRegistry != null) if (tagRegistry != null)
{ {
builder.put(registryName, ITagCollection.func_242202_a(tagRegistry.func_241288_c_().stream().distinct().collect(Collectors.toMap(INamedTag::func_230234_a_, namedTag -> namedTag)))); if (makeEmpty)
{
if (withOptional)
builder.put(registryName, tagRegistry.reinjectOptionalTags(ITagCollection.func_242202_a(Collections.emptyMap())));
else
builder.put(registryName, ITagCollection.func_242202_a(Collections.emptyMap()));
}
else
{
builder.put(registryName, ITagCollection.func_242202_a(tagRegistry.func_241288_c_().stream().distinct().collect(Collectors.toMap(INamedTag::func_230234_a_, namedTag -> namedTag))));
}
} }
} }
customTagTypes = builder.build(); customTagTypes = builder.build();
@ -270,7 +285,7 @@ public class ForgeTagHandler
public static ITagCollectionSupplier populateTagCollectionManager(ITagCollection<Block> blockTags, ITagCollection<Item> itemTags, ITagCollection<Fluid> fluidTags, ITagCollection<EntityType<?>> entityTypeTags) public static ITagCollectionSupplier populateTagCollectionManager(ITagCollection<Block> blockTags, ITagCollection<Item> itemTags, ITagCollection<Fluid> fluidTags, ITagCollection<EntityType<?>> entityTypeTags)
{ {
//Default the tag collections //Default the tag collections
resetCachedTagCollections(); resetCachedTagCollections(false, false);
if (!customTagTypes.isEmpty()) if (!customTagTypes.isEmpty())
{ {
LOGGER.debug("Populated the TagCollectionManager with {} extra types", customTagTypes.size()); LOGGER.debug("Populated the TagCollectionManager with {} extra types", customTagTypes.size());
@ -301,6 +316,7 @@ public class ForgeTagHandler
public static void updateCustomTagTypes(SyncCustomTagTypes packet) public static void updateCustomTagTypes(SyncCustomTagTypes packet)
{ {
customTagTypes = packet.getCustomTagTypes(); customTagTypes = packet.getCustomTagTypes();
reinjectOptionalTagsCustomTypes();
} }
/** /**
@ -321,6 +337,84 @@ public class ForgeTagHandler
return customResults; 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, ITagCollection<?>> builder = ImmutableMap.builder();
for (Entry<ResourceLocation, ITagCollection<?>> entry : customTagTypes.entrySet())
{
ResourceLocation registry = entry.getKey();
TagRegistry<?> tagRegistry = TagRegistryManager.get(registry);
ITagCollection<?> tagCollection = entry.getValue();
builder.put(registry, tagRegistry == null ? tagCollection : tagRegistry.reinjectOptionalTags((ITagCollection) tagCollection));
}
customTagTypes = builder.build();
}
/**
* Gets an {@link ITagCollectionSupplier} 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 ITagCollectionSupplier withNoCustom(ITagCollectionSupplier tagCollectionSupplier)
{
ImmutableMap.Builder<ResourceLocation, ITagCollection<?>> builder = ImmutableMap.builder();
for (ResourceLocation registryName : customTagTypeNames)
{
TagRegistry<?> tagRegistry = TagRegistryManager.get(registryName);
if (tagRegistry != null)
{
builder.put(registryName, ITagCollection.func_242202_a(Collections.emptyMap()));
}
}
return withSpecificCustom(tagCollectionSupplier, builder.build());
}
/**
* Gets an {@link ITagCollectionSupplier} with specific custom tag types for testing if any tags are missing.
*
* @apiNote Internal
*/
public static ITagCollectionSupplier withSpecificCustom(ITagCollectionSupplier tagCollectionSupplier, Map<ResourceLocation, ITagCollection<?>> customTagTypes)
{
return new ITagCollectionSupplier()
{
@Override
public ITagCollection<Block> func_241835_a()
{
return tagCollectionSupplier.func_241835_a();
}
@Override
public ITagCollection<Item> func_241836_b()
{
return tagCollectionSupplier.func_241836_b();
}
@Override
public ITagCollection<Fluid> func_241837_c()
{
return tagCollectionSupplier.func_241837_c();
}
@Override
public ITagCollection<EntityType<?>> func_241838_d()
{
return tagCollectionSupplier.func_241838_d();
}
@Override
public Map<ResourceLocation, ITagCollection<?>> 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. * Helper storage class for keeping track of various data for all custom tag types in the NetworkTagReader to make the code easier to read.
* *

View file

@ -70,4 +70,10 @@ public abstract class ForgeRegistryTagsProvider<T extends IForgeRegistryEntry<T>
{ {
return generator.getOutputFolder().resolve("data/" + id.getNamespace() + "/tags/" + folder + "/" + id.getPath() + ".json"); return generator.getOutputFolder().resolve("data/" + id.getNamespace() + "/tags/" + folder + "/" + id.getPath() + ".json");
} }
@Override
protected String getTagFolder()
{
return folder;
}
} }

View file

@ -195,10 +195,10 @@ public class ModLoader
dispatchAndHandleError(ModLoadingStage.CREATE_REGISTRIES, syncExecutor, parallelExecutor, periodicTask); dispatchAndHandleError(ModLoadingStage.CREATE_REGISTRIES, syncExecutor, parallelExecutor, periodicTask);
ObjectHolderRegistry.findObjectHolders(); ObjectHolderRegistry.findObjectHolders();
CapabilityManager.INSTANCE.injectCapabilities(modList.getAllScanData()); CapabilityManager.INSTANCE.injectCapabilities(modList.getAllScanData());
statusConsumer.ifPresent(c->c.accept("Populating registries"));
dispatchAndHandleError(ModLoadingStage.LOAD_REGISTRIES, syncExecutor, parallelExecutor, periodicTask);
statusConsumer.ifPresent(c->c.accept("Adding custom tag types")); statusConsumer.ifPresent(c->c.accept("Adding custom tag types"));
GameData.setCustomTagTypesFromRegistries(); GameData.setCustomTagTypesFromRegistries();
statusConsumer.ifPresent(c->c.accept("Populating registries"));
dispatchAndHandleError(ModLoadingStage.LOAD_REGISTRIES, syncExecutor, parallelExecutor, periodicTask);
statusConsumer.ifPresent(c->c.accept("Early mod loading complete")); statusConsumer.ifPresent(c->c.accept("Early mod loading complete"));
} }

View file

@ -26,7 +26,6 @@ import com.google.common.collect.Multimap;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.IHasContainer; import net.minecraft.client.gui.IHasContainer;
import net.minecraft.client.gui.ScreenManager; import net.minecraft.client.gui.ScreenManager;
@ -34,10 +33,8 @@ import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.fluid.Fluid;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.Item;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.tags.ITag; import net.minecraft.tags.ITag;
import net.minecraft.tags.ITagCollection; import net.minecraft.tags.ITagCollection;
@ -414,39 +411,8 @@ public class FMLPlayMessages
// to the last working set of tags // 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 //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 // so they won't be validated
Multimap<ResourceLocation, ResourceLocation> missingTags = TagRegistryManager.func_242198_b(new ITagCollectionSupplier() //Override and use the tags from the packet to test for validation before we actually set them
{ Multimap<ResourceLocation, ResourceLocation> missingTags = TagRegistryManager.func_242198_b(ForgeTagHandler.withSpecificCustom(tagCollectionSupplier, msg.customTagTypeCollections));
@Override
public ITagCollection<Block> func_241835_a()
{
return tagCollectionSupplier.func_241835_a();
}
@Override
public ITagCollection<Item> func_241836_b()
{
return tagCollectionSupplier.func_241836_b();
}
@Override
public ITagCollection<Fluid> func_241837_c()
{
return tagCollectionSupplier.func_241837_c();
}
@Override
public ITagCollection<EntityType<?>> func_241838_d()
{
return tagCollectionSupplier.func_241838_d();
}
@Override
public Map<ResourceLocation, ITagCollection<?>> getCustomTagTypes()
{
//Override and use the tags from the packet to test for validation before we actually set them
return msg.customTagTypeCollections;
}
});
if (missingTags.isEmpty()) if (missingTags.isEmpty())
{ {
//If we have no missing tags, update the custom tag types //If we have no missing tags, update the custom tag types

View file

@ -119,9 +119,14 @@ public class NetworkHooks
FMLNetworkConstants.playChannel.sendTo(new FMLPlayMessages.DimensionInfoMessage(player.dimension), manager, NetworkDirection.PLAY_TO_CLIENT); FMLNetworkConstants.playChannel.sendTo(new FMLPlayMessages.DimensionInfoMessage(player.dimension), manager, NetworkDirection.PLAY_TO_CLIENT);
}*/ }*/
public static void handleClientLoginSuccess(NetworkManager manager) { public static boolean isVanillaConnection(NetworkManager manager)
{
if (manager == null || manager.channel() == null) throw new NullPointerException("ARGH! Network Manager is null (" + manager != null ? "CHANNEL" : "MANAGER"+")" ); if (manager == null || manager.channel() == null) throw new NullPointerException("ARGH! Network Manager is null (" + manager != null ? "CHANNEL" : "MANAGER"+")" );
if (getConnectionType(()->manager) == ConnectionType.VANILLA) { return getConnectionType(() -> manager) == ConnectionType.VANILLA;
}
public static void handleClientLoginSuccess(NetworkManager manager) {
if (isVanillaConnection(manager)) {
LOGGER.info("Connected to a vanilla server. Catching up missing behaviour."); LOGGER.info("Connected to a vanilla server. Catching up missing behaviour.");
ConfigTracker.INSTANCE.loadDefaultServerConfigs(); ConfigTracker.INSTANCE.loadDefaultServerConfigs();
} else { } else {

View file

@ -179,7 +179,7 @@ public class GameData
makeRegistry(TREE_DECORATOR_TYPES, c(TreeDecoratorType.class)).disableSaving().disableSync().create(); makeRegistry(TREE_DECORATOR_TYPES, c(TreeDecoratorType.class)).disableSaving().disableSync().create();
// Dynamic Worldgen // Dynamic Worldgen
makeRegistry(BIOMES, Biome.class).tagFolder("biomes").create(); makeRegistry(BIOMES, Biome.class).create();
// Custom forge registries // Custom forge registries
makeRegistry(DATA_SERIALIZERS, DataSerializerEntry.class, 256 /*vanilla space*/, MAX_VARINT).disableSaving().disableOverrides().addCallback(SerializerCallbacks.INSTANCE).create(); makeRegistry(DATA_SERIALIZERS, DataSerializerEntry.class, 256 /*vanilla space*/, MAX_VARINT).disableSaving().disableOverrides().addCallback(SerializerCallbacks.INSTANCE).create();

View file

@ -19,44 +19,54 @@
package net.minecraftforge.debug.misc; package net.minecraftforge.debug.misc;
import com.google.common.collect.Sets;
import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.minecraft.data.DataGenerator; import net.minecraft.data.DataGenerator;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.tags.ITag; import net.minecraft.tags.ITag;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagCollectionManager;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraftforge.common.ForgeTagHandler; import net.minecraftforge.common.ForgeTagHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.common.data.ForgeRegistryTagsProvider; import net.minecraftforge.common.data.ForgeRegistryTagsProvider;
import net.minecraftforge.common.util.ReverseTagWrapper;
import net.minecraftforge.event.entity.ProjectileImpactEvent;
import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent; import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ForgeRegistryEntry; import net.minecraftforge.registries.ForgeRegistryEntry;
import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryBuilder; import net.minecraftforge.registries.RegistryBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Mod(CustomTagTypesTest.MODID) @Mod(CustomTagTypesTest.MODID)
public class CustomTagTypesTest public class CustomTagTypesTest
{ {
public static final String MODID = "custom_tag_types_test"; public static final String MODID = "custom_tag_types_test";
private static final Logger LOGGER = LogManager.getLogger(MODID);
private static final ResourceLocation customRegistryName = new ResourceLocation(MODID, "custom_type_registry"); 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 DeferredRegister<Custom> CUSTOMS = DeferredRegister.create(Custom.class, MODID);
private static final RegistryObject<Custom> CUSTOM = CUSTOMS.register("custom", Custom::new); private static final RegistryObject<Custom> CUSTOM = CUSTOMS.register("custom", Custom::new);
private static final Supplier<IForgeRegistry<Custom>> CUSTOM_REG = CUSTOMS.makeRegistry(customRegistryName.getPath(), private static final Supplier<IForgeRegistry<Custom>> CUSTOM_REG = CUSTOMS.makeRegistry(customRegistryName.getPath(),
() -> new RegistryBuilder<Custom>().tagFolder(MODID + "/custom_types")); () -> new RegistryBuilder<Custom>().tagFolder(MODID + "/custom_types"));
private static final ITag.INamedTag<Biome> OCEANS = ForgeTagHandler.makeWrapperTag(ForgeRegistries.BIOMES, new ResourceLocation(MODID, "oceans")); private static final ITag.INamedTag<Custom> TESTS = ForgeTagHandler.createOptionalTag(customRegistryName, new ResourceLocation(MODID, "tests"), Sets.newHashSet(CUSTOM));
private static final ITag.INamedTag<Custom> TESTS = ForgeTagHandler.makeWrapperTag(customRegistryName, new ResourceLocation(MODID, "tests")); private static final ITag.INamedTag<Item> OPTIONAL_TEST = ItemTags.createOptional(new ResourceLocation(MODID, "optional_test"), Sets.newHashSet(() -> Items.BONE));
public CustomTagTypesTest() public CustomTagTypesTest()
{ {
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus(); IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
CUSTOMS.register(modBus); CUSTOMS.register(modBus);
modBus.addListener(this::gatherData); modBus.addListener(this::gatherData);
MinecraftForge.EVENT_BUS.addListener(this::projectileImpact);
} }
private void gatherData(GatherDataEvent event) private void gatherData(GatherDataEvent event)
@ -64,32 +74,27 @@ public class CustomTagTypesTest
if (event.includeServer()) if (event.includeServer())
{ {
DataGenerator gen = event.getGenerator(); DataGenerator gen = event.getGenerator();
ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); gen.addProvider(new CustomRegistryTags(gen, event.getExistingFileHelper()));
gen.addProvider(new BiomeTags(gen, existingFileHelper));
gen.addProvider(new CustomRegistryTags(gen, existingFileHelper));
} }
} }
public static class Custom extends ForgeRegistryEntry<Custom> { private void projectileImpact(ProjectileImpactEvent.Arrow event)
}
public static class BiomeTags extends ForgeRegistryTagsProvider<Biome>
{ {
public BiomeTags(DataGenerator gen, @Nullable ExistingFileHelper existingFileHelper) LOGGER.info("{} {} {}", Items.BONE.getTags(), OPTIONAL_TEST.func_230236_b_().size(), TagCollectionManager.func_242178_a().func_241836_b().get(new ResourceLocation(MODID, "optional_test")));
}
public static class Custom extends ForgeRegistryEntry<Custom>
{
private final ReverseTagWrapper<Custom> reverseTags = new ReverseTagWrapper<>(this, () -> TagCollectionManager.func_242178_a().getCustomTypeCollection(CUSTOM_REG.get()));
public Set<ResourceLocation> getTags()
{ {
super(gen, ForgeRegistries.BIOMES, MODID, existingFileHelper); return reverseTags.getTagNames();
} }
@Override public boolean isIn(ITag<Custom> tag)
protected void registerTags()
{ {
func_240522_a_(OCEANS).add(Biomes.OCEAN, Biomes.FROZEN_OCEAN, Biomes.DEEP_OCEAN, Biomes.WARM_OCEAN, Biomes.LUKEWARM_OCEAN, return tag.func_230235_a_(this);
Biomes.COLD_OCEAN, Biomes.DEEP_WARM_OCEAN, Biomes.DEEP_LUKEWARM_OCEAN, Biomes.DEEP_COLD_OCEAN, Biomes.DEEP_FROZEN_OCEAN);
}
@Override
public String getName() {
return "Biome Tags";
} }
} }