Recipes are now added to the recipe book when a tree tap is used.

This commit is contained in:
modmuss50 2017-06-15 11:35:08 +01:00
parent 5536a6cd94
commit aa615f86bd
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA
23 changed files with 124 additions and 36 deletions

View file

@ -51,7 +51,7 @@ import techreborn.compat.ICompatModule;
import techreborn.dispenser.BehaviorDispenseScrapbox;
import techreborn.entities.EntityNukePrimed;
import techreborn.events.BlockBreakHandler;
import techreborn.events.TREventHandler;
import techreborn.events.TRRecipeHandler;
import techreborn.events.TRTickHandler;
import techreborn.init.*;
import techreborn.lib.ModInfo;
@ -138,7 +138,7 @@ public class Core {
}
MinecraftForge.EVENT_BUS.register(new StackWIPHandler());
MinecraftForge.EVENT_BUS.register(new BlockBreakHandler());
MinecraftForge.EVENT_BUS.register(new TREventHandler());
MinecraftForge.EVENT_BUS.register(new TRRecipeHandler());
// Recipes
StopWatch watch = new StopWatch();

View file

@ -51,6 +51,7 @@ import reborncore.common.util.OreDrop;
import reborncore.common.util.OreDropSet;
import reborncore.common.util.StringUtils;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModBlocks;
import techreborn.items.ItemDusts;
import techreborn.items.ItemGems;
@ -82,6 +83,7 @@ public class BlockOre extends Block implements IOreNameProvider {
for (int i = 0; i < ores.length; i++) {
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i).setInvVariant("type=" + ores[i]).setFileName("ores"));
}
TRRecipeHandler.hideEntry(this);
}
public static ItemStack getOreByName(String name, int count) {

View file

@ -44,6 +44,7 @@ import reborncore.common.blocks.PropertyString;
import reborncore.common.util.ArrayUtils;
import reborncore.common.util.StringUtils;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModBlocks;
import techreborn.lib.ModInfo;
import techreborn.world.config.IOreNameProvider;
@ -66,6 +67,7 @@ public class BlockOre2 extends Block implements IOreNameProvider {
for (int i = 0; i < ores.length; i++) {
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i).setInvVariant("type=" + ores[i]).setFileName("ores"));
}
TRRecipeHandler.hideEntry(this);
}
public static ItemStack getOreByName(String name, int count) {

View file

@ -33,6 +33,7 @@ import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
@ -45,6 +46,7 @@ import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound;
import reborncore.common.powerSystem.PoweredItem;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModSounds;
import techreborn.items.ItemParts;
import techreborn.items.tools.ItemElectricTreetap;
@ -182,6 +184,9 @@ public class BlockRubberLog extends Block {
item.motionZ = rand.nextGaussian() * factor;
worldIn.spawnEntity(item);
}
if(playerIn instanceof EntityPlayerMP){
TRRecipeHandler.unlockTRRecipes((EntityPlayerMP) playerIn);
}
}
return true;
}

View file

@ -40,6 +40,7 @@ import reborncore.common.BaseBlock;
import reborncore.common.blocks.PropertyString;
import reborncore.common.util.ArrayUtils;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModBlocks;
import techreborn.lib.ModInfo;
@ -61,6 +62,7 @@ public class BlockStorage extends BaseBlock {
for (int i = 0; i < types.length; i++) {
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i).setInvVariant("type=" + types[i]).setFileName("storage"));
}
TRRecipeHandler.hideEntry(this);
}
public static ItemStack getStorageBlockByName(String name, int count) {

View file

@ -41,6 +41,7 @@ import reborncore.common.BaseBlock;
import reborncore.common.blocks.PropertyString;
import reborncore.common.util.ArrayUtils;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModBlocks;
import techreborn.lib.ModInfo;
@ -64,6 +65,7 @@ public class BlockStorage2 extends BaseBlock {
for (int i = 0; i < types.length; i++) {
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, i).setInvVariant("type=" + types[i]).setFileName("storage"));
}
TRRecipeHandler.hideEntry(this);
}
public static ItemStack getStorageBlockByName(String name, int count) {

View file

@ -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);
}
}
}
}

View 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;
}
}

View file

@ -49,6 +49,7 @@ import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack;
import org.apache.commons.lang3.Validate;
import techreborn.client.TechRebornCreativeTab;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModItems;
/**
@ -63,6 +64,7 @@ public class DynamicCell extends Item {
setCreativeTab(TechRebornCreativeTab.instance);
setUnlocalizedName("techreborn.cell");
setMaxStackSize(64);
TRRecipeHandler.hideEntry(this);
}
@Override

View file

@ -30,6 +30,7 @@ import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModItems;
import java.security.InvalidParameterException;
@ -48,6 +49,7 @@ public class ItemDusts extends ItemTR {
setUnlocalizedName("techreborn.dust");
setHasSubtypes(true);
setCreativeTab(TechRebornCreativeTabMisc.instance);
TRRecipeHandler.hideEntry(this);
}
public static ItemStack getDustByName(String name, int count) {

View file

@ -29,6 +29,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModItems;
import java.security.InvalidParameterException;
@ -48,6 +49,7 @@ public class ItemDustsSmall extends ItemTR {
setUnlocalizedName("techreborn.dustsmall");
setHasSubtypes(true);
setCreativeTab(TechRebornCreativeTabMisc.instance);
TRRecipeHandler.hideEntry(this);
}
public static ItemStack getSmallDustByName(String name, int count) {

View file

@ -29,6 +29,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModItems;
import java.security.InvalidParameterException;
@ -41,6 +42,7 @@ public class ItemGems extends ItemTR {
setCreativeTab(TechRebornCreativeTabMisc.instance);
setUnlocalizedName("techreborn.gem");
setHasSubtypes(true);
TRRecipeHandler.hideEntry(this);
}
public static ItemStack getGemByName(String name, int count) {

View file

@ -30,6 +30,7 @@ import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModItems;
import java.security.InvalidParameterException;
@ -44,6 +45,7 @@ public class ItemIngots extends ItemTR {
setCreativeTab(TechRebornCreativeTabMisc.instance);
setHasSubtypes(true);
setUnlocalizedName("techreborn.ingot");
TRRecipeHandler.hideEntry(this);
}
public static ItemStack getIngotByName(String name, int count) {

View file

@ -25,10 +25,12 @@
package techreborn.items;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
public class ItemMissingRecipe extends ItemTR {
public ItemMissingRecipe() {
setCreativeTab(TechRebornCreativeTabMisc.instance);
setUnlocalizedName("techreborn.missingrecipe");
TRRecipeHandler.hideEntry(this);
}
}
}

View file

@ -29,6 +29,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModItems;
import java.security.InvalidParameterException;
@ -44,6 +45,7 @@ public class ItemNuggets extends ItemTR {
setCreativeTab(TechRebornCreativeTabMisc.instance);
setHasSubtypes(true);
setUnlocalizedName("techreborn.nuggets");
TRRecipeHandler.hideEntry(this);
}
public static ItemStack getNuggetByName(String name, int count) {

View file

@ -30,6 +30,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.oredict.OreDictionary;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModItems;
import java.security.InvalidParameterException;
@ -45,6 +46,7 @@ public class ItemPlates extends ItemTR {
setUnlocalizedName("techreborn.plate");
setHasSubtypes(true);
setCreativeTab(TechRebornCreativeTabMisc.instance);
TRRecipeHandler.hideEntry(this);
}
public static ItemStack getPlateByName(String name, int count) {

View file

@ -27,6 +27,7 @@ package techreborn.items.armor;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
/**
* Created by modmuss50 on 26/02/2016.
@ -49,5 +50,6 @@ public class ItemTRArmour extends ItemArmor {
setCreativeTab(TechRebornCreativeTabMisc.instance);
this.material = material;
this.slot = slot;
TRRecipeHandler.hideEntry(this);
}
}

View file

@ -26,6 +26,7 @@ package techreborn.items.tools;
import net.minecraft.item.ItemAxe;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
public class ItemTRAxe extends ItemAxe {
private ToolMaterial material = ToolMaterial.WOOD;
@ -35,5 +36,6 @@ public class ItemTRAxe extends ItemAxe {
setUnlocalizedName(material.name().toLowerCase() + "Axe");
setCreativeTab(TechRebornCreativeTabMisc.instance);
this.material = material;
TRRecipeHandler.hideEntry(this);
}
}

View file

@ -28,6 +28,7 @@ import net.minecraft.item.ItemHoe;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
public class ItemTRHoe extends ItemHoe {
private ToolMaterial material = ToolMaterial.WOOD;
@ -37,6 +38,7 @@ public class ItemTRHoe extends ItemHoe {
setUnlocalizedName(material.name().toLowerCase() + "Hoe");
setCreativeTab(TechRebornCreativeTabMisc.instance);
this.material = material;
TRRecipeHandler.hideEntry(this);
}
@SideOnly(Side.CLIENT)

View file

@ -26,6 +26,7 @@ package techreborn.items.tools;
import net.minecraft.item.ItemPickaxe;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
public class ItemTRPickaxe extends ItemPickaxe {
private ToolMaterial material = ToolMaterial.WOOD;
@ -35,5 +36,6 @@ public class ItemTRPickaxe extends ItemPickaxe {
setUnlocalizedName(material.name().toLowerCase() + "Pickaxe");
setCreativeTab(TechRebornCreativeTabMisc.instance);
this.material = material;
TRRecipeHandler.hideEntry(this);
}
}

View file

@ -26,6 +26,7 @@ package techreborn.items.tools;
import net.minecraft.item.ItemSpade;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
public class ItemTRSpade extends ItemSpade {
private ToolMaterial material = ToolMaterial.WOOD;
@ -35,5 +36,6 @@ public class ItemTRSpade extends ItemSpade {
setUnlocalizedName(material.name().toLowerCase() + "Spade");
setCreativeTab(TechRebornCreativeTabMisc.instance);
this.material = material;
TRRecipeHandler.hideEntry(this);
}
}

View file

@ -26,6 +26,7 @@ package techreborn.items.tools;
import net.minecraft.item.ItemSword;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
public class ItemTRSword extends ItemSword {
private ToolMaterial material = ToolMaterial.WOOD;
@ -35,5 +36,6 @@ public class ItemTRSword extends ItemSword {
setUnlocalizedName(material.name().toLowerCase() + "Sword");
setCreativeTab(TechRebornCreativeTabMisc.instance);
this.material = material;
TRRecipeHandler.hideEntry(this);
}
}

View file

@ -28,6 +28,7 @@ import ic2.core.item.tool.ItemTreetap;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
@ -36,6 +37,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import techreborn.client.TechRebornCreativeTab;
import techreborn.compat.CompatManager;
import techreborn.events.TRRecipeHandler;
import techreborn.items.ItemTR;
public class ItemTreeTap extends ItemTR {
@ -53,8 +55,12 @@ public class ItemTreeTap extends ItemTR {
Block block = state.getBlock();
if (CompatManager.isIC2Loaded && block == Block.getBlockFromName("ic2:rubber_wood")) {
ItemTreetap.attemptExtract(playerIn, worldIn, pos, side, state, null);
if (!worldIn.isRemote)
if (!worldIn.isRemote){
playerIn.getHeldItem(hand).damageItem(1, playerIn);
}
if(playerIn instanceof EntityPlayerMP){
TRRecipeHandler.unlockTRRecipes((EntityPlayerMP) playerIn);
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;