mrkirby153

Untitled

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