mrkirby153

Untitled

Jan 9th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 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 me.mrkirby153.KCNerfer.recipie.RecipieHandler;
  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(RecipieHandler.isDisabled(output.getItem(), player)){
  34. return false;
  35. }
  36. return super.matches(inv, world);
  37. }
  38.  
  39. @Override
  40. public ItemStack getCraftingResult(InventoryCrafting inv) {
  41. return super.getCraftingResult(inv);
  42. }
  43.  
  44. @Override
  45. public int getRecipeSize() {
  46. return super.getRecipeSize();
  47. }
  48.  
  49. @Override
  50. public ItemStack getRecipeOutput() {
  51. return super.getRecipeOutput();
  52. }
  53.  
  54. // TODO: SRG names for non-dev env
  55. private static final String eventHandlerFieldName = (KCNerfer.isDev) ? "eventHandler" : "field_70465_c";
  56. private static final String containerThePlayerName = (KCNerfer.isDev) ? "thePlayer" : "field_82862_h";
  57. private static final String slotCraftingThePlayerName = (KCNerfer.isDev) ? "thePlayer" : "field_75238_b";
  58. private static final Field eventHandlerField = ReflectionHelper.findField(InventoryCrafting.class, eventHandlerFieldName);
  59. private static final Field containerPlayerPlayerField = ReflectionHelper.findField(ContainerPlayer.class, containerThePlayerName);
  60. private static final Field slotCraftingPlayerField = ReflectionHelper.findField(SlotCrafting.class, slotCraftingThePlayerName);
  61.  
  62. private static EntityPlayer findPlayer(InventoryCrafting inv) {
  63. try {
  64. Container container = (Container) eventHandlerField.get(inv);
  65. if (container instanceof ContainerPlayer) {
  66. return (EntityPlayer) containerPlayerPlayerField.get(container);
  67. } else if (container instanceof ContainerWorkbench) {
  68. return (EntityPlayer) slotCraftingPlayerField.get(container.getSlot(0));
  69. } else {
  70. // don't know the player
  71. return null;
  72. }
  73. } catch (Exception e) {
  74. throw Throwables.propagate(e);
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment