Fix a few minor issues with custom tag types and fix OptionalNamedTags (#7316)
This commit is contained in:
parent
37be3aff2d
commit
af75547d37
18 changed files with 258 additions and 114 deletions
|
@ -77,21 +77,23 @@
|
|||
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.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_) {
|
||||
PacketThreadUtil.func_218797_a(p_199723_1_, this, this.field_147299_f);
|
||||
ITagCollectionSupplier itagcollectionsupplier = p_199723_1_.func_199858_a();
|
||||
- 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()) {
|
||||
field_147301_d.warn("Incomplete server tags, disconnecting. Missing: {}", (Object)multimap);
|
||||
this.field_147302_e.func_150718_a(new TranslationTextComponent("multiplayer.disconnect.missing_tags"));
|
||||
} else {
|
||||
+ net.minecraftforge.common.ForgeTagHandler.resetCachedTagCollections();
|
||||
+ net.minecraftforge.common.ForgeTagHandler.resetCachedTagCollections(true, vanillaConnection);
|
||||
+ itagcollectionsupplier = ITagCollectionSupplier.reinjectOptionalTags(itagcollectionsupplier);
|
||||
this.field_199725_m = itagcollectionsupplier;
|
||||
if (!this.field_147302_e.func_150731_c()) {
|
||||
itagcollectionsupplier.func_242212_e();
|
||||
@@ -1883,10 +1897,12 @@
|
||||
@@ -1883,10 +1899,12 @@
|
||||
int l5 = packetbuffer.readInt();
|
||||
this.field_147299_f.field_184132_p.field_229018_q_.func_229022_a_(blockpos8, l3, s10, l5);
|
||||
} else {
|
||||
|
|
|
@ -8,3 +8,11 @@
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
--- a/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_);
|
||||
}
|
||||
|
||||
+ 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() {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
--- a/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_);
|
||||
}
|
||||
|
||||
+ 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() {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
--- a/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_);
|
||||
}
|
||||
|
||||
+ 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_() {
|
||||
|
|
|
@ -17,3 +17,36 @@
|
|||
}
|
||||
|
||||
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;
|
||||
+ }
|
||||
+ };
|
||||
+ }
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
--- a/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_);
|
||||
}
|
||||
|
||||
+ 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() {
|
||||
|
|
|
@ -23,3 +23,12 @@
|
|||
ITagCollectionSupplier itagcollectionsupplier = ITagCollectionSupplier.func_242209_a(itagcollection, itagcollection1, itagcollection2, itagcollection3);
|
||||
Multimap<ResourceLocation, ResourceLocation> multimap = TagRegistryManager.func_242198_b(itagcollectionsupplier);
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
+ 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));
|
||||
+ }
|
||||
+
|
||||
|
@ -24,8 +24,8 @@
|
|||
+ 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)} */
|
||||
+ public static <T> net.minecraftforge.common.Tags.IOptionalNamedTag<T> createDelayedOptional(ResourceLocation tagRegistry, ResourceLocation key, @Nullable java.util.function.Supplier<Set<T>> defaults) {
|
||||
+ /** 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 Set<java.util.function.Supplier<T>> defaults) {
|
||||
+ return delayedAdd(tagRegistry, new TagRegistry.OptionalNamedTag<>(key, defaults));
|
||||
+ }
|
||||
+
|
||||
|
@ -53,7 +53,28 @@
|
|||
this.field_232931_c_.add(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_) {
|
||||
ITagCollection<T> itagcollection = this.field_242184_c.apply(p_242189_1_);
|
||||
|
@ -62,7 +83,7 @@
|
|||
ImmutableSet<ResourceLocation> immutableset = ImmutableSet.copyOf(itagcollection.func_199908_a());
|
||||
return Sets.difference(set, immutableset);
|
||||
}
|
||||
@@ -93,5 +131,45 @@
|
||||
@@ -93,5 +145,40 @@
|
||||
public List<T> 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> {
|
||||
+ @Nullable
|
||||
+ private final java.util.function.Supplier<Set<T>> defaults;
|
||||
+ private boolean defaulted = true;
|
||||
+ private final Set<java.util.function.Supplier<T>> defaults;
|
||||
+ 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);
|
||||
+ this.defaults = defaults;
|
||||
+ }
|
||||
|
@ -90,16 +111,11 @@
|
|||
+ return defaulted;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ void func_232943_a_(Function<ResourceLocation, ITag<T>> p_232943_1_) {
|
||||
+ super.func_232943_a_(p_232943_1_);
|
||||
+ 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;
|
||||
+ Tag<T> resolveDefaulted() {
|
||||
+ if (defaults == null || defaults.isEmpty()) {
|
||||
+ return Tag.func_241284_a_();
|
||||
+ }
|
||||
+ return Tag.func_241286_a_(ImmutableSet.copyOf(defaults.stream().map(java.util.function.Supplier::get).collect(Collectors.toSet())));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
|
|
|
@ -67,7 +67,6 @@ a012d6d92bab1c91913bd0f2dc0492a0fce916f2 assets/minecraft/blockstates/wall_torch
|
|||
d2c8e860521c5e738ed0798337f5728d610825ff assets/piston_event_test/models/block/shiftonmove.json
|
||||
f51f026a75e27a0a53a76771d553c0e3385a2966 assets/piston_event_test/models/item/shiftonmove.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
|
||||
4fbaf6f4a3ea05cc071076e27f44ac81f9cc50e3 data/data_gen_test/advancements/conditional.json
|
||||
ed4cbf1a3a2f5d8969f6346fdc9acdbe81d0c919 data/data_gen_test/recipes/conditional.json
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
}
|
|
@ -25,6 +25,7 @@ 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;
|
||||
|
@ -121,7 +122,7 @@ public class ForgeTagHandler
|
|||
* @param <T> Type of the registry
|
||||
* @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);
|
||||
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
|
||||
* 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)
|
||||
{
|
||||
|
@ -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");
|
||||
tagTypesSet = true;
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -248,17 +253,27 @@ public class ForgeTagHandler
|
|||
*
|
||||
* @apiNote Internal
|
||||
*/
|
||||
public static void resetCachedTagCollections()
|
||||
public static void resetCachedTagCollections(boolean makeEmpty, boolean withOptional)
|
||||
{
|
||||
ImmutableMap.Builder<ResourceLocation, ITagCollection<?>> builder = ImmutableMap.builder();
|
||||
for (ResourceLocation registryName : customTagTypeNames)
|
||||
{
|
||||
TagRegistry<?> tagRegistry = TagRegistryManager.get(registryName);
|
||||
if (tagRegistry != null)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -270,7 +285,7 @@ public class ForgeTagHandler
|
|||
public static ITagCollectionSupplier populateTagCollectionManager(ITagCollection<Block> blockTags, ITagCollection<Item> itemTags, ITagCollection<Fluid> fluidTags, ITagCollection<EntityType<?>> entityTypeTags)
|
||||
{
|
||||
//Default the tag collections
|
||||
resetCachedTagCollections();
|
||||
resetCachedTagCollections(false, false);
|
||||
if (!customTagTypes.isEmpty())
|
||||
{
|
||||
LOGGER.debug("Populated the TagCollectionManager with {} extra types", customTagTypes.size());
|
||||
|
@ -301,6 +316,7 @@ public class ForgeTagHandler
|
|||
public static void updateCustomTagTypes(SyncCustomTagTypes packet)
|
||||
{
|
||||
customTagTypes = packet.getCustomTagTypes();
|
||||
reinjectOptionalTagsCustomTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -321,6 +337,84 @@ public class ForgeTagHandler
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -70,4 +70,10 @@ public abstract class ForgeRegistryTagsProvider<T extends IForgeRegistryEntry<T>
|
|||
{
|
||||
return generator.getOutputFolder().resolve("data/" + id.getNamespace() + "/tags/" + folder + "/" + id.getPath() + ".json");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTagFolder()
|
||||
{
|
||||
return folder;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -195,10 +195,10 @@ public class ModLoader
|
|||
dispatchAndHandleError(ModLoadingStage.CREATE_REGISTRIES, syncExecutor, parallelExecutor, periodicTask);
|
||||
ObjectHolderRegistry.findObjectHolders();
|
||||
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"));
|
||||
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"));
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import com.google.common.collect.Multimap;
|
|||
import io.netty.buffer.Unpooled;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.IHasContainer;
|
||||
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.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.tags.ITagCollection;
|
||||
|
@ -414,39 +411,8 @@ public class FMLPlayMessages
|
|||
// 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
|
||||
Multimap<ResourceLocation, ResourceLocation> missingTags = TagRegistryManager.func_242198_b(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()
|
||||
{
|
||||
//Override and use the tags from the packet to test for validation before we actually set them
|
||||
return msg.customTagTypeCollections;
|
||||
}
|
||||
});
|
||||
Multimap<ResourceLocation, ResourceLocation> missingTags = TagRegistryManager.func_242198_b(ForgeTagHandler.withSpecificCustom(tagCollectionSupplier, msg.customTagTypeCollections));
|
||||
if (missingTags.isEmpty())
|
||||
{
|
||||
//If we have no missing tags, update the custom tag types
|
||||
|
|
|
@ -119,9 +119,14 @@ public class NetworkHooks
|
|||
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 (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.");
|
||||
ConfigTracker.INSTANCE.loadDefaultServerConfigs();
|
||||
} else {
|
||||
|
|
|
@ -179,7 +179,7 @@ public class GameData
|
|||
makeRegistry(TREE_DECORATOR_TYPES, c(TreeDecoratorType.class)).disableSaving().disableSync().create();
|
||||
|
||||
// Dynamic Worldgen
|
||||
makeRegistry(BIOMES, Biome.class).tagFolder("biomes").create();
|
||||
makeRegistry(BIOMES, Biome.class).create();
|
||||
|
||||
// Custom forge registries
|
||||
makeRegistry(DATA_SERIALIZERS, DataSerializerEntry.class, 256 /*vanilla space*/, MAX_VARINT).disableSaving().disableOverrides().addCallback(SerializerCallbacks.INSTANCE).create();
|
||||
|
|
|
@ -19,44 +19,54 @@
|
|||
|
||||
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.data.DataGenerator;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tags.TagCollectionManager;
|
||||
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.MinecraftForge;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
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.fml.RegistryObject;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.RegistryBuilder;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(CustomTagTypesTest.MODID)
|
||||
public class CustomTagTypesTest
|
||||
{
|
||||
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 DeferredRegister<Custom> CUSTOMS = DeferredRegister.create(Custom.class, MODID);
|
||||
private static final RegistryObject<Custom> CUSTOM = CUSTOMS.register("custom", Custom::new);
|
||||
private static final Supplier<IForgeRegistry<Custom>> CUSTOM_REG = CUSTOMS.makeRegistry(customRegistryName.getPath(),
|
||||
() -> 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.makeWrapperTag(customRegistryName, new ResourceLocation(MODID, "tests"));
|
||||
private static final ITag.INamedTag<Custom> TESTS = ForgeTagHandler.createOptionalTag(customRegistryName, new ResourceLocation(MODID, "tests"), Sets.newHashSet(CUSTOM));
|
||||
private static final ITag.INamedTag<Item> OPTIONAL_TEST = ItemTags.createOptional(new ResourceLocation(MODID, "optional_test"), Sets.newHashSet(() -> Items.BONE));
|
||||
|
||||
public CustomTagTypesTest()
|
||||
{
|
||||
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
CUSTOMS.register(modBus);
|
||||
modBus.addListener(this::gatherData);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::projectileImpact);
|
||||
}
|
||||
|
||||
private void gatherData(GatherDataEvent event)
|
||||
|
@ -64,32 +74,27 @@ public class CustomTagTypesTest
|
|||
if (event.includeServer())
|
||||
{
|
||||
DataGenerator gen = event.getGenerator();
|
||||
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
|
||||
gen.addProvider(new BiomeTags(gen, existingFileHelper));
|
||||
gen.addProvider(new CustomRegistryTags(gen, existingFileHelper));
|
||||
gen.addProvider(new CustomRegistryTags(gen, event.getExistingFileHelper()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Custom extends ForgeRegistryEntry<Custom> {
|
||||
}
|
||||
|
||||
public static class BiomeTags extends ForgeRegistryTagsProvider<Biome>
|
||||
private void projectileImpact(ProjectileImpactEvent.Arrow event)
|
||||
{
|
||||
public BiomeTags(DataGenerator gen, @Nullable ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(gen, ForgeRegistries.BIOMES, MODID, 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")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerTags()
|
||||
public static class Custom extends ForgeRegistryEntry<Custom>
|
||||
{
|
||||
func_240522_a_(OCEANS).add(Biomes.OCEAN, Biomes.FROZEN_OCEAN, Biomes.DEEP_OCEAN, Biomes.WARM_OCEAN, Biomes.LUKEWARM_OCEAN,
|
||||
Biomes.COLD_OCEAN, Biomes.DEEP_WARM_OCEAN, Biomes.DEEP_LUKEWARM_OCEAN, Biomes.DEEP_COLD_OCEAN, Biomes.DEEP_FROZEN_OCEAN);
|
||||
private final ReverseTagWrapper<Custom> reverseTags = new ReverseTagWrapper<>(this, () -> TagCollectionManager.func_242178_a().getCustomTypeCollection(CUSTOM_REG.get()));
|
||||
|
||||
public Set<ResourceLocation> getTags()
|
||||
{
|
||||
return reverseTags.getTagNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Biome Tags";
|
||||
public boolean isIn(ITag<Custom> tag)
|
||||
{
|
||||
return tag.func_230235_a_(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue