Recipes are now added to the recipe book when a tree tap is used.
This commit is contained in:
parent
5536a6cd94
commit
aa615f86bd
23 changed files with 124 additions and 36 deletions
src/main/java/techreborn/events
|
@ -1,32 +0,0 @@
|
|||
package techreborn.events;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TREventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void pickupEvent(EntityItemPickupEvent entityItemPickupEvent){
|
||||
if(entityItemPickupEvent.getEntityPlayer() instanceof EntityPlayerMP){
|
||||
if(entityItemPickupEvent.getItem().getItem().getItem().getRegistryName().getResourceDomain().equals(ModInfo.MOD_ID)){
|
||||
List<IRecipe> recipeList = new ArrayList<>();
|
||||
for(IRecipe recipe : CraftingManager.REGISTRY){
|
||||
if(recipe.getRegistryName() != null && recipe.getRegistryName().getResourceDomain().equals(ModInfo.MOD_ID)){
|
||||
if(recipe.getRecipeOutput().getItem().getRegistryName().getResourceDomain().equals(ModInfo.MOD_ID)){
|
||||
recipeList.add(recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
entityItemPickupEvent.getEntityPlayer().unlockRecipes(recipeList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
73
src/main/java/techreborn/events/TRRecipeHandler.java
Normal file
73
src/main/java/techreborn/events/TRRecipeHandler.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
package techreborn.events;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.init.ModItems;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TRRecipeHandler {
|
||||
|
||||
private static List<IForgeRegistryEntry> hiddenEntrys = new ArrayList<>();
|
||||
|
||||
public static void hideEntry(IForgeRegistryEntry entry){
|
||||
hiddenEntrys.add(entry);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void pickupEvent(EntityItemPickupEvent entityItemPickupEvent){
|
||||
if(entityItemPickupEvent.getEntityPlayer() instanceof EntityPlayerMP){
|
||||
if(ItemUtils.isInputEqual("logWood", entityItemPickupEvent.getItem().getItem(), false, false, true)){
|
||||
for(IRecipe recipe : CraftingManager.REGISTRY){
|
||||
if(recipe.getRecipeOutput().getItem() == ModItems.TREE_TAP){
|
||||
entityItemPickupEvent.getEntityPlayer().unlockRecipes(Collections.singletonList(recipe));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void unlockTRRecipes(EntityPlayerMP playerMP){
|
||||
List<IRecipe> recipeList = new ArrayList<>();
|
||||
for(IRecipe recipe : CraftingManager.REGISTRY){
|
||||
if(isRecipeValid(recipe)){
|
||||
recipeList.add(recipe);
|
||||
}
|
||||
}
|
||||
playerMP.unlockRecipes(recipeList);
|
||||
}
|
||||
|
||||
private static boolean isRecipeValid(IRecipe recipe){
|
||||
if(recipe.getRegistryName() == null){
|
||||
return false;
|
||||
}
|
||||
if(!recipe.getRegistryName().getResourceDomain().equals(ModInfo.MOD_ID)){
|
||||
return false;
|
||||
}
|
||||
if(!recipe.getRecipeOutput().getItem().getRegistryName().getResourceDomain().equals(ModInfo.MOD_ID)){
|
||||
return false;
|
||||
}
|
||||
if(hiddenEntrys.contains(recipe.getRecipeOutput().getItem())){
|
||||
return false;
|
||||
}
|
||||
//Hide uu recipes
|
||||
for(Ingredient ingredient : recipe.getIngredients()){
|
||||
if(ingredient.apply(new ItemStack(ModItems.UU_MATTER))){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue