Advertisement
Fej

FejRecipeShaped

Fej
Apr 21st, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. package com.fejcraft.FejCraftRPG.FejRecipeTypes;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.inventory.ContainerPlayer;
  5. import net.minecraft.inventory.ContainerWorkbench;
  6. import net.minecraft.inventory.InventoryCrafting;
  7. import net.minecraft.inventory.SlotCrafting;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.item.crafting.IRecipe;
  10. import net.minecraft.world.World;
  11.  
  12. public class FejRecipeShaped extends net.minecraft.item.crafting.ShapedRecipes {
  13.  
  14. public int levelRequired;
  15.  
  16. public FejRecipeShaped(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack, int levelRequired) {
  17. super(par1, par2, par3ArrayOfItemStack, par4ItemStack);
  18. this.levelRequired = levelRequired;
  19. }
  20.  
  21. @Override
  22. public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
  23. {
  24. System.out.println("Trying to match crafting inventory.");
  25. if(super.matches(par1InventoryCrafting, par2World) && getPlayerFromInventory(par1InventoryCrafting).experienceLevel >= levelRequired) {
  26. return true;
  27. }
  28. else {
  29. return false;
  30. }
  31. }
  32.  
  33. private static EntityPlayer getPlayerFromInventory(InventoryCrafting inventory)
  34. {
  35. if(inventory.eventHandler instanceof ContainerPlayer) {
  36. return ((ContainerPlayer)inventory.eventHandler).thePlayer;
  37. }
  38. else if(inventory.eventHandler instanceof ContainerWorkbench) {
  39. if(((ContainerWorkbench)inventory.eventHandler).getSlot(0) instanceof SlotCrafting) {
  40. return ((SlotCrafting)((ContainerWorkbench)inventory.eventHandler).getSlot(0)).thePlayer;
  41. }
  42. else {
  43. System.err.println("[FejCraftRPG] Was not able to get player from inventory (Slot not SlotCrafting)!");
  44. return null;
  45. }
  46. }
  47. else {
  48. System.err.println("[FejCraftRPG] Was not able to get player from inventory!");
  49. return null;
  50. }
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement