Add support for tagging StructureFeatures (#8408)

This commit is contained in:
Marc Hermans authored and GitHub committed 2022-02-08 12:48:57 -08:00
1 parent 82a20911cb
commit 2765c0d8d9
5 files changed
+76 -3

No files matched your search

@@ -9,6 +9,29 @@
public static final BiMap<String, StructureFeature<?>> f_67012_ = HashBiMap.create();
private static final Map<StructureFeature<?>, GenerationStep.Decoration> f_67032_ = Maps.newHashMap();
private static final Logger f_67033_ = LogManager.getLogger();
@@ -79,6 +_,7 @@
public static final StructureFeature<JigsawConfiguration> f_67030_ = m_67089_("Bastion_Remnant", new BastionFeature(JigsawConfiguration.f_67756_), GenerationStep.Decoration.SURFACE_STRUCTURES);
public static final List<StructureFeature<?>> f_67031_ = ImmutableList.of(f_67013_, f_67028_, f_67029_, f_67022_);
public static final int f_160446_ = 8;
+ private final net.minecraftforge.common.util.ReverseTagWrapper<StructureFeature<?>> reverseTags = new net.minecraftforge.common.util.ReverseTagWrapper<>(this, () -> net.minecraft.tags.SerializationTags.m_13199_().m_144452_(Registry.f_122840_));
private final Codec<ConfiguredStructureFeature<C, StructureFeature<C>>> f_67036_;
private final PieceGeneratorSupplier<C> f_191106_;
private final PostPlacementProcessor f_191107_;
@@ -103,6 +_,14 @@
this.f_191107_ = p_197170_;
}
+ public java.util.Set<net.minecraft.resources.ResourceLocation> getTags() {
+ return reverseTags.getTagNames();
+ }
+
+ public boolean is(net.minecraft.tags.Tag<StructureFeature<?>> tag) {
+ return tag.m_8110_(this);
+ }
+
public GenerationStep.Decoration m_67095_() {
return f_67032_.get(this);
}
@@ -256,6 +_,11 @@
public String m_67098_() {
@@ -89,6 +89,7 @@ cf16f861eaf5815238c2278eb48bde0688cb73b7 assets/scaffolding_test/blockstates/sca
8c1969250406edfbd470cc06aca4dcccfd6ce682 data/custom_tag_types_test/tags/enchantments/fire.json
acd80cfdb22681f810e41f38776a4ff7ef703799 data/custom_tag_types_test/tags/mob_effects/beacon.json
44985f1cb0df54b632187ed97a6a443455f1e51c data/custom_tag_types_test/tags/potions/damage.json
0b9850b6647ef27f5af6b459749b386ae396aac1 data/custom_tag_types_test/tags/structure_features/overworld_temple.json
806659ba3e9c12797df0fe7211a222795834fdfd data/data_gen_test/advancements/conditional.json
0001aa55877ddee50e3180db7337e926797d7e4d data/data_gen_test/advancements/obtain_dirt.json
76e760c8e8a1bbd3fb5538bc2d773c117016c0ce data/data_gen_test/advancements/recipes/conditional2.json
@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"minecraft:desert_pyramid",
"minecraft:jungle_pyramid"
]
}
@@ -1,6 +1,6 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2021.
* Copyright (c) 2016-2022.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -163,7 +163,7 @@ public class GameData
makeRegistry(WORLD_CARVERS, c(WorldCarver.class)).disableSaving().disableSync().create();
makeRegistry(FEATURES, c(Feature.class)).addCallback(FeatureCallbacks.INSTANCE).disableSaving().disableSync().create();
makeRegistry(CHUNK_STATUS, ChunkStatus.class, "empty").disableSaving().disableSync().create();
makeRegistry(STRUCTURE_FEATURES, c(StructureFeature.class)).disableSaving().disableSync().create();
makeRegistry(STRUCTURE_FEATURES, c(StructureFeature.class)).disableSaving().disableSync().tagFolder("structure_features").create();
makeRegistry(BLOCK_STATE_PROVIDER_TYPES, c(BlockStateProviderType.class)).disableSaving().disableSync().create();
makeRegistry(FOLIAGE_PLACER_TYPES, c(FoliagePlacerType.class)).disableSaving().disableSync().create();
makeRegistry(TREE_DECORATOR_TYPES, c(TreeDecoratorType.class)).disableSaving().disableSync().create();
@@ -1,6 +1,6 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2021.
* Copyright (c) 2016-2022.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -22,9 +22,12 @@ package net.minecraftforge.debug.misc;
import java.util.Set;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.data.DataGenerator;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.item.enchantment.Enchantment;
@@ -43,6 +46,7 @@ import net.minecraft.tags.SerializationTags;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraftforge.common.ForgeTagHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.data.ExistingFileHelper;
@@ -79,6 +83,7 @@ public class CustomTagTypesTest
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"));
private static final Tag.Named<MobEffect> BEACON = ForgeTagHandler.createOptionalTag(ForgeRegistries.MOB_EFFECTS, new ResourceLocation(MODID, "beacon"));
private static final Tag.Named<StructureFeature<?>> OVERWORLD_TEMPLE = ForgeTagHandler.createOptionalTag(ForgeRegistries.STRUCTURE_FEATURES, new ResourceLocation(MODID, "overworld_temple"));
public CustomTagTypesTest()
{
@@ -99,6 +104,7 @@ public class CustomTagTypesTest
gen.addProvider(new PotionTags(gen, existingFileHelper));
gen.addProvider(new BlockEntityTypeTags(gen, existingFileHelper));
gen.addProvider(new MobEffectTypeTags(gen, existingFileHelper));
gen.addProvider(new StructureFeatureTags(gen, existingFileHelper));
}
}
@@ -115,6 +121,21 @@ public class CustomTagTypesTest
if (blockEntity != null) logTagsIfPresent(blockEntity.getType().getTags());
event.getEntityLiving().getActiveEffects().forEach((mobEffectInstance) -> logTagsIfPresent(mobEffectInstance.getEffect().getTags()));
}
if (event.getPlayer().getLevel() instanceof ServerLevel serverLevel)
{
OVERWORLD_TEMPLE.getValues().forEach(temple -> {
final BlockPos found = serverLevel.findNearestMapFeature(temple, event.getPos(), 100, false);
if (found != null)
{
LOGGER.info("Found {} at {}", temple.getRegistryName(), found);
}
else
{
LOGGER.info("Could not find {}", temple.getRegistryName());
}
});
}
}
private void logTagsIfPresent(Set<ResourceLocation> tags)
@@ -234,4 +255,25 @@ public class CustomTagTypesTest
return "Mob Effect Tags";
}
}
public static class StructureFeatureTags extends ForgeRegistryTagsProvider<StructureFeature<?>>
{
public StructureFeatureTags(DataGenerator gen, @Nullable ExistingFileHelper existingFileHelper)
{
super(gen, ForgeRegistries.STRUCTURE_FEATURES, MODID, existingFileHelper);
}
@Override
public String getName()
{
return "Structure Feature Tags";
}
@Override
protected void addTags()
{
tag(OVERWORLD_TEMPLE).add(StructureFeature.DESERT_PYRAMID, StructureFeature.JUNGLE_TEMPLE);
}
}
}