Skip to content

Commit

Permalink
add entity interaction to IInteractionItem (#169)
Browse files Browse the repository at this point in the history
* add entity interaction to IInteractionItem

* add ability for addons to register their own recipes through our system
  • Loading branch information
screret authored Jul 15, 2023
1 parent 4c58273 commit 5839a07
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.gregtechceu.gtceu.api.addon;

import com.gregtechceu.gtceu.api.addon.events.MaterialCasingCollectionEvent;
import net.minecraft.data.recipes.FinishedRecipe;

import java.util.function.Consumer;

public interface IGTAddon {

Expand Down Expand Up @@ -42,6 +45,10 @@ default void registerVeinGenerators() {

}

default void initializeRecipes(Consumer<FinishedRecipe> provider) {

}

default void collectMaterialCasings(MaterialCasingCollectionEvent event) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ public InteractionResult onItemUseFirst(ItemStack itemStack, UseOnContext contex
return InteractionResult.PASS;
}

@Override
public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand) {
for (IItemComponent component : components) {
if (component instanceof IInteractionItem interactionItem) {
var result = interactionItem.interactLivingEntity(stack, player, interactionTarget, usedHand);
if (result != InteractionResult.PASS) {
return result;
}
}
}
return InteractionResult.PASS;
}

@Override
public String getDescriptionId(ItemStack stack) {
for (IItemComponent component : components) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ default ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity liv
default InteractionResult onItemUseFirst(ItemStack itemStack, UseOnContext context) {
return InteractionResult.PASS;
}

default InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand) {
return InteractionResult.PASS;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gregtechceu.gtceu.common.data;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.addon.AddonFinder;
import com.gregtechceu.gtceu.data.recipe.MaterialInfoLoader;
import com.gregtechceu.gtceu.data.recipe.configurable.RecipeAddition;
import com.gregtechceu.gtceu.data.recipe.configurable.RecipeRemoval;
Expand Down Expand Up @@ -65,6 +66,8 @@ public static void recipeAddition(Consumer<FinishedRecipe> consumer) {
if (GTCEu.isCreateLoaded()) {
CreateRecipeLoader.init(consumer);
}

AddonFinder.getAddons().forEach(addon -> addon.initializeRecipes(consumer));
}

/*
Expand Down

0 comments on commit 5839a07

Please sign in to comment.