mrkirby153

Untitled

Jan 10th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. package me.mrkirby153.KCNerfer.recipie;
  2.  
  3. import com.google.common.base.Throwables;
  4. import cpw.mods.fml.relauncher.ReflectionHelper;
  5. import me.mrkirby153.KCNerfer.KCNerfer;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.inventory.*;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.item.crafting.ShapedRecipes;
  10. import net.minecraft.world.World;
  11.  
  12. import java.lang.reflect.Field;
  13.  
  14. public class CustomShapedRecipie extends ShapedRecipes {
  15.  
  16. // private IRecipe recipe;
  17. private ItemStack output;
  18.  
  19. public CustomShapedRecipie(int width, int height, ItemStack[] items, ItemStack output) {
  20. super(width, height, items, output);
  21. this.output = output;
  22. }
  23.  
  24.  
  25. /* public CustomRecipie(IRecipe recipie) {
  26. this.recipe = recipie;
  27. }*/
  28.  
  29. @Override
  30. public boolean matches(InventoryCrafting inv, World world) {
  31. // Check the player first
  32. EntityPlayer player = findPlayer(inv);
  33. if(player == null)
  34. return super.matches(inv, world);
  35. if(RecipieHandler.isDisabled(output.getItem(), player)){
  36. return false;
  37. }
  38. return super.matches(inv, world);
  39. }
  40.  
  41. @Override
  42. public ItemStack getCraftingResult(InventoryCrafting inv) {
  43. return super.getCraftingResult(inv);
  44. }
  45.  
  46. @Override
  47. public int getRecipeSize() {
  48. return super.getRecipeSize();
  49. }
  50.  
  51. @Override
  52. public ItemStack getRecipeOutput() {
  53. return super.getRecipeOutput();
  54. }
  55.  
  56. // TODO: SRG names for non-dev env
  57. private static final String eventHandlerFieldName = (KCNerfer.isDev) ? "eventHandler" : "field_70465_c";
  58. private static final String containerThePlayerName = (KCNerfer.isDev) ? "thePlayer" : "field_82862_h";
  59. private static final String slotCraftingThePlayerName = (KCNerfer.isDev) ? "thePlayer" : "field_75238_b";
  60. private static final Field eventHandlerField = ReflectionHelper.findField(InventoryCrafting.class, eventHandlerFieldName);
  61. private static final Field containerPlayerPlayerField = ReflectionHelper.findField(ContainerPlayer.class, containerThePlayerName);
  62. private static final Field slotCraftingPlayerField = ReflectionHelper.findField(SlotCrafting.class, slotCraftingThePlayerName);
  63.  
  64. private static EntityPlayer findPlayer(InventoryCrafting inv) {
  65. try {
  66. Container container = (Container) eventHandlerField.get(inv);
  67. if (container instanceof ContainerPlayer) {
  68. return (EntityPlayer) containerPlayerPlayerField.get(container);
  69. } else if (container instanceof ContainerWorkbench) {
  70. return (EntityPlayer) slotCraftingPlayerField.get(container.getSlot(0));
  71. } else {
  72. // don't know the player
  73. return null;
  74. }
  75. } catch (Exception e) {
  76. throw Throwables.propagate(e);
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment