mrkirby153

Untitled

Jan 9th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 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.ShapedRecipes;
  9. import net.minecraft.world.World;
  10.  
  11. import java.lang.reflect.Field;
  12.  
  13. public class CustomShapedRecipie extends ShapedRecipes {
  14.  
  15. // private IRecipe recipe;
  16. private ItemStack output;
  17.  
  18. public CustomShapedRecipie(int width, int height, ItemStack[] items, ItemStack output) {
  19. super(width, height, items, output);
  20. this.output = output;
  21. }
  22.  
  23.  
  24. /* public CustomRecipie(IRecipe recipie) {
  25. this.recipe = recipie;
  26. }*/
  27.  
  28. @Override
  29. public boolean matches(InventoryCrafting inv, World world) {
  30. // Check the player first
  31. /* EntityPlayer player = findPlayer(inv);
  32. if(RecipieHandler.isDisabled(output.getItem(), player)){
  33. return false;
  34. }
  35. return super.matches(inv, world);*/
  36. return false;
  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