mrkirby153

Untitled

Jan 9th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 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.world.World;
  10. import net.minecraftforge.oredict.ShapedOreRecipe;
  11.  
  12. import java.lang.reflect.Field;
  13.  
  14. public class CustomOreRecipie extends ShapedOreRecipe {
  15. public CustomOreRecipie(ItemStack result, Object... recipe) {
  16. super(result, recipe);
  17. }
  18.  
  19. @Override
  20. public boolean matches(InventoryCrafting inv, World world) {
  21. // Check the player first
  22. /* EntityPlayer player = findPlayer(inv);
  23. if(RecipieHandler.isDisabled(output.getItem(), player)){
  24. return false;
  25. }
  26. return super.matches(inv, world);*/
  27. return false;
  28. }
  29.  
  30. @Override
  31. public ItemStack getCraftingResult(InventoryCrafting inv) {
  32. return super.getCraftingResult(inv);
  33. }
  34.  
  35. @Override
  36. public int getRecipeSize() {
  37. return super.getRecipeSize();
  38. }
  39.  
  40. @Override
  41. public ItemStack getRecipeOutput() {
  42. return super.getRecipeOutput();
  43. }
  44.  
  45. // TODO: SRG names for non-dev env
  46. private static final String eventHandlerFieldName = (KCNerfer.isDev) ? "eventHandler" : "field_70465_c";
  47. private static final String containerThePlayerName = (KCNerfer.isDev) ? "thePlayer" : "field_82862_h";
  48. private static final String slotCraftingThePlayerName = (KCNerfer.isDev) ? "thePlayer" : "field_75238_b";
  49. private static final Field eventHandlerField = ReflectionHelper.findField(InventoryCrafting.class, eventHandlerFieldName);
  50. private static final Field containerPlayerPlayerField = ReflectionHelper.findField(ContainerPlayer.class, containerThePlayerName);
  51. private static final Field slotCraftingPlayerField = ReflectionHelper.findField(SlotCrafting.class, slotCraftingThePlayerName);
  52.  
  53. private static EntityPlayer findPlayer(InventoryCrafting inv) {
  54. try {
  55. Container container = (Container) eventHandlerField.get(inv);
  56. if (container instanceof ContainerPlayer) {
  57. return (EntityPlayer) containerPlayerPlayerField.get(container);
  58. } else if (container instanceof ContainerWorkbench) {
  59. return (EntityPlayer) slotCraftingPlayerField.get(container.getSlot(0));
  60. } else {
  61. // don't know the player
  62. return null;
  63. }
  64. } catch (Exception e) {
  65. throw Throwables.propagate(e);
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment