Skip to content

Commit

Permalink
Allow tags to be used in datagen
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed Apr 4, 2022
1 parent 81797ad commit 10977db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.blamejared.crafttweaker.api.ingredient.type.TagIngredient;
import com.blamejared.crafttweaker.api.item.IItemStack;
import com.blamejared.crafttweaker.api.tag.type.KnownTag;
import com.blamejared.crafttweaker.platform.Services;
import com.blamejared.crafttweaker_annotations.annotations.Document;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import org.openzen.zencode.java.ZenCodeType;

Expand All @@ -30,7 +32,8 @@ public class ExpandItemTag {
@ZenCodeType.Caster(implicit = true)
public static IIngredient asIIngredient(KnownTag<Item> internal) {

if(!internal.exists()) {
TagKey<?> tagKey = internal.getTagKey();
if(!internal.exists() && !Services.PLATFORM.isDataGen()) {
CraftTweakerAPI.LOGGER.warn("Tag '{}' does not exist, replacing with empty IIngredient", internal.getCommandString());
return IIngredientEmpty.INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ default String getLogFormat() {

boolean isDevelopmentEnvironment();

boolean isDataGen();

List<Mod> getMods();

Optional<Mod> getMod(String modid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public boolean isDevelopmentEnvironment() {
return FabricLoader.getInstance().isDevelopmentEnvironment();
}

@Override
public boolean isDataGen() {

// If / When fabric has a way to detect datagen, update this.
return false;
}

@Override
public List<Mod> getMods() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.minecraftforge.common.loot.IGlobalLootModifier;
import net.minecraftforge.common.loot.LootModifierManager;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.data.loading.DatagenModLoader;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import net.minecraftforge.fml.ModList;
Expand Down Expand Up @@ -115,6 +116,12 @@ public boolean isDevelopmentEnvironment() {
return !FMLLoader.isProduction();
}

@Override
public boolean isDataGen() {

return DatagenModLoader.isRunningDataGen();
}

@Override
public List<Mod> getMods() {

Expand Down

0 comments on commit 10977db

Please sign in to comment.