Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PlayerSpecificCrafting;
- import java.lang.reflect.Field;
- import net.minecraft.block.Block;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Items;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.ContainerPlayer;
- import net.minecraft.inventory.ContainerWorkbench;
- import net.minecraft.inventory.InventoryCrafting;
- import net.minecraft.inventory.SlotCrafting;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.crafting.IRecipe;
- import net.minecraft.world.World;
- import palmerjj01.YoshiCraft.Main.YoshiCraft;
- import com.google.common.base.Throwables;
- import cpw.mods.fml.relauncher.ReflectionHelper;
- public class SpecificPlayerRecipe implements IRecipe {
- @Override
- public boolean matches(InventoryCrafting inv, World world) {
- EntityPlayer player = findPlayer(inv);
- if(player != null && (player.getCommandSenderName().matches("palmerjj01") || player.getCommandSenderName().matches("Baked_Potato132"))
- && inventoryContainsItem(inv, YoshiCraft.itemStick)){
- return true;
- }else{
- return false;
- }
- }
- /**
- * What the output of the recipe should be.
- */
- @Override
- public ItemStack getCraftingResult(InventoryCrafting inv) {
- return new ItemStack(YoshiCraft.kingYoshiStaff);
- }
- @Override
- public int getRecipeSize() {
- return 1;
- }
- /**
- * What the output of the recipe should be.
- */
- @Override
- public ItemStack getRecipeOutput() {
- return new ItemStack(YoshiCraft.kingYoshiStaff);
- }
- private boolean inventoryContainsItem(InventoryCrafting inv, Item item){
- for(int i = 0; i < inv.getSizeInventory(); i++){
- ItemStack stack = inv.getStackInSlot(i);
- if(stack != null && stack.getItem() == item){
- return true;
- }
- }
- return false;
- }
- private boolean inventoryContainsItem(InventoryCrafting inv, Block block){
- Item block2 = Item.getItemFromBlock(block);
- for(int i = 0; i < inv.getSizeInventory(); i++){
- ItemStack stack = inv.getStackInSlot(i);
- if(stack != null && stack.getItem() == block2){
- return true;
- }
- }
- return false;
- }
- private static final Field eventHandlerField = ReflectionHelper.findField(InventoryCrafting.class, "eventHandler");
- private static final Field containerPlayerPlayerField = ReflectionHelper.findField(ContainerPlayer.class, "thePlayer");
- private static final Field slotCraftingPlayerField = ReflectionHelper.findField(SlotCrafting.class, "thePlayer");
- private static EntityPlayer findPlayer(InventoryCrafting inv) {
- try{
- Container container = (Container) eventHandlerField.get(inv);
- if(container instanceof ContainerPlayer){
- return (EntityPlayer) containerPlayerPlayerField.get(container);
- }else if(container instanceof ContainerWorkbench){
- return(EntityPlayer) slotCraftingPlayerField.get(container.getSlot(0));
- }else{
- return null;
- }
- }catch(Exception e){
- throw Throwables.propagate(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement