Skip to content
Permalink
Browse files

Added crafttweaker hooks for recipes, IItemSize and IFood

  • Loading branch information
DisasterMoo committed Jul 21, 2019
1 parent 8999ac3 commit dab37565d4651966e48a227f463440464b48efca
Showing with 1,395 additions and 67 deletions.
  1. +18 −2 src/main/java/net/dries007/tfc/CommonEventHandler.java
  2. +3 −0 src/main/java/net/dries007/tfc/api/capability/food/CapabilityFood.java
  3. +11 −0 src/main/java/net/dries007/tfc/api/capability/food/FoodHandler.java
  4. +4 −0 src/main/java/net/dries007/tfc/api/capability/size/CapabilityItemSize.java
  5. +11 −0 src/main/java/net/dries007/tfc/api/capability/size/ItemSizeHandler.java
  6. +1 −1 src/main/java/net/dries007/tfc/api/recipes/AnvilRecipe.java
  7. +1 −1 src/main/java/net/dries007/tfc/api/recipes/LoomRecipe.java
  8. +3 −2 src/main/java/net/dries007/tfc/api/recipes/PitKilnRecipe.java
  9. +1 −1 src/main/java/net/dries007/tfc/api/recipes/QuernRecipe.java
  10. +1 −1 src/main/java/net/dries007/tfc/api/recipes/WeldingRecipe.java
  11. +1 −1 src/main/java/net/dries007/tfc/api/registries/TFCRegistries.java
  12. +117 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/Anvil.java
  13. +113 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/Barrel.java
  14. +50 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/CTHelper.java
  15. +98 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/ClayKnapping.java
  16. +98 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/FireClayKnapping.java
  17. +123 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/ItemRegistry.java
  18. +98 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/LeatherKnapping.java
  19. +104 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/Loom.java
  20. +104 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/PitKiln.java
  21. +104 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/Quern.java
  22. +161 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/StoneKnapping.java
  23. +107 −0 src/main/java/net/dries007/tfc/compat/crafttweaker/Welding.java
  24. +1 −1 src/main/java/net/dries007/tfc/{ → compat}/jei/BaseRecipeCategory.java
  25. +1 −1 src/main/java/net/dries007/tfc/{ → compat}/jei/IJEISimpleRecipe.java
  26. +14 −6 src/main/java/net/dries007/tfc/{ → compat}/jei/TFCJEIPlugin.java
  27. +3 −3 src/main/java/net/dries007/tfc/{ → compat}/jei/categories/AlloyCategory.java
  28. +3 −3 src/main/java/net/dries007/tfc/{ → compat}/jei/categories/AnvilCategory.java
  29. +3 −3 src/main/java/net/dries007/tfc/{ → compat}/jei/categories/BarrelCategory.java
  30. +3 −3 src/main/java/net/dries007/tfc/{ → compat}/jei/categories/KnappingCategory.java
  31. +3 −3 src/main/java/net/dries007/tfc/{ → compat}/jei/categories/LoomCategory.java
  32. +3 −3 src/main/java/net/dries007/tfc/{ → compat}/jei/categories/PitKilnCategory.java
  33. +3 −3 src/main/java/net/dries007/tfc/{ → compat}/jei/categories/QuernCategory.java
  34. +3 −3 src/main/java/net/dries007/tfc/{ → compat}/jei/categories/WeldingCategory.java
  35. +1 −1 src/main/java/net/dries007/tfc/{ → compat}/jei/wrappers/AlloyWrapper.java
  36. +3 −3 src/main/java/net/dries007/tfc/{ → compat}/jei/wrappers/BarrelWrapper.java
  37. +2 −2 src/main/java/net/dries007/tfc/{ → compat}/jei/wrappers/KnappingWrapper.java
  38. +3 −3 src/main/java/net/dries007/tfc/{ → compat}/jei/wrappers/SimpleRecipeWrapper.java
  39. +1 −1 src/main/java/net/dries007/tfc/objects/entity/animal/EntityPheasantTFC.java
  40. +3 −3 src/main/java/net/dries007/tfc/objects/inventory/ingredient/IIngredient.java
  41. +1 −1 src/main/java/net/dries007/tfc/objects/inventory/ingredient/IngredientFluidStack.java
  42. +1 −1 src/main/java/net/dries007/tfc/objects/inventory/ingredient/IngredientItemStack.java
  43. +1 −1 src/main/java/net/dries007/tfc/objects/inventory/ingredient/IngredientMultipleFluidStack.java
  44. +1 −1 src/main/java/net/dries007/tfc/objects/inventory/ingredient/IngredientOreDict.java
  45. +4 −4 src/main/java/net/dries007/tfc/types/DefaultRecipes.java
  46. +1 −1 src/main/java/net/dries007/tfc/types/Registries.java
  47. +0 −3 src/main/java/net/dries007/tfc/util/TFCSoundEvents.java
  48. +1 −1 src/main/resources/assets
@@ -44,6 +44,7 @@
import net.dries007.tfc.api.capability.food.FoodStatsTFC;
import net.dries007.tfc.api.capability.food.IFoodStatsTFC;
import net.dries007.tfc.api.capability.size.CapabilityItemSize;
import net.dries007.tfc.api.capability.size.ItemSizeHandler;
import net.dries007.tfc.api.capability.size.Size;
import net.dries007.tfc.api.capability.size.Weight;
import net.dries007.tfc.api.capability.skill.CapabilityPlayerSkills;
@@ -236,7 +237,12 @@ public static void attachItemCapabilities(AttachCapabilitiesEvent<ItemStack> eve
boolean canStack = stack.getMaxStackSize() > 1; // This is necessary so it isn't accidentally overridden by a default implementation

// todo: Add more items here
if (item == Items.COAL)
if (CapabilityItemSize.CUSTOM_ITEMS.containsKey(item))
{
ItemSizeHandler handler = CapabilityItemSize.CUSTOM_ITEMS.get(item).copy();
CapabilityItemSize.add(event, item, handler.getSize(stack), handler.getWeight(stack), canStack);
}
else if (item == Items.COAL)
CapabilityItemSize.add(event, Items.COAL, Size.SMALL, Weight.MEDIUM, canStack);
else if (item == Items.STICK)
event.addCapability(ItemStickCapability.KEY, new ItemStickCapability(event.getObject().getTagCompound()));
@@ -258,7 +264,17 @@ else if (item instanceof ItemBlock)
// future plans: add via craft tweaker or json (1.14)
if (stack.getItem() instanceof ItemFood && !stack.hasCapability(CapabilityFood.CAPABILITY, null))
{
event.addCapability(CapabilityFood.KEY, new FoodHandler(stack.getTagCompound(), new float[] {1, 0, 0, 0, 0}, 0, 0, 1));
//noinspection SuspiciousMethodCalls
if (CapabilityFood.CUSTOM_FOODS.containsKey(item))
{
//noinspection SuspiciousMethodCalls
FoodHandler handler = CapabilityFood.CUSTOM_FOODS.get(item).copy();
event.addCapability(CapabilityFood.KEY, handler);
}
else
{
event.addCapability(CapabilityFood.KEY, new FoodHandler(stack.getTagCompound(), new float[] {1, 0, 0, 0, 0}, 0, 0, 1));
}
}
if (stack.getItem() == Items.EGG && !stack.hasCapability(CapabilityEgg.CAPABILITY, null))
{
@@ -8,6 +8,7 @@
import java.util.HashMap;
import java.util.Map;

import net.minecraft.item.ItemFood;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
@@ -25,6 +26,8 @@
public static final Capability<IFood> CAPABILITY = Helpers.getNull();
public static final ResourceLocation KEY = new ResourceLocation(MOD_ID, "food");

public static final Map<ItemFood, FoodHandler> CUSTOM_FOODS = new HashMap<>(); //Used inside CT, set custom IFood for food items outside TFC

/**
* Most TFC foods have decay modifiers in the range [1, 4] (high = faster decay)
* That puts decay times at 25% - 100% of this value
@@ -163,6 +163,17 @@ private float calculateDecayModifier()
return mod == 0 ? Float.POSITIVE_INFINITY : 1 / mod;
}

/**
* Makes a copy of this FoodHandler instance.
* (eg: Used to apply custom set nutrients to food item, set by CT scripts)
*
* @return a copy of this object
*/
public FoodHandler copy()
{
return new FoodHandler(this.serializeNBT(), this.nutrients, this.calories, this.water, this.decayModifier);
}

@Nonnull
@Override
public List<IFoodTrait> getTraits()
@@ -5,6 +5,8 @@

package net.dries007.tfc.api.capability.size;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;

import net.minecraft.item.Item;
@@ -25,6 +27,8 @@
public static final Capability<IItemSize> ITEM_SIZE_CAPABILITY = Helpers.getNull();
private static final ResourceLocation ID = new ResourceLocation(TFCConstants.MOD_ID, "item_size");

public static final Map<Item, ItemSizeHandler> CUSTOM_ITEMS = new HashMap<>(); //Used inside CT, set custom IItemSize for items outside TFC

public static void preInit()
{
CapabilityManager.INSTANCE.register(IItemSize.class, new DumbStorage<>(), ItemSizeHandler::new);
@@ -45,6 +45,17 @@ public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFa
return capability == CapabilityItemSize.ITEM_SIZE_CAPABILITY ? (T) this : null;
}

/**
* Makes a copy of this ItemSizeHandler instance.
* (eg: Used to apply custom set sizes to item, set by CT scripts)
*
* @return a copy of this object
*/
public ItemSizeHandler copy()
{
return new ItemSizeHandler(this.size, this.weight, this.canStack);
}

@Nonnull
@Override
public Size getSize(@Nonnull ItemStack stack)
@@ -18,7 +18,7 @@

import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.jei.IJEISimpleRecipe;
import net.dries007.tfc.compat.jei.IJEISimpleRecipe;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;
import net.dries007.tfc.objects.te.TEAnvilTFC;
import net.dries007.tfc.util.forge.ForgeRule;
@@ -13,7 +13,7 @@
import net.minecraftforge.registries.IForgeRegistryEntry;

import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.jei.IJEISimpleRecipe;
import net.dries007.tfc.compat.jei.IJEISimpleRecipe;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;

public class LoomRecipe extends IForgeRegistryEntry.Impl<LoomRecipe> implements IJEISimpleRecipe
@@ -17,7 +17,7 @@
import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.api.util.IFireable;
import net.dries007.tfc.jei.IJEISimpleRecipe;
import net.dries007.tfc.compat.jei.IJEISimpleRecipe;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;

/**
@@ -86,6 +86,7 @@ else if (input.getItem() instanceof ItemBlock && ((ItemBlock) input.getItem()).g
@Override
public NonNullList<ItemStack> getOutputs()
{
return NonNullList.withSize(1, getOutput(ingredient.getValidInputList().get(0), Metal.Tier.TIER_I));
NonNullList<ItemStack> list = ingredient.getValidIngredients();
return NonNullList.withSize(1, getOutput(list.size() > 0 ? list.get(0) : ItemStack.EMPTY, Metal.Tier.TIER_I));
}
}
@@ -15,7 +15,7 @@
import net.dries007.tfc.api.capability.food.CapabilityFood;
import net.dries007.tfc.api.capability.food.IFood;
import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.jei.IJEISimpleRecipe;
import net.dries007.tfc.compat.jei.IJEISimpleRecipe;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;

public class QuernRecipe extends IForgeRegistryEntry.Impl<QuernRecipe> implements IJEISimpleRecipe
@@ -14,7 +14,7 @@
import net.minecraftforge.registries.IForgeRegistryEntry;

import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.jei.IJEISimpleRecipe;
import net.dries007.tfc.compat.jei.IJEISimpleRecipe;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;

/**
@@ -73,4 +73,4 @@
throw new RuntimeException(e);
}
}
}
}
@@ -0,0 +1,117 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.compat.crafttweaker;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.IForgeRegistryModifiable;

import crafttweaker.CraftTweakerAPI;
import crafttweaker.IAction;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.liquid.ILiquidStack;
import net.dries007.tfc.api.recipes.AnvilRecipe;
import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.api.types.Metal;
import net.dries007.tfc.objects.inventory.ingredient.IIngredient;
import net.dries007.tfc.util.forge.ForgeRule;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;

@ZenClass("mods.terrafirmacraft.Anvil")
@ZenRegister
public class Anvil
{
@SuppressWarnings("unchecked")
@ZenMethod
public static void addRecipe(IItemStack output, int minTier, crafttweaker.api.item.IIngredient input, String... rules)
{
if (output == null || input == null)
throw new IllegalArgumentException("Input and output are not allowed to be empty");
if (input instanceof ILiquidStack)
throw new IllegalArgumentException("There is a fluid where it's supposed to be an item!");
IIngredient ingredient = CTHelper.getInternalIngredient(input);
if (rules.length == 0 || rules.length > 3)
throw new IllegalArgumentException("Rules length must be within the closed interval [1, 3]");
ForgeRule[] forgeRules = new ForgeRule[rules.length];
for (int i = 0; i < rules.length; i++)
{
String str = rules[i];
ForgeRule rl = ForgeRule.valueOf(str.toUpperCase());
forgeRules[i] = rl;
}
Metal.Tier tier = Metal.Tier.valueOf(minTier);
ItemStack outputItem = (ItemStack) output.getInternal();
AnvilRecipe recipe = new AnvilRecipe(new ResourceLocation("crafttweaker", outputItem.getTranslationKey()),
ingredient, outputItem, tier, forgeRules);
CraftTweakerAPI.apply(new Add(recipe));
}

@ZenMethod
public static void removeRecipe(IItemStack output)
{
if (output == null) throw new IllegalArgumentException("Output not allowed to be empty");
ItemStack item = (ItemStack) output.getInternal();
List<Remove> removeList = new ArrayList<>();
TFCRegistries.ANVIL.getValuesCollection()
.stream()
.filter(x -> x.getOutputs().get(0).isItemEqual(item))
.forEach(x -> removeList.add(new Remove(x.getRegistryName())));
for (Remove rem : removeList)
{
CraftTweakerAPI.apply(rem);
}
}

private static class Add implements IAction
{
private final AnvilRecipe recipe;

Add(AnvilRecipe recipe)
{
this.recipe = recipe;
}

@Override
public void apply()
{
TFCRegistries.ANVIL.register(recipe);
}

@Override
public String describe()
{
return "Adding anvil recipe for " + recipe.getOutputs().get(0).getDisplayName();
}
}

private static class Remove implements IAction
{
private final ResourceLocation location;

Remove(ResourceLocation location)
{
this.location = location;
}

@Override
public void apply()
{
IForgeRegistryModifiable modRegistry = (IForgeRegistryModifiable) TFCRegistries.ANVIL;
modRegistry.remove(location);
}

@Override
public String describe()
{
return "Removing anvil recipe " + location.toString();
}
}
}

0 comments on commit dab3756

Please sign in to comment.
You can’t perform that action at this time.