Adds tag support for Enchantments, Potions, and TileEntityTypes (#7379)

This commit is contained in:
Richard Freimer 2020-10-15 15:45:25 -04:00 committed by GitHub
parent 93226bbcff
commit b1659300e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 188 additions and 13 deletions

View file

@ -1,15 +1,31 @@
--- a/net/minecraft/enchantment/Enchantment.java --- a/net/minecraft/enchantment/Enchantment.java
+++ b/net/minecraft/enchantment/Enchantment.java +++ b/net/minecraft/enchantment/Enchantment.java
@@ -18,7 +18,7 @@ @@ -18,7 +18,8 @@
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
-public abstract class Enchantment { -public abstract class Enchantment {
+public abstract class Enchantment extends net.minecraftforge.registries.ForgeRegistryEntry<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.TagCollectionManager.func_242178_a().getCustomTypeCollection(net.minecraftforge.registries.ForgeRegistries.ENCHANTMENTS));
private final EquipmentSlotType[] field_185263_a; private final EquipmentSlotType[] field_185263_a;
private final Enchantment.Rarity field_77333_a; private final Enchantment.Rarity field_77333_a;
public final EnchantmentType field_77351_y; public final EnchantmentType field_77351_y;
@@ -114,7 +114,7 @@ @@ -37,6 +38,14 @@
this.field_185263_a = p_i46731_3_;
}
+ public java.util.Set<net.minecraft.util.ResourceLocation> getTags() {
+ return reverseTags.getTagNames();
+ }
+
+ public boolean isIn(net.minecraft.tags.ITag<Enchantment> tag) {
+ return tag.func_230235_a_(this);
+ }
+
public Map<EquipmentSlotType, ItemStack> func_222181_a(LivingEntity p_222181_1_) {
Map<EquipmentSlotType, ItemStack> map = Maps.newEnumMap(EquipmentSlotType.class);
@@ -114,7 +123,7 @@
} }
public boolean func_92089_a(ItemStack p_92089_1_) { public boolean func_92089_a(ItemStack p_92089_1_) {
@ -18,7 +34,7 @@
} }
public void func_151368_a(LivingEntity p_151368_1_, Entity p_151368_2_, int p_151368_3_) { public void func_151368_a(LivingEntity p_151368_1_, Entity p_151368_2_, int p_151368_3_) {
@@ -139,6 +139,24 @@ @@ -139,6 +148,24 @@
return true; return true;
} }

View file

@ -1,11 +1,27 @@
--- a/net/minecraft/potion/Potion.java --- a/net/minecraft/potion/Potion.java
+++ b/net/minecraft/potion/Potion.java +++ b/net/minecraft/potion/Potion.java
@@ -6,7 +6,7 @@ @@ -6,7 +6,8 @@
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
-public class Potion { -public class Potion {
+public class Potion extends net.minecraftforge.registries.ForgeRegistryEntry<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<>(this, () -> net.minecraft.tags.TagCollectionManager.func_242178_a().getCustomTypeCollection(net.minecraftforge.registries.ForgeRegistries.POTION_TYPES));
private final String field_185179_d; private final String field_185179_d;
private final ImmutableList<EffectInstance> field_185180_e; private final ImmutableList<EffectInstance> field_185180_e;
@@ -23,6 +24,14 @@
this.field_185180_e = ImmutableList.copyOf(p_i46740_2_);
}
+ public java.util.Set<net.minecraft.util.ResourceLocation> getTags() {
+ return reverseTags.getTagNames();
+ }
+
+ public boolean isIn(net.minecraft.tags.ITag<Potion> tag) {
+ return tag.func_230235_a_(this);
+ }
+
public String func_185174_b(String p_185174_1_) {
return p_185174_1_ + (this.field_185179_d == null ? Registry.field_212621_j.func_177774_c(this).func_110623_a() : this.field_185179_d);
}

View file

@ -9,3 +9,26 @@
private static final Logger field_206866_A = LogManager.getLogger(); private static final Logger field_206866_A = LogManager.getLogger();
public static final TileEntityType<FurnaceTileEntity> field_200971_b = func_200966_a("furnace", TileEntityType.Builder.func_223042_a(FurnaceTileEntity::new, Blocks.field_150460_al)); public static final TileEntityType<FurnaceTileEntity> field_200971_b = func_200966_a("furnace", TileEntityType.Builder.func_223042_a(FurnaceTileEntity::new, Blocks.field_150460_al));
public static final TileEntityType<ChestTileEntity> field_200972_c = func_200966_a("chest", TileEntityType.Builder.func_223042_a(ChestTileEntity::new, Blocks.field_150486_ae)); public static final TileEntityType<ChestTileEntity> field_200972_c = func_200966_a("chest", TileEntityType.Builder.func_223042_a(ChestTileEntity::new, Blocks.field_150486_ae));
@@ -54,6 +54,7 @@
private final Supplier<? extends T> field_200995_z;
private final Set<Block> field_223046_I;
private final Type<?> field_206867_C;
+ private final net.minecraftforge.common.util.ReverseTagWrapper<TileEntityType<?>> reverseTags = new net.minecraftforge.common.util.ReverseTagWrapper<>(this, () -> net.minecraft.tags.TagCollectionManager.func_242178_a().getCustomTypeCollection(net.minecraftforge.registries.ForgeRegistries.TILE_ENTITIES));
@Nullable
public static ResourceLocation func_200969_a(TileEntityType<?> p_200969_0_) {
@@ -75,6 +76,14 @@
this.field_206867_C = p_i51497_3_;
}
+ public java.util.Set<net.minecraft.util.ResourceLocation> getTags() {
+ return reverseTags.getTagNames();
+ }
+
+ public boolean isIn(net.minecraft.tags.ITag<TileEntityType<?>> tag) {
+ return tag.func_230235_a_(this);
+ }
+
@Nullable
public T func_200968_a() {
return this.field_200995_z.get();

View file

@ -68,6 +68,9 @@ d2c8e860521c5e738ed0798337f5728d610825ff assets/piston_event_test/models/block/s
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
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
8c1969250406edfbd470cc06aca4dcccfd6ce682 data/custom_tag_types_test/tags/enchantments/fire.json
44985f1cb0df54b632187ed97a6a443455f1e51c data/custom_tag_types_test/tags/potions/damage.json
9405b72d54aad3f4377035d9707bb9947e9032a3 data/custom_tag_types_test/tags/tile_entity_types/storage.json
4fbaf6f4a3ea05cc071076e27f44ac81f9cc50e3 data/data_gen_test/advancements/conditional.json 4fbaf6f4a3ea05cc071076e27f44ac81f9cc50e3 data/data_gen_test/advancements/conditional.json
66442c8000af9af4ba36109b3c9d09d9ffd57277 data/data_gen_test/advancements/recipes/conditional2.json 66442c8000af9af4ba36109b3c9d09d9ffd57277 data/data_gen_test/advancements/recipes/conditional2.json
ed4cbf1a3a2f5d8969f6346fdc9acdbe81d0c919 data/data_gen_test/recipes/conditional.json ed4cbf1a3a2f5d8969f6346fdc9acdbe81d0c919 data/data_gen_test/recipes/conditional.json

View file

@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"minecraft:fire_aspect",
"minecraft:flame"
]
}

View file

@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"minecraft:harming",
"minecraft:strong_harming"
]
}

View file

@ -0,0 +1,8 @@
{
"replace": false,
"values": [
"minecraft:barrel",
"minecraft:chest",
"minecraft:ender_chest"
]
}

View file

@ -143,10 +143,10 @@ public class GameData
makeRegistry(EFFECTS, Effect.class ).legacyName("potions").create(); makeRegistry(EFFECTS, Effect.class ).legacyName("potions").create();
//makeRegistry(BIOMES, Biome.class).legacyName("biomes").create(); //makeRegistry(BIOMES, Biome.class).legacyName("biomes").create();
makeRegistry(SOUND_EVENTS, SoundEvent.class).legacyName("soundevents").create(); makeRegistry(SOUND_EVENTS, SoundEvent.class).legacyName("soundevents").create();
makeRegistry(POTIONS, Potion.class, "empty").legacyName("potiontypes").create(); makeRegistry(POTIONS, Potion.class, "empty").legacyName("potiontypes").tagFolder("potions").create();
makeRegistry(ENCHANTMENTS, Enchantment.class).legacyName("enchantments").create(); makeRegistry(ENCHANTMENTS, Enchantment.class).legacyName("enchantments").tagFolder("enchantments").create();
makeRegistry(ENTITY_TYPES, c(EntityType.class), "pig").legacyName("entities").create(); makeRegistry(ENTITY_TYPES, c(EntityType.class), "pig").legacyName("entities").create();
makeRegistry(TILE_ENTITY_TYPES, c(TileEntityType.class)).disableSaving().legacyName("tileentities").create(); makeRegistry(TILE_ENTITY_TYPES, c(TileEntityType.class)).disableSaving().legacyName("tileentities").tagFolder("tile_entity_types").create();
makeRegistry(PARTICLE_TYPES, c(ParticleType.class)).disableSaving().create(); makeRegistry(PARTICLE_TYPES, c(ParticleType.class)).disableSaving().create();
makeRegistry(CONTAINER_TYPES, c(ContainerType.class)).disableSaving().create(); makeRegistry(CONTAINER_TYPES, c(ContainerType.class)).disableSaving().create();
makeRegistry(PAINTING_TYPES, PaintingType.class, "kebab").create(); makeRegistry(PAINTING_TYPES, PaintingType.class, "kebab").create();

View file

@ -24,24 +24,35 @@ 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.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.item.PotionItem;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionUtils;
import net.minecraft.potion.Potions;
import net.minecraft.tags.ITag; import net.minecraft.tags.ITag;
import net.minecraft.tags.ItemTags; import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagCollectionManager; import net.minecraft.tags.TagCollectionManager;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeTagHandler; import net.minecraftforge.common.ForgeTagHandler;
import net.minecraftforge.common.MinecraftForge; 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.common.util.ReverseTagWrapper;
import net.minecraftforge.event.entity.ProjectileImpactEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
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;
@ -60,13 +71,16 @@ public class CustomTagTypesTest
() -> new RegistryBuilder<Custom>().tagFolder(MODID + "/custom_types")); () -> new RegistryBuilder<Custom>().tagFolder(MODID + "/custom_types"));
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.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)); private static final ITag.INamedTag<Item> OPTIONAL_TEST = ItemTags.createOptional(new ResourceLocation(MODID, "optional_test"), Sets.newHashSet(() -> Items.BONE));
private static final ITag.INamedTag<Enchantment> FIRE = ForgeTagHandler.createOptionalTag(ForgeRegistries.ENCHANTMENTS, new ResourceLocation(MODID, "fire"));
private static final ITag.INamedTag<Potion> DAMAGE = ForgeTagHandler.createOptionalTag(ForgeRegistries.POTION_TYPES, new ResourceLocation(MODID, "damage"));
private static final ITag.INamedTag<TileEntityType<?>> STORAGE = ForgeTagHandler.createOptionalTag(ForgeRegistries.TILE_ENTITIES, new ResourceLocation(MODID, "storage"));
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); MinecraftForge.EVENT_BUS.addListener(this::leftClick);
} }
private void gatherData(GatherDataEvent event) private void gatherData(GatherDataEvent event)
@ -74,13 +88,33 @@ public class CustomTagTypesTest
if (event.includeServer()) if (event.includeServer())
{ {
DataGenerator gen = event.getGenerator(); DataGenerator gen = event.getGenerator();
gen.addProvider(new CustomRegistryTags(gen, event.getExistingFileHelper())); ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
gen.addProvider(new CustomRegistryTags(gen, existingFileHelper));
gen.addProvider(new EnchantmentTags(gen, existingFileHelper));
gen.addProvider(new PotionTags(gen, existingFileHelper));
gen.addProvider(new TileEntityTypeTags(gen, existingFileHelper));
} }
} }
private void projectileImpact(ProjectileImpactEvent.Arrow event) private void leftClick(PlayerInteractEvent.LeftClickBlock event)
{ {
LOGGER.info("{} {} {}", Items.BONE.getTags(), OPTIONAL_TEST.func_230236_b_().size(), TagCollectionManager.func_242178_a().func_241836_b().get(new ResourceLocation(MODID, "optional_test"))); ItemStack itemStack = event.getItemStack();
if (!itemStack.isEmpty())
{
LOGGER.info("{} {} {}", Items.BONE.getTags(), OPTIONAL_TEST.func_230236_b_().size(), TagCollectionManager.func_242178_a().func_241836_b().get(new ResourceLocation(MODID, "optional_test")));
EnchantmentHelper.getEnchantments(itemStack).forEach((enchantment, level) -> logTagsIfPresent(enchantment.getTags()));
if (itemStack.getItem() instanceof PotionItem) logTagsIfPresent(PotionUtils.getPotionFromItem(itemStack).getTags());
TileEntity tileEntity = event.getWorld().getTileEntity(event.getPos());
if (tileEntity != null) logTagsIfPresent(tileEntity.getType().getTags());
}
}
private void logTagsIfPresent(Set<ResourceLocation> tags)
{
if (!tags.isEmpty())
{
LOGGER.info("Tags: {}", tags);
}
} }
public static class Custom extends ForgeRegistryEntry<Custom> public static class Custom extends ForgeRegistryEntry<Custom>
@ -112,8 +146,69 @@ public class CustomTagTypesTest
} }
@Override @Override
public String getName() { public String getName()
{
return "Custom Registry Tags"; return "Custom Registry Tags";
} }
} }
public static class EnchantmentTags extends ForgeRegistryTagsProvider<Enchantment>
{
public EnchantmentTags(DataGenerator gen, @Nullable ExistingFileHelper existingFileHelper)
{
super(gen, ForgeRegistries.ENCHANTMENTS, MODID, existingFileHelper);
}
@Override
protected void registerTags()
{
func_240522_a_(FIRE).func_240534_a_(Enchantments.FIRE_ASPECT, Enchantments.FLAME);
}
@Override
public String getName()
{
return "Enchantment Tags";
}
}
public static class PotionTags extends ForgeRegistryTagsProvider<Potion>
{
public PotionTags(DataGenerator gen, @Nullable ExistingFileHelper existingFileHelper)
{
super(gen, ForgeRegistries.POTION_TYPES, MODID, existingFileHelper);
}
@Override
protected void registerTags()
{
func_240522_a_(DAMAGE).func_240534_a_(Potions.HARMING, Potions.STRONG_HARMING);
}
@Override
public String getName()
{
return "Potion Tags";
}
}
public static class TileEntityTypeTags extends ForgeRegistryTagsProvider<TileEntityType<?>>
{
public TileEntityTypeTags(DataGenerator gen, @Nullable ExistingFileHelper existingFileHelper)
{
super(gen, ForgeRegistries.TILE_ENTITIES, MODID, existingFileHelper);
}
@Override
protected void registerTags()
{
func_240522_a_(STORAGE).func_240534_a_(TileEntityType.BARREL, TileEntityType.CHEST, TileEntityType.ENDER_CHEST);
}
@Override
public String getName()
{
return "Tile Entity Type Tags";
}
}
} }