@Override
 public void executeActivateBehavior(TileEntityTrophy tile, EntityPlayer player) {
   if (tile.worldObj.isRemote) {
     return;
   }
   double midX = tile.xCoord + 0.5;
   double midZ = tile.zCoord + 0.5;
   EntityArrow entityarrow = new EntityArrow(tile.worldObj, midX, tile.yCoord + 1, midZ);
   entityarrow.setDamage(0.1);
   entityarrow.setThrowableHeading(
       tile.worldObj.rand.nextInt(10) - 5, 40, tile.worldObj.rand.nextInt(10) - 5, 1.0f, 6.0f);
   player.playSound("random.bow", 1.0F, 1.0F / (tile.worldObj.rand.nextFloat() * 0.4F + 0.8F));
   tile.worldObj.spawnEntityInWorld(entityarrow);
 }
  @SubscribeEvent
  public void onInteract(PlayerInteractEvent.RightClickBlock event) {
    // does the player clicks on an echanting table with moss with 5 levels?
    if (ItemStack.areItemsEqual(event.getItemStack(), TinkerCommons.matMoss)) {
      if (event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.BOOKSHELF) {
        if (event.getEntityPlayer().experienceLevel >= ModMendingMoss.MENDING_MOSS_LEVELS) {
          // convert moss to mending moss
          EntityPlayer player = event.getEntityPlayer();
          player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f);

          if (!event.getWorld().isRemote) {
            event.getItemStack().stackSize--;
            player.removeExperienceLevel(ModMendingMoss.MENDING_MOSS_LEVELS);
            ItemHandlerHelper.giveItemToPlayer(player, TinkerCommons.matMendingMoss.copy());

            event.setUseBlock(Event.Result.DENY);
            event.setUseItem(Event.Result.DENY);
            event.setCanceled(true);
          }
        }
      }
    }
  }
Example #3
0
  @Override
  public void control(EntityPlayerCustom playerCustom, EntityPlayer player, Side side) {
    int x = MathHelper.floor_double(player.posX);
    int y = MathHelper.floor_double(player.posY);
    int z = MathHelper.floor_double(player.posZ);
    int heading = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
    if (!playerCustom.isSneaking) {
      if (((((Util.isCube(player.worldObj.getBlock(x, y, z - 1)) && heading == 2)
                  || (Util.isCube(player.worldObj.getBlock(x, y, z + 1)) && heading == 0)
                  || (Util.isCube(player.worldObj.getBlock(x - 1, y, z)) && heading == 1)
                  || (Util.isCube(player.worldObj.getBlock(x + 1, y, z)) && heading == 3))
              && ((!Util.isCube(player.worldObj.getBlock(x, y + 1, z - 1)) && heading == 2)
                  || (!Util.isCube(player.worldObj.getBlock(x, y + 1, z + 1)) && heading == 0)
                  || (!Util.isCube(player.worldObj.getBlock(x - 1, y + 1, z)) && heading == 1)
                  || (!Util.isCube(player.worldObj.getBlock(x + 1, y + 1, z)) && heading == 3))
              && (!Util.isCube(player.worldObj.getBlock(x, y - 2, z)))))
          && player.worldObj.getBlock(x, y, z) != Blocks.ladder
          && player.getCurrentEquippedItem() == null) {
        playerCustom.isGrabbing = true;
        playerCustom.rotationYaw = player.rotationYaw;
        playerCustom.rotationPitch = player.rotationPitch;
        playerCustom.prevRotationPitch = player.prevRotationPitch;
        playerCustom.prevRotationYaw = player.prevRotationYaw;
        playerCustom.grabbingDirections[heading] = true;
        if (heading == 0) {
          playerCustom.grabbingDirections[3] = true;
        } else {
          playerCustom.grabbingDirections[heading - 1] = true;
        }

        if (heading == 3) {
          playerCustom.grabbingDirections[0] = true;
        } else {
          playerCustom.grabbingDirections[heading + 1] = true;
        }
      } else {
        playerCustom.isGrabbing = false;
        playerCustom.rotationYaw = 0;
        if (!playerCustom.isRolling) {
          playerCustom.rotationPitch = 0;
        }
        playerCustom.prevRotationPitch = 0;
        playerCustom.prevRotationYaw = 0;
        playerCustom.grabbingDirections[0] = false;
        playerCustom.grabbingDirections[1] = false;
        playerCustom.grabbingDirections[2] = false;
        playerCustom.grabbingDirections[3] = false;
      }
      if (playerCustom.isGrabbing && !playerCustom.wasSneaking && player.isSneaking()) {
        playerCustom.wasSneaking = true;
      }
      if (!playerCustom.isGrabbing) {
        playerCustom.wasSneaking = false;
      }
      if (playerCustom.wasSneaking) {
        return;
      }
      if (!player.isSneaking()
          && !(Boolean)
              ObfuscationReflectionHelper.getPrivateValue(
                  EntityLivingBase.class, (EntityLivingBase) player, 41)
          && playerCustom.isGrabbing) {
        if (heading == 1 || heading == 3) {
          player.setPosition(x + 0.5F, y + 0.9F, player.posZ);
          player.motionX = 0;
        }
        if (heading == 2 || heading == 0) {
          player.setPosition(player.posX, y + 0.9F, z + 0.5F);
          player.motionZ = 0;
        }
        player.motionY = 0.0;
        if (player.isSprinting()) {
          player.setSprinting(false);
        }
      } else if ((Boolean)
              ObfuscationReflectionHelper.getPrivateValue(
                  EntityLivingBase.class, (EntityLivingBase) player, 41)
          && playerCustom.isGrabbing) {
        player.motionY = 0.55D;
      }
    }

    //		if(side == Side.CLIENT){
    ////			Util.channel.sendToServer(new CPacketPlayerAction(playerCustom.isGrabbing ? 0 : 1));
    //		}
    //
    //		if(side == Side.SERVER){
    //			System.out.println("1 : " + playerCustom.isGrabbing);
    //		}
    /*    CLIENT    */
    if (!player.worldObj.isRemote) {
      if (playerCustom.isGrabbing && !player.capabilities.isCreativeMode) {
        PotionEffect potioneffect = player.getActivePotionEffect(Potion.jump);
        float f1 = potioneffect != null ? (float) (potioneffect.getAmplifier() + 1) : 0.0F;
        int i = MathHelper.ceiling_float_int(player.fallDistance - 3.0F - f1);
        if (i > 0) {
          player.playSound(
              i > 4 ? "game.neutral.hurt.fall.big" : "game.neutral.hurt.fall.small", 1.0F, 1.0F);
          damageEntity(EntityLivingBase.class, player, DamageSource.fall, (float) i);
        }
        player.fallDistance = 0;
      }
    }
  }
  @SideOnly(Side.CLIENT)
  @Override
  public void handleClientSide(EntityPlayer player) {
    GCEntityClientPlayerMP playerBaseClient = null;

    if (player instanceof GCEntityClientPlayerMP) {
      playerBaseClient = (GCEntityClientPlayerMP) player;
    } else {
      return;
    }

    switch (this.type) {
      case C_AIR_REMAINING:
        if (String.valueOf(this.data.get(2))
            .equals(
                String.valueOf(
                    FMLClientHandler.instance()
                        .getClient()
                        .thePlayer
                        .getGameProfile()
                        .getName()))) {
          TickHandlerClient.airRemaining = (Integer) this.data.get(0);
          TickHandlerClient.airRemaining2 = (Integer) this.data.get(1);
        }
        break;
      case C_UPDATE_DIMENSION_LIST:
        if (String.valueOf(this.data.get(0))
            .equals(FMLClientHandler.instance().getClient().thePlayer.getGameProfile().getName())) {
          final String[] destinations = ((String) this.data.get(1)).split("\\.");

          if (FMLClientHandler.instance().getClient().theWorld != null
              && !(FMLClientHandler.instance().getClient().currentScreen
                      instanceof GuiCelestialSelection
                  || FMLClientHandler.instance().getClient().currentScreen
                      instanceof GuiGalaxyMap)) {
            FMLClientHandler.instance().getClient().displayGuiScreen(new GuiCelestialSelection());
          }
        }
        break;
      case C_SPAWN_SPARK_PARTICLES:
        int x, y, z;
        x = (Integer) this.data.get(0);
        y = (Integer) this.data.get(1);
        z = (Integer) this.data.get(2);
        Minecraft mc = Minecraft.getMinecraft();

        for (int i = 0; i < 4; i++) {
          if (mc != null
              && mc.renderViewEntity != null
              && mc.effectRenderer != null
              && mc.theWorld != null) {
            final EntityFX fx =
                new EntityFXSparks(
                    mc.theWorld,
                    x - 0.15 + 0.5,
                    y + 1.2,
                    z + 0.15 + 0.5,
                    mc.theWorld.rand.nextDouble() / 20 - mc.theWorld.rand.nextDouble() / 20,
                    mc.theWorld.rand.nextDouble() / 20 - mc.theWorld.rand.nextDouble() / 20);

            if (fx != null) {
              mc.effectRenderer.addEffect(fx);
            }
          }
        }
        break;
      case C_UPDATE_GEAR_SLOT:
        int subtype = (Integer) this.data.get(2);
        EntityPlayer gearDataPlayer = null;
        MinecraftServer server = MinecraftServer.getServer();

        if (server != null) {
          gearDataPlayer =
              server.getConfigurationManager().getPlayerForUsername((String) this.data.get(0));
        } else {
          gearDataPlayer = player.worldObj.getPlayerEntityByName((String) this.data.get(0));
        }

        if (gearDataPlayer != null) {
          PlayerGearData gearData =
              ClientProxyCore.playerItemData.get(gearDataPlayer.getPersistentID());

          if (gearData == null) {
            gearData = new PlayerGearData(player);
          }

          EnumModelPacket type = EnumModelPacket.values()[(Integer) this.data.get(1)];

          switch (type) {
            case ADDMASK:
              gearData.setMask(0);
              break;
            case REMOVEMASK:
              gearData.setMask(-1);
              break;
            case ADDGEAR:
              gearData.setGear(0);
              break;
            case REMOVEGEAR:
              gearData.setGear(-1);
              break;
            case ADDLEFTGREENTANK:
              gearData.setLeftTank(0);
              break;
            case ADDLEFTORANGETANK:
              gearData.setLeftTank(1);
              break;
            case ADDLEFTREDTANK:
              gearData.setLeftTank(2);
              break;
            case ADDRIGHTGREENTANK:
              gearData.setRightTank(0);
              break;
            case ADDRIGHTORANGETANK:
              gearData.setRightTank(1);
              break;
            case ADDRIGHTREDTANK:
              gearData.setRightTank(2);
              break;
            case REMOVE_LEFT_TANK:
              gearData.setLeftTank(-1);
              break;
            case REMOVE_RIGHT_TANK:
              gearData.setRightTank(-1);
              break;
            case ADD_PARACHUTE:
              String name = "";

              if (subtype != -1) {
                name = ItemParaChute.names[subtype];
                gearData.setParachute(
                    new ResourceLocation(
                        GalacticraftCore.ASSET_DOMAIN,
                        "textures/model/parachute/" + name + ".png"));
              }
              break;
            case REMOVE_PARACHUTE:
              gearData.setParachute(null);
              break;
            case ADD_FREQUENCY_MODULE:
              gearData.setFrequencyModule(0);
              break;
            case REMOVE_FREQUENCY_MODULE:
              gearData.setFrequencyModule(-1);
              break;
            case ADD_THERMAL_HELMET:
              gearData.setThermalPadding(0, 0);
              break;
            case ADD_THERMAL_CHESTPLATE:
              gearData.setThermalPadding(1, 0);
              break;
            case ADD_THERMAL_LEGGINGS:
              gearData.setThermalPadding(2, 0);
              break;
            case ADD_THERMAL_BOOTS:
              gearData.setThermalPadding(3, 0);
              break;
            case REMOVE_THERMAL_HELMET:
              gearData.setThermalPadding(0, -1);
              break;
            case REMOVE_THERMAL_CHESTPLATE:
              gearData.setThermalPadding(1, -1);
              break;
            case REMOVE_THERMAL_LEGGINGS:
              gearData.setThermalPadding(2, -1);
              break;
            case REMOVE_THERMAL_BOOTS:
              gearData.setThermalPadding(3, -1);
              break;
            default:
              break;
          }

          ClientProxyCore.playerItemData.put(playerBaseClient.getPersistentID(), gearData);
        }

        break;
      case C_CLOSE_GUI:
        FMLClientHandler.instance().getClient().displayGuiScreen(null);
        break;
      case C_RESET_THIRD_PERSON:
        FMLClientHandler.instance().getClient().gameSettings.thirdPersonView =
            playerBaseClient.getThirdPersonView();
        break;
      case C_UPDATE_SPACESTATION_LIST:
        try {
          if (WorldUtil.registeredSpaceStations != null) {
            for (Integer registeredID : WorldUtil.registeredSpaceStations) {
              DimensionManager.unregisterDimension(registeredID);
            }
          }
          WorldUtil.registeredSpaceStations = new ArrayList<Integer>();

          if (this.data.size() > 0) {
            if (this.data.get(0) instanceof Integer) {
              for (Object o : this.data) {
                Integer dimID = (Integer) o;

                if (!WorldUtil.registeredSpaceStations.contains(dimID)) {
                  WorldUtil.registeredSpaceStations.add(dimID);
                  if (!DimensionManager.isDimensionRegistered(dimID)) {
                    DimensionManager.registerDimension(
                        dimID, ConfigManagerCore.idDimensionOverworldOrbit);
                  } else {
                    GCLog.severe(
                        "Dimension already registered on client: unable to register space station dimension "
                            + dimID);
                  }
                }
              }
            } else if (this.data.get(0) instanceof Integer[]) {
              for (Object o : (Integer[]) this.data.get(0)) {
                Integer dimID = (Integer) o;

                if (!WorldUtil.registeredSpaceStations.contains(dimID)) {
                  WorldUtil.registeredSpaceStations.add(dimID);
                  if (!DimensionManager.isDimensionRegistered(dimID)) {
                    DimensionManager.registerDimension(
                        dimID, ConfigManagerCore.idDimensionOverworldOrbit);
                  } else {
                    GCLog.severe(
                        "Dimension already registered on client: unable to register space station dimension "
                            + dimID);
                  }
                }
              }
            }
          }
          break;
        } catch (final Exception e) {
          e.printStackTrace();
        }
      case C_UPDATE_SPACESTATION_DATA:
        SpaceStationWorldData var4 =
            SpaceStationWorldData.getMPSpaceStationData(
                player.worldObj, (Integer) this.data.get(0), player);
        var4.readFromNBT((NBTTagCompound) this.data.get(1));
        break;
      case C_UPDATE_SPACESTATION_CLIENT_ID:
        ClientProxyCore.clientSpaceStationID = (Integer) this.data.get(0);
        break;
      case C_UPDATE_PLANETS_LIST:
        try {
          if (WorldUtil.registeredPlanets != null) {
            for (Integer registeredID : WorldUtil.registeredPlanets) {
              DimensionManager.unregisterDimension(registeredID);
            }
          }
          WorldUtil.registeredPlanets = new ArrayList<Integer>();

          if (this.data.size() > 0) {
            if (this.data.get(0) instanceof Integer) {
              for (Object o : this.data) {
                Integer dimID = (Integer) o;

                if (!WorldUtil.registeredPlanets.contains(dimID)) {
                  WorldUtil.registeredPlanets.add(dimID);
                  DimensionManager.registerDimension(dimID, dimID);
                }
              }
            } else if (this.data.get(0) instanceof Integer[]) {
              for (Object o : (Integer[]) this.data.get(0)) {
                Integer dimID = (Integer) o;

                if (!WorldUtil.registeredPlanets.contains(dimID)) {
                  WorldUtil.registeredPlanets.add(dimID);
                  DimensionManager.registerDimension(dimID, dimID);
                }
              }
            }
          }
          break;
        } catch (final Exception e) {
          e.printStackTrace();
        }
      case C_ADD_NEW_SCHEMATIC:
        final ISchematicPage page =
            SchematicRegistry.getMatchingRecipeForID((Integer) this.data.get(0));
        if (!playerBaseClient.unlockedSchematics.contains(page)) {
          playerBaseClient.unlockedSchematics.add(page);
        }
        break;
      case C_UPDATE_SCHEMATIC_LIST:
        for (Object o : this.data) {
          Integer schematicID = (Integer) o;

          if (schematicID != -2) {
            Collections.sort(playerBaseClient.unlockedSchematics);

            if (!playerBaseClient.unlockedSchematics.contains(
                SchematicRegistry.getMatchingRecipeForID(Integer.valueOf(schematicID)))) {
              playerBaseClient.unlockedSchematics.add(
                  SchematicRegistry.getMatchingRecipeForID(Integer.valueOf(schematicID)));
            }
          }
        }
        break;
      case C_PLAY_SOUND_BOSS_DEATH:
        player.playSound(GalacticraftCore.ASSET_PREFIX + "entity.bossdeath", 10.0F, 0.8F);
        break;
      case C_PLAY_SOUND_EXPLODE:
        player.playSound("random.explode", 10.0F, 0.7F);
        break;
      case C_PLAY_SOUND_BOSS_LAUGH:
        player.playSound(GalacticraftCore.ASSET_PREFIX + "entity.bosslaugh", 10.0F, 0.2F);
        break;
      case C_PLAY_SOUND_BOW:
        player.playSound("random.bow", 10.0F, 0.2F);
        break;
      case C_UPDATE_OXYGEN_VALIDITY:
        playerBaseClient.oxygenSetupValid = (Boolean) this.data.get(0);
        break;
      case C_OPEN_PARACHEST_GUI:
        switch ((Integer) this.data.get(1)) {
          case 0:
            if (player.ridingEntity instanceof EntityBuggy) {
              FMLClientHandler.instance()
                  .getClient()
                  .displayGuiScreen(
                      new GuiBuggy(
                          player.inventory,
                          (EntityBuggy) player.ridingEntity,
                          ((EntityBuggy) player.ridingEntity).getType()));
              player.openContainer.windowId = (Integer) this.data.get(0);
            }
            break;
          case 1:
            int entityID = (Integer) this.data.get(2);
            Entity entity = player.worldObj.getEntityByID(entityID);

            if (entity != null && entity instanceof IInventorySettable) {
              FMLClientHandler.instance()
                  .getClient()
                  .displayGuiScreen(
                      new GuiParaChest(player.inventory, (IInventorySettable) entity));
            }

            player.openContainer.windowId = (Integer) this.data.get(0);
            break;
        }
        break;
      case C_UPDATE_WIRE_BOUNDS:
        TileEntity tile =
            player.worldObj.getTileEntity(
                (Integer) this.data.get(0), (Integer) this.data.get(1), (Integer) this.data.get(2));

        if (tile instanceof TileEntityConductor) {
          ((TileEntityConductor) tile).adjacentConnections = null;
          player
              .worldObj
              .getBlock(tile.xCoord, tile.yCoord, tile.zCoord)
              .setBlockBoundsBasedOnState(player.worldObj, tile.xCoord, tile.yCoord, tile.zCoord);
        }
        break;
      case C_OPEN_SPACE_RACE_GUI:
        if (Minecraft.getMinecraft().currentScreen == null) {
          TickHandlerClient.spaceRaceGuiScheduled = false;
          player.openGui(
              GalacticraftCore.instance,
              GuiIdsCore.SPACE_RACE_START,
              player.worldObj,
              (int) player.posX,
              (int) player.posY,
              (int) player.posZ);
        } else {
          TickHandlerClient.spaceRaceGuiScheduled = true;
        }
        break;
      case C_UPDATE_SPACE_RACE_DATA:
        Integer teamID = (Integer) this.data.get(0);
        String teamName = (String) this.data.get(1);
        FlagData flagData = (FlagData) this.data.get(2);
        Vector3 teamColor = (Vector3) this.data.get(3);
        List<String> playerList = new ArrayList<String>();

        for (int i = 4; i < this.data.size(); i++) {
          String playerName = (String) this.data.get(i);
          ClientProxyCore.flagRequestsSent.remove(playerName);
          playerList.add(playerName);
        }

        SpaceRace race = new SpaceRace(playerList, teamName, flagData, teamColor);
        race.setSpaceRaceID(teamID);
        SpaceRaceManager.addSpaceRace(race);
        break;
      case C_OPEN_JOIN_RACE_GUI:
        playerBaseClient.spaceRaceInviteTeamID = (Integer) this.data.get(0);
        player.openGui(
            GalacticraftCore.instance,
            GuiIdsCore.SPACE_RACE_JOIN,
            player.worldObj,
            (int) player.posX,
            (int) player.posY,
            (int) player.posZ);
        break;
      case C_UPDATE_FOOTPRINT_LIST:
        ClientProxyCore.footprintRenderer.footprints.clear();
        for (int i = 0; i < this.data.size(); i++) {
          Footprint print = (Footprint) this.data.get(i);
          ClientProxyCore.footprintRenderer.addFootprint(print);
        }
        break;
      case C_UPDATE_STATION_SPIN:
        if (playerBaseClient.worldObj.provider instanceof WorldProviderOrbit) {
          ((WorldProviderOrbit) playerBaseClient.worldObj.provider)
              .setSpinRate((Float) this.data.get(0), (Boolean) this.data.get(1));
        }
        break;
      case C_UPDATE_STATION_DATA:
        if (playerBaseClient.worldObj.provider instanceof WorldProviderOrbit) {
          ((WorldProviderOrbit) playerBaseClient.worldObj.provider)
              .setSpinCentre((Double) this.data.get(0), (Double) this.data.get(1));
        }
        break;
      case C_UPDATE_STATION_BOX:
        if (playerBaseClient.worldObj.provider instanceof WorldProviderOrbit) {
          ((WorldProviderOrbit) playerBaseClient.worldObj.provider)
              .setSpinBox(
                  (Integer) this.data.get(0),
                  (Integer) this.data.get(1),
                  (Integer) this.data.get(2),
                  (Integer) this.data.get(3),
                  (Integer) this.data.get(4),
                  (Integer) this.data.get(5));
        }
        break;
      case C_UPDATE_THERMAL_LEVEL:
        playerBaseClient.thermalLevel = (Integer) this.data.get(0);
        break;
      case C_DISPLAY_ROCKET_CONTROLS:
        player.addChatMessage(
            new ChatComponentText(
                Keyboard.getKeyName(KeyHandlerClient.spaceKey.getKeyCode())
                    + "  - "
                    + GCCoreUtil.translate("gui.rocket.launch.name")));
        player.addChatMessage(
            new ChatComponentText(
                Keyboard.getKeyName(KeyHandlerClient.leftKey.getKeyCode())
                    + " / "
                    + Keyboard.getKeyName(KeyHandlerClient.rightKey.getKeyCode())
                    + "  - "
                    + GCCoreUtil.translate("gui.rocket.turn.name")));
        player.addChatMessage(
            new ChatComponentText(
                Keyboard.getKeyName(KeyHandlerClient.accelerateKey.getKeyCode())
                    + " / "
                    + Keyboard.getKeyName(KeyHandlerClient.decelerateKey.getKeyCode())
                    + "  - "
                    + GCCoreUtil.translate("gui.rocket.updown.name")));
        player.addChatMessage(
            new ChatComponentText(
                Keyboard.getKeyName(KeyHandlerClient.openFuelGui.getKeyCode())
                    + "       - "
                    + GCCoreUtil.translate("gui.rocket.inv.name")));
        break;
      default:
        break;
    }
  }
 @Override
 public boolean interact(EntityPlayer player) {
   ItemStack itemstack = player.inventory.getCurrentItem();
   if (!this.worldObj.isRemote) {
     // Allow taming in creative mode without items
     if (!this.isTamed() && player.capabilities.isCreativeMode) {
       this.func_152115_b(player.getUniqueID().toString()); // Set owner UUID
       this.setTamed(true);
     }
     // If tamed
     if (this.isTamed()) {
       // If player has item
       if (itemstack != null) {
         // If armour, equip it
         if (itemstack.getItem() instanceof ItemArmor && !player.isSneaking()) {
           int i = EntityLiving.getArmorPosition(itemstack) - 1;
           if (this.getEquipmentInSlot(i + 1) == null) {
             this.setCurrentItemOrArmor(i + 1, itemstack.copy());
             if (!player.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
               player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
           } else {
             EntityItem entityItem =
                 new EntityItem(
                     this.worldObj,
                     this.posX,
                     this.posY,
                     this.posZ,
                     this.getEquipmentInSlot(i + 1));
             this.worldObj.spawnEntityInWorld(entityItem);
             this.setCurrentItemOrArmor(i + 1, null);
           }
           return true;
         }
         // If lead and mounted, unmount
         else if (itemstack.getItem() == Items.lead && this.isRiding() && !player.isSneaking())
           this.mountEntity(null);
         // If entity is holding something and player is holding a stick, drop current item
         else if (itemstack.getItem() == Items.stick && this.getHeldItem() != null) {
           EntityItem entityItem =
               new EntityItem(
                   player.worldObj, this.posX, this.posY, this.posZ, this.getHeldItem().copy());
           player.worldObj.spawnEntityInWorld(entityItem);
           this.setCarrying(null);
           // Drop chest contents
           for (int i = 0; i < inventory.getSizeInventory(); i++) {
             ItemStack itemStackToDrop = inventory.getStackInSlot(i);
             if (itemStackToDrop != null) {
               entityItem =
                   new EntityItem(
                       player.worldObj, this.posX, this.posY, this.posZ, itemStackToDrop);
               player.worldObj.spawnEntityInWorld(entityItem);
             }
             inventory.setInventorySlotContents(i, null);
           }
         } else if (this.getHeldItem() == null) {
           ItemStack newItemStack = itemstack.copy();
           newItemStack.stackSize = 1;
           this.setCarrying(newItemStack);
           player.playSound(
               "mob.chickenplop",
               1.0F,
               (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
           if (!player.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
             player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
         }
       }
       // If entity is holding something and player isn't, open GUI
       if (this.getHeldItem() != null && !player.isSneaking()) {
         if (Block.getBlockFromItem(this.getHeldItem().getItem()) == Blocks.chest)
           player.openGui(MiniCreatures.instance, 0, player.worldObj, this.getEntityId(), 0, 0);
         else if (Block.getBlockFromItem(this.getHeldItem().getItem()) == Blocks.anvil)
           player.openGui(
               MiniCreatures.instance,
               1,
               player.worldObj,
               (int) this.posX,
               (int) this.posY,
               (int) this.posZ);
       } else if (player.isEntityEqual(this.getOwner()) && !this.worldObj.isRemote) {
         if (this.isRiding()) {
           EntityTameable ridingEntity = (EntityTameable) this.ridingEntity;
           ridingEntity.func_70907_r().setSitting(!ridingEntity.isSitting());
           ridingEntity.setSitting(!ridingEntity.isSitting());
           ridingEntity.setJumping(false);
           ridingEntity.setPathToEntity(null);
           ridingEntity.setTarget(null);
           ridingEntity.setAttackTarget(null);
         } else {
           this.aiSit.setSitting(!this.isSitting());
           this.setSitting(!this.isSitting());
           this.isJumping = false;
           this.setPathToEntity(null);
           this.setTarget(null);
           this.setAttackTarget(null);
         }
       }
     }
   }
   return super.interact(player);
 }
  protected ItemStack doTrade(final Slot slot, final EntityPlayer player) {

    final ItemStack[] entityInventory = entity.getRawInventory();
    final ItemStack[] playerInventory = player.inventory.mainInventory;

    // Get the result of the potential trade. If there is nothing,
    // or the player inventory cannot hold the stack then return null.
    final ItemStack result = slot.getStack();
    if (result == null
        || !InventoryHelper.canInventoryAccept(
            playerInventory, 0, playerInventory.length - 1, result, null)) return null;

    final boolean normalMode = !entity.isAdminMode();

    // Can the inventory provide the result item?
    if (normalMode
        && !InventoryHelper.doesInventoryContain(
            entityInventory,
            VendingTileEntity.INVENTORY_SLOT_START,
            VendingTileEntity.GENERAL_INVENTORY_SIZE - 1,
            result,
            null)) return null;

    // Get the input slots. We do some math on the slot index to
    // figure out the right input slots.
    final int index = slot.slotNumber / 3 + VendingTileEntity.CONFIG_SLOT_START;
    final ItemStack input1 = entity.getStackInSlot(index);
    final ItemStack input2 = entity.getStackInSlot(index + 6);

    // See if the vending inventory can accept the required items
    if (normalMode
        && !InventoryHelper.canInventoryAccept(
            entityInventory,
            VendingTileEntity.INVENTORY_SLOT_START,
            VendingTileEntity.GENERAL_INVENTORY_SIZE - 1,
            input1,
            input2)) return null;

    // See if the player can provide the payment
    if (!InventoryHelper.doesInventoryContain(
        playerInventory, 0, playerInventory.length - 1, input1, input2)) return null;

    // OK - things should work. Do the transaction.
    if (input1 != null) {
      if (!entity.isAdminMode()) {
        entity.addStackToOutput(input1.copy());
      }
      InventoryHelper.removeItemStackFromInventory(
          playerInventory, input1.copy(), 0, playerInventory.length - 1);
    }
    if (input2 != null) {
      if (!entity.isAdminMode()) {
        entity.addStackToOutput(input2.copy());
      }
      InventoryHelper.removeItemStackFromInventory(
          playerInventory, input2.copy(), 0, playerInventory.length - 1);
    }

    if (!entity.isAdminMode()) {
      entity.removeStackFromOutput(result.copy());
    }

    player.inventory.addItemStackToInventory(result.copy());

    // play a tink sound to signal the trade
    if (player.worldObj.isRemote) player.playSound("random.orb", 0.5F, 5F);
    player.onUpdate();

    return null;
  }