Skip to content

Commit

Permalink
Update to 1.18.2 (tterrag1098#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 authored Mar 19, 2022
1 parent 9ce77a4 commit 90b70f5
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 32 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod_version=1.0.x
minecraft_version=1.18
forge_version=38.0.4
minecraft_version=1.18.2
forge_version=40.0.12
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraftforge.common.util.NonNullFunction;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.RegistryObject;
Expand Down Expand Up @@ -51,7 +53,7 @@ public abstract class AbstractBuilder<R extends IForgeRegistryEntry<R>, T extend
@Getter(onMethod_ = {@Override})
private final Class<? super R> registryType;

private final Multimap<ProviderType<? extends RegistrateTagsProvider<?>>, Tag.Named<?>> tagsByType = HashMultimap.create();
private final Multimap<ProviderType<? extends RegistrateTagsProvider<?>>, TagKey<?>> tagsByType = HashMultimap.create();

/** A supplier for the entry that will discard the reference to this builder after it is resolved */
private final LazyRegistryEntry<T> safeSupplier = new LazyRegistryEntry<>(this);
Expand Down Expand Up @@ -89,10 +91,10 @@ public NonNullSupplier<T> asSupplier() {
*/
@SuppressWarnings("unchecked")
@SafeVarargs
public final S tag(ProviderType<? extends RegistrateTagsProvider<R>> type, Tag.Named<R>... tags) {
public final S tag(ProviderType<? extends RegistrateTagsProvider<R>> type, TagKey<R>... tags) {
if (!tagsByType.containsKey(type)) {
setData(type, (ctx, prov) -> tagsByType.get(type).stream()
.map(t -> (Tag.Named<R>) t)
.map(t -> (TagKey<R>) t)
.map(prov::tag)
.forEach(b -> b.add(asSupplier().get())));
}
Expand All @@ -111,9 +113,9 @@ public final S tag(ProviderType<? extends RegistrateTagsProvider<R>> type, Tag.N
*/
@SuppressWarnings("unchecked")
@SafeVarargs
public final S removeTag(ProviderType<RegistrateTagsProvider<R>> type, Tag.Named<R>... tags) {
public final S removeTag(ProviderType<RegistrateTagsProvider<R>> type, TagKey<R>... tags) {
if (tagsByType.containsKey(type)) {
for (Tag.Named<R> tag : tags) {
for (TagKey<R> tag : tags) {
tagsByType.remove(type, tag);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -391,14 +392,14 @@ public BlockBuilder<T, P> recipe(NonNullBiConsumer<DataGenContext<Block, T>, Reg
}

/**
* Assign {@link Tag.Named}{@code s} to this block. Multiple calls will add additional tags.
* Assign {@link TagKey}{@code s} to this block. Multiple calls will add additional tags.
*
* @param tags
* The tags to assign
* @return this {@link BlockBuilder}
*/
@SafeVarargs
public final BlockBuilder<T, P> tag(Tag.Named<Block>... tags) {
public final BlockBuilder<T, P> tag(TagKey<Block>... tags) {
return tag(ProviderType.BLOCK_TAGS, tags);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -275,14 +276,14 @@ public EntityBuilder<T, P> loot(NonNullBiConsumer<RegistrateEntityLootTables, En
}

/**
* Assign {@link Tag.Named}{@code s} to this entity. Multiple calls will add additional tags.
* Assign {@link TagKey}{@code s} to this entity. Multiple calls will add additional tags.
*
* @param tags
* The tags to assign
* @return this {@link EntityBuilder}
*/
@SafeVarargs
public final EntityBuilder<T, P> tag(Tag.Named<EntityType<?>>... tags) {
public final EntityBuilder<T, P> tag(TagKey<EntityType<?>>... tags) {
return tag(ProviderType.ENTITY_TAGS, tags);
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/tterrag/registrate/builders/FluidBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.FluidTags;
import net.minecraft.tags.Tag;
import net.minecraft.tags.Tag.Named;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
Expand Down Expand Up @@ -194,7 +194,7 @@ public static <T extends ForgeFlowingFluid, P> FluidBuilder<T, P> create(Abstrac
private NonNullConsumer<ForgeFlowingFluid.Properties> properties;
@Nullable
private NonNullSupplier<? extends ForgeFlowingFluid> source;
private List<Named<Fluid>> tags = new ArrayList<>();
private List<TagKey<Fluid>> tags = new ArrayList<>();

protected FluidBuilder(AbstractRegistrate<?> owner, P parent, String name, BuilderCallback callback, ResourceLocation stillTexture, ResourceLocation flowingTexture,
@Nullable BiFunction<FluidAttributes.Builder, Fluid, FluidAttributes> attributesFactory, NonNullFunction<ForgeFlowingFluid.Properties, T> factory) {
Expand Down Expand Up @@ -404,14 +404,14 @@ public FluidBuilder<T, P> noBucket() {
}

/**
* Assign {@link Tag.Named}{@code s} to this fluid and its source fluid. Multiple calls will add additional tags.
* Assign {@link TagKey}{@code s} to this fluid and its source fluid. Multiple calls will add additional tags.
*
* @param tags
* The tags to assign
* @return this {@link FluidBuilder}
*/
@SafeVarargs
public final FluidBuilder<T, P> tag(Tag.Named<Fluid>... tags) {
public final FluidBuilder<T, P> tag(TagKey<Fluid>... tags) {
FluidBuilder<T, P> ret = this.tag(ProviderType.FLUID_TAGS, tags);
if (this.tags.isEmpty()) {
ret.getOwner().<RegistrateTagsProvider<Fluid>, Fluid> setDataGenerator(ret.sourceName, getRegistryType(), ProviderType.FLUID_TAGS,
Expand All @@ -422,14 +422,14 @@ public final FluidBuilder<T, P> tag(Tag.Named<Fluid>... tags) {
}

/**
* Remove {@link Tag.Named}{@code s} from this fluid and its source fluid. Multiple calls will remove additional tags.
* Remove {@link TagKey}{@code s} from this fluid and its source fluid. Multiple calls will remove additional tags.
*
* @param tags
* The tags to remove
* @return this {@link FluidBuilder}
*/
@SafeVarargs
public final FluidBuilder<T, P> removeTag(Tag.Named<Fluid>... tags) {
public final FluidBuilder<T, P> removeTag(TagKey<Fluid>... tags) {
this.tags.removeAll(Arrays.asList(tags));
return this.removeTag(ProviderType.FLUID_TAGS, tags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;

import net.minecraft.client.color.item.ItemColor;
import net.minecraft.tags.Tag;
import net.minecraft.tags.Tag.Named;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraftforge.api.distmarker.Dist;
Expand Down Expand Up @@ -224,14 +223,14 @@ public ItemBuilder<T, P> recipe(NonNullBiConsumer<DataGenContext<Item, T>, Regis
}

/**
* Assign {@link Tag.Named}{@code s} to this item. Multiple calls will add additional tags.
* Assign {@link TagKey<Item>}{@code s} to this item. Multiple calls will add additional tags.
*
* @param tags
* The tag to assign
* @return this {@link ItemBuilder}
*/
@SafeVarargs
public final ItemBuilder<T, P> tag(Named<Item>... tags) {
public final ItemBuilder<T, P> tag(TagKey<Item>... tags) {
return tag(ProviderType.ITEM_TAGS, tags);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
import net.minecraft.core.Registry;
import net.minecraft.data.DataGenerator;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.data.ExistingFileHelper;

public class RegistrateItemTagsProvider extends RegistrateTagsProvider<Item> {

private final Function<Tag.Named<Block>, Tag.Builder> builderLookup;
private final Function<TagKey<Block>, Tag.Builder> builderLookup;

@SuppressWarnings({ "deprecation", "null" })
public RegistrateItemTagsProvider(AbstractRegistrate<?> owner, ProviderType<RegistrateItemTagsProvider> type, String name, DataGenerator generatorIn, ExistingFileHelper existingFileHelper, RegistrateTagsProvider<Block> blockTags) {
super(owner, type, name, generatorIn, Registry.ITEM, existingFileHelper);
this.builderLookup = blockTags::getOrCreateRawBuilder;
}

public void copy(Tag.Named<Block> p_240521_1_, Tag.Named<Item> p_240521_2_) {
public void copy(TagKey<Block> p_240521_1_, TagKey<Item> p_240521_2_) {
Tag.Builder itag$builder = this.getOrCreateRawBuilder(p_240521_2_);
Tag.Builder itag$builder1 = this.builderLookup.apply(p_240521_1_);
itag$builder1.getEntries().forEach(itag$builder::add);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.data.recipes.SingleItemRecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.SimpleCookingSerializer;
Expand Down Expand Up @@ -302,7 +303,7 @@ public <T extends ItemLike & IForgeRegistryEntry<?>> void trapDoor(DataIngredien

public static InventoryChangeTrigger.TriggerInstance has(ItemLike p_125978_) { return RecipeProvider.has(p_125978_); }

public static InventoryChangeTrigger.TriggerInstance has(Tag<Item> p_125976_) { return RecipeProvider.has(p_125976_); }
public static InventoryChangeTrigger.TriggerInstance has(TagKey<Item> p_125976_) { return RecipeProvider.inventoryTrigger(ItemPredicate.Builder.item().of(p_125976_).build()); }

public static InventoryChangeTrigger.TriggerInstance inventoryTrigger(ItemPredicate... p_126012_) { return RecipeProvider.inventoryTrigger(p_126012_); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.data.tags.TagsProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.fml.LogicalSide;

Expand Down Expand Up @@ -44,8 +45,8 @@ public LogicalSide getSide() {
}

@Override
public TagAppender<T> tag(Tag.Named<T> tag) { return super.tag(tag); }
public TagAppender<T> tag(TagKey<T> tag) { return super.tag(tag); }

@Override
public Tag.Builder getOrCreateRawBuilder(Tag.Named<T> tag) { return super.getOrCreateRawBuilder(tag); }
public Tag.Builder getOrCreateRawBuilder(TagKey<T> tag) { return super.getOrCreateRawBuilder(tag); }
}
14 changes: 8 additions & 6 deletions src/main/java/com/tterrag/registrate/util/DataIngredient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag.Named;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
Expand All @@ -27,7 +27,7 @@
* A helper for data generation when using ingredients as input(s) to recipes.<br>
* It remembers the name of the primary ingredient for use in creating recipe names/criteria.
* <p>
* Create an instance of this class with the various factory methods such as {@link #items(ItemLike, ItemLike...)} and {@link #tag(Tag.Named)}.
* Create an instance of this class with the various factory methods such as {@link #items(ItemLike, ItemLike...)} and {@link #tag(TagKey<Item>)}.
* <p>
* <strong>This class should not be used for any purpose other than data generation</strong>, it will throw an exception if it is serialized to a packet buffer.
*/
Expand All @@ -40,6 +40,8 @@ private interface Excludes {
void toNetwork(FriendlyByteBuf buffer);

boolean isVanilla();

public boolean checkInvalidation();
}

@Delegate(excludes = Excludes.class)
Expand All @@ -55,10 +57,10 @@ private DataIngredient(Ingredient parent, ItemLike item) {
this.criteriaFactory = prov -> RegistrateRecipeProvider.has(item);
}

private DataIngredient(Ingredient parent, Named<Item> tag) {
private DataIngredient(Ingredient parent, TagKey<Item> tag) {
super(Stream.empty());
this.parent = parent;
this.id = tag.getName();
this.id = tag.location();
this.criteriaFactory = prov -> RegistrateRecipeProvider.has(tag);
}

Expand Down Expand Up @@ -93,15 +95,15 @@ public static DataIngredient stacks(ItemStack first, ItemStack... others) {
return ingredient(Ingredient.of(ObjectArrays.concat(first, others)), first.getItem());
}

public static DataIngredient tag(Named<Item> tag) {
public static DataIngredient tag(TagKey<Item> tag) {
return ingredient(Ingredient.of(tag), tag);
}

public static DataIngredient ingredient(Ingredient parent, ItemLike required) {
return new DataIngredient(parent, required);
}

public static DataIngredient ingredient(Ingredient parent, Named<Item> required) {
public static DataIngredient ingredient(Ingredient parent, TagKey<Item> required) {
return new DataIngredient(parent, required);
}

Expand Down

0 comments on commit 90b70f5

Please sign in to comment.